Exemplo n.º 1
0
        /// <summary>
        /// Apply marker properties
        /// </summary>
        /// <param name="dataPoint">DataPoint</param>
        /// <param name="markerSize">Marker size</param>
        //internal static void ApplyMarkerProperties(DataPoint dataPoint)
        //{
        //    Marker marker = dataPoint.Marker;
        //    marker.ScaleFactor = (Double)dataPoint.MarkerScale;
        //    marker.MarkerSize = new Size((Double)dataPoint.MarkerSize, (Double)dataPoint.MarkerSize);

        //    if ((Boolean)dataPoint.MarkerEnabled)
        //        marker.BorderColor = dataPoint.MarkerBorderColor;
        //    else
        //        marker.BorderColor = new SolidColorBrush(Colors.Transparent);

        //    marker.BorderThickness = ((Thickness)dataPoint.MarkerBorderThickness).Left;
        //    marker.ShadowEnabled = (Boolean)dataPoint.ShadowEnabled;
        //    marker.MarkerFillColor = dataPoint.MarkerColor;
        //}

        /// <summary>
        /// Apply animation for line chart
        /// </summary>
        /// <param name="canvas">Line chart canvas</param>
        /// <param name="storyboard">Storyboard</param>
        /// <param name="isLineCanvas">Whether canvas is line canvas</param>
        /// <returns>Storyboard</returns>
        //private static Storyboard ApplyLineChartAnimation(DataSeries currentDataSeries, Panel canvas, Storyboard storyboard, Boolean isLineCanvas)
        //{
        //    LinearGradientBrush opacityMaskBrush = new LinearGradientBrush() { StartPoint = new Point(0, 0.5), EndPoint = new Point(1, 0.5) };

        //    // Create gradients for opacity mask animation
        //    GradientStop GradStop1 = new GradientStop() { Color = Colors.White, Offset = 0 };
        //    GradientStop GradStop2 = new GradientStop() { Color = Colors.White, Offset = 0 };
        //    GradientStop GradStop3 = new GradientStop() { Color = Colors.Transparent, Offset = 0.01 };
        //    GradientStop GradStop4 = new GradientStop() { Color = Colors.Transparent, Offset = 1 };

        //    // Add gradients to gradient stop list
        //    opacityMaskBrush.GradientStops.Add(GradStop1);
        //    opacityMaskBrush.GradientStops.Add(GradStop2);
        //    opacityMaskBrush.GradientStops.Add(GradStop3);
        //    opacityMaskBrush.GradientStops.Add(GradStop4);

        //    canvas.OpacityMask = opacityMaskBrush;

        //    double beginTime = (isLineCanvas) ? 0.25 + 0.5 : 0.5;

        //    DoubleCollection values = Graphics.GenerateDoubleCollection(0, 1);
        //    DoubleCollection timeFrames = Graphics.GenerateDoubleCollection(0, 1);
        //    List<KeySpline> splines = AnimationHelper.GenerateKeySplineList(new Point(0, 0), new Point(1, 1), new Point(0, 0), new Point(1, 1));

        //    storyboard.Children.Add(AnimationHelper.CreateDoubleAnimation(currentDataSeries, GradStop2, "(GradientStop.Offset)", beginTime, timeFrames, values, splines));

        //    values = Graphics.GenerateDoubleCollection(0.01, 1);
        //    timeFrames = Graphics.GenerateDoubleCollection(0, 1);
        //    splines = AnimationHelper.GenerateKeySplineList(new Point(0, 0), new Point(1, 1), new Point(0, 0), new Point(1, 1));

        //    storyboard.Children.Add(AnimationHelper.CreateDoubleAnimation(currentDataSeries, GradStop3, "(GradientStop.Offset)", beginTime, timeFrames, values, splines));


        //    storyboard.Completed += delegate
        //    {
        //        GradStop2.Offset = 1;
        //        GradStop3.Offset = 1;
        //        GradStop1.Color = Colors.White;
        //        GradStop2.Color = Colors.White;
        //        GradStop3.Color = Colors.White;
        //        GradStop4.Color = Colors.White;

        //    };
        //    return storyboard;
        //}

        #endregion

        #region Internal Methods

        //internal static void CalculateMarkerPosition(DataPoint dataPoint, Double width, Double height, out Double xPosition, out Double yPosition)
        //{
        //    xPosition = Double.NaN;
        //    yPosition = Double.NaN;
        //    if (Double.IsNaN(dataPoint.InternalYValue))
        //        return;

        //    PlotGroup plotGroup = dataPoint.Parent.PlotGroup;
        //    Chart chart = dataPoint.Chart as Chart;

        //    xPosition = Graphics.ValueToPixelPosition(0, width, (Double)plotGroup.AxisX.InternalAxisMinimum, (Double)plotGroup.AxisX.InternalAxisMaximum, dataPoint.InternalXValue);
        //    yPosition = Graphics.ValueToPixelPosition(height, 0, (Double)plotGroup.AxisY.InternalAxisMinimum, (Double)plotGroup.AxisY.InternalAxisMaximum, dataPoint.InternalYValue);

        //}

        //internal static Marker CreateMarkerAForLineDataPoint(DataPoint dataPoint, Double width, Double height, ref Canvas line2dLabelCanvas, out Double xPosition, out Double yPosition)
        //{
        //    xPosition = Double.NaN;
        //    yPosition = Double.NaN;
        //    if (Double.IsNaN(dataPoint.InternalYValue))
        //        return null;

        //    PlotGroup plotGroup = dataPoint.Parent.PlotGroup;
        //    Chart chart = dataPoint.Chart as Chart;

        //    xPosition = Graphics.ValueToPixelPosition(0, width, (Double)plotGroup.AxisX.InternalAxisMinimum, (Double)plotGroup.AxisX.InternalAxisMaximum, dataPoint.InternalXValue);
        //    yPosition = Graphics.ValueToPixelPosition(height, 0, (Double)plotGroup.AxisY.InternalAxisMinimum, (Double)plotGroup.AxisY.InternalAxisMaximum, dataPoint.InternalYValue);

        //    dataPoint._visualPosition = new Point(xPosition, yPosition);

        //    // Create Marker
        //    Marker marker = GetMarkerForDataPoint(true, chart, width, height, yPosition, dataPoint, dataPoint.InternalYValue > 0);
        //    marker.AddToParent(line2dLabelCanvas, xPosition, yPosition, new Point(0.5, 0.5));

        //    //Graphics.DrawPointAt(new Point(xPosition, yPosition), line2dLabelCanvas, Colors.Red);

        //    return marker;
        //}

        internal static void CreateAstepLineSeries(DataSeries series, Double width, Double height, Canvas labelCanvas, Canvas chartsCanvas, Boolean animationEnabled)
        {
            Canvas line2dCanvas;
            Canvas line2dLabelCanvas;

            // Removing exising line chart for a series
            if (series.Faces != null)
            {
                line2dCanvas = series.Faces.Visual as Canvas;
                line2dLabelCanvas = series.Faces.LabelCanvas;

                if (line2dCanvas != null)
                {
                    Panel parent = line2dCanvas.Parent as Panel;

                    if (parent != null)
                        parent.Children.Remove(line2dCanvas);
                }

                if (line2dLabelCanvas != null)
                {
                    Panel parent = line2dLabelCanvas.Parent as Panel;

                    if (parent != null)
                        parent.Children.Remove(line2dLabelCanvas);
                }
            }

            if ((Boolean)series.Enabled == false)
            {
                return;
            }

            Double xPosition, yPosition;
            Chart chart = (series.Chart as Chart);

            line2dLabelCanvas = new Canvas() { Width = width, Height = height };   // Canvas for placing labels

            List<List<DataPoint>> pointCollectionList = new List<List<DataPoint>>();
            List<List<DataPoint>> shadowPointCollectionList = new List<List<DataPoint>>();

            PlotGroup plotGroup = series.PlotGroup;
            StepLineChartShapeParams lineParams = new StepLineChartShapeParams();

            #region Set LineParms

            lineParams.Points = new List<DataPoint>();
            lineParams.ShadowPoints = new List<DataPoint>();
            lineParams.LineGeometryGroup = new GeometryGroup();
            lineParams.LineThickness = (Double)series.LineThickness;
            lineParams.LineColor = series.Color;
            lineParams.LineStyle = ExtendedGraphics.GetDashArray(series.LineStyle);
            lineParams.Lighting = (Boolean)series.LightingEnabled;
            lineParams.ShadowEnabled = (Boolean)series.ShadowEnabled;
            lineParams.Opacity = series.Opacity;

            if ((Boolean)series.ShadowEnabled)
                lineParams.LineShadowGeometryGroup = new GeometryGroup();

            #endregion

            series.VisualParams = lineParams;

            Point variableStartPoint = new Point(), endPoint = new Point();
            Boolean IsStartPoint = true;

            // Polyline polyline, PolylineShadow;
            // Canvas line2dCanvas = new Canvas();
            // Canvas lineCanvas;

            List<DataPoint> viewPortDataPoints = RenderHelper.GetDataPointsUnderViewPort(series, false);

            foreach (DataPoint dataPoint in viewPortDataPoints)
            {   
                if (dataPoint.Enabled == false)
                    continue;

                dataPoint.Marker = null;
                dataPoint.LabelVisual = null;
                dataPoint.Faces = null;

                if (Double.IsNaN(dataPoint.InternalYValue))
                {
                    xPosition = Double.NaN;
                    yPosition = Double.NaN;
                    IsStartPoint = true;
                }
                else
                {
                    //CreateMarkerAForLineDataPoint(dataPoint, width, height, ref line2dLabelCanvas, out xPosition, out yPosition);
                    LineChart.CalculateMarkerPosition(dataPoint, width, height, out xPosition, out yPosition);

                    #region Generate GeometryGroup for line and line shadow

                    if (IsStartPoint)
                    {
                        variableStartPoint = new Point(xPosition, yPosition);

                        IsStartPoint = !IsStartPoint;

                        if (lineParams.Points.Count > 0)
                        {
                            pointCollectionList.Add(lineParams.Points);
                            shadowPointCollectionList.Add(lineParams.ShadowPoints);
                        }

                        lineParams.Points = new List<DataPoint>();
                        lineParams.ShadowPoints = new List<DataPoint>();
                    }
                    else
                    {
                        endPoint = new Point(xPosition, yPosition);

                        variableStartPoint = endPoint;
                        IsStartPoint = false;
                    }

                    #endregion Generate GeometryGroup for line and line shadow

                    dataPoint._visualPosition = new Point(xPosition, yPosition);
                    lineParams.Points.Add(dataPoint);

                    if (lineParams.ShadowEnabled)
                        lineParams.ShadowPoints.Add(dataPoint);
                }
            }

            pointCollectionList.Add(lineParams.Points);
            shadowPointCollectionList.Add(lineParams.ShadowPoints);

            series.Faces = new Faces();

            Path polyline, PolylineShadow;
            line2dCanvas = GetStepLine2D(series, width, height, line2dLabelCanvas, lineParams, out polyline, out PolylineShadow, pointCollectionList, shadowPointCollectionList);

            line2dCanvas.Width = width;
            line2dCanvas.Height = height;

            series.Faces.Parts.Add(polyline);

            if (!VisifireControl.IsMediaEffectsEnabled)
                series.Faces.Parts.Add(PolylineShadow);

            labelCanvas.Children.Add(line2dLabelCanvas);
            chartsCanvas.Children.Add(line2dCanvas);

            series.Faces.Visual = line2dCanvas;
            series.Faces.LabelCanvas = line2dLabelCanvas;

            // Apply animation
            if (animationEnabled)
            {
                if (series.Storyboard == null)
                    series.Storyboard = new Storyboard();
                else
                    series.Storyboard.Stop();

                // Apply animation to the lines
                series.Storyboard = LineChart.ApplyLineChartAnimation(series, line2dCanvas, series.Storyboard, true);
            }

            // Create Moving Marker
            //if (series.MovingMarkerEnabled)
            {
                Double movingMarkerSize = (Double)series.MarkerSize * (Double)series.MarkerScale * MOVING_MARKER_SCALE;

                if (movingMarkerSize < 6)
                    movingMarkerSize = 6;

                Ellipse movingMarker = new Ellipse() { Visibility = Visibility.Collapsed, IsHitTestVisible = false, Height = movingMarkerSize, Width = movingMarkerSize, Fill = lineParams.LineColor };

                labelCanvas.Children.Add(movingMarker);
                series._movingMarker = movingMarker;
            }
            //else
            //series._movingMarker = null;

        }
