Пример #1
0
        /// <summary>
        /// Draws a All Stacked column under a XValue with a particular dtrawingIndex
        /// </summary>
        /// <param name="xValue">XValue</param>
        /// <param name="plotGroup">PlotGroup reference</param>
        /// <param name="columnCanvas">Parent canvas of StackedColumn visuals</param>
        /// <param name="labelCanvas">Parent canvas of StackedColumn labels</param>
        /// <param name="drawingIndex">Drawing index of the DataSeries</param>
        /// <param name="widthPerColumn">Width par each column</param>
        /// <param name="maxColumnWidth">Max width of a Column</param>
        /// <param name="limitingYValue">Limiting value</param>
        /// <param name="depth3d">3d depth for 3d charts</param>
        /// <param name="animationEnabled">Whether animation for chart is enabled</param>
        private static void DrawStackedColumnsAtXValue(RenderAs chartType, Double xValue, PlotGroup plotGroup, Canvas columnCanvas, Canvas labelCanvas, Double drawingIndex, Double widthPerColumn, Double maxColumnWidth, Double limitingYValue, Double depth3d, Boolean animationEnabled)
        {
            Double    top;
            Double    prevSum = 0;
            Int32     positiveIndex = 1, negativeIndex = 1;
            Boolean   isTopOFStack;
            DataPoint dataPointAtTopOfStack = null;
            Double    columnHeight          = 0;
            Double    absoluteSum           = 0;
            Double    left   = Graphics.ValueToPixelPosition(0, columnCanvas.Width, (Double)plotGroup.AxisX.InternalAxisMinimum, (Double)plotGroup.AxisX.InternalAxisMaximum, xValue) + drawingIndex * widthPerColumn - (maxColumnWidth / 2);
            Double    bottom = Graphics.ValueToPixelPosition(columnCanvas.Height, 0, (Double)plotGroup.AxisY.InternalAxisMinimum, (Double)plotGroup.AxisY.InternalAxisMaximum, limitingYValue);

            if (plotGroup.XWiseStackedDataList[xValue].Positive.Count > 0)
            {
                dataPointAtTopOfStack = plotGroup.XWiseStackedDataList[xValue].Positive.Last();
            }

            if (chartType == RenderAs.StackedColumn100)
            {
                absoluteSum = plotGroup.XWiseStackedDataList[xValue].AbsoluteYValueSum;
            }

            Double animationBeginTime = 0.4;
            Double animationTime      = 1.0 / plotGroup.XWiseStackedDataList[xValue].Positive.Count;

            // Plot positive values
            foreach (DataPoint dataPoint in plotGroup.XWiseStackedDataList[xValue].Positive)
            {
                dataPoint.Parent.Faces = new Faces()
                {
                    Visual = columnCanvas, LabelCanvas = labelCanvas
                };

                if (!(Boolean)dataPoint.Enabled || Double.IsNaN(dataPoint.InternalYValue))
                {
                    continue;
                }

                isTopOFStack = (dataPoint == dataPointAtTopOfStack);

                if (chartType == RenderAs.StackedColumn)
                {
                    top          = Graphics.ValueToPixelPosition(columnCanvas.Height, 0, (Double)plotGroup.AxisY.InternalAxisMinimum, (Double)plotGroup.AxisY.InternalAxisMaximum, dataPoint.InternalYValue + prevSum);
                    prevSum     += dataPoint.InternalYValue;
                    columnHeight = Math.Abs(top - bottom);
                }
                else // if (chartType == RenderAs.StackedColumn100)
                {
                    Double percentYValue = 0;

                    if (absoluteSum != 0)
                    {
                        percentYValue = (dataPoint.InternalYValue / absoluteSum * 100);
                    }

                    top          = Graphics.ValueToPixelPosition(columnCanvas.Height, 0, (Double)plotGroup.AxisY.InternalAxisMinimum, (Double)plotGroup.AxisY.InternalAxisMaximum, percentYValue + prevSum);
                    columnHeight = Math.Abs(top - bottom);
                    prevSum     += percentYValue;
                }

                if (chartType == RenderAs.StackedColumn || chartType == RenderAs.StackedColumn100)
                {
                    CreateStackedColumnVisual(true, columnCanvas, labelCanvas, dataPoint,
                                              isTopOFStack, left, ref top, ref bottom, widthPerColumn, columnHeight, depth3d,
                                              ref positiveIndex, animationEnabled, animationBeginTime);
                }
                else if (chartType == RenderAs.StackedColumn || chartType == RenderAs.StackedColumn100)
                {
                    BarChart.CreateBarDataPointVisual(dataPoint, labelCanvas, columnCanvas, dataPoint.InternalYValue >= 0, widthPerColumn, depth3d, false);
                }

                animationBeginTime += animationTime;
                positiveIndex++;
            }

            prevSum = 0;

            top = Graphics.ValueToPixelPosition(columnCanvas.Height, 0, (Double)plotGroup.AxisY.InternalAxisMinimum, (Double)plotGroup.AxisY.InternalAxisMaximum, limitingYValue);

            dataPointAtTopOfStack = null;

            if (plotGroup.XWiseStackedDataList[xValue].Negative.Count > 0)
            {
                dataPointAtTopOfStack = plotGroup.XWiseStackedDataList[xValue].Negative.Last();
                animationTime         = 1.0 / plotGroup.XWiseStackedDataList[xValue].Negative.Count;
                animationBeginTime    = 0.4;
            }

            // Plot negative values
            foreach (DataPoint dataPoint in plotGroup.XWiseStackedDataList[xValue].Negative)
            {
                dataPoint.Parent.Faces = new Faces()
                {
                    Visual = columnCanvas, LabelCanvas = labelCanvas
                };

                if (!(Boolean)dataPoint.Enabled || Double.IsNaN(dataPoint.InternalYValue))
                {
                    continue;
                }

                isTopOFStack = (dataPoint == dataPointAtTopOfStack);

                if (chartType == RenderAs.StackedColumn)
                {
                    bottom       = Graphics.ValueToPixelPosition(columnCanvas.Height, 0, (Double)plotGroup.AxisY.InternalAxisMinimum, (Double)plotGroup.AxisY.InternalAxisMaximum, dataPoint.InternalYValue + prevSum);
                    prevSum     += dataPoint.InternalYValue;
                    columnHeight = Math.Abs(top - bottom);
                }
                else // if (chartType == RenderAs.StackedColumn100)
                {
                    Double percentYValue = (dataPoint.InternalYValue / absoluteSum * 100);
                    bottom       = Graphics.ValueToPixelPosition(columnCanvas.Height, 0, (Double)plotGroup.AxisY.InternalAxisMinimum, (Double)plotGroup.AxisY.InternalAxisMaximum, percentYValue + prevSum);
                    columnHeight = Math.Abs(top - bottom);
                    prevSum     += percentYValue;
                }

                CreateStackedColumnVisual(false, columnCanvas, labelCanvas, dataPoint,
                                          isTopOFStack, left, ref top, ref bottom, widthPerColumn, columnHeight, depth3d,
                                          ref negativeIndex, animationEnabled, animationBeginTime);

                animationBeginTime += animationTime;
                negativeIndex--;
            }
        }