Пример #1
0
        private void DrawBars(IBin[] bins, CanvasDrawingSession session, CanvasControl canvas)
        {
            if (bins.Length == 0)
            {
                return;
            }

            double[] binValues = bins.Select(b => b.Value).ToArray();
            double[] secondaryValues = null;
            if (ShowSecondary)
            {
                secondaryValues = bins.Select(b => b.SecondaryValue).ToArray();
            }

            if (!DrawPrimaryFirst && ShowSecondary)
            {
                double[] temp = binValues;
                binValues = secondaryValues;
                secondaryValues = temp;
            }

            double maxBarHeight = canvas.ActualHeight - (BarPadding.Top + BarPadding.Bottom) - LabelSize.Height;
            int binCount = binValues.Length;
            double barWidth = canvas.ActualWidth / binCount;

            double maxValue = MaxValue;
            if (maxValue == 0)
            {
                maxValue = binValues.Max();
                if (secondaryValues != null)
                {
                    maxValue = Math.Max(maxValue, secondaryValues.Max());
                }
            }

	        double minValue = MinValue;
	        if (minValue > 0)
	        {
		        maxValue = Math.Max(minValue, maxValue);
	        }
	        double valueFactor = Math.Max(maxBarHeight / maxValue, 0);


            Color barColor = BarColor;
            Color secondaryBarColor = SecondaryBarColor;
	        Color highlightColor = HighlightBarColor;

			for (int barIndex = 0; barIndex < binValues.Length; barIndex++)
            {
                double value = binValues[barIndex];
                double left = barIndex * barWidth;

                Rect r = new Rect();
                r.X = left + BarPadding.Left;
                r.Width = Math.Max(barWidth - (BarPadding.Left + BarPadding.Right), 0.1);

                if (secondaryValues != null)
                {
                    double secondaryValue = secondaryValues[barIndex];
                    r.Height = secondaryValue * valueFactor;
                    r.Y = maxBarHeight + BarPadding.Top - r.Height;
                    session.FillRectangle(r, secondaryBarColor);
                }

                r.Height = value * valueFactor;
                r.Y = maxBarHeight + BarPadding.Top - r.Height;
	            if (bins[barIndex].IsHighlighted)
	            {
		            session.FillRectangle(r, highlightColor);
	            }
	            else
	            {
		            session.FillRectangle(r, barColor);
	            }
            }
        }