Exemple #1
0
        public static void UpdateVisualForYValue4StackedColumnChart(RenderAs chartType, Chart chart, DataPoint dataPoint, Boolean isAxisChanged)
        {
            if (dataPoint.Faces == null)
                return;

            System.Diagnostics.Debug.WriteLine("Animate--YValue" + dataPoint.YValue.ToString() + " IsAxisChange=" + isAxisChanged.ToString());
            
            Boolean animationEnabled = chart.AnimatedUpdate;                                            // Whether the animation for the DataPoint is enabled   
            DataSeries dataSeries = dataPoint.Parent;                                   // parent of the current DataPoint
            Canvas dataPointVisual = dataPoint.Faces.Visual as Canvas;                  // Old visual for the column
            Canvas labelCanvas = dataPoint.Faces.LabelCanvas;// (columnCanvas.Parent as Canvas).Children[0] as Canvas; // Parent canvas of Datapoint label
            Canvas columnCanvas = (labelCanvas.Parent as Canvas).Children[1] as Canvas; 
                //dataSeries.Faces.Visual as Canvas;// dataPointVisual.Parent as Canvas;                     // Existing parent canvas of column

            UpdateParentVisualCanvasSize(chart, columnCanvas);
            UpdateParentVisualCanvasSize(chart, labelCanvas);

            Double height = labelCanvas.Height;
            Double width = labelCanvas.Width;

            PlotGroup plotGroup = dataSeries.PlotGroup;                                 // PlotGroup reference

            // Calculate 3d depth for the DataPoints
            Double depth3d = chart.ChartArea.PLANK_DEPTH / chart.PlotDetails.Layer3DCount * (chart.View3D ? 1 : 0);

            // Calculate required parameters for Creating new Stacked Columns
            Double minDiff, widthPerColumn, maxColumnWidth;
            widthPerColumn = CalculateWidthOfEachStackedColumn(chart, plotGroup, width, out minDiff, out  maxColumnWidth);

            // List of effected DataPoints for the current update of YValue property of the DataPoint
            XWiseStackedData effectedDataPoints = plotGroup.XWiseStackedDataList[dataPoint.InternalXValue];

            // Marging all DataPoints in to single a single list of DataPoint
            List<DataPoint> positiveList = effectedDataPoints.Positive.ToList();
            List<DataPoint> negativeList = effectedDataPoints.Negative.ToList();
            List<DataPoint> listOfDataPoint = new List<DataPoint>();
            listOfDataPoint.AddRange(positiveList);
            listOfDataPoint.AddRange(negativeList);

            // Storing reference of old Visual 
            foreach(DataPoint dp in listOfDataPoint)
            {   
                if (dp.Marker != null && dp.Marker.Visual != null)
                    dp._oldMarkerPosition = new Point((Double)dp.Marker.Visual.GetValue(Canvas.LeftProperty), (Double)dp.Marker.Visual.GetValue(Canvas.TopProperty));

                if (dp.LabelVisual != null)
                    dp._oldLabelPosition = new Point((Double)dp.LabelVisual.GetValue(Canvas.LeftProperty), (Double)dp.LabelVisual.GetValue(Canvas.TopProperty));

                if (dp.Faces != null)
                {
                    dp._oldVisual = dp.Faces.Visual;
                    columnCanvas.Children.Remove(dp._oldVisual);
                }
            }

            // Calculate limiting value
            Double limitingYValue = (plotGroup.AxisY.InternalAxisMinimum > 0)? plotGroup.AxisY.InternalAxisMinimum : (plotGroup.AxisY.InternalAxisMaximum < 0)? plotGroup.AxisY.InternalAxisMaximum : 0;

            // Create new Column with new YValue
            DrawStackedColumnsAtXValue(chartType, dataPoint.InternalXValue, plotGroup, columnCanvas, labelCanvas, plotGroup.DrawingIndex, dataPointVisual.Width, maxColumnWidth, limitingYValue, depth3d, false);
            
            Boolean isPositive;

            if (animationEnabled)
            {
                // Create new Storyboard for animation
                if (dataPoint.Storyboard != null)
                {
                    dataPoint.Storyboard.Stop();
                    dataPoint.Storyboard = null;
                }

                dataPoint.Storyboard = new Storyboard();

                // Whether to animate the top of DataPoint Visual
                Boolean isAnimateTop = false;

                // Loop through all Datapoints under the PlotGroup of the current DataPoint and apply animation
                foreach (DataPoint dp in listOfDataPoint)
                {
                    if (dp.Faces == null || dp._oldVisual == null)
                        continue;

                    FrameworkElement newVisual = dp.Faces.Visual;                       // New StackedColumn visual reference of DataPoint
                    Double oldTop = (Double)dp._oldVisual.GetValue(Canvas.TopProperty); // Top of the old visual of the DataPoint
                    Double newTop = (Double)newVisual.GetValue(Canvas.TopProperty);     // Top of the new visual of the DataPoint
                    Double oldHeight = dp._oldVisual.Height;                            // Height of the old visual of the DataPoint
                    Double newHeight = newVisual.Height;                                // Height of the new visual of the DataPoint
                    Double oldScale = oldHeight / newHeight;                            // Scale value for the old DataPoint                       

                    System.Diagnostics.Debug.WriteLine("DataPoint--oldTop =" + oldTop.ToString() + " newTop=" + newTop.ToString() + "oldYValue=" + dp._oldYValue.ToString() + " newYValue=" + dp.InternalYValue.ToString());

                    if (dp == dataPoint)
                    {   
                        isPositive = (dataPoint._oldYValue < 0 && dataPoint.InternalYValue > 0) ? true : 
                            (dataPoint._oldYValue > 0 && dataPoint.InternalYValue < 0) ? false : 
                            dp._oldYValue >= 0 ? true : false;
                    }
                    else
                        isPositive = dp.InternalYValue >= 0 ? true : false;

                    if (isPositive)
                        newVisual.RenderTransformOrigin = new Point(0.5, 1);
                    else
                        newVisual.RenderTransformOrigin = new Point(0.5, 0);

                    // Apply new RenderTransform to the DataPoint Visual
                    newVisual.RenderTransform = new ScaleTransform();


                    if(Double.IsInfinity(oldScale) || Double.IsNaN(oldScale))
                        oldScale = 0;

                    // if (oldScale > 1)
                    //    oldScale = 1.1;

                    if (oldScale != 1)
                        dataPoint.Storyboard = AnimationHelper.ApplyPropertyAnimation(newVisual, "(UIElement.RenderTransform).(ScaleTransform.ScaleY)", dataPoint, dataPoint.Storyboard, 0,
                            new Double[] { 0, 1 }, new Double[] { oldScale, 1 }, null);

                    if ((isAnimateTop && oldTop != newTop) || (dp._oldYValue == dp.InternalYValue && oldTop != newTop))
                    {   
                        System.Diagnostics.Debug.WriteLine("Animate Top ----");
                        newVisual.SetValue(Canvas.TopProperty, oldTop);
                        dataPoint.Storyboard = AnimationHelper.ApplyPropertyAnimation(newVisual, "(Canvas.Top)", dataPoint, dataPoint.Storyboard, 0,
                              new Double[] { 0, 1 }, new Double[] { oldTop, newTop }, null);
                    }

                    if (dp == dataPoint)
                        isAnimateTop = true;

                    // Apply animation to markers if marker exists
                    if (dp.Marker != null && dp.Marker.Visual != null)
                    {
                        Double markerNewTop = (Double)dp.Marker.Visual.GetValue(Canvas.TopProperty);

                        dataPoint.Storyboard = AnimationHelper.ApplyPropertyAnimation(dp.Marker.Visual, "(Canvas.Top)", dataPoint, dataPoint.Storyboard, 0,
                            new Double[] { 0, 1 }, new Double[] { dp._oldMarkerPosition.Y, markerNewTop }, null);

                        dp.Marker.Visual.SetValue(Canvas.TopProperty, dp._oldMarkerPosition.Y);
                    }

                    if (dp.LabelVisual != null)
                    {   
                        Double labelNewTop = (Double)dp.LabelVisual.GetValue(Canvas.TopProperty);

                        dataPoint.Storyboard = AnimationHelper.ApplyPropertyAnimation(dp.LabelVisual, "(Canvas.Top)", dataPoint, dataPoint.Storyboard, 0,
                            new Double[] { 0, 1 }, new Double[] { dp._oldLabelPosition.Y, labelNewTop }, null);

                        dp.LabelVisual.SetValue(Canvas.TopProperty, dp._oldLabelPosition.Y);
                    }

                    dataPoint.Storyboard.SpeedRatio = 2;

                    // Remove old visual of the DataPoint from the columncanvas
                    dp._oldVisual = null;
                }

                dataPoint.Storyboard.SpeedRatio = 2;

                // Begin storyboard animation

#if WPF
                dataPoint.Storyboard.Begin(dataPoint.Chart._rootElement, true);
#else
                dataPoint.Storyboard.Begin();
#endif
            }

            if (columnCanvas.Parent != null)
            {
                width = chart.ChartArea.ChartVisualCanvas.Width;
                height = chart.ChartArea.ChartVisualCanvas.Height;

                RectangleGeometry clipRectangle = new RectangleGeometry();
                clipRectangle.Rect = new Rect(0, -chart.ChartArea.PLANK_DEPTH - (chart.View3D ? 0 : 5), width + chart.ChartArea.PLANK_DEPTH, height + chart.ChartArea.PLANK_DEPTH + chart.ChartArea.PLANK_THICKNESS + (chart.View3D ? 0 : 10));
                (columnCanvas.Parent as Canvas).Clip = clipRectangle;
            }

            if (dataPoint.Parent.SelectionEnabled && dataPoint.Selected)
                dataPoint.Select(true);
        }
