Example #1
0
        private void _drawPerspectiveXYValues()
        {
            bool   animate = (this.AnimationDuration > 0);
            double xOffset = XOffsetPerspective, yOffset = YOffsetPerspective;

            double marginLeft = MarginLeft, marginTop = MarginTop;
            double marginRight = MarginRight, marginBottom = MarginBottom;

            double           gridWidth  = (ChartCanvas.Width - marginLeft - marginRight - xOffset);
            double           gridHeight = (ChartCanvas.Height - marginTop - marginBottom - yOffset);
            LookAndFeel      lf         = CurrentLookAndFeel;
            string           pathXAML   = lf.GetLinePath3DXAML();
            Path             pathElem;
            List <UIElement> dataElems = null;

            if (animate)
            {
                dataElems = DataElements;
            }

            ChartModel model = Model;

            string[] seriesLabels = model.SeriesLabels;
            int      seriesCount  = seriesLabels.Length;

            Color[] seriesColors = model.SeriesColors;

            double[,] yValues = model.YValues;
            double minYValue = model.MinYValue, maxYValue = model.MaxYValue;
            int    nValues = yValues.GetUpperBound(0) + 1;

            double[,] xValues = model.XValues;
            double minXValue = model.MinXValue, maxXValue = model.MaxXValue;

            double          gridBottom = gridHeight + marginTop + yOffset;
            double          dx, dy;
            string          gradientXAML = lf.GetElementGradientXAML();
            MatrixTransform defaultTransform;

            for (int i = 0; i < seriesCount; ++i)
            {
                StringBuilder sb = new StringBuilder();

                for (var j = 0; j < nValues; ++j)
                {
                    dy = gridBottom - gridHeight * (yValues[j, i] - minYValue) / (maxYValue - minYValue);
                    dx = marginLeft + gridWidth * (xValues[j, i] - minXValue) / (maxXValue - minXValue);
                    if (j != nValues - 1)
                    {
                        sb.Append(" M").Append(dx).Append(",").Append(dy);
                        sb.Append(" l").Append(xOffset).Append(",").Append(-yOffset);
                        double nextdy, nextdx;
                        nextdx = marginLeft + gridWidth * (xValues[j + 1, i] - minXValue) / (maxXValue - minXValue);
                        nextdy = gridBottom -
                                 gridHeight * (yValues[j + 1, i] - minYValue) / (maxYValue - minYValue);
                        sb.Append(" L").Append(nextdx + xOffset).Append(",").Append(nextdy - yOffset);
                        sb.Append(" l").Append(-xOffset).Append(",").Append(yOffset);
                        sb.Append(" L").Append(dx).Append(",").Append(dy);
                    }
                }

                pathElem = CreatePathFromXAMLAndData(pathXAML, sb);

                if (animate)
                {
                    dataElems.Add(pathElem);
                    defaultTransform = new MatrixTransform();
                    Matrix m = new Matrix();
                    m.M11 = 0.0;
                    defaultTransform.Matrix = m;
                    pathElem.SetValue(UIElement.RenderTransformProperty, defaultTransform);
                }

                if (gradientXAML != null)
                {
                    SetGradientOnElement(pathElem, gradientXAML, seriesColors[i], 0xC0);
                }
                else
                {
                    SetFillOnElement(pathElem, seriesColors[i]);
                }

                pathElem.SetValue(Path.StrokeProperty, new SolidColorBrush(seriesColors[i]));
                (pathElem.Data as PathGeometry).FillRule = FillRule.Nonzero;

                SetExpandosOnElement(pathElem, -1, i, new Point());

                if (DisplayToolTip)
                {
                    pathElem.MouseMove  += new MouseEventHandler(ShowToolTip);
                    pathElem.MouseLeave += new MouseEventHandler(HideToolTip);
                }

                pathElem.MouseLeftButtonUp += new MouseButtonEventHandler(ChartDataClicked);

                ChartCanvas.Children.Add(pathElem);
            }
        }
