示例#1
0
        protected override void DrawGroupLabels()
        {
            ChartModel model     = Model;
            Canvas     container = new Canvas();

            HLabelContainer = container;

            List <UIElement> labelElems = LabelElements;
            bool             animate    = (AnimationDuration > 0);

            string[] groupLabels = model.GroupLabels;
            int      vLineCount  = groupLabels.Length;

            TextBlock labelElem;
            string    labelText;
            string    labelXAML = CurrentLookAndFeel.GetGroupLabelXAML();
            double    maxWidth = 0, maxHeight = 0;

            TextBlock [] gLabelElems = new TextBlock[vLineCount];

            GroupLabelElems = gLabelElems;

            for (int i = 0; i < vLineCount; ++i)
            {
                labelText = groupLabels[i];

                if (labelText == null || labelText.Length == 0)
                {
                    continue;
                }

                labelElem = XamlReader.Load(labelXAML) as TextBlock;

                if (animate)
                {
                    labelElems.Add(labelElem);
                    labelElem.Opacity = 0;
                }

                labelElem.Text = labelText;
                container.Children.Add(labelElem);
                gLabelElems[i] = labelElem;
                maxWidth       = Math.Max(maxWidth, labelElem.ActualWidth);
                maxHeight      = Math.Max(maxHeight, labelElem.ActualHeight);
            }
            ChartCanvas.Children.Add(container);
            HLabelBounds = new Size(maxWidth, maxHeight);
        }
示例#2
0
        public override void DrawChartData()
        {
            var rootElem = ChartCanvas;

            // 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));
            string    labelXAML = CurrentLookAndFeel.GetGroupLabelXAML();
            TextBlock labelElem = null;

            double dx = MarginLeft, dy = MarginTop;
            double quadWidth = (rootElem.Width - dx - MarginRight) / nCols;
            bool   animate   = (AnimationDuration > 0);

            double vGap       = 2 * _TEXT_MARGIN;
            var    quadHeight = (rootElem.Height - MarginTop - MarginBottom - (nRows - 1) * vGap) / nRows;

            if (animate)
            {
                _pieAnimAngles = new List <double>();
                _pieAnimRadii  = new List <double>();
            }

            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 pieContainer = new Canvas();
                    rootElem.Children.Add(pieContainer);

                    double newHeight = DrawGroupLabelTitle(groupLabel, rootElem, labelXAML, ref labelElem,
                                                           dx, dy, quadWidth, quadHeight);

                    double newWidth = quadWidth - 2 * _TEXT_MARGIN;
                    double cx = dx + quadWidth / 2 + _TEXT_MARGIN, cy = dy + newHeight / 2;

                    if (animate)
                    {
                        _pieAnimRadii.Add(Math.Max(cx, cy));
                    }

                    if (IsPerspective)
                    {
                        this._draw3DPies(pieContainer, newWidth, newHeight, iGroup);
                        MatrixTransform mt = new MatrixTransform();
                        mt.Matrix = new Matrix(1, 0, 0, .707, cx, cy);
                        // The chart is draw with the center at 0 so we need to compensate for it.
                        pieContainer.RenderTransform = mt;
                    }
                    else
                    {
                        this._drawPies(pieContainer, newWidth, newHeight, iGroup);
                        TranslateTransform tt = new TranslateTransform();
                        tt.X = cx;
                        tt.Y = cy;
                        pieContainer.RenderTransform = tt;
                    }
                    dx += quadWidth;
                }

                dx  = MarginLeft;
                dy += quadHeight + vGap;
            }
        }
示例#3
0
        public override void DrawChartData()
        {
            if (YMinorGridCount < 0)
            {
                YMinorGridCount = 4;
            }

            var rootCanvas = ChartCanvas;

            // 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 = (rootCanvas.Width - MarginLeft - MarginRight) / nCols;
            double vGap      = 2 * _TEXT_MARGIN;

            double    quadHeight = (rootCanvas.Height - MarginTop - MarginBottom - (nRows - 1) * vGap) / nRows;
            string    labelXAML  = CurrentLookAndFeel.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 gaugeContainer = new Canvas();

                    rootCanvas.Children.Add(gaugeContainer);

                    if (groupLabel != null)
                    {
                        labelElem = XamlReader.Load(labelXAML) as TextBlock;
                    }

                    double newHeight = DrawGroupLabelTitle(groupLabel, rootCanvas, labelXAML, ref labelElem,
                                                           dx, dy, quadWidth, quadHeight);

                    double newWidth = quadWidth - 2 * _TEXT_MARGIN;

                    Size gaugeSize = DrawDial(gaugeContainer, newWidth, newHeight, iGroup);

                    TranslateTransform tt = new TranslateTransform();

                    tt.X = (dx + _TEXT_MARGIN);
                    tt.Y = dy;
                    gaugeContainer.RenderTransform = tt;

                    if (groupLabel != null)
                    {
                        if (gaugeSize.Height < newHeight - vGap)
                        {
                            var newY = (double)labelElem.GetValue(Canvas.TopProperty);
                            newY -= (newHeight - gaugeSize.Height) / 2 - vGap;
                            labelElem.SetValue(Canvas.TopProperty, newY);
                        }
                    }
                    dx += quadWidth;
                }

                dx  = MarginLeft;
                dy += quadHeight + vGap;
            }
        }