Exemplo n.º 2
0
        /// <summary>
        /// Apply default interactivity for Marker
        /// </summary>
        /// <param name="dataPoint">DataPoint</param>
        //internal static void ApplyDefaultInteractivityForMarker(DataPoint dataPoint)
        //{
        //    if ((Boolean)dataPoint.MarkerEnabled)
        //    {
        //        if (!dataPoint.Parent.MovingMarkerEnabled)
        //        {
        //            dataPoint.Marker.MarkerShape.MouseEnter += delegate(object sender, MouseEventArgs e)
        //            {
        //                if (!dataPoint.Selected)
        //                {
        //                    Shape shape = sender as Shape;
        //                    shape.Stroke = new SolidColorBrush(Colors.Red);
        //                    shape.StrokeThickness = dataPoint.Marker.BorderThickness;
        //                }
        //            };

        //            dataPoint.Marker.MarkerShape.MouseLeave += delegate(object sender, MouseEventArgs e)
        //            {
        //                if (!dataPoint.Selected)
        //                {
        //                    Shape shape = sender as Shape;
        //                    shape.Stroke = dataPoint.Marker.BorderColor;
        //                    shape.StrokeThickness = dataPoint.Marker.BorderThickness;
        //                }
        //            };
        //        }
        //    }
        //    else
        //    {
        //        HideDataPointMarker(dataPoint);
        //    }
        //}

        /// <summary>
        /// Hides a DataPoint Marker
        /// </summary>
        /// <param name="dataPoint"></param>
        //internal static void HideDataPointMarker(DataPoint dataPoint)
        //{
        //    Brush tarnsparentColor = new SolidColorBrush(Colors.Transparent);
        //    dataPoint.Marker.MarkerShape.Fill = tarnsparentColor;

        //    SolidColorBrush stroke = dataPoint.Marker.MarkerShape.Stroke as SolidColorBrush;

        //    if (!(stroke != null && stroke.Color.ToString().Equals(tarnsparentColor.ToString())))
        //        dataPoint.Marker.MarkerShape.Stroke = tarnsparentColor;

        //    if (dataPoint.Marker.MarkerShadow != null)
        //        dataPoint.Marker.MarkerShadow.Visibility = Visibility.Collapsed;

        //    if (dataPoint.Marker.BevelLayer != null)
        //        dataPoint.Marker.BevelLayer.Visibility = Visibility.Collapsed;
        //}

        /// <summary>
        /// Hides a DataPoint Marker
        /// </summary>
        /// <param name="dataPoint"></param>
        //internal static void ShowDataPointMarker(DataPoint dataPoint)
        //{
        //    if (dataPoint.MarkerColor != null)
        //        dataPoint.Marker.MarkerShape.Fill = dataPoint.MarkerColor;

        //    if (dataPoint.MarkerBorderColor != null)
        //        dataPoint.Marker.MarkerShape.Stroke = dataPoint.MarkerBorderColor;
        //    else
        //        dataPoint.Marker.MarkerShape.Stroke = dataPoint.Color;

        //    if (dataPoint.Marker.MarkerShadow != null)
        //        dataPoint.Marker.MarkerShadow.Visibility = Visibility.Visible;

        //    if (dataPoint.Marker.BevelLayer != null)
        //        dataPoint.Marker.BevelLayer.Visibility = Visibility.Visible;
        //}

        /// <summary>
        /// Create line in 2D and place inside a canvas
        /// </summary>
        /// <param name="lineParams">Line parameters</param>
        /// <param name="line">line path reference</param>
        /// <param name="lineShadow">line shadow path reference</param>
        /// <returns>Canvas</returns>
        private static Canvas GetStepLine2D(DataSeries tagReference, Double width, Double height, Canvas line2dLabelCanvas, StepLineChartShapeParams lineParams, out Path line, out Path lineShadow, List<List<DataPoint>> pointCollectionList, List<List<DataPoint>> shadowPointCollectionList)
        {
            Canvas visual = new Canvas();
            line = new Path() { Tag = new ElementData() { Element = tagReference } };
            line.StrokeLineJoin = PenLineJoin.Round;

            line.StrokeStartLineCap = PenLineCap.Round;
            line.StrokeEndLineCap = PenLineCap.Round;

            line.Stroke = lineParams.Lighting ? Graphics.GetLightingEnabledBrush(lineParams.LineColor, "Linear", new Double[] { 0.65, 0.55 }) : lineParams.LineColor;
            line.StrokeThickness = lineParams.LineThickness;
            line.StrokeDashArray = lineParams.LineStyle;
            line.Opacity = lineParams.Opacity;

            line.Data = GetPathGeometry(null, pointCollectionList, false, width, height, line2dLabelCanvas);

            if (lineParams.ShadowEnabled)
            {
                if (!VisifireControl.IsMediaEffectsEnabled)
                {
                    lineShadow = new Path() { IsHitTestVisible = false };
                    lineShadow.Stroke = Graphics.GetLightingEnabledBrush(new SolidColorBrush(Colors.LightGray), "Linear", new Double[] { 0.65, 0.55 });
                    lineShadow.StrokeStartLineCap = PenLineCap.Round;
                    lineShadow.StrokeEndLineCap = PenLineCap.Round;
                    lineShadow.StrokeLineJoin = PenLineJoin.Round;
                    lineShadow.StrokeThickness = lineParams.LineThickness;
                    lineShadow.Opacity = 0.5;

                    if (lineParams.ShadowEnabled)
                        lineShadow.Data = GetPathGeometry(null, shadowPointCollectionList, true, width, height, null);

                    TranslateTransform tt = new TranslateTransform() { X = 2, Y = 2 };
                    lineShadow.RenderTransform = tt;

                    visual.Children.Add(lineShadow);
                }
                else
                {
#if !WP
                    visual.Effect = ExtendedGraphics.GetShadowEffect(315, 2.5, 1);
#endif
                    lineShadow = null;
                }
            }
            else
                lineShadow = null;

            //lineShadow = null;

            visual.Children.Add(line);

            return visual;
        }