Example #1
0
        private void _drawPerspectiveAreas(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.GetAreaPathXAML();
            Path             pathElem;
            List <UIElement> dataElems        = null;
            MatrixTransform  defaultTransform = null;

            if (animate)
            {
                dataElems = DataElements;
            }

            bool       isStacked = (Type == ChartType.AREA_STACKED);
            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;

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

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

            double[] cumYs = isStacked? new double[yValueCount] : null;

            if (isStacked)
            {
                cumYs = new double[yValueCount];
                for (int j = 0; j < yValueCount; ++j)
                {
                    cumYs[j] = double.NaN;
                }
            }

            string gradientXAML = lf.GetElementGradientXAML();

            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.0;

                // If we use non zero min and it is a stacked graph, we need to remove the min for only
                // the first series.
                stackBase = (i == 0?minValue:0);

                StringBuilder sb = new StringBuilder();

                for (int j = 0; j < yValueCount; ++j)
                {
                    barHeight = gridHeight * (yValues[j, i] - stackBase) / (maxValue - minValue);
                    if (isStacked)
                    {
                        if (double.IsNaN(cumYs[j]))
                        {
                            cumYs[j] = gridBottom;
                        }

                        dy = (cumYs[j] -= barHeight);
                    }
                    else
                    {
                        dy = gridBottom - barHeight;
                    }

                    if (j == yValueCount - 1)
                    {
                        break;
                    }

                    sb.Append("M").Append(dx).Append(",").Append(dy);
                    sb.Append(" l").Append(xOffset).Append(",").Append(-yOffset);

                    if (i == 0 || !isStacked)
                    {
                        sb.Append(" L").Append(dx + xOffset).Append(",").Append(gridHeight + marginTop);
                    }
                    else
                    {
                        sb.Append(" v").Append(barHeight);
                    }

                    sb.Append(" l").Append(-xOffset).Append(",").Append(yOffset);
                    sb.Append(" z");

                    sb.Append("M").Append(dx).Append(",").Append(dy);
                    sb.Append(" l").Append(xOffset).Append(",").Append(-yOffset);

                    double nextdy, nextdx = dx + barWidth;

                    if (isStacked)
                    {
                        if (double.IsNaN(cumYs[j + 1]))
                        {
                            cumYs[j + 1] = gridBottom;
                        }

                        nextdy = (cumYs[j + 1] - gridHeight * (yValues[j + 1, i] - stackBase) / (maxValue - minValue));
                    }
                    else
                    {
                        nextdy = gridBottom - gridHeight * (yValues[j + 1, i] - minValue) / (maxValue - minValue);
                    }

                    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);
                    sb.Append(" M").Append(nextdx).Append(",").Append(nextdy);
                    sb.Append(" l").Append(xOffset).Append(",").Append(-yOffset);

                    if (i == 0 || !isStacked)
                    {
                        sb.Append(" L").Append(nextdx + xOffset).Append(",").Append(gridHeight + marginTop);
                    }
                    else
                    {
                        sb.Append(" L").Append(nextdx + xOffset).Append(",").Append(cumYs[j + 1] - yOffset);
                    }

                    sb.Append(" l").Append(-xOffset).Append(",").Append(yOffset);
                    sb.Append(" L").Append(nextdx).Append(",").Append(nextdy);

                    sb.Append(" M").Append(dx).Append(",").Append(dy);
                    sb.Append(" L").Append(nextdx).Append(",").Append(nextdy);

                    if (i == 0 || !isStacked)
                    {
                        sb.Append(" L").Append(nextdx).Append(",").Append(gridBottom);
                        sb.Append(" L").Append(dx).Append(",").Append(gridBottom);
                    }
                    else
                    {
                        sb.Append(" L").Append(nextdx).Append(",").Append(cumYs[j + 1]);
                        sb.Append(" L").Append(dx).Append(",").Append(
                            cumYs[j] + gridHeight * (yValues[j, i] - stackBase) / (maxValue - minValue));
                    }

                    sb.Append(" L").Append(dx).Append(",").Append(dy);

                    dx += barWidth;
                }

                pathElem = CreatePathFromXAMLAndData(pathXAML, sb);

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

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

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

                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);
            }
        }
        private void _drawBars(int mod, int rem)
        {
            bool animate = (this.AnimationDuration > 0);

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

            double gridWidth  = (ChartCanvas.Width - marginLeft - marginRight);
            double gridHeight = (ChartCanvas.Height - marginTop - marginBottom);

            LookAndFeel      lf       = CurrentLookAndFeel;
            string           rectXAML = lf.GetBarPathXAML();
            Path             rectElem;
            List <UIElement> dataElems        = null;
            MatrixTransform  defaultTransform = null;

            if (animate)
            {
                dataElems = DataElements;
            }

            int  barItemPadding = _BARITEM_PADDING;
            bool isStacked      = (Type == ChartType.HBAR_STACKED);

            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
            double barDivider  = isStacked ? 1 : ((mod > 1) ? Math.Ceiling(seriesCount / mod) : seriesCount);
            double stackBase   = minValue;
            int    yValueCount = yValues.GetUpperBound(0) + 1;

            double barHeight = (gridHeight / Math.Max(yValueCount, groupCount) - 2 * barItemPadding) / barDivider;
            double dx = marginLeft, dy = gridHeight + marginTop, barWidth;
            string gradientXAML = lf.GetElementGradientXAML();

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

                    // If we use non zero min and it is a stacked graph, we need to remove the min for only
                    // the first series.
                    if (isStacked)
                    {
                        stackBase = (j == 0 ? minValue : 0);
                    }

                    rectElem = XamlReader.Load(rectXAML) as Path;
                    if (animate)
                    {
                        dataElems.Add(rectElem);

                        // FIXTHIS: This is inefficient. However Silverlight currently does not allow sharing transform attribute
                        defaultTransform = new MatrixTransform();
                        Matrix m = new Matrix();
                        m.M11 = 0.0;
                        defaultTransform.Matrix = m;
                        rectElem.SetValue(UIElement.RenderTransformProperty, defaultTransform);
                    }

                    barWidth = gridWidth * (yValues[i, j] - stackBase) / (maxValue - minValue);
                    RectangleGeometry rectGeometry = new RectangleGeometry();
                    rectGeometry.RadiusX = rectGeometry.RadiusY = 2;
                    rectGeometry.Rect    = new Rect(dx, dy - barHeight, barWidth, barHeight);
                    rectElem.SetValue(Path.DataProperty, rectGeometry);

                    if (gradientXAML != null)
                    {
                        SetGradientOnElement(rectElem, gradientXAML, seriesColors[j], 0xe5);
                    }
                    else
                    {
                        SetFillOnElement(rectElem, seriesColors[j]);
                    }

                    rectElem.SetValue(Rectangle.StrokeProperty, new SolidColorBrush(seriesColors[j]));

                    if (isStacked)
                    {
                        dx += barWidth;
                    }

                    SetExpandosOnElement(rectElem, i, j, new Point(dx + barWidth, dy - barHeight / 2.0));

                    if (DisplayToolTip)
                    {
                        rectElem.MouseEnter += new MouseEventHandler(ShowToolTip);
                        rectElem.MouseLeave += new MouseEventHandler(HideToolTip);
                    }

                    rectElem.MouseLeftButtonUp += new MouseButtonEventHandler(ChartDataClicked);

                    ChartCanvas.Children.Add(rectElem);
                    if (!isStacked)
                    {
                        dy -= barHeight;
                    }
                }
                if (isStacked)
                {
                    dy -= barHeight;
                }
                dy -= barItemPadding;
            }
        }