Example #2
0
        private void _drawPerspectiveLines(int mod, int rem)
        {
            bool   animate = (this.AnimationDuration > 0);
            double xOffset = XOffsetPerspective, yOffset = YOffsetPerspective;

            double marginLeft = MarginLeft, marginTop = MarginTop;
            double marginRight = MarginRight, marginBottom = MarginBottom;

            double           gridWidth  = (ChartCanvas.Width - marginLeft - marginRight - xOffset);
            double           gridHeight = (ChartCanvas.Height - marginTop - marginBottom - yOffset);
            LookAndFeel      lf         = CurrentLookAndFeel;
            string           pathXAML   = lf.GetLinePath3DXAML();
            Path             pathElem;
            List <UIElement> dataElems        = null;
            MatrixTransform  defaultTransform = null;

            if (animate)
            {
                dataElems = DataElements;
            }

            ChartModel model = Model;

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

            string[] seriesLabels = model.SeriesLabels;
            int      seriesCount  = seriesLabels.Length;

            Color[] seriesColors = model.SeriesColors;
            double[,] yValues = model.YValues;

            double minValue = model.MinYValue, maxValue = model.MaxYValue;

            // For combo graphs we display every once in mod
            int seriesBars = (mod > 1) ? (int)Math.Ceiling(1 / (double)mod) : seriesCount;

            int yValueCount = yValues.GetUpperBound(0) + 1;

            string gradientXAML = lf.GetElementGradientXAML();

            double barWidth = (gridWidth / Math.Max(yValueCount, groupCount));
            double gridBottom = gridHeight + marginTop + yOffset, dx, dy;

            for (int i = 0; i < seriesCount; ++i)
            {
                // for combo charts we draw a bar every once in a mod.
                if ((mod > 1) && (i % mod) != rem)
                {
                    continue;
                }

                dx = marginLeft + barWidth / 2;

                StringBuilder sb = new StringBuilder();

                for (int j = 0; j < yValueCount; ++j)
                {
                    dy = gridBottom - gridHeight * (yValues[j, i] - minValue) / (maxValue - minValue);

                    if (j != yValueCount - 1)
                    {
                        sb.Append("M").Append(dx).Append(",").Append(dy);
                        sb.Append(" l").Append(xOffset).Append(",").Append(-yOffset);

                        var nextdy = gridBottom - gridHeight * (yValues[j + 1, i] - minValue) / (maxValue - minValue);
                        var nextdx = dx + barWidth;

                        sb.Append(" L").Append(nextdx + xOffset).Append(",").Append(nextdy - yOffset);
                        sb.Append(" L").Append(nextdx).Append(",").Append(nextdy);
                        sb.Append(" L").Append(dx).Append(",").Append(dy);
                        dx += barWidth;
                    }
                }
                pathElem = CreatePathFromXAMLAndData(pathXAML, sb);

                if (gradientXAML != null)
                {
                    SetGradientOnElement(pathElem, gradientXAML, seriesColors[i], 0xC0);
                }
                else
                {
                    SetFillOnElement(pathElem, seriesColors[i]);
                }
                pathElem.SetValue(Path.StrokeProperty, new SolidColorBrush(seriesColors[i]));
                (pathElem.Data as PathGeometry).FillRule = FillRule.Nonzero;

                SetExpandosOnElement(pathElem, -1, i, new Point());

                if (DisplayToolTip)
                {
                    pathElem.MouseMove  += new MouseEventHandler(ShowToolTip);
                    pathElem.MouseLeave += new MouseEventHandler(HideToolTip);
                }

                pathElem.MouseLeftButtonUp += new MouseButtonEventHandler(ChartDataClicked);

                if (animate)
                {
                    dataElems.Add(pathElem);
                    defaultTransform = new MatrixTransform();
                    Matrix m = new Matrix();
                    m.M11 = 0.0;
                    defaultTransform.Matrix = m;
                    pathElem.SetValue(UIElement.RenderTransformProperty, defaultTransform);
                }
                ChartCanvas.Children.Add(pathElem);
            }
        }