Example #1
0
        public override void DrawChartData()
        {
            // calculate the number of rows and columns
            ChartModel model = Model;

            double [,] yValues = model.YValues;
            int yValueCount = yValues.GetUpperBound(0) + 1;

            string[] groupLabels = model.GroupLabels;
            int      groupCount  = (groupLabels != null)?groupLabels.Length:1;

            int nCols = (int)Math.Ceiling(Math.Sqrt(yValueCount)),
                nRows = (int)Math.Round(Math.Sqrt(yValueCount));

            double dx = MarginLeft, dy = MarginTop;
            double quadWidth = (ChartCanvas.Width - MarginLeft - MarginRight) / (double)nCols;

            // We do not need any gap for 3D pie chart because of the vertical scaling
            double      vGap       = IsPerspective?0:2.0 * _TEXT_MARGIN;
            double      quadHeight = (ChartCanvas.Height - MarginTop - MarginBottom - (nRows - 1) * vGap) / (double)nRows;
            LookAndFeel lf         = CurrentLookAndFeel;
            string      labelXAML  = lf.GetGroupLabelXAML();
            TextBlock   labelElem  = null;

            for (int i = 0; i < nRows; ++i)
            {
                for (int j = 0; j < nCols; ++j)
                {
                    int iGroup = (groupLabels != null)?(i * nCols + j):(-1);
                    if (iGroup >= yValueCount)
                    {
                        break;
                    }

                    string groupLabel = (iGroup == -1)?null:groupLabels[iGroup];

                    Canvas fnlContainer = new Canvas();

                    ChartCanvas.Children.Add(fnlContainer);

                    double newHeight = DrawGroupLabelTitle(groupLabel, ChartCanvas, labelXAML, ref labelElem,
                                                           dx, dy, quadWidth, quadHeight);
                    double newWidth = quadWidth - 2 * _TEXT_MARGIN;

                    TranslateTransform transform = new TranslateTransform();
                    if (IsPerspective)
                    {
                        // Top ring has a height of 1/6 that of the width. So we need to compensate for half of it.
                        newHeight -= newWidth / 6;
                        _drawPerspectiveFunnel(fnlContainer, newWidth, newHeight, iGroup);
                        transform.X = (dx + _TEXT_MARGIN);
                        transform.Y = (dy + newWidth / 12);
                    }
                    else
                    {
                        _drawFunnel(fnlContainer, newWidth, newHeight, iGroup);
                        transform.X = dx + _TEXT_MARGIN;
                        transform.Y = dy;
                    }

                    fnlContainer.RenderTransform = transform;
                    dx += quadWidth;
                }
                dx  = MarginLeft;
                dy += quadHeight + vGap;
            }
        }