Example #3
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);
            }
        }
        private void _drawPerspectivePoints()
        {
            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           dotXAML    = lf.GetScatterDot3DXAML();
            Path             dotElem;
            List <UIElement> dataElems = 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 minYValue = model.MinYValue, maxYValue = model.MaxYValue;
            int    nValues = yValues.GetUpperBound(0) + 1;

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

            double barWidth = (gridWidth / (double)(groupCount - 1));
            double gridBottom = gridHeight + marginTop + yOffset;
            double dx, dy, gridCx = 0, gridCy = 0;

            string gradientXAML = lf.GetElementGradientXAML();

            if (animate)
            {
                _cxs   = new double[seriesCount * nValues];
                _cys   = new double[seriesCount * nValues];
                gridCx = gridWidth / 2 + marginLeft + xOffset;
                gridCy = gridHeight / 2 + marginTop;
            }

            for (int i = 0; i < seriesCount; ++i)
            {
                for (int j = 0; j < nValues; ++j)
                {
                    dy = gridBottom - gridHeight * (yValues[j, i] - minYValue) / (maxYValue - minYValue);
                    dx = marginLeft + gridWidth * (xValues[j, i] - minXValue) / (maxXValue - minXValue);

                    dotElem = XamlReader.Load(dotXAML) as Path;

                    EllipseGeometry eg = dotElem.Data as EllipseGeometry;

                    if (animate)
                    {
                        dataElems.Add(dotElem);
                        eg.Center = new Point(gridCx, gridCy);

                        // we will use it during animation
                        int cIndex = (i * nValues + j);
                        _cxs[cIndex] = dx;
                        _cys[cIndex] = dy;
                    }
                    else
                    {
                        eg.Center = new Point(dx, dy);
                    }

                    if (gradientXAML != null)
                    {
                        SetGradientOnElement(dotElem, gradientXAML, seriesColors[i], 0xe5);
                    }
                    else
                    {
                        SetFillOnElement(dotElem, seriesColors[i]);
                    }
                    dotElem.SetValue(Path.StrokeProperty, new SolidColorBrush(seriesColors[i]));

                    SetExpandosOnElement(dotElem, j, i, new Point(dx, dy));

                    if (DisplayToolTip)
                    {
                        dotElem.MouseEnter += new MouseEventHandler(ShowToolTip);
                        dotElem.MouseLeave += new MouseEventHandler(HideToolTip);
                    }

                    dotElem.MouseLeftButtonUp += new MouseButtonEventHandler(ChartDataClicked);

                    //TODO:
                    // Silverlight does not support Filter effects so use another do as a shadow for it.

                    var shadowElem = XamlReader.Load(dotXAML) as Path;
                    eg = shadowElem.Data as EllipseGeometry;
                    if (animate)
                    {
                        dataElems.Add(shadowElem);
                        eg.Center = new Point(gridCx, gridCy);
                    }
                    else
                    {
                        eg.Center = new Point(dx, dy);
                    }

                    shadowElem.Fill = new SolidColorBrush(Color.FromArgb(0x7f, 0x33, 0x33, 0x33));
                    shadowElem.SetValue(Path.StrokeThicknessProperty, 0.0);

                    TranslateTransform tt = new TranslateTransform();
                    tt.X = tt.Y = 3;
                    shadowElem.SetValue(UIElement.RenderTransformProperty, tt);

                    ChartCanvas.Children.Add(shadowElem);
                    ChartCanvas.Children.Add(dotElem);
                }
            }
        }
        private void _drawPerspectiveBars(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.GetBarPathXAML();
            Path             pathElem;
            List <UIElement> dataElems        = null;
            MatrixTransform  defaultTransform = null;

            if (animate)
            {
                dataElems = DataElements;
            }

            int  barItemPadding = _BARITEM_PADDING;
            bool isStacked      = (Type == ChartType.HBAR_STACKED);

            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;
            double barHeight, stackBase = minValue;

            if (isStacked)
            {
                barHeight = gridHeight / Math.Max(yValueCount, groupCount) - 2 * barItemPadding;
            }
            else
            {
                barHeight = (gridHeight / Math.Max(yValueCount, groupCount)
                             - 2 * barItemPadding - (seriesCount) * barItemPadding) / seriesBars;
            }

            double dx = marginLeft, dy = gridHeight + marginTop + yOffset, barWidth;
            string gradientXAML = lf.GetElementGradientXAML();

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

                    // If we use non zero min and it is a stacked graph, we need to remove the min for only
                    // the first series.
                    if (isStacked)
                    {
                        stackBase = (j == 0 ? minValue : 0);
                    }

                    barWidth = gridWidth * (yValues[i, j] - stackBase) / (maxValue - minValue);


                    StringBuilder sb = new StringBuilder();
                    sb.Append("M").Append(dx).Append(",").Append(dy);
                    sb.Append(" h").Append(barWidth);
                    sb.Append(" v").Append(-barHeight);
                    sb.Append(" h").Append(-barWidth);
                    sb.Append(" v").Append(barHeight);

                    sb.Append(" M").Append(dx).Append(",").Append(dy - barHeight);
                    sb.Append(" l").Append(xOffset).Append(",").Append(-yOffset);
                    sb.Append(" h").Append(barWidth);
                    sb.Append(" l").Append(-xOffset).Append(",").Append(yOffset);
                    sb.Append(" z");
                    sb.Append(" M").Append(dx + barWidth).Append(",").Append(dy);
                    sb.Append(" v").Append(-barHeight);
                    sb.Append(" l").Append(xOffset).Append(",").Append(-yOffset);
                    sb.Append(" v").Append(barHeight);
                    sb.Append(" z");

                    pathElem = CreatePathFromXAMLAndData(lf.GetBarPathXAML(), 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);
                    }

                    pathElem.SetValue(Path.StrokeProperty, new SolidColorBrush(seriesColors[j]));

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

                    SetExpandosOnElement(pathElem, i, j, new Point(dx + barWidth + (xOffset) / 2.0, dy - (barHeight + yOffset) / 2.0));

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

                    pathElem.MouseLeftButtonUp += new MouseButtonEventHandler(ChartDataClicked);

                    ChartCanvas.Children.Add(pathElem);
                    if (isStacked)
                    {
                        dx += barWidth;
                    }
                    else
                    {
                        dy -= barHeight;
                        dy -= barItemPadding;
                    }
                }
                if (isStacked)
                {
                    dy -= barHeight;
                }
                dy -= barItemPadding;
            }
        }
        private void _drawPoints()
        {
            bool animate = (this.AnimationDuration > 0);

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

            double           gridWidth  = (ChartCanvas.Width - marginLeft - marginRight);
            double           gridHeight = (ChartCanvas.Height - marginTop - marginBottom);
            LookAndFeel      lf         = CurrentLookAndFeel;
            string           dotXAML    = lf.GetScatterDotXAML();
            Path             dotElem;
            List <UIElement> dataElems = 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 minYValue = model.MinYValue, maxYValue = model.MaxYValue;
            int    nValues = yValues.GetUpperBound(0) + 1;

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

            double barWidth = (gridWidth / (double)(groupCount - 1));
            double dx, dy, gridCx = 0, gridCy = 0;

            string gradientXAML = lf.GetElementGradientXAML();

            if (animate)
            {
                _cxs   = new double[seriesCount * nValues];
                _cys   = new double[seriesCount * nValues];
                gridCx = gridWidth / 2 + marginLeft;
                gridCy = gridHeight / 2 + marginTop;
            }

            for (int i = 0; i < seriesCount; ++i)
            {
                for (int j = 0; j < nValues; ++j)
                {
                    dy = gridHeight + marginTop - gridHeight * (yValues[j, i] - minYValue) / (maxYValue - minYValue);
                    dx = marginLeft + gridWidth * (xValues[j, i] - minXValue) / (maxXValue - minXValue);

                    dotElem = XamlReader.Load(dotXAML) as Path;

                    EllipseGeometry eg = dotElem.Data as EllipseGeometry;

                    if (gradientXAML != null)
                    {
                        SetGradientOnElement(dotElem, gradientXAML, seriesColors[i], 0xe5);
                    }
                    else
                    {
                        SetFillOnElement(dotElem, seriesColors[i]);
                    }
                    dotElem.SetValue(Path.StrokeProperty, new SolidColorBrush(seriesColors[i]));

                    SetExpandosOnElement(dotElem, j, i, new Point(dx, dy));

                    if (DisplayToolTip)
                    {
                        dotElem.MouseEnter += new MouseEventHandler(ShowToolTip);
                        dotElem.MouseLeave += new MouseEventHandler(HideToolTip);
                    }

                    dotElem.MouseLeftButtonUp += new MouseButtonEventHandler(ChartDataClicked);

                    if (animate)
                    {
                        dataElems.Add(dotElem);
                        eg.Center = new Point(gridCx, gridCy);

                        // we will use it during animation
                        int cIndex = (i * nValues + j);
                        _cxs[cIndex] = dx;
                        _cys[cIndex] = dy;
                    }
                    else
                    {
                        eg.Center = new Point(dx, dy);
                    }
                    ChartCanvas.Children.Add(dotElem);
                }
            }
        }