Exemple #2
0
        // Canvas bubleChartCanvas, DataPoint dataPoint, Double minimumZVal, Double maximumZVal, Double plotWidth, Double plotHeight
        private static void CreateOrUpdateAPointDataPoint(Canvas pointChartCanvas, DataPoint dataPoint, Double plotAreaWidth, Double plotAreaHeight)
        {   
            Faces dpFaces = dataPoint.Faces;

            // Remove preexisting dataPoint visual and label visual
            if (dpFaces != null && dpFaces.Visual != null && pointChartCanvas == dpFaces.Visual.Parent)
            {
                pointChartCanvas.Children.Remove(dataPoint.Faces.Visual);
                //dpFaces = null;
            }

            dataPoint.Faces = null;
            dpFaces = new Faces();

            if (Double.IsNaN(dataPoint.InternalYValue) || (dataPoint.Enabled == false))
                return;
            
            Chart chart = dataPoint.Chart as Chart;
            PlotGroup plotGroup = dataPoint.Parent.PlotGroup;

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

            Brush markerColor = dataPoint.Color;
            //markerColor = (chart.View3D ? Graphics.GetLightingEnabledBrush3D(markerColor) :
            //    ((Boolean)dataPoint.LightingEnabled ? Graphics.GetLightingEnabledBrush(markerColor, "Linear", null) : markerColor));
            
            markerColor = (chart.View3D ? Graphics.Get3DBrushLighting(dataPoint.Color, (Boolean)dataPoint.LightingEnabled) :
                ((Boolean)dataPoint.LightingEnabled ? Graphics.GetLightingEnabledBrush(markerColor, "Linear", null) : markerColor));

            Size markerSize = new Size((Double)dataPoint.MarkerSize, (Double)dataPoint.MarkerSize);
            Boolean markerBevel = false;
            String labelText = (Boolean)dataPoint.LabelEnabled ? dataPoint.TextParser(dataPoint.LabelText) : "";
            Marker marker = new Marker((MarkerTypes)dataPoint.MarkerType, (Double)dataPoint.MarkerScale, markerSize, markerBevel, markerColor, labelText);

            marker.Tag = new ElementData() { Element = dataPoint };

            marker.ShadowEnabled = (Boolean)dataPoint.ShadowEnabled;

            if (!VisifireControl.IsMediaEffectsEnabled)
                marker.PixelLavelShadow = false;
            else
                marker.PixelLavelShadow = true;

            marker.MarkerSize = new Size((Double)dataPoint.MarkerSize, (Double)dataPoint.MarkerSize);

            if (marker.MarkerType != MarkerTypes.Cross)
            {
                if (dataPoint.BorderColor != null)
                    marker.BorderColor = dataPoint.BorderColor;
            }
            else
                marker.BorderColor = markerColor;
            marker.BorderThickness = ((Thickness)dataPoint.MarkerBorderThickness).Left;

            if (!String.IsNullOrEmpty(labelText))
            {
                marker.FontColor = Chart.CalculateDataPointLabelFontColor(chart, dataPoint, dataPoint.LabelFontColor, LabelStyles.OutSide);
                marker.FontSize = (Double)dataPoint.LabelFontSize;
                marker.FontWeight = (FontWeight)dataPoint.LabelFontWeight;
                marker.FontFamily = dataPoint.LabelFontFamily;
                marker.FontStyle = (FontStyle)dataPoint.LabelFontStyle;
                marker.TextBackground = dataPoint.LabelBackground;

                marker.TextAlignmentX = AlignmentX.Center;
                marker.TextAlignmentY = AlignmentY.Center;

                if (!Double.IsNaN(dataPoint.LabelAngle) && dataPoint.LabelAngle != 0)
                {
                    marker.LabelAngle = dataPoint.LabelAngle;
                    marker.TextOrientation = Orientation.Vertical;

                    marker.TextAlignmentX = AlignmentX.Center;
                    marker.TextAlignmentY = AlignmentY.Center;

                    marker.LabelStyle = (LabelStyles)dataPoint.LabelStyle;
                }

                marker.CreateVisual();

                if (Double.IsNaN(dataPoint.LabelAngle) || dataPoint.LabelAngle == 0)
                {
                    if ((yPosition - marker.TextBlockSize.Height / 2) < 0)
                        marker.TextAlignmentY = AlignmentY.Bottom;
                    else if ((yPosition + marker.TextBlockSize.Height / 2) > plotAreaHeight)
                        marker.TextAlignmentY = AlignmentY.Top;

                    if ((xPosition - marker.TextBlockSize.Width / 2) < 0)
                        marker.TextAlignmentX = AlignmentX.Right;
                    else if ((xPosition + marker.TextBlockSize.Width / 2) > plotAreaWidth)
                        marker.TextAlignmentX = AlignmentX.Left;
                }
            }

            //marker.LabelEnabled =(Boolean) dataPoint.LabelEnabled;
            //marker.TextBackground = dataPoint.LabelBackground;
            //marker.FontColor = Chart.CalculateDataPointLabelFontColor(chart, dataPoint, dataPoint.LabelFontColor, LabelStyles.OutSide);
            //marker.FontSize = (Double)dataPoint.LabelFontSize;
            //marker.FontWeight = (FontWeight)dataPoint.LabelFontWeight;
            //marker.FontFamily = dataPoint.LabelFontFamily;
            //marker.FontStyle = (FontStyle)dataPoint.LabelFontStyle;

            //marker.TextAlignmentX = AlignmentX.Center;
            //marker.TextAlignmentY = AlignmentY.Center;

            marker.CreateVisual();

            marker.Visual.Opacity = (Double)dataPoint.Opacity * (Double)dataPoint.Parent.Opacity;

            marker.AddToParent(pointChartCanvas, xPosition, yPosition, new Point(0.5, 0.5));

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

            dpFaces.VisualComponents.Add(marker.Visual);
            dpFaces.Visual = marker.Visual;

            dpFaces.BorderElements.Add(marker.MarkerShape);

            dataPoint.Marker = marker;
            dataPoint.Faces = dpFaces;

            dataPoint.Faces.Visual.Opacity = (Double)dataPoint.Opacity * (Double)dataPoint.Parent.Opacity;
            dataPoint.AttachEvent2DataPointVisualFaces(dataPoint);
            dataPoint.AttachEvent2DataPointVisualFaces(dataPoint.Parent);
            dataPoint._parsedToolTipText = dataPoint.TextParser(dataPoint.ToolTipText);
            if(!chart.IndicatorEnabled)
                dataPoint.AttachToolTip(chart, dataPoint, dataPoint.Faces.VisualComponents);
            dataPoint.AttachHref(chart, dataPoint.Faces.VisualComponents, dataPoint.Href, (HrefTargets)dataPoint.HrefTarget);
            dataPoint.SetCursor2DataPointVisualFaces();

            if (dataPoint.Parent.SelectionEnabled && dataPoint.Selected)
                dataPoint.Select(true);
        }
