private static void UpdateDataSeries(DataSeries dataSeries, VcProperties property, object newValue, Boolean isAxisChanged) { Chart chart = dataSeries.Chart as Chart; if (chart == null) { return; } switch (property) { case VcProperties.DataPoints: //case VcProperties.YValues: chart.ChartArea.RenderSeries(); //Canvas ChartVisualCanvas = chart.ChartArea.ChartVisualCanvas; //Double width = chart.ChartArea.ChartVisualCanvas.Width; //Double height = chart.ChartArea.ChartVisualCanvas.Height; //PlotDetails plotDetails = chart.PlotDetails; //PlotGroup plotGroup = dataSeries.PlotGroup; //List<DataSeries> dataSeriesListInDrawingOrder = plotDetails.SeriesDrawingIndex.Keys.ToList(); //List<DataSeries> selectedDataSeries4Rendering = new List<DataSeries>(); //RenderAs currentRenderAs = dataSeries.RenderAs; //Int32 currentDrawingIndex = plotDetails.SeriesDrawingIndex[dataSeries]; //for (Int32 i = 0; i < chart.InternalSeries.Count; i++) //{ // if (currentRenderAs == dataSeriesListInDrawingOrder[i].RenderAs && currentDrawingIndex == plotDetails.SeriesDrawingIndex[dataSeriesListInDrawingOrder[i]]) // selectedDataSeries4Rendering.Add(dataSeriesListInDrawingOrder[i]); //} //if (selectedDataSeries4Rendering.Count == 0) // return; //Panel oldPanel = null; //Dictionary<RenderAs, Panel> RenderedCanvasList = chart.ChartArea.RenderedCanvasList; //if (chart.ChartArea.RenderedCanvasList.ContainsKey(currentRenderAs)) //{ // oldPanel = RenderedCanvasList[currentRenderAs]; //} //Panel renderedChart = chart.ChartArea.RenderSeriesFromList(oldPanel, selectedDataSeries4Rendering); //if (oldPanel == null) //{ // chart.ChartArea.RenderedCanvasList.Add(currentRenderAs, renderedChart); // renderedChart.SetValue(Canvas.ZIndexProperty, currentDrawingIndex); // ChartVisualCanvas.Children.Add(renderedChart); //} //else // chart.ChartArea.RenderedCanvasList[currentRenderAs] = renderedChart; break; default: List <DataPoint> dataPointsInViewPort = RenderHelper.GetDataPointsUnderViewPort(dataSeries, false); // case VcProperties.Enabled: foreach (DataPoint dataPoint in dataPointsInViewPort) { UpdateDataPoint(dataPoint, property, newValue, isAxisChanged); } break; } }
/// <summary> /// Get visual object for point chart /// </summary> /// <param name="width">Width of the charat</param> /// <param name="height">Height of the charat</param> /// <param name="plotDetails">plotDetails</param> /// <param name="seriesList">List of DataSeries</param> /// <param name="chart">Chart</param> /// <param name="plankDepth">Plank depth</param> /// <param name="animationEnabled">Whether animation is enabled</param> /// <returns>Point chart canvas</returns> internal static Canvas GetVisualObjectForPointChart(Panel preExistingPanel, Double plotAreaWidth, Double plotAreaHeight, PlotDetails plotDetails, List <DataSeries> seriesList, Chart chart, Double plankDepth, bool animationEnabled) { if (Double.IsNaN(plotAreaWidth) || Double.IsNaN(plotAreaHeight) || plotAreaWidth <= 0 || plotAreaHeight <= 0) { return(null); } Canvas visual, pointChartCanvas; // pointChartCanvas holds all points for all series RenderHelper.RepareCanvas4Drawing(preExistingPanel as Canvas, out visual, out pointChartCanvas, plotAreaWidth, plotAreaHeight); Double depth3d = plankDepth / (plotDetails.Layer3DCount == 0 ? 1 : plotDetails.Layer3DCount) * (chart.View3D ? 1 : 0); Double visualOffset = depth3d * (plotDetails.SeriesDrawingIndex[seriesList[0]] + 1 - (plotDetails.Layer3DCount == 0 ? 0 : 1)); visual.SetValue(Canvas.TopProperty, visualOffset); visual.SetValue(Canvas.LeftProperty, -visualOffset); foreach (DataSeries series in seriesList) { series.Faces = new Faces() { Visual = pointChartCanvas }; if (series.Enabled == false) { continue; } List <DataPoint> dataPointsInViewPort = RenderHelper.GetDataPointsUnderViewPort(series, false); foreach (DataPoint dataPoint in dataPointsInViewPort) { CreateOrUpdateAPointDataPoint(pointChartCanvas, dataPoint, plotAreaWidth, plotAreaHeight); // Apply initial animation if (animationEnabled && dataPoint.Marker != null) { if (dataPoint.Parent.Storyboard == null) { dataPoint.Parent.Storyboard = new Storyboard(); } // Apply animation to the points dataPoint.Parent.Storyboard = ApplyPointChartAnimation(dataPoint.Parent, dataPoint.Marker.Visual, dataPoint.Parent.Storyboard, plotAreaWidth, plotAreaHeight); } } } Double tickLengthOfAxisX = (from tick in chart.AxesX[0].Ticks where (Boolean)chart.AxesX[0].Enabled && (Boolean)tick.Enabled select(Double) tick.TickLength).Sum(); if (tickLengthOfAxisX == 0) { tickLengthOfAxisX = 5; } Double tickLengthOfPrimaryAxisY = (from axis in chart.AxesY where axis.AxisType == AxisTypes.Primary from tick in axis.Ticks where (Boolean)axis.Enabled && (Boolean)tick.Enabled select(Double) tick.TickLength).Sum(); if (tickLengthOfPrimaryAxisY == 0) { tickLengthOfPrimaryAxisY = 8; } Double tickLengthOfSecondaryAxisY = (from axis in chart.AxesY where axis.AxisType == AxisTypes.Secondary from tick in axis.Ticks where (Boolean)axis.Enabled && (Boolean)tick.Enabled select(Double) tick.TickLength).Sum(); if (tickLengthOfSecondaryAxisY == 0) { tickLengthOfSecondaryAxisY = 8; } Double plotGroupCount = (from c in chart.PlotDetails.PlotGroups where c.AxisY.AxisType == AxisTypes.Secondary select c).Count(); RectangleGeometry clipRectangle = new RectangleGeometry(); clipRectangle.Rect = new Rect(-tickLengthOfPrimaryAxisY, -chart.ChartArea.PLANK_DEPTH - 4, plotAreaWidth + tickLengthOfSecondaryAxisY + (plotGroupCount > 0 ? tickLengthOfPrimaryAxisY : 8) + chart.ChartArea.PLANK_OFFSET, plotAreaHeight + chart.ChartArea.PLANK_DEPTH + chart.ChartArea.PLANK_THICKNESS + tickLengthOfAxisX + 4); visual.Clip = clipRectangle; return(visual); }
/// <summary> /// Get visual object for bubble chart /// </summary> /// <param name="width">Width of the chart</param> /// <param name="height">Height of the chart</param> /// <param name="plotDetails">plotDetails</param> /// <param name="seriesList">List of DataSeries</param> /// <param name="chart">Chart</param> /// <param name="plankDepth">Plank depth</param> /// <param name="animationEnabled">Whether animation is enabled</param> /// <returns>Bubble chart canvas</returns> internal static Canvas GetVisualObjectForBubbleChart(Panel preExistingPanel, Double width, Double height, PlotDetails plotDetails, List <DataSeries> seriesList, Chart chart, Double plankDepth, bool animationEnabled) { if (Double.IsNaN(width) || Double.IsNaN(height) || width <= 0 || height <= 0) { return(null); } // Visual for all bubble charts, Nothing but presisting visual for buble chart Canvas visual; // Holds all bubbles of all series Canvas bubbleChartCanvas; RenderHelper.RepareCanvas4Drawing(preExistingPanel as Canvas, out visual, out bubbleChartCanvas, width, height); Double depth3d = plankDepth / (plotDetails.Layer3DCount == 0 ? 1 : plotDetails.Layer3DCount) * (chart.View3D ? 1 : 0); Double visualOffset = depth3d * (plotDetails.SeriesDrawingIndex[seriesList[0]] + 1 - (plotDetails.Layer3DCount == 0 ? 0 : 1)); visual.SetValue(Canvas.TopProperty, visualOffset); visual.SetValue(Canvas.LeftProperty, -visualOffset); Double minimumZVal, maximumZVal; CalculateMaxAndMinZValueFromAllSeries(ref seriesList, out minimumZVal, out maximumZVal); foreach (DataSeries series in seriesList) { Faces dsFaces = new Faces() { Visual = bubbleChartCanvas }; series.Faces = dsFaces; if (series.Enabled == false) { continue; } //out Double minimumZVal, out Double maximumZVal PlotGroup plotGroup = series.PlotGroup; List <DataPoint> dataPointsInViewPort = RenderHelper.GetDataPointsUnderViewPort(series, false); foreach (DataPoint dataPoint in dataPointsInViewPort) { CreateOrUpdateAPointDataPoint(bubbleChartCanvas, dataPoint, minimumZVal, maximumZVal, width, height); // Apply animation if (animationEnabled && dataPoint.Marker != null) { if (dataPoint.Parent.Storyboard == null) { dataPoint.Parent.Storyboard = new Storyboard(); } // Apply animation to the bubbles dataPoint.Parent.Storyboard = ApplyBubbleChartAnimation(dataPoint.Parent, dataPoint.Marker.Visual, dataPoint.Parent.Storyboard, width, height); } } } RectangleGeometry clipRectangle = new RectangleGeometry(); clipRectangle.Rect = new Rect(0, -chart.ChartArea.PLANK_DEPTH, width + chart.ChartArea.PLANK_OFFSET, height + chart.ChartArea.PLANK_DEPTH); visual.Clip = clipRectangle; return(visual); }
/// <summary> /// Get visual object for CandleStick chart /// </summary> /// <param name="width">Width of the chart</param> /// <param name="height">Height of the chart</param> /// <param name="plotDetails">plotDetails</param> /// <param name="seriesList">List of DataSeries</param> /// <param name="chart">Chart</param> /// <param name="plankDepth">Plank depth</param> /// <param name="animationEnabled">Whether animation is enabled</param> /// <returns>CandleStick chart canvas</returns> internal static Canvas GetVisualObjectForCandleStick(Panel preExistingPanel, Double width, Double height, PlotDetails plotDetails, List <DataSeries> seriesList, Chart chart, Double plankDepth, bool animationEnabled) { // return new Canvas() { Background = Graphics.GetRandonColor() , Width = width, Height = height}; if (Double.IsNaN(width) || Double.IsNaN(height) || width <= 0 || height <= 0) { return(null); } Canvas visual, labelCanvas, candleStickCanvas; RenderHelper.RepareCanvas4Drawing(preExistingPanel as Canvas, out visual, out labelCanvas, out candleStickCanvas, width, height); Double depth3d = plankDepth / (plotDetails.Layer3DCount == 0 ? 1 : plotDetails.Layer3DCount) * (chart.View3D ? 1 : 0); Double visualOffset = depth3d * (plotDetails.SeriesDrawingIndex[seriesList[0]] + 1 - (plotDetails.Layer3DCount == 0 ? 0 : 1)); visual.SetValue(Canvas.TopProperty, visualOffset); visual.SetValue(Canvas.LeftProperty, -visualOffset); Double animationBeginTime = 0; DataSeries _tempDataSeries = null; // Calculate width of a DataPoint Double dataPointWidth = CalculateDataPointWidth(width, height, chart); foreach (DataSeries series in seriesList) { if (series.Enabled == false) { continue; } Faces dsFaces = new Faces() { Visual = candleStickCanvas, LabelCanvas = labelCanvas }; series.Faces = dsFaces; PlotGroup plotGroup = series.PlotGroup; _tempDataSeries = series; foreach (DataPoint dataPoint in series.InternalDataPoints) { CreateOrUpdateACandleStick(dataPoint, candleStickCanvas, labelCanvas, width, height, dataPointWidth); } // Apply animation to series if (animationEnabled) { if (_tempDataSeries.Storyboard == null) { _tempDataSeries.Storyboard = new Storyboard(); } _tempDataSeries.Storyboard = AnimationHelper.ApplyOpacityAnimation(candleStickCanvas, _tempDataSeries, _tempDataSeries.Storyboard, animationBeginTime, 1, 0, 1); animationBeginTime += 0.5; } } // Label animation if (animationEnabled && _tempDataSeries != null) { _tempDataSeries.Storyboard = AnimationHelper.ApplyOpacityAnimation(labelCanvas, _tempDataSeries, _tempDataSeries.Storyboard, animationBeginTime, 1, 0, 1); } candleStickCanvas.Tag = null; // ColumnChart.CreateOrUpdatePlank(chart, seriesList[0].PlotGroup.AxisY, candleStickCanvas, depth3d, Orientation.Horizontal); // Remove old visual and add new visual in to the existing panel if (preExistingPanel != null) { visual.Children.RemoveAt(1); visual.Children.Add(candleStickCanvas); } else { labelCanvas.SetValue(Canvas.ZIndexProperty, 1); visual.Children.Add(labelCanvas); visual.Children.Add(candleStickCanvas); } RectangleGeometry clipRectangle = new RectangleGeometry(); clipRectangle.Rect = new Rect(0, -chart.ChartArea.PLANK_DEPTH, width + chart.ChartArea.PLANK_OFFSET, height + chart.ChartArea.PLANK_DEPTH); visual.Clip = clipRectangle; return(visual); // visual.Children.Add(candleStickCanvas); // visual.Children.Add(labelCanvas); // return visual; }