Example #7
0
        private void _drawRadar()
        {
            ChartModel model = Model;

            List <UIElement> dataElems = DataElements;
            bool             animate = (AnimationDuration > 0);
            double           marginLeft = MarginLeft, marginTop = MarginTop;
            double           gridWidth  = (ChartCanvas.Width - marginLeft - MarginRight);
            double           gridHeight = (ChartCanvas.Height - marginTop - MarginBottom);

            double cx = marginLeft + gridWidth / 2.0, cy = marginTop + gridHeight / 2.0;
            double radius = Math.Min(gridWidth, gridHeight) / 2.0;

            bool        isRadarArea = (Type == Chart.ChartType.RADAR_AREA);
            LookAndFeel lf          = CurrentLookAndFeel;
            string      pathXAML    = isRadarArea ? lf.GetAreaPathXAML() : lf.GetLinePathXAML();

            string lineDotXAML = null;

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

            Color [] seriesColors = model.SeriesColors;
            double[,] yValues = model.YValues;
            double minValue = model.MinYValue, maxValue = model.MaxYValue;

            string          gradientXAML = lf.GetElementGradientXAML();
            MatrixTransform defaultTransform = null;

            int    yValueCount = yValues.GetUpperBound(0) + 1;
            double dx, dy;

            if (!isRadarArea)
            {
                lineDotXAML = CurrentLookAndFeel.GetLineDotXAML();
            }

            if (animate && _dotElements == null)
            {
                _dotElements = new UIElement[seriesCount, yValueCount];
            }

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

                for (int j = 0; j < yValueCount; ++j)
                {
                    double yPoint = radius * (yValues[j, i] - minValue) / (maxValue - minValue);

                    dx = cx + yPoint * Math.Sin((j) * 2 * Math.PI / yValueCount);
                    dy = cy - yPoint * Math.Cos((j) * 2 * Math.PI / yValueCount);

                    if (j == 0)
                    {
                        sb.Append("M").Append(dx).Append(",").Append(dy);
                    }
                    else
                    {
                        sb.Append(" L").Append(dx).Append(",").Append(dy);
                    }

                    if (!isRadarArea)
                    {
                        Path            dotElem = XamlReader.Load(lineDotXAML) as Path;
                        EllipseGeometry eg      = dotElem.Data as EllipseGeometry;
                        eg.Center = new Point(dx, dy);

                        if (gradientXAML != null)
                        {
                            SetGradientOnElement(dotElem, gradientXAML, seriesColors[i], 0xe5);
                        }
                        else
                        {
                            SetFillOnElement(dotElem, seriesColors[i]);
                        }
                        dotElem.SetValue(Path.StrokeProperty, new SolidColorBrush(seriesColors[i]));

                        if (animate)
                        {
                            _dotElements[i, j] = dotElem;
                            defaultTransform   = new MatrixTransform();
                            Matrix m = new Matrix();
                            m.M11 = m.M22 = 0.0;
                            defaultTransform.Matrix = m;
                            dotElem.SetValue(UIElement.RenderTransformProperty, defaultTransform);
                        }
                        ChartCanvas.Children.Add(dotElem);
                    }
                }
                sb.Append("Z");

                Path pathElem = CreatePathFromXAMLAndData(pathXAML, sb);

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

                if (isRadarArea)
                {
                    if (gradientXAML != null)
                    {
                        SetGradientOnElement(pathElem, gradientXAML, seriesColors[i], 0x72);
                    }
                    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 #8
0
        private void _drawLines(int mod, int rem)
        {
            bool animate = (this.AnimationDuration > 0);

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

            double      gridWidth = (ChartCanvas.Width - marginLeft - marginRight);
            double      gridHeight = (ChartCanvas.Height - marginTop - marginBottom);
            LookAndFeel lf = CurrentLookAndFeel;
            string      lineDotXAML = lf.GetLineDotXAML(),
                        pathXAML = lf.GetLinePathXAML();
            Path             pathElem, dotElement;
            List <UIElement> dataElems        = null;
            MatrixTransform  defaultTransform = null;

            if (animate)
            {
                dataElems = DataElements;
            }

            bool       isStacked = (Type == ChartType.AREA_STACKED);
            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;

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

            string gradientXAML = lf.GetElementGradientXAML();
            double barWidth = gridWidth / Math.Max(yValueCount, groupCount);
            double 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 = gridHeight + marginTop - gridHeight * (yValues[j, i] - minValue) / (maxValue - minValue);

                    if (j == 0)
                    {
                        sb.Append("M").Append(dx).Append(",").Append(dy);
                    }
                    else
                    {
                        sb.Append("L").Append(dx).Append(",").Append(dy);
                    }

                    dotElement = XamlReader.Load(lineDotXAML) as Path;
                    EllipseGeometry rectG = dotElement.Data as EllipseGeometry;
                    rectG.Center = new Point(dx, dy);

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

                    dotElement.SetValue(Path.StrokeProperty, new SolidColorBrush(seriesColors[i]));

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

                    dx += barWidth;
                }

                pathElem = CreatePathFromXAMLAndData(pathXAML, sb);
                // There is no fill for lines
                pathElem.SetValue(Path.StrokeProperty, new SolidColorBrush(seriesColors[i]));

                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);
            }
        }
Example #9
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);
            }
        }
        public override void DrawChartData()
        {
            bool animate = (this.AnimationDuration > 0);

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

            double gridWidth  = (ChartCanvas.Width - marginLeft - marginRight);
            double gridHeight = (ChartCanvas.Height - marginTop - marginBottom);

            LookAndFeel      lf       = CurrentLookAndFeel;
            string           rectXAML = lf.GetBarPathXAML();
            Path             rectElem;
            List <UIElement> dataElems        = null;
            MatrixTransform  defaultTransform = null;

            if (animate)
            {
                dataElems = DataElements;
            }

            if (!(Model is CandleStickChartModel))
            {
                throw new Exception("model is not a CandleStickChartModel");
            }

            CandleStickChartModel model = Model as CandleStickChartModel;

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

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

            Color[]      seriesColors       = model.SeriesColors;
            double[][][] candleStickYValues = model.CandleStickYValues;


            double minValue = model.MinYValue, maxValue = model.MaxYValue;
            int    yValueCount = candleStickYValues.Length;
            double barWidth    = ((gridWidth - _PADDING_LEFT) / Math.Max(yValueCount, groupCount));

            double dx = marginLeft + _PADDING_LEFT, dy, barStart, barEnd, stackBase = minValue;
            string gradientXAML = lf.GetElementGradientXAML();

            for (int i = 0; i < yValueCount; ++i)
            {
                dy = gridHeight + marginTop;

                // skip over missing values
                if (candleStickYValues[i] != null)
                {
                    for (int j = 0; j < seriesCount; ++j)
                    {
                        rectElem = XamlReader.Load(rectXAML) as Path;
                        double openValue  = candleStickYValues[i][j][0];
                        double closeValue = candleStickYValues[i][j][3];
                        double highValue  = candleStickYValues[i][j][1];
                        double lowValue   = candleStickYValues[i][j][2];

                        // use the stock open value
                        barStart = (gridHeight + marginTop) - (gridHeight * (openValue - stackBase) / (maxValue - minValue));
                        // use the stock close value
                        barEnd = (gridHeight + marginTop) - (gridHeight * (closeValue - stackBase) / (maxValue - minValue));

                        bool doFill = openValue > closeValue;

                        RectangleGeometry rectGeometry = new RectangleGeometry();
                        rectGeometry.Rect = new Rect(dx, Math.Min(barStart, barEnd), _CANDLE_WIDTH, Math.Abs(barStart - barEnd));
                        rectElem.SetValue(Path.DataProperty, rectGeometry);

                        if (doFill)
                        {
                            if (gradientXAML != null)
                            {
                                SetGradientOnElement(rectElem, gradientXAML, seriesColors[j], 0xe5);
                            }
                            else
                            {
                                SetFillOnElement(rectElem, seriesColors[j]);
                            }
                        }

                        SolidColorBrush scb = new SolidColorBrush(seriesColors[j]);
                        rectElem.SetValue(Rectangle.StrokeProperty, scb);

                        SetExpandosOnElement(rectElem, i, j,
                                             new Point(dx + _CANDLE_WIDTH / 2.0, Math.Min(barStart, barEnd)));

                        if (DisplayToolTip)
                        {
                            rectElem.MouseEnter += new MouseEventHandler(ShowToolTip);
                            rectElem.MouseLeave += new MouseEventHandler(HideToolTip);
                        }

                        rectElem.MouseLeftButtonUp += new MouseButtonEventHandler(ChartDataClicked);
                        ChartCanvas.Children.Add(rectElem);

                        // Draw the sticks for the candle
                        Line lineTop = new Line(), lineBottom = new Line();
                        if (animate)
                        {
                            dataElems.Add(lineTop);
                            dataElems.Add(lineBottom);
                            dataElems.Add(rectElem);
                            defaultTransform = new MatrixTransform();
                            Matrix m = new Matrix();
                            m.M22 = 0.0;
                            defaultTransform.Matrix = m;

                            lineTop.SetValue(UIElement.RenderTransformProperty, defaultTransform);
                            lineBottom.SetValue(UIElement.RenderTransformProperty, defaultTransform);
                            rectElem.SetValue(UIElement.RenderTransformProperty, defaultTransform);
                        }

                        lineTop.SetValue(Line.StrokeProperty, scb);
                        lineBottom.SetValue(Line.StrokeProperty, scb);

                        lineTop.X1    = lineTop.X2 = lineBottom.X1 = lineBottom.X2 = dx + _CANDLE_WIDTH / 2.0;
                        lineTop.Y1    = doFill ? barStart : barEnd;
                        lineTop.Y2    = (gridHeight + marginTop) - (gridHeight * (highValue - stackBase) / (maxValue - minValue));
                        lineBottom.Y1 = doFill ? barEnd : barStart;
                        lineBottom.Y2 = (gridHeight + marginTop) - (gridHeight * (lowValue - stackBase) / (maxValue - minValue));

                        ChartCanvas.Children.Add(lineTop);
                        ChartCanvas.Children.Add(lineBottom);
                    }
                }
                dx += barWidth;
            }
        }