Exemple #3
0
        private static void ApplySelectionChanged(DataPoint dataPoint, Boolean selectedValue)
        {
            if (dataPoint.Parent == null)
                return;

            Boolean selected = selectedValue & dataPoint.Parent.SelectionEnabled;

            if (selected)
            {
                dataPoint.Select(true);

                if(dataPoint.Parent.SelectionMode == SelectionModes.Single ||  dataPoint.Parent.RenderAs == RenderAs.SectionFunnel || dataPoint.Parent.RenderAs == RenderAs.StreamLineFunnel)
                   dataPoint.DeSelectOthers();
            }
            else
                dataPoint.DeSelect(dataPoint , true, true);
        }
Exemple #4
0
        private static void UpdateDataPoint(DataPoint dataPoint, VcProperties property, object newValue, Boolean isAxisChanged)
        {
            Chart chart = dataPoint.Chart as Chart;
            DataSeries dataSeries = dataPoint.Parent;
            PlotGroup plotGroup = dataSeries.PlotGroup;
            Faces dsFaces = dataSeries.Faces;
            Faces dpFaces = dataPoint.Faces;
            Double dataPointWidth;

            if (dsFaces != null)
                ColumnChart.UpdateParentVisualCanvasSize(chart, dsFaces.Visual as Canvas);

            if (dpFaces != null && dpFaces.Visual != null)
                dataPointWidth = dpFaces.Visual.Width;
            else if (dsFaces == null)
                return;
            else
                dataPointWidth = CalculateDataPointWidth(dsFaces.Visual.Width, dsFaces.Visual.Height, chart);
            
            switch (property)
            {   
                case VcProperties.BorderThickness:
                      ApplyOrUpdateBorder(dataPoint, dataPointWidth);
                      ApplyOrRemoveBevel(dataPoint, dataPointWidth);
                    break;

                case VcProperties.BorderStyle:
                    ApplyOrUpdateBorder(dataPoint, dataPointWidth);
                    break;

                case VcProperties.BorderColor:
                    ApplyOrUpdateBorder(dataPoint, dataPointWidth);
                    break;

                case VcProperties.Bevel:
                    ApplyOrRemoveBevel(dataPoint, dataPointWidth);
                    break;

                case VcProperties.Color:
                case VcProperties.PriceUpColor:
                case VcProperties.PriceDownColor:
                    ApplyOrUpdateColorForACandleStick(dataPoint);
                    break;
                    
                case VcProperties.Cursor:
                    dataPoint.SetCursor2DataPointVisualFaces();
                    break;

                case VcProperties.Href:
                    dataPoint.SetHref2DataPointVisualFaces();
                    break;

                case VcProperties.HrefTarget:
                    dataPoint.SetHref2DataPointVisualFaces();
                    break;

                case VcProperties.LabelBackground:
                case VcProperties.LabelEnabled:
                case VcProperties.LabelFontColor:
                case VcProperties.LabelFontFamily:
                case VcProperties.LabelFontStyle:
                case VcProperties.LabelFontSize:
                case VcProperties.LabelFontWeight:
                case VcProperties.LabelStyle:
                case VcProperties.LabelText:
                    CreateAndPositionLabel(dsFaces.LabelCanvas, dataPoint);
                    break;


                case VcProperties.LegendText:
                    chart.InvokeRender();
                    break;

                case VcProperties.LightingEnabled:
                    ApplyOrUpdateColorForACandleStick(dataPoint);
                    break;

                //case VcProperties.MarkerBorderColor:
                //case VcProperties.MarkerBorderThickness:
                //case VcProperties.MarkerColor:
                //case VcProperties.MarkerEnabled:
                //case VcProperties.MarkerScale:
                //case VcProperties.MarkerSize:
                //case VcProperties.MarkerType:
                case VcProperties.ShadowEnabled:
                    ApplyOrRemoveShadow(dataPoint, dataPointWidth);
                    break;

                case VcProperties.Opacity:
                    dpFaces.Visual.Opacity = dataSeries.Opacity * dataPoint.Opacity;
                    break;

                case VcProperties.ShowInLegend:
                    chart.InvokeRender();
                    break;
                case VcProperties.ToolTipText:
                    dataPoint._parsedToolTipText = dataPoint.TextParser(dataPoint.ToolTipText);
                    break;

                case VcProperties.XValueFormatString:
                case VcProperties.YValueFormatString:
                    dataPoint._parsedToolTipText = dataPoint.TextParser(dataPoint.ToolTipText);
                    CreateAndPositionLabel(dsFaces.LabelCanvas, dataPoint);
                    break;

                case VcProperties.XValueType:
                    chart.InvokeRender();
                    break;

                case VcProperties.Enabled:
                    CreateOrUpdateACandleStick(dataPoint, dsFaces.Visual as Canvas, dsFaces.LabelCanvas, dsFaces.Visual.Width, dsFaces.Visual.Height, dataPointWidth);
                    break;

                case VcProperties.XValue:
                case VcProperties.YValues:
                    if (isAxisChanged)
                        UpdateDataSeries(dataSeries, property, newValue, isAxisChanged);
                    else
                    {
                        dataPoint._parsedToolTipText = dataPoint.TextParser(dataPoint.ToolTipText);
                        UpdateYValueAndXValuePosition(dataPoint, dsFaces.Visual.Width, dsFaces.Visual.Height, dpFaces.Visual.Width);
                        
                        if ((Boolean)dataPoint.LabelEnabled)
                            CreateAndPositionLabel(dsFaces.LabelCanvas, dataPoint);
                    }

                    if (dataPoint.Parent.SelectionEnabled && dataPoint.Selected)
                        dataPoint.Select(true);
                    
                        break;
            }
        }
Exemple #5
0
        private static void UpdateDataPoint(DataPoint dataPoint, VcProperties property, object newValue, Boolean isAxisChanged)
        {
            Chart chart = dataPoint.Chart as Chart;

            if (chart == null)
                return;

            DataSeries dataSeries = dataPoint.Parent;
            PlotGroup plotGroup = dataSeries.PlotGroup;
            Faces dsFaces = dataSeries.Faces;
            Faces dpFaces = dataPoint.Faces;
            
            Double dataPointWidth;

            if (dsFaces != null)
                ColumnChart.UpdateParentVisualCanvasSize(chart, dsFaces.Visual as Canvas);

            if (dpFaces != null && dpFaces.Visual != null)
                dataPointWidth = dpFaces.Visual.Width;
            else if (dsFaces == null)
                return;
            else
                dataPointWidth = CandleStick.CalculateDataPointWidth(dsFaces.Visual.Width, dsFaces.Visual.Height, chart);

            if (property == VcProperties.Enabled || (dpFaces == null && (property == VcProperties.XValue || property == VcProperties.YValues)))
            {
                CreateOrUpdateAStockDataPoint(dataPoint, dsFaces.Visual as Canvas, dsFaces.LabelCanvas, dsFaces.Visual.Width, dsFaces.Visual.Height, dataPointWidth);
                return;
            }

            if (dpFaces == null)
                return;

            Canvas dataPointVisual = dpFaces.Visual as Canvas;       // DataPoint visual canvas
            Line highLowLine = dpFaces.VisualComponents[0] as Line;  // HighLowline
            Line closeLine = dpFaces.VisualComponents[1] as Line;    // Closeline
            Line openLine = dpFaces.VisualComponents[2] as Line;     // Openline

            switch (property)
            {   
                case VcProperties.BorderThickness:
                case VcProperties.BorderStyle:
                    ApplyBorderProperties(dataPoint, highLowLine, openLine, closeLine, dataPointWidth);
                    break;

                case VcProperties.Color:
                    ApplyOrUpdateColorForAStockDp(dataPoint, highLowLine, openLine, closeLine);
                    break;

                case VcProperties.Cursor:
                    dataPoint.SetCursor2DataPointVisualFaces();
                    break;

                case VcProperties.Href:
                    dataPoint.SetHref2DataPointVisualFaces();
                    break;

                case VcProperties.HrefTarget:
                    dataPoint.SetHref2DataPointVisualFaces();
                    break;

                case VcProperties.LabelBackground:
                case VcProperties.LabelEnabled:
                case VcProperties.LabelFontColor:
                case VcProperties.LabelFontFamily:
                case VcProperties.LabelFontStyle:
                case VcProperties.LabelFontSize:
                case VcProperties.LabelFontWeight:
                case VcProperties.LabelStyle:
                case VcProperties.LabelText:
                    CandleStick.CreateAndPositionLabel(dsFaces.LabelCanvas, dataPoint);
                    break;

                case VcProperties.LegendText:
                    chart.InvokeRender();
                    break;

                case VcProperties.LightingEnabled:
                    ApplyOrUpdateColorForAStockDp(dataPoint, highLowLine, openLine, closeLine);
                    break;

                //case VcProperties.MarkerBorderColor:
                //case VcProperties.MarkerBorderThickness:
                //case VcProperties.MarkerColor:
                //case VcProperties.MarkerEnabled:
                //case VcProperties.MarkerScale:
                //case VcProperties.MarkerSize:
                //case VcProperties.MarkerType:
                case VcProperties.ShadowEnabled:
                    ApplyOrUpdateShadow(dataPoint, dataPointVisual, highLowLine, openLine, closeLine, dataPointWidth);
                    break;

                case VcProperties.Opacity:
                    dpFaces.Visual.Opacity = (Double)dataSeries.Opacity * (Double)dataPoint.Opacity;
                    break;

                case VcProperties.ShowInLegend:
                    chart.InvokeRender();
                    break;

                case VcProperties.ToolTipText:
                    dataPoint._parsedToolTipText = dataPoint.TextParser(dataPoint.ToolTipText);
                    break;

                case VcProperties.XValueFormatString:
                case VcProperties.YValueFormatString:
                    dataPoint._parsedToolTipText = dataPoint.TextParser(dataPoint.ToolTipText);
                    CandleStick.CreateAndPositionLabel(dsFaces.LabelCanvas, dataPoint);
                    break;

                case VcProperties.XValueType:
                    chart.InvokeRender();
                    break;

                case VcProperties.Enabled:
                    CreateOrUpdateAStockDataPoint(dataPoint, dsFaces.Visual as Canvas, dsFaces.LabelCanvas, dsFaces.Visual.Width, dsFaces.Visual.Height, dataPointWidth);
                    break;

                case VcProperties.XValue:
                case VcProperties.YValue:
                case VcProperties.YValues:
                    if (isAxisChanged || dataPoint.InternalYValues == null)
                        UpdateDataSeries(dataSeries, property, newValue, isAxisChanged);
                    else
                    {
                        dataPoint._parsedToolTipText = dataPoint.TextParser(dataPoint.ToolTipText);
                        UpdateYValueAndXValuePosition(dataPoint, dsFaces.Visual.Width, dsFaces.Visual.Height, dpFaces.Visual.Width);

                        if ((Boolean)dataPoint.LabelEnabled)
                            CandleStick.CreateAndPositionLabel(dsFaces.LabelCanvas, dataPoint);
                    }

                    if (dataPoint.Parent.SelectionEnabled && dataPoint.Selected)
                        dataPoint.Select(true);

                    break;
            }
        }
        public static void UpdateVisualForYValue4StackedBarChart(RenderAs chartType, Chart chart, DataPoint dataPoint, Boolean isAxisChanged)
        {
            //if (dataPoint.Faces == null)
            //    return;

            if (chart != null && !chart._internalPartialUpdateEnabled)
                return;

            Boolean animationEnabled = (Boolean)chart.AnimatedUpdate;                                            // Whether the animation for the DataPoint is enabled   
            DataSeries dataSeries = dataPoint.Parent;                                   // parent of the current DataPoint
            Canvas columnCanvas, labelCanvas;

            PlotGroup plotGroup = dataSeries.PlotGroup;                                 // PlotGroup reference

            // Calculate 3d depth for the DataPoints
            Double depth3d = chart.ChartArea.PLANK_DEPTH / chart.PlotDetails.Layer3DCount * (chart.View3D ? 1 : 0);

            // Calculate required parameters for Creating new Stacked Columns
            Double minDiff, heightPerBar, maxBarHeight;

            // Calculate limiting value
            Double limitingYValue = (plotGroup.AxisY.InternalAxisMinimum > 0) ? plotGroup.AxisY.InternalAxisMinimum : (plotGroup.AxisY.InternalAxisMaximum < 0) ? plotGroup.AxisY.InternalAxisMaximum : 0;

            if (dataPoint.Faces == null)
            {
                if (dataSeries != null && dataSeries.Faces != null)
                {
                    labelCanvas = dataSeries.Faces.LabelCanvas as Canvas;
                    columnCanvas = dataSeries.Faces.Visual as Canvas;

                    heightPerBar = CalculateWidthOfEachStackedColumn(chart, plotGroup, columnCanvas.Height, out minDiff, out  maxBarHeight);

                    if (dataPoint.Parent.RenderAs == RenderAs.StackedBar || dataPoint.Parent.RenderAs == RenderAs.StackedBar100)
                    {
                        // Create new Column with new YValue
                        BarChart.DrawStackedBarsAtXValue(chartType, dataPoint.InternalXValue, plotGroup, columnCanvas, labelCanvas, plotGroup.DrawingIndex, heightPerBar, maxBarHeight, limitingYValue, depth3d, false);
                    }

                    if (dataPoint.Faces == null)
                        return;
                }
                else
                {
                    UpdateDataSeries(dataSeries, VcProperties.YValue, null);
                    return;
                }
            }

            Canvas dataPointVisual = dataPoint.Faces.Visual as Canvas;                  // Old visual for the column
            labelCanvas = dataPoint.Faces.LabelCanvas;  // Parent canvas of Datapoint label

            if (labelCanvas == null)
                return;

            columnCanvas = (labelCanvas.Parent as Canvas).Children[1] as Canvas;//dataPointVisual.Parent as Canvas;                     // Existing parent canvas of column

            heightPerBar = CalculateWidthOfEachStackedColumn(chart, plotGroup, columnCanvas.Height, out minDiff, out  maxBarHeight);

            UpdateParentVisualCanvasSize(chart, columnCanvas);
            UpdateParentVisualCanvasSize(chart, labelCanvas);

            // List of effected DataPoints for the current update of YValue property of the DataPoint
            XWiseStackedData effectedDataPoints = plotGroup.XWiseStackedDataList[dataPoint.InternalXValue];

            // Marging all DataPoints in to single a single list of DataPoint
            List<DataPoint> positiveList = effectedDataPoints.Positive.ToList();
            List<DataPoint> negativeList = effectedDataPoints.Negative.ToList();
            List<DataPoint> listOfDataPoint = new List<DataPoint>();
            listOfDataPoint.AddRange(positiveList);
            listOfDataPoint.AddRange(negativeList);

            // Storing reference of old Visual 
            foreach (DataPoint dp in listOfDataPoint)
            {
                if (dp.Marker != null && dp.Marker.Visual != null)
                    dp._oldMarkerPosition = new Point((Double)dp.Marker.Visual.GetValue(Canvas.LeftProperty), (Double)dp.Marker.Visual.GetValue(Canvas.TopProperty));
                    
                if (dp.LabelVisual != null)
                    dp._oldLabelPosition = new Point((Double)dp.LabelVisual.GetValue(Canvas.LeftProperty), (Double)dp.LabelVisual.GetValue(Canvas.TopProperty));
                    
                if (dp.Faces != null)
                {   
                    dp._oldVisual = dp.Faces.Visual;
                    columnCanvas.Children.Remove(dp._oldVisual);
                    CleanUpMarkerAndLabel(dp, labelCanvas);
                }
            }

            // Create new Column with new YValue
            BarChart.DrawStackedBarsAtXValue(chartType, dataPoint.InternalXValue, plotGroup, columnCanvas, labelCanvas, plotGroup.DrawingIndex, dataPointVisual.Height, maxBarHeight, limitingYValue, depth3d, false);

            if (dataSeries.ToolTipElement != null)
                dataSeries.ToolTipElement.Hide();

            CreateOrUpdatePlank(chart, dataSeries.PlotGroup.AxisY, columnCanvas, depth3d,
                (dataPoint.Parent.RenderAs == RenderAs.StackedColumn || dataPoint.Parent.RenderAs == RenderAs.StackedColumn100) ? Orientation.Horizontal : Orientation.Vertical);

            Boolean isPositive;

            if (animationEnabled)
            {   
                // Create new Storyboard for animation
                if (dataPoint.Storyboard != null)
                {
                    dataPoint.Storyboard.Stop();
                    //dataPoint.Storyboard = null;
                    dataPoint.Storyboard.Children.Clear();
                }

                if (dataPoint.Storyboard == null)
                    dataPoint.Storyboard = new Storyboard();

                // Whether to animate the top of DataPoint Visual
                Boolean isAnimateLeft = false;

                // Loop through all Datapoints under the PlotGroup of the current DataPoint and apply animation
                foreach (DataPoint dp in listOfDataPoint)
                {   
                    if (dp.Faces == null || dp._oldVisual == null)
                        continue;

                    FrameworkElement newVisual = dp.Faces.Visual;                          // New StackedColumn visual reference of DataPoint
                    Double oldLeft = (Double)dp._oldVisual.GetValue(Canvas.LeftProperty);  // Left of the old visual of the DataPoint
                    Double newLeft = (Double)newVisual.GetValue(Canvas.LeftProperty);      // Left of the new visual of the DataPoint
                    Double oldWidth = dp._oldVisual.Width;                                 // Width of the old visual of the DataPoint
                    Double newWidth = newVisual.Width;                                     // Width of the new visual of the DataPoint
                    Double oldScale = oldWidth / newWidth;                                 // Scale value for the old DataPoint                       

                    if (dp == dataPoint)
                    {   
                        isPositive = (dataPoint._oldYValue < 0 && dataPoint.InternalYValue > 0) ? true :
                            (dataPoint._oldYValue > 0 && dataPoint.InternalYValue < 0) ? false :
                            dp._oldYValue >= 0 ? true : false;
                    }
                    else
                        isPositive = dp.InternalYValue >= 0 ? true : false;
                        
                    if (isPositive)
                        newVisual.RenderTransformOrigin = new Point(0, 0.5);
                    else
                        newVisual.RenderTransformOrigin = new Point(1, 0.5);

                    // Apply new RenderTransform to the DataPoint Visual
                    newVisual.RenderTransform = new ScaleTransform();

                    if (Double.IsInfinity(oldScale) || Double.IsNaN(oldScale))
                        oldScale = 0;
                        
                    if (oldScale != 1)
                        dataPoint.Storyboard = AnimationHelper.ApplyPropertyAnimation(newVisual, "(UIElement.RenderTransform).(ScaleTransform.ScaleX)", dataPoint, dataPoint.Storyboard, 0,
                            new Double[] { 0, 1 }, new Double[] { oldScale, 1 }, null);
                        
                    if ((isAnimateLeft && oldLeft != newLeft) || dp._oldYValue == dp.InternalYValue && oldLeft != newLeft)
                    {   
                        newVisual.SetValue(Canvas.LeftProperty, oldLeft);

                        dataPoint.Storyboard = AnimationHelper.ApplyPropertyAnimation(newVisual, "(Canvas.Left)", dataPoint, dataPoint.Storyboard, 0,
                               new Double[] { 0, 1 }, new Double[] { oldLeft, newLeft }, null);
                    }

                    if (dp == dataPoint)
                        isAnimateLeft = true;

                    // Apply animation to markers if marker exists
                    if (dp.Marker != null && dp.Marker.Visual != null)
                    {   
                        Double markerNewLeft = (Double)dp.Marker.Visual.GetValue(Canvas.LeftProperty);

                        dp.Marker.Visual.SetValue(Canvas.LeftProperty, dp._oldMarkerPosition.X);

                        dataPoint.Storyboard = AnimationHelper.ApplyPropertyAnimation(dp.Marker.Visual, "(Canvas.Left)", dataPoint, dataPoint.Storyboard, 0,
                            new Double[] { 0, 1 }, new Double[] { dp._oldMarkerPosition.X, markerNewLeft }, null);
                    }

                    if (dp.LabelVisual != null)
                    {
                        Double labelNewLeft = (Double)dp.LabelVisual.GetValue(Canvas.LeftProperty);
                        System.Diagnostics.Debug.WriteLine("oldPos=" + dp._oldLabelPosition.X.ToString() + " NewPos=" + labelNewLeft.ToString());
                        dp.LabelVisual.SetValue(Canvas.LeftProperty, dp._oldLabelPosition.X);

                        dataPoint.Storyboard = AnimationHelper.ApplyPropertyAnimation(dp.LabelVisual, "(Canvas.Left)", dataPoint, dataPoint.Storyboard, 0,
                            new Double[] { 0, 1 }, new Double[] { dp._oldLabelPosition.X, labelNewLeft }, null);

                    }

                    dataPoint.Storyboard.SpeedRatio = 2;

                    // Remove old visual of the DataPoint from the columncanvas
                    dp._oldVisual = null;
                }

                dataPoint.Storyboard.SpeedRatio = 2;

                // Begin storyboard animation

#if WPF
                dataPoint.Storyboard.Begin(dataPoint.Chart._rootElement, true);
#else
                dataPoint.Storyboard.Begin();
#endif
            }

            if (columnCanvas.Parent != null)
            {
                Double width = chart.ChartArea.ChartVisualCanvas.Width;
                Double height = chart.ChartArea.ChartVisualCanvas.Height;

                RectangleGeometry clipRectangle = new RectangleGeometry();
              
                clipRectangle.Rect = new Rect(-(chart.View3D ? 0 : 5) - chart.ChartArea.PLANK_THICKNESS, -chart.ChartArea.PLANK_DEPTH, width + chart.ChartArea.PLANK_DEPTH + chart.ChartArea.PLANK_THICKNESS + (chart.View3D ? 0 : 10)
                    , height + chart.ChartArea.PLANK_DEPTH);
                (columnCanvas.Parent as Canvas).Clip = clipRectangle;
            }

            if (dataPoint.Parent.SelectionEnabled && dataPoint.Selected)
                dataPoint.Select(true);
        }
Exemple #7
0
        private static void CreateOrUpdateAPointDataPoint(Canvas bubleChartCanvas, DataPoint dataPoint, Double minimumZVal, Double maximumZVal, Double plotWidth, Double plotHeight)
        {
            Faces dpFaces = dataPoint.Faces;

            // Remove preexisting dataPoint visual and label visual
            if (dpFaces != null && dpFaces.Visual != null && bubleChartCanvas == dpFaces.Visual.Parent)
            {   
                bubleChartCanvas.Children.Remove(dataPoint.Faces.Visual);
                // dpFaces = null;
            }

            dataPoint.Faces = null;

            if (Double.IsNaN(dataPoint.InternalYValue) || (dataPoint.Enabled == false))
                return;

            Chart chart = dataPoint.Chart as Chart;

            PlotGroup plotGroup = dataPoint.Parent.PlotGroup;

            Canvas dataPointVisual = new Canvas();

            Faces bubbleFaces = new Faces();

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

            Brush markerColor = dataPoint.Color;
            markerColor = (chart.View3D ? Graphics.Get3DBrushLighting(markerColor, (Boolean)dataPoint.LightingEnabled) : ((Boolean)dataPoint.LightingEnabled ? Graphics.GetLightingEnabledBrush(markerColor, "Linear", null) : markerColor));
            
            String labelText = (Boolean)dataPoint.LabelEnabled ? dataPoint.TextParser(dataPoint.LabelText) : "";

            Marker marker = new Marker((MarkerTypes)dataPoint.MarkerType, 1, new Size(6,6), false, markerColor, labelText);
            dataPoint.Marker = marker;

            ApplyZValue(dataPoint, minimumZVal, maximumZVal, plotWidth, plotHeight);
                       
            marker.ShadowEnabled = (Boolean)dataPoint.ShadowEnabled;

            if (dataPoint.BorderColor != null)
                marker.BorderColor = dataPoint.BorderColor;

            marker.TextBackground = dataPoint.LabelBackground;
            marker.BorderThickness = ((Thickness)dataPoint.MarkerBorderThickness).Left;
            marker.TextAlignmentX = AlignmentX.Center;
            marker.TextAlignmentY = AlignmentY.Center;
            marker.Tag = new ElementData() { Element = dataPoint };

            Double gap = ((Double)dataPoint.MarkerScale * (Double)dataPoint.MarkerSize) / 2;

            if (!String.IsNullOrEmpty(labelText))
            {
                marker.FontColor = Chart.CalculateDataPointLabelFontColor(chart, dataPoint, dataPoint.LabelFontColor, LabelStyles.OutSide);
                marker.FontSize = (Double)dataPoint.LabelFontSize;
                marker.FontWeight = (FontWeight)dataPoint.LabelFontWeight;
                marker.FontFamily = dataPoint.LabelFontFamily;
                marker.FontStyle = (FontStyle)dataPoint.LabelFontStyle;
                marker.TextBackground = dataPoint.LabelBackground;

                marker.TextAlignmentX = AlignmentX.Center;
                marker.TextAlignmentY = AlignmentY.Center;

                if (!Double.IsNaN(dataPoint.LabelAngle) && dataPoint.LabelAngle != 0)
                {
                    marker.LabelAngle = dataPoint.LabelAngle;
                    marker.TextOrientation = Orientation.Vertical;

                    marker.TextAlignmentX = AlignmentX.Center;
                    marker.TextAlignmentY = AlignmentY.Center;

                    marker.LabelStyle = (LabelStyles)dataPoint.LabelStyle;
                }

                marker.CreateVisual();

                if (Double.IsNaN(dataPoint.LabelAngle) || dataPoint.LabelAngle == 0)
                {
                    if (yPosition - gap < 0 && (yPosition - marker.TextBlockSize.Height / 2) < 0)
                        marker.TextAlignmentY = AlignmentY.Bottom;
                    else if (yPosition + gap > plotHeight && (yPosition + marker.TextBlockSize.Height / 2) > plotHeight)
                        marker.TextAlignmentY = AlignmentY.Top;

                    if (xPosition - gap < 0 && (xPosition - marker.TextBlockSize.Width / 2) < 0)
                        marker.TextAlignmentX = AlignmentX.Right;
                    else if (xPosition + gap > plotWidth && (xPosition + marker.TextBlockSize.Width / 2) > plotWidth)
                        marker.TextAlignmentX = AlignmentX.Left;
                }
            }

            marker.PixelLavelShadow = false; // pixelLavelShadow;
            marker.CreateVisual();

            UpdateBubblePositionAccording2XandYValue(dataPoint, plotWidth, plotHeight, false, 0, 0);
            bubleChartCanvas.Children.Add(marker.Visual);
            
            bubbleFaces.Parts.Add(marker.MarkerShape);
            bubbleFaces.VisualComponents.Add(marker.Visual);
            bubbleFaces.BorderElements.Add(marker.MarkerShape);

            bubbleFaces.Visual = marker.Visual;
            dataPoint.Faces = bubbleFaces;

            dataPoint.Faces.Visual.Opacity = dataPoint.Opacity * dataPoint.Parent.Opacity;
            dataPoint.AttachEvent2DataPointVisualFaces(dataPoint);
            dataPoint.AttachEvent2DataPointVisualFaces(dataPoint.Parent);
            dataPoint._parsedToolTipText = dataPoint.TextParser(dataPoint.ToolTipText);
            dataPoint.AttachToolTip(chart, dataPoint, dataPoint.Faces.VisualComponents);
            dataPoint.AttachHref(chart, dataPoint.Faces.VisualComponents, dataPoint.Href, (HrefTargets)dataPoint.HrefTarget);
            dataPoint.SetCursor2DataPointVisualFaces();

            if (dataPoint.Parent.SelectionEnabled && dataPoint.Selected)
                dataPoint.Select(true);
        }