internal static void UpdateBubblePositionAccording2XandYValue(DataPoint dataPoint, Double drawingAreaWidth, Double drawingAreaHeight, Boolean animatedUpdate, Double oldSize, Double newSize) { dataPoint._parsedToolTipText = dataPoint.TextParser(dataPoint.ToolTipText); //animatedUpdate = false; Marker marker = dataPoint.Marker; PlotGroup plotGroup = dataPoint.Parent.PlotGroup; Double xPosition = Graphics.ValueToPixelPosition(0, drawingAreaWidth, (Double)plotGroup.AxisX.InternalAxisMinimum, (Double)plotGroup.AxisX.InternalAxisMaximum, dataPoint.InternalXValue); Double yPosition = Graphics.ValueToPixelPosition(drawingAreaHeight, 0, (Double)plotGroup.AxisY.InternalAxisMinimum, (Double)plotGroup.AxisY.InternalAxisMaximum, dataPoint.InternalYValue); if (animatedUpdate) { Point newPosition = marker.CalculateActualPosition(xPosition, yPosition, new Point(0.5, 0.5)); ApplyAnimation4XYZUpdate(dataPoint, newPosition, oldSize, newSize); //dataPoint.Storyboard.SpeedRatio = 2; //dataPoint.Storyboard.Begin(); } else { marker.SetPosition(xPosition, yPosition, new Point(0.5, 0.5)); } if (dataPoint.Parent.ToolTipElement != null) { dataPoint.Parent.ToolTipElement.Hide(); } (dataPoint.Chart as Chart).ChartArea.DisableIndicators(); dataPoint._visualPosition = new Point(xPosition, yPosition); }
/// <summary> /// Calculate ControlPoints of a DataSeries /// </summary> /// <param name="chart">Chart</param> /// <param name="plotGroup">Corresponding plotGroup</param> /// <param name="dataPoints">List of DataPoints</param> /// <returns>ControlPoints</returns> internal static Point[] CalculateControlPointsOfADataSeries(Chart chart, PlotGroup plotGroup, List <DataPoint> dataPoints) { List <Point> tempCPoints = new List <Point>(); if (chart != null && chart.InternalSeries != null && plotGroup != null && dataPoints.Count > 0) { Double minimumZVal, maximumZVal; List <DataSeries> seriesList = chart.InternalSeries; CalculateMaxAndMinZValueFromAllSeries(ref seriesList, out minimumZVal, out maximumZVal); Double tempAxisMinimum = plotGroup._initialAxisXMin; Double tempAxisMaximum = plotGroup._initialAxisXMax; dataPoints = dataPoints.OrderBy(a => a.ZValue).ToList(); DataPoint dataPointHavingMaxZVal = dataPoints.Last(); Double maxBubbleRadius = CalculateBubbleSize(dataPointHavingMaxZVal, minimumZVal, maximumZVal); foreach (DataPoint dataPoint in dataPoints) { // Double maxBubbleRadius = CalculateBubbleSize(dataPoint, minimumZVal, maximumZVal); List <Point> controlPointsOfDp = CalculateControlPointsOfDataPoint(dataPoint, plotGroup, maxBubbleRadius, minimumZVal, maximumZVal, plotGroup.AxisX, plotGroup.AxisY); tempCPoints.InsertRange(0, controlPointsOfDp); } if (tempCPoints.Count > 0) { tempCPoints = tempCPoints.OrderBy(x => x.X).ToList(); } // tempCPoints.Clear(); } return(tempCPoints.ToArray()); }
/// <summary> /// Get point for Radar /// </summary> /// <param name="circularPlotDetails"></param> /// <param name="plotGroup"></param> /// <param name="dp"></param> /// <param name="dataPointIndex"></param> /// <returns></returns> private static Point GetRadarPoint(CircularPlotDetails circularPlotDetails, PlotGroup plotGroup, DataPoint dp, Double dataPointIndex) { Double yValue; if (Double.IsNaN(dp.InternalYValue)) { yValue = 0; } else { yValue = dp.InternalYValue; } Double yPosition = Graphics.ValueToPixelPosition(circularPlotDetails.Radius, 0, plotGroup.AxisY.InternalAxisMinimum, plotGroup.AxisY.InternalAxisMaximum, yValue); Double radius = circularPlotDetails.Radius - yPosition; Double minAngle = circularPlotDetails.MinAngleInDegree * dataPointIndex; Double actualAngle = AxisLabel.GetRadians(minAngle) - (Math.PI / 2); Double x = radius * Math.Cos(actualAngle) + circularPlotDetails.Center.X; Double y = radius * Math.Sin(actualAngle) + circularPlotDetails.Center.Y; return(new Point(x, y)); }
private static void UpdateYValueAndXValuePosition(DataPoint dataPoint, Double canvasWidth, Double canvasHeight, Double dataPointWidth) { Canvas dataPointVisual = dataPoint.Faces.Visual as Canvas; Faces faces = dataPoint.Faces; Line highLowLine = faces.VisualComponents[0] as Line; // HighLowline Line closeLine = faces.VisualComponents[1] as Line; // Closeline Line openLine = faces.VisualComponents[2] as Line; // Openline Double highY = 0, lowY = 0, openY = 0, closeY = 0; PlotGroup plotGroup = dataPoint.Parent.PlotGroup; CandleStick.SetDataPointValues(dataPoint, ref highY, ref lowY, ref openY, ref closeY); // Calculate required pixel positions Double xPositionOfDataPoint = Graphics.ValueToPixelPosition(0, canvasWidth, (Double)plotGroup.AxisX.InternalAxisMinimum, (Double)plotGroup.AxisX.InternalAxisMaximum, dataPoint.InternalXValue); openY = Graphics.ValueToPixelPosition(canvasHeight, 0, (Double)plotGroup.AxisY.InternalAxisMinimum, (Double)plotGroup.AxisY.InternalAxisMaximum, openY); closeY = Graphics.ValueToPixelPosition(canvasHeight, 0, (Double)plotGroup.AxisY.InternalAxisMinimum, (Double)plotGroup.AxisY.InternalAxisMaximum, closeY); highY = Graphics.ValueToPixelPosition(canvasHeight, 0, (Double)plotGroup.AxisY.InternalAxisMinimum, (Double)plotGroup.AxisY.InternalAxisMaximum, highY); lowY = Graphics.ValueToPixelPosition(canvasHeight, 0, (Double)plotGroup.AxisY.InternalAxisMinimum, (Double)plotGroup.AxisY.InternalAxisMaximum, lowY); Double dataPointTop = (lowY < highY) ? lowY : highY; openY = openY - dataPointTop; closeY = closeY - dataPointTop; dataPointVisual.Width = dataPointWidth; dataPointVisual.Height = Math.Abs(lowY - highY); // Set DataPoint Visual position dataPointVisual.SetValue(Canvas.LeftProperty, xPositionOfDataPoint - dataPointWidth / 2); dataPointVisual.SetValue(Canvas.TopProperty, dataPointTop); // Set position for high-low line highLowLine.X1 = dataPointVisual.Width / 2; highLowLine.X2 = dataPointVisual.Width / 2; highLowLine.Y1 = 0; highLowLine.Y2 = dataPointVisual.Height; // Set position for open line openLine.X1 = 0; openLine.X2 = dataPointVisual.Width / 2; openLine.Y1 = openY; openLine.Y2 = openY; // Set position for close line closeLine.X1 = dataPointVisual.Width / 2; closeLine.X2 = dataPointVisual.Width; closeLine.Y1 = closeY; closeLine.Y2 = closeY; // Need to apply shadow according to position of DataPoint ApplyOrUpdateShadow(dataPoint, dataPointVisual, highLowLine, openLine, closeLine, dataPointWidth); // Place label for the DataPoint CandleStick.CreateAndPositionLabel(dataPoint.Parent.Faces.LabelCanvas, dataPoint); }
/// <summary> /// Calculate width of each stacked column /// </summary> /// <param name="chart">Chart reference</param> /// <param name="plotGroup">PlotGroup</param> /// <param name="width">Width of the PlotArea</param> /// <param name="height">Width of the PlotArea</param> /// <param name="minDiff">Minimum difference between two DataPoints</param> /// <param name="maxColumnWidth">Maximum width of a StackedColumn</param> /// <returns>Width of a stacked column</returns> internal static Double CalculateWidthOfEachStackedColumn(Chart chart, PlotGroup plotGroup, Double heightOrWidth, out Double minDiff, out Double maxColumnWidth) { Double widthPerColumn; PlotDetails plotDetails = chart.PlotDetails; Double widthDivisionFactor = plotDetails.DrawingDivisionFactor; if (chart.PlotDetails.ChartOrientation == ChartOrientationType.Vertical) { minDiff = plotDetails.GetMinOfMinDifferencesForXValue(RenderAs.Column, RenderAs.StackedColumn, RenderAs.StackedColumn100); } else { minDiff = plotDetails.GetMinOfMinDifferencesForXValue(RenderAs.Bar, RenderAs.StackedBar, RenderAs.StackedBar100); } if (Double.IsPositiveInfinity(minDiff)) { minDiff = 0; } maxColumnWidth = Graphics.ValueToPixelPosition(0, heightOrWidth, (Double)plotGroup.AxisX.InternalAxisMinimum, (Double)plotGroup.AxisX.InternalAxisMaximum, minDiff + (Double)plotGroup.AxisX.InternalAxisMinimum) * (1 - ColumnChart.COLUMN_GAP_RATIO); widthPerColumn = maxColumnWidth / widthDivisionFactor; if (minDiff == 0) { widthPerColumn = heightOrWidth * .5 / widthDivisionFactor; maxColumnWidth = widthPerColumn * widthDivisionFactor; } else { widthPerColumn = Graphics.ValueToPixelPosition(0, heightOrWidth, plotGroup.AxisX.InternalAxisMinimum, plotGroup.AxisX.InternalAxisMaximum, minDiff + plotGroup.AxisX.InternalAxisMinimum); widthPerColumn *= (1 - ((chart.PlotDetails.ChartOrientation == ChartOrientationType.Vertical) ? ColumnChart.COLUMN_GAP_RATIO : BarChart.BAR_GAP_RATIO)); maxColumnWidth = widthPerColumn; widthPerColumn /= widthDivisionFactor; } if (!Double.IsNaN(chart.DataPointWidth)) { if (chart.DataPointWidth >= 0) { widthPerColumn = maxColumnWidth = chart.DataPointWidth / 100 * ((chart.PlotDetails.ChartOrientation == ChartOrientationType.Vertical) ? chart.PlotArea.Width: chart.PlotArea.Height); maxColumnWidth *= widthDivisionFactor; } } if (maxColumnWidth < 2) { maxColumnWidth = 2; } return(widthPerColumn); }
/// <summary> /// Create Polar series /// </summary> /// <param name="chart"></param> /// <param name="series"></param> /// <param name="polarCanvas"></param> /// <param name="labelCanvas"></param> /// <param name="width"></param> /// <param name="height"></param> /// <param name="plotGroup"></param> /// <param name="circularPlotDetails"></param> private static void CreatePolarSeries(Chart chart, DataSeries series, Canvas polarCanvas, Canvas labelCanvas, Double width, Double height, PlotGroup plotGroup, CircularPlotDetails circularPlotDetails) { List<List<DataPoint>> brokenLineDataPointsGroup = GetBrokenLineDataPointsGroup(series, circularPlotDetails, plotGroup); foreach (List<DataPoint> dataPointList in brokenLineDataPointsGroup) { foreach (DataPoint dataPoint in dataPointList) DrawMarker(dataPoint, labelCanvas, width, height, circularPlotDetails.Center); DrawDataSeriesPath(series, dataPointList, polarCanvas); } }
/// <summary> /// Get visual for DataSeries /// </summary> /// <param name="chart">Chart</param> /// <param name="width">Width</param> /// <param name="height">Height</param> /// <param name="series">DataSeries</param> /// <param name="circularPlotDetails">CircularPlotDetails</param> /// <returns>Canvas</returns> private static Canvas GetDataSeriesVisual(Chart chart, Double width, Double height, DataSeries series, CircularPlotDetails circularPlotDetails) { Canvas visual = new Canvas(); Canvas radarCanvas = new Canvas(); Canvas labelCanvas = new Canvas(); if ((Boolean)series.Enabled) { PlotGroup plotGroup = series.PlotGroup; List <Point> listOfRadarPoints = new List <Point>(); series.Faces = new Faces(); CalculateRadarPoints(series, ref listOfRadarPoints, plotGroup, circularPlotDetails); DrawMarkers(series, labelCanvas, chart, width, height, circularPlotDetails.Center); DrawDataSeriesPolygon(listOfRadarPoints, series, radarCanvas); } // Apply animation for DataSeries if (chart._internalAnimationEnabled) { if (series.Storyboard == null) { series.Storyboard = new Storyboard(); } // Apply animation to radar visual series.Storyboard = AnimationHelper.ApplyOpacityAnimation(radarCanvas, series, series.Storyboard, 1, 1, 0, 1); // Apply animation to the marker and labels series.Storyboard = AnimationHelper.ApplyOpacityAnimation(labelCanvas, series, series.Storyboard, 1.5, 1, 0, 1); } visual.Children.Add(radarCanvas); visual.Children.Add(labelCanvas); return(visual); }
/// <summary> /// Get visual for DataSeries /// </summary> /// <param name="chart">Chart</param> /// <param name="width">Width</param> /// <param name="height">Height</param> /// <param name="series">DataSeries</param> /// <param name="circularPlotDetails">CircularPlotDetails</param> /// <returns>Canvas</returns> private static Canvas GetDataSeriesVisual(Chart chart, Double width, Double height, DataSeries series, CircularPlotDetails circularPlotDetails) { Canvas visual = new Canvas(); Canvas polarCanvas = new Canvas(); Canvas labelCanvas = new Canvas(); if ((Boolean)series.Enabled) { PlotGroup plotGroup = series.PlotGroup; if (circularPlotDetails.ListOfPoints4CircularAxis.Count > 0) { series.Faces = new Faces(); CreatePolarSeries(chart, series, polarCanvas, labelCanvas, width, height, plotGroup, circularPlotDetails); } } // Apply animation for DataSeries if (chart._internalAnimationEnabled) { if (series.Storyboard == null) { series.Storyboard = new Storyboard(); } // Apply animation to radar visual series.Storyboard = AnimationHelper.ApplyOpacityAnimation(polarCanvas, series, series.Storyboard, 1, 1, 0, 1); // Apply animation to the marker and labels series.Storyboard = AnimationHelper.ApplyOpacityAnimation(labelCanvas, series, series.Storyboard, 1.5, 1, 0, 1); } visual.Children.Add(polarCanvas); visual.Children.Add(labelCanvas); return(visual); }
/// <summary> /// Get point for Polar /// </summary> /// <param name="circularPlotDetails"></param> /// <param name="plotGroup"></param> /// <param name="dp"></param> /// <returns></returns> private static Point GetPolarPoint(CircularPlotDetails circularPlotDetails, PlotGroup plotGroup, DataPoint dp) { Double yValue = dp.InternalYValue; Double yPosition = Graphics.ValueToPixelPosition(circularPlotDetails.Radius, 0, plotGroup.AxisY.InternalAxisMinimum, plotGroup.AxisY.InternalAxisMaximum, yValue); Double radius = circularPlotDetails.Radius - yPosition; Axis axisX = plotGroup.AxisX; Double minValInRadian; if (axisX.InternalAxisMinimum != 0) { minValInRadian = AxisLabel.GetRadians(axisX.InternalAxisMinimum - 90); } else { minValInRadian = 2 * Math.PI - Math.PI / 2; } Double actualAngle; if (dp.Parent.XValueType == ChartValueTypes.Time) { actualAngle = Graphics.ValueToPixelPosition(minValInRadian, 2 * Math.PI + minValInRadian, AxisLabel.GetRadians(0), AxisLabel.GetRadians(360), AxisLabel.GetRadians(dp.InternalXValue)); } else { actualAngle = Graphics.ValueToPixelPosition(minValInRadian, 2 * Math.PI + minValInRadian, AxisLabel.GetRadians(axisX.InternalAxisMinimum), AxisLabel.GetRadians(axisX.InternalAxisMaximum), AxisLabel.GetRadians(axisX.InternalAxisMinimum + dp.InternalXValue)); } Double x = radius * Math.Cos(actualAngle) + circularPlotDetails.Center.X; Double y = radius * Math.Sin(actualAngle) + circularPlotDetails.Center.Y; return(new Point(x, y)); }
internal static void Clip(Chart chart, Canvas chartsCanvas, Canvas labelCanvas, PlotGroup plotGroup) { Double depth3d = chart.ChartArea.PLANK_DEPTH / (chart.PlotDetails.Layer3DCount == 0 ? 1 : chart.PlotDetails.Layer3DCount) * (chart.View3D ? 1 : 0); RectangleGeometry clipRectangle = new RectangleGeometry(); Double clipLeft = 0; Double clipTop = -depth3d - 4; Double clipWidth = labelCanvas.Width + depth3d; Double clipHeight = labelCanvas.Height + depth3d + chart.ChartArea.PLANK_THICKNESS + 10; AreaChart.GetClipCoordinates(chart, ref clipLeft, ref clipTop, ref clipWidth, ref clipHeight, plotGroup.MinimumX, plotGroup.MaximumX); clipRectangle.Rect = new Rect(clipLeft, clipTop, clipWidth, clipHeight); labelCanvas.Clip = clipRectangle; clipRectangle = new RectangleGeometry(); clipRectangle.Rect = new Rect(0, -depth3d - 4, labelCanvas.Width + depth3d, labelCanvas.Height + chart.ChartArea.PLANK_DEPTH + chart.ChartArea.PLANK_THICKNESS + 10); // System.Diagnostics.Debug.WriteLine(clipRectangle.Rect.ToString()); chartsCanvas.Clip = clipRectangle; }
internal static void DrawStackedBarsAtXValue(RenderAs chartType, Double xValue, PlotGroup plotGroup, Canvas columnCanvas, Canvas labelCanvas, Double drawingIndex, Double heightPerBar, Double maxBarHeight, Double limitingYValue, Double depth3d, Boolean animationEnabled) { RectangularChartShapeParams barParams = new RectangularChartShapeParams(); barParams.ShadowOffset = 5; barParams.Depth = depth3d; barParams.IsStacked = true; Boolean isTopOFStack; DataPoint dataPointAtTopOfStack = null; Int32 positiveIndex = 1, negativeIndex = 1; Double top = Graphics.ValueToPixelPosition(columnCanvas.Height, 0, (Double)plotGroup.AxisX.InternalAxisMinimum, (Double)plotGroup.AxisX.InternalAxisMaximum, xValue) + drawingIndex * heightPerBar - (maxBarHeight / 2); Double left = Graphics.ValueToPixelPosition(0, columnCanvas.Width, (Double)plotGroup.AxisY.InternalAxisMinimum, (Double)plotGroup.AxisY.InternalAxisMaximum, limitingYValue); Double columnHeight = CalculateHeightOfEachColumn(ref top, heightPerBar, columnCanvas.Height); Double right=0; Double prevSum = 0; Double animationBeginTime = 0.4; Double animationTime = 1.0 / plotGroup.XWiseStackedDataList[xValue].Positive.Count; if (plotGroup.XWiseStackedDataList[xValue].Positive.Count > 0) dataPointAtTopOfStack = plotGroup.XWiseStackedDataList[xValue].Positive.Last(); Double absoluteSum = Double.NaN; if (chartType == RenderAs.StackedBar100) absoluteSum = plotGroup.XWiseStackedDataList[xValue].AbsoluteYValueSum; // Plot positive values foreach (DataPoint dataPoint in plotGroup.XWiseStackedDataList[xValue].Positive) { dataPoint.Parent.Faces = new Faces { Visual = columnCanvas, LabelCanvas = labelCanvas }; if (!(Boolean)dataPoint.Enabled || Double.IsNaN(dataPoint.InternalYValue)) { ColumnChart.CleanUpMarkerAndLabel(dataPoint, labelCanvas); continue; } isTopOFStack = (dataPoint == dataPointAtTopOfStack); CreateStackedBarVisual(dataPoint.Parent.RenderAs, dataPoint.InternalYValue >= 0, columnCanvas, labelCanvas, dataPoint, top, ref left, ref right, columnHeight, ref prevSum, absoluteSum, depth3d, animationEnabled, animationBeginTime, isTopOFStack, positiveIndex, plotGroup.XWiseStackedDataList[xValue].Positive.ToList()); animationBeginTime += animationTime; positiveIndex++; } prevSum = 0; right = Graphics.ValueToPixelPosition(0, columnCanvas.Width, (Double)plotGroup.AxisY.InternalAxisMinimum, (Double)plotGroup.AxisY.InternalAxisMaximum, limitingYValue); dataPointAtTopOfStack = null; if (plotGroup.XWiseStackedDataList[xValue].Negative.Count > 0) { dataPointAtTopOfStack = plotGroup.XWiseStackedDataList[xValue].Negative.Last(); animationTime = 1.0 / plotGroup.XWiseStackedDataList[xValue].Negative.Count; animationBeginTime = 0.4; } // Plot negative values foreach (DataPoint dataPoint in plotGroup.XWiseStackedDataList[xValue].Negative) { dataPoint.Parent.Faces = new Faces { Visual = columnCanvas, LabelCanvas = labelCanvas }; if (!(Boolean)dataPoint.Enabled || Double.IsNaN(dataPoint.InternalYValue)) continue; isTopOFStack = (dataPoint == dataPointAtTopOfStack); CreateStackedBarVisual(dataPoint.Parent.RenderAs, dataPoint.InternalYValue >= 0, columnCanvas, labelCanvas, dataPoint, top, ref left, ref right, columnHeight, ref prevSum, absoluteSum, depth3d, animationEnabled, animationBeginTime, isTopOFStack, negativeIndex, plotGroup.XWiseStackedDataList[xValue].Negative.ToList()); animationBeginTime += animationTime; negativeIndex--; } }
/// <summary> /// Calculate ControlPoints of a DataPoint /// </summary> /// <param name="dataPoint">DataPoint</param> /// <param name="minimumZVal">Minimum ZValue</param> /// <param name="maximumZVal">Maximum ZValue</param> /// <param name="axisX">AxisX</param> /// <param name="axisY">AxisY</param> /// <returns></returns> private static List<Point> CalculateControlPointsOfDataPoint(DataPoint dataPoint, PlotGroup plotGroup, Double maxBubbleRadius, Double minimumZVal, Double maximumZVal, Axis axisX, Axis axisY) { Chart chart = dataPoint.Chart as Chart; List<Point> ctPoints = new List<Point>(); if (chart != null && axisX !=null && axisY != null) { Double leftRightOffset = 4; // One Pixel Double topBottomOffset = 4; // One Pixel Size initialPlotAreaSize = new Size(plotGroup._intialAxisXWidth, plotGroup._intialAxisYHeight); Double xPosition = Graphics.ValueToPixelPosition(0, initialPlotAreaSize.Width, (Double)plotGroup._initialAxisXMin, (Double)plotGroup._initialAxisXMax, dataPoint.InternalXValue); Double yPosition = Graphics.ValueToPixelPosition(initialPlotAreaSize.Height, 0, (Double)plotGroup._initialAxisYMin, (Double)plotGroup._initialAxisYMax, dataPoint.InternalYValue); if (axisY.Logarithmic) { Double yValueInLog = Graphics.PixelPositionToValue(initialPlotAreaSize.Height, 0, plotGroup._initialAxisYMin, plotGroup._initialAxisYMax, yPosition); Double actualYValue = DataPoint.ConvertLogarithmicValue2ActualValue(chart, yValueInLog, axisY.AxisType); Point pointLeft = new Point( Graphics.PixelPositionToValue(0, initialPlotAreaSize.Width, plotGroup._initialAxisXMin, plotGroup._initialAxisXMax, xPosition - (maxBubbleRadius + leftRightOffset)) , actualYValue); // Calculate right point of bubble in terms of XValue and YValue Point pointRight = new Point( Graphics.PixelPositionToValue(0, initialPlotAreaSize.Width, plotGroup._initialAxisXMin, plotGroup._initialAxisXMax, xPosition + (maxBubbleRadius + leftRightOffset)) , actualYValue); yValueInLog = Graphics.PixelPositionToValue(initialPlotAreaSize.Height, 0, plotGroup._initialAxisYMin, plotGroup._initialAxisYMax, yPosition - (maxBubbleRadius + topBottomOffset)); actualYValue = DataPoint.ConvertLogarithmicValue2ActualValue(chart, yValueInLog, axisY.AxisType); // Calculate top point of bubble in terms of XValue and YValue Point pointTop = new Point( Graphics.PixelPositionToValue(0, initialPlotAreaSize.Width, plotGroup._initialAxisXMin, plotGroup._initialAxisXMax, xPosition) , actualYValue); yValueInLog = Graphics.PixelPositionToValue(initialPlotAreaSize.Height, 0, plotGroup._initialAxisYMin, plotGroup._initialAxisYMax, yPosition + (maxBubbleRadius + topBottomOffset)); actualYValue = DataPoint.ConvertLogarithmicValue2ActualValue(chart, yValueInLog, axisY.AxisType); // Calculate bottom point of bubble in terms of XValue and YValue Point pointBottom = new Point( Graphics.PixelPositionToValue(0, initialPlotAreaSize.Width, plotGroup._initialAxisXMin, plotGroup._initialAxisXMax, xPosition) , actualYValue); ctPoints.Add(pointLeft); ctPoints.Add(pointRight); ctPoints.Add(pointTop); ctPoints.Add(pointBottom); } else { // Calculate left point of bubble in terms of XValue and YValue Point pointLeft = new Point( Graphics.PixelPositionToValue(0, initialPlotAreaSize.Width, plotGroup._initialAxisXMin, plotGroup._initialAxisXMax, xPosition - (maxBubbleRadius + leftRightOffset)) , Graphics.PixelPositionToValue(0, initialPlotAreaSize.Height, plotGroup._initialAxisYMin, plotGroup._initialAxisYMax, yPosition)); // Calculate right point of bubble in terms of XValue and YValue Point pointRight = new Point( Graphics.PixelPositionToValue(0, initialPlotAreaSize.Width, plotGroup._initialAxisXMin, plotGroup._initialAxisXMax, xPosition + (maxBubbleRadius + leftRightOffset)) , Graphics.PixelPositionToValue(0, initialPlotAreaSize.Height, plotGroup._initialAxisYMin, plotGroup._initialAxisYMax, yPosition)); // Calculate top point of bubble in terms of XValue and YValue Point pointTop = new Point( Graphics.PixelPositionToValue(0, initialPlotAreaSize.Width, plotGroup._initialAxisXMin, plotGroup._initialAxisXMax, xPosition) , Graphics.PixelPositionToValue(initialPlotAreaSize.Height, 0, plotGroup._initialAxisYMin, plotGroup._initialAxisYMax, yPosition - (maxBubbleRadius + topBottomOffset))); // Calculate bottom point of bubble in terms of XValue and YValue Point pointBottom = new Point( Graphics.PixelPositionToValue(0, initialPlotAreaSize.Width, plotGroup._initialAxisXMin, plotGroup._initialAxisXMax, xPosition) , Graphics.PixelPositionToValue(initialPlotAreaSize.Height, 0, plotGroup._initialAxisYMin, plotGroup._initialAxisYMax, yPosition + (maxBubbleRadius + topBottomOffset))); ctPoints.Add(pointLeft); ctPoints.Add(pointRight); ctPoints.Add(pointTop); ctPoints.Add(pointBottom); } } return ctPoints; }
/// <summary> /// Calculate ControlPoints of a DataSeries /// </summary> /// <param name="chart">Chart</param> /// <param name="plotGroup">Corresponding plotGroup</param> /// <param name="dataPoints">List of DataPoints</param> /// <returns>ControlPoints</returns> internal static Point[] CalculateControlPointsOfADataSeries(Chart chart, PlotGroup plotGroup, List<DataPoint> dataPoints) { List<Point> tempCPoints = new List<Point>(); if (chart != null && chart.InternalSeries != null && plotGroup != null && dataPoints.Count > 0) { Double minimumZVal, maximumZVal; List<DataSeries> seriesList = chart.InternalSeries; CalculateMaxAndMinZValueFromAllSeries(ref seriesList, out minimumZVal, out maximumZVal); Double tempAxisMinimum = plotGroup._initialAxisXMin; Double tempAxisMaximum = plotGroup._initialAxisXMax; dataPoints = dataPoints.OrderBy(a => a.ZValue).ToList(); DataPoint dataPointHavingMaxZVal = dataPoints.Last(); Double maxBubbleRadius = CalculateBubbleSize(dataPointHavingMaxZVal, minimumZVal, maximumZVal); foreach (DataPoint dataPoint in dataPoints) { // Double maxBubbleRadius = CalculateBubbleSize(dataPoint, minimumZVal, maximumZVal); List<Point> controlPointsOfDp = CalculateControlPointsOfDataPoint(dataPoint, plotGroup, maxBubbleRadius, minimumZVal, maximumZVal, plotGroup.AxisX, plotGroup.AxisY); tempCPoints.InsertRange(0, controlPointsOfDp); } if (tempCPoints.Count > 0) { tempCPoints = tempCPoints.OrderBy(x => x.X).ToList(); } // tempCPoints.Clear(); } return tempCPoints.ToArray(); }
/// <summary> /// Calculate ControlPoints of a DataPoint /// </summary> /// <param name="dataPoint">DataPoint</param> /// <param name="minimumZVal">Minimum ZValue</param> /// <param name="maximumZVal">Maximum ZValue</param> /// <param name="axisX">AxisX</param> /// <param name="axisY">AxisY</param> /// <returns></returns> private static List <Point> CalculateControlPointsOfDataPoint(DataPoint dataPoint, PlotGroup plotGroup, Double maxBubbleRadius, Double minimumZVal, Double maximumZVal, Axis axisX, Axis axisY) { Chart chart = dataPoint.Chart as Chart; List <Point> ctPoints = new List <Point>(); if (chart != null && axisX != null && axisY != null) { Double leftRightOffset = 4; // One Pixel Double topBottomOffset = 4; // One Pixel Size initialPlotAreaSize = new Size(plotGroup._intialAxisXWidth, plotGroup._intialAxisYHeight); Double xPosition = Graphics.ValueToPixelPosition(0, initialPlotAreaSize.Width, (Double)plotGroup._initialAxisXMin, (Double)plotGroup._initialAxisXMax, dataPoint.InternalXValue); Double yPosition = Graphics.ValueToPixelPosition(initialPlotAreaSize.Height, 0, (Double)plotGroup._initialAxisYMin, (Double)plotGroup._initialAxisYMax, dataPoint.InternalYValue); if (axisY.Logarithmic) { Double yValueInLog = Graphics.PixelPositionToValue(initialPlotAreaSize.Height, 0, plotGroup._initialAxisYMin, plotGroup._initialAxisYMax, yPosition); Double actualYValue = DataPoint.ConvertLogarithmicValue2ActualValue(chart, yValueInLog, axisY.AxisType); Point pointLeft = new Point( Graphics.PixelPositionToValue(0, initialPlotAreaSize.Width, plotGroup._initialAxisXMin, plotGroup._initialAxisXMax, xPosition - (maxBubbleRadius + leftRightOffset)) , actualYValue); // Calculate right point of bubble in terms of XValue and YValue Point pointRight = new Point( Graphics.PixelPositionToValue(0, initialPlotAreaSize.Width, plotGroup._initialAxisXMin, plotGroup._initialAxisXMax, xPosition + (maxBubbleRadius + leftRightOffset)) , actualYValue); yValueInLog = Graphics.PixelPositionToValue(initialPlotAreaSize.Height, 0, plotGroup._initialAxisYMin, plotGroup._initialAxisYMax, yPosition - (maxBubbleRadius + topBottomOffset)); actualYValue = DataPoint.ConvertLogarithmicValue2ActualValue(chart, yValueInLog, axisY.AxisType); // Calculate top point of bubble in terms of XValue and YValue Point pointTop = new Point( Graphics.PixelPositionToValue(0, initialPlotAreaSize.Width, plotGroup._initialAxisXMin, plotGroup._initialAxisXMax, xPosition) , actualYValue); yValueInLog = Graphics.PixelPositionToValue(initialPlotAreaSize.Height, 0, plotGroup._initialAxisYMin, plotGroup._initialAxisYMax, yPosition + (maxBubbleRadius + topBottomOffset)); actualYValue = DataPoint.ConvertLogarithmicValue2ActualValue(chart, yValueInLog, axisY.AxisType); // Calculate bottom point of bubble in terms of XValue and YValue Point pointBottom = new Point( Graphics.PixelPositionToValue(0, initialPlotAreaSize.Width, plotGroup._initialAxisXMin, plotGroup._initialAxisXMax, xPosition) , actualYValue); ctPoints.Add(pointLeft); ctPoints.Add(pointRight); ctPoints.Add(pointTop); ctPoints.Add(pointBottom); } else { // Calculate left point of bubble in terms of XValue and YValue Point pointLeft = new Point( Graphics.PixelPositionToValue(0, initialPlotAreaSize.Width, plotGroup._initialAxisXMin, plotGroup._initialAxisXMax, xPosition - (maxBubbleRadius + leftRightOffset)) , Graphics.PixelPositionToValue(0, initialPlotAreaSize.Height, plotGroup._initialAxisYMin, plotGroup._initialAxisYMax, yPosition)); // Calculate right point of bubble in terms of XValue and YValue Point pointRight = new Point( Graphics.PixelPositionToValue(0, initialPlotAreaSize.Width, plotGroup._initialAxisXMin, plotGroup._initialAxisXMax, xPosition + (maxBubbleRadius + leftRightOffset)) , Graphics.PixelPositionToValue(0, initialPlotAreaSize.Height, plotGroup._initialAxisYMin, plotGroup._initialAxisYMax, yPosition)); // Calculate top point of bubble in terms of XValue and YValue Point pointTop = new Point( Graphics.PixelPositionToValue(0, initialPlotAreaSize.Width, plotGroup._initialAxisXMin, plotGroup._initialAxisXMax, xPosition) , Graphics.PixelPositionToValue(initialPlotAreaSize.Height, 0, plotGroup._initialAxisYMin, plotGroup._initialAxisYMax, yPosition - (maxBubbleRadius + topBottomOffset))); // Calculate bottom point of bubble in terms of XValue and YValue Point pointBottom = new Point( Graphics.PixelPositionToValue(0, initialPlotAreaSize.Width, plotGroup._initialAxisXMin, plotGroup._initialAxisXMax, xPosition) , Graphics.PixelPositionToValue(initialPlotAreaSize.Height, 0, plotGroup._initialAxisYMin, plotGroup._initialAxisYMax, yPosition + (maxBubbleRadius + topBottomOffset))); ctPoints.Add(pointLeft); ctPoints.Add(pointRight); ctPoints.Add(pointTop); ctPoints.Add(pointBottom); } } return(ctPoints); }
internal static Double CalculatePositionOfDataPointForLogAxis(DataPoint dataPoint, Double canvasSize, PlotGroup plotGroup, List<DataPoint> stackedDataPoints, Double absoluteSum) { Double yValue = dataPoint.InternalYValue; Double pixelPos = 0; if (stackedDataPoints.First() == dataPoint) { Double newValue = 0; if (dataPoint.Parent.RenderAs == RenderAs.StackedColumn100 || dataPoint.Parent.RenderAs == RenderAs.StackedBar100) { newValue = dataPoint.YValue / absoluteSum * 100; newValue = Math.Log(newValue, plotGroup.AxisY.LogarithmBase); } else newValue = yValue; if((dataPoint.Chart as Chart).PlotDetails.ChartOrientation == ChartOrientationType.Vertical) pixelPos = Graphics.ValueToPixelPosition(canvasSize, 0, (Double)plotGroup.AxisY.InternalAxisMinimum, (Double)plotGroup.AxisY.InternalAxisMaximum, newValue); else pixelPos = Graphics.ValueToPixelPosition(0, canvasSize, (Double)plotGroup.AxisY.InternalAxisMinimum, (Double)plotGroup.AxisY.InternalAxisMaximum, newValue); return pixelPos; } else { Int32 index = stackedDataPoints.IndexOf(dataPoint); Double totalOfBottomDps = 0; for (; index >= 0; index--) { if (dataPoint.Parent.RenderAs == RenderAs.StackedColumn100 || dataPoint.Parent.RenderAs == RenderAs.StackedBar100) { totalOfBottomDps += dataPoint.YValue / absoluteSum * 100; } else totalOfBottomDps += (Double)stackedDataPoints[index].YValue; } totalOfBottomDps = Math.Log(totalOfBottomDps, plotGroup.AxisY.LogarithmBase); Double pixelPos4AllDPs = 0; if ((dataPoint.Chart as Chart).PlotDetails.ChartOrientation == ChartOrientationType.Vertical) pixelPos4AllDPs = Graphics.ValueToPixelPosition(canvasSize, 0, (Double)plotGroup.AxisY.InternalAxisMinimum, (Double)plotGroup.AxisY.InternalAxisMaximum, totalOfBottomDps); else pixelPos4AllDPs = Graphics.ValueToPixelPosition(0, canvasSize, (Double)plotGroup.AxisY.InternalAxisMinimum, (Double)plotGroup.AxisY.InternalAxisMaximum, totalOfBottomDps); return pixelPos4AllDPs; } }
/// <summary> /// Draws a All Stacked column under a XValue with a particular dtrawingIndex /// </summary> /// <param name="xValue">XValue</param> /// <param name="plotGroup">PlotGroup reference</param> /// <param name="columnCanvas">Parent canvas of StackedColumn visuals</param> /// <param name="labelCanvas">Parent canvas of StackedColumn labels</param> /// <param name="drawingIndex">Drawing index of the DataSeries</param> /// <param name="widthPerColumn">Width par each column</param> /// <param name="maxColumnWidth">Max width of a Column</param> /// <param name="limitingYValue">Limiting value</param> /// <param name="depth3d">3d depth for 3d charts</param> /// <param name="animationEnabled">Whether animation for chart is enabled</param> private static void DrawStackedColumnsAtXValue(RenderAs chartType, Double xValue, PlotGroup plotGroup, Canvas columnCanvas, Canvas labelCanvas, Double drawingIndex, Double widthPerColumn, Double maxColumnWidth, Double limitingYValue, Double depth3d, Boolean animationEnabled) { Double top; Double prevSum = 0; Int32 positiveIndex = 1, negativeIndex = 1; Boolean isTopOFStack; DataPoint dataPointAtTopOfStack = null; Double columnHeight = 0; Double absoluteSum = 0; Double left = Graphics.ValueToPixelPosition(0, columnCanvas.Width, (Double)plotGroup.AxisX.InternalAxisMinimum, (Double)plotGroup.AxisX.InternalAxisMaximum, xValue) + drawingIndex * widthPerColumn - (maxColumnWidth / 2); Double bottom = Graphics.ValueToPixelPosition(columnCanvas.Height, 0, (Double)plotGroup.AxisY.InternalAxisMinimum, (Double)plotGroup.AxisY.InternalAxisMaximum, limitingYValue); if (plotGroup.XWiseStackedDataList[xValue].Positive.Count > 0) { dataPointAtTopOfStack = plotGroup.XWiseStackedDataList[xValue].Positive.Last(); } if (chartType == RenderAs.StackedColumn100) { absoluteSum = plotGroup.XWiseStackedDataList[xValue].AbsoluteYValueSum; } Double animationBeginTime = 0.4; Double animationTime = 1.0 / plotGroup.XWiseStackedDataList[xValue].Positive.Count; // Plot positive values foreach (DataPoint dataPoint in plotGroup.XWiseStackedDataList[xValue].Positive) { dataPoint.Parent.Faces = new Faces() { Visual = columnCanvas, LabelCanvas = labelCanvas }; if (!(Boolean)dataPoint.Enabled || Double.IsNaN(dataPoint.InternalYValue)) { continue; } isTopOFStack = (dataPoint == dataPointAtTopOfStack); if (chartType == RenderAs.StackedColumn) { top = Graphics.ValueToPixelPosition(columnCanvas.Height, 0, (Double)plotGroup.AxisY.InternalAxisMinimum, (Double)plotGroup.AxisY.InternalAxisMaximum, dataPoint.InternalYValue + prevSum); prevSum += dataPoint.InternalYValue; columnHeight = Math.Abs(top - bottom); } else // if (chartType == RenderAs.StackedColumn100) { Double percentYValue = 0; if (absoluteSum != 0) { percentYValue = (dataPoint.InternalYValue / absoluteSum * 100); } top = Graphics.ValueToPixelPosition(columnCanvas.Height, 0, (Double)plotGroup.AxisY.InternalAxisMinimum, (Double)plotGroup.AxisY.InternalAxisMaximum, percentYValue + prevSum); columnHeight = Math.Abs(top - bottom); prevSum += percentYValue; } if (chartType == RenderAs.StackedColumn || chartType == RenderAs.StackedColumn100) { CreateStackedColumnVisual(true, columnCanvas, labelCanvas, dataPoint, isTopOFStack, left, ref top, ref bottom, widthPerColumn, columnHeight, depth3d, ref positiveIndex, animationEnabled, animationBeginTime); } else if (chartType == RenderAs.StackedColumn || chartType == RenderAs.StackedColumn100) { BarChart.CreateBarDataPointVisual(dataPoint, labelCanvas, columnCanvas, dataPoint.InternalYValue >= 0, widthPerColumn, depth3d, false); } animationBeginTime += animationTime; positiveIndex++; } prevSum = 0; top = Graphics.ValueToPixelPosition(columnCanvas.Height, 0, (Double)plotGroup.AxisY.InternalAxisMinimum, (Double)plotGroup.AxisY.InternalAxisMaximum, limitingYValue); dataPointAtTopOfStack = null; if (plotGroup.XWiseStackedDataList[xValue].Negative.Count > 0) { dataPointAtTopOfStack = plotGroup.XWiseStackedDataList[xValue].Negative.Last(); animationTime = 1.0 / plotGroup.XWiseStackedDataList[xValue].Negative.Count; animationBeginTime = 0.4; } // Plot negative values foreach (DataPoint dataPoint in plotGroup.XWiseStackedDataList[xValue].Negative) { dataPoint.Parent.Faces = new Faces() { Visual = columnCanvas, LabelCanvas = labelCanvas }; if (!(Boolean)dataPoint.Enabled || Double.IsNaN(dataPoint.InternalYValue)) { continue; } isTopOFStack = (dataPoint == dataPointAtTopOfStack); if (chartType == RenderAs.StackedColumn) { bottom = Graphics.ValueToPixelPosition(columnCanvas.Height, 0, (Double)plotGroup.AxisY.InternalAxisMinimum, (Double)plotGroup.AxisY.InternalAxisMaximum, dataPoint.InternalYValue + prevSum); prevSum += dataPoint.InternalYValue; columnHeight = Math.Abs(top - bottom); } else // if (chartType == RenderAs.StackedColumn100) { Double percentYValue = (dataPoint.InternalYValue / absoluteSum * 100); bottom = Graphics.ValueToPixelPosition(columnCanvas.Height, 0, (Double)plotGroup.AxisY.InternalAxisMinimum, (Double)plotGroup.AxisY.InternalAxisMaximum, percentYValue + prevSum); columnHeight = Math.Abs(top - bottom); prevSum += percentYValue; } CreateStackedColumnVisual(false, columnCanvas, labelCanvas, dataPoint, isTopOFStack, left, ref top, ref bottom, widthPerColumn, columnHeight, depth3d, ref negativeIndex, animationEnabled, animationBeginTime); animationBeginTime += animationTime; negativeIndex--; } }
/// <summary> /// Draws a All Stacked column under a XValue with a particular dtrawingIndex /// </summary> /// <param name="xValue">XValue</param> /// <param name="plotGroup">PlotGroup reference</param> /// <param name="columnCanvas">Parent canvas of StackedColumn visuals</param> /// <param name="labelCanvas">Parent canvas of StackedColumn labels</param> /// <param name="drawingIndex">Drawing index of the DataSeries</param> /// <param name="widthPerColumn">Width par each column</param> /// <param name="maxColumnWidth">Max width of a Column</param> /// <param name="limitingYValue">Limiting value</param> /// <param name="depth3d">3d depth for 3d charts</param> /// <param name="animationEnabled">Whether animation for chart is enabled</param> private static void DrawStackedColumnsAtXValue(RenderAs chartType, Double xValue, PlotGroup plotGroup, Canvas columnCanvas, Canvas labelCanvas, Double drawingIndex, Double widthPerColumn, Double maxColumnWidth, Double limitingYValue, Double depth3d, Boolean animationEnabled) { Double top; Double prevSum = 0; Int32 positiveIndex = 1, negativeIndex = 1; Boolean isTopOFStack; DataPoint dataPointAtTopOfStack = null; Double columnHeight = 0; Double absoluteSum = 0; Double left = Graphics.ValueToPixelPosition(0, columnCanvas.Width, (Double)plotGroup.AxisX.InternalAxisMinimum, (Double)plotGroup.AxisX.InternalAxisMaximum, xValue) + drawingIndex * widthPerColumn - (maxColumnWidth / 2); Double bottom = Graphics.ValueToPixelPosition(columnCanvas.Height, 0, (Double)plotGroup.AxisY.InternalAxisMinimum, (Double)plotGroup.AxisY.InternalAxisMaximum, limitingYValue); if (plotGroup.XWiseStackedDataList[xValue].Positive.Count > 0) dataPointAtTopOfStack = plotGroup.XWiseStackedDataList[xValue].Positive.Last(); if(chartType == RenderAs.StackedColumn100) absoluteSum = plotGroup.XWiseStackedDataList[xValue].AbsoluteYValueSum; Double animationBeginTime = 0.4; Double animationTime = 1.0 / plotGroup.XWiseStackedDataList[xValue].Positive.Count; // Plot positive values foreach (DataPoint dataPoint in plotGroup.XWiseStackedDataList[xValue].Positive) { dataPoint.Parent.Faces = new Faces() { Visual = columnCanvas, LabelCanvas = labelCanvas }; if (!(Boolean)dataPoint.Enabled || Double.IsNaN(dataPoint.InternalYValue)) continue; isTopOFStack = (dataPoint == dataPointAtTopOfStack); if (chartType == RenderAs.StackedColumn) { top = Graphics.ValueToPixelPosition(columnCanvas.Height, 0, (Double)plotGroup.AxisY.InternalAxisMinimum, (Double)plotGroup.AxisY.InternalAxisMaximum, dataPoint.InternalYValue + prevSum); prevSum += dataPoint.InternalYValue; columnHeight = Math.Abs(top - bottom); } else // if (chartType == RenderAs.StackedColumn100) { Double percentYValue = 0; if(absoluteSum != 0) percentYValue = (dataPoint.InternalYValue / absoluteSum * 100); top = Graphics.ValueToPixelPosition(columnCanvas.Height, 0, (Double)plotGroup.AxisY.InternalAxisMinimum, (Double)plotGroup.AxisY.InternalAxisMaximum, percentYValue + prevSum); columnHeight = Math.Abs(top - bottom); prevSum += percentYValue; } if (chartType == RenderAs.StackedColumn || chartType == RenderAs.StackedColumn100) CreateStackedColumnVisual(true, columnCanvas, labelCanvas, dataPoint, isTopOFStack, left, ref top, ref bottom, widthPerColumn, columnHeight, depth3d, ref positiveIndex, animationEnabled, animationBeginTime); else if (chartType == RenderAs.StackedColumn || chartType == RenderAs.StackedColumn100) BarChart.CreateBarDataPointVisual(dataPoint, labelCanvas, columnCanvas, dataPoint.InternalYValue >= 0, widthPerColumn, depth3d, false); animationBeginTime += animationTime; positiveIndex++; } prevSum = 0; top = Graphics.ValueToPixelPosition(columnCanvas.Height, 0, (Double)plotGroup.AxisY.InternalAxisMinimum, (Double)plotGroup.AxisY.InternalAxisMaximum, limitingYValue); dataPointAtTopOfStack = null; if (plotGroup.XWiseStackedDataList[xValue].Negative.Count > 0) { dataPointAtTopOfStack = plotGroup.XWiseStackedDataList[xValue].Negative.Last(); animationTime = 1.0 / plotGroup.XWiseStackedDataList[xValue].Negative.Count; animationBeginTime = 0.4; } // Plot negative values foreach (DataPoint dataPoint in plotGroup.XWiseStackedDataList[xValue].Negative) { dataPoint.Parent.Faces = new Faces() { Visual = columnCanvas, LabelCanvas = labelCanvas }; if (!(Boolean)dataPoint.Enabled || Double.IsNaN(dataPoint.InternalYValue)) continue; isTopOFStack = (dataPoint == dataPointAtTopOfStack); if (chartType == RenderAs.StackedColumn) { bottom = Graphics.ValueToPixelPosition(columnCanvas.Height, 0, (Double)plotGroup.AxisY.InternalAxisMinimum, (Double)plotGroup.AxisY.InternalAxisMaximum, dataPoint.InternalYValue + prevSum); prevSum += dataPoint.InternalYValue; columnHeight = Math.Abs(top - bottom); } else // if (chartType == RenderAs.StackedColumn100) { Double percentYValue = (dataPoint.InternalYValue / absoluteSum * 100); bottom = Graphics.ValueToPixelPosition(columnCanvas.Height, 0, (Double)plotGroup.AxisY.InternalAxisMinimum, (Double)plotGroup.AxisY.InternalAxisMaximum, percentYValue + prevSum); columnHeight = Math.Abs(top - bottom); prevSum += percentYValue; } CreateStackedColumnVisual(false, columnCanvas, labelCanvas, dataPoint, isTopOFStack, left, ref top, ref bottom, widthPerColumn, columnHeight, depth3d, ref negativeIndex, animationEnabled, animationBeginTime); animationBeginTime += animationTime; negativeIndex--; } }
/// <summary> /// Get broken list of polar DataPoints collection /// </summary> /// <param name="dataSeries"></param> /// <param name="circularPlotDetails"></param> /// <param name="plotGroup"></param> /// <returns></returns> private static List<List<DataPoint>> GetBrokenLineDataPointsGroup(DataSeries dataSeries, CircularPlotDetails circularPlotDetails, PlotGroup plotGroup) { Boolean IsStartPoint = true; Double xPosition; Double yPosition; Point endPoint = new Point(); List<List<DataPoint>> brokenLineDataPointsCollection = new List<List<DataPoint>>(); List<DataPoint> pointsList4EachBrokenLineGroup = new List<DataPoint>(); foreach (DataPoint dataPoint in dataSeries.InternalDataPoints) { if (dataPoint.Enabled == false) continue; if (Double.IsNaN(dataPoint.InternalYValue) || ((dataPoint.InternalYValue > plotGroup.AxisY.InternalAxisMaximum) || (dataPoint.InternalYValue < plotGroup.AxisY.InternalAxisMinimum))) { xPosition = Double.NaN; yPosition = Double.NaN; IsStartPoint = true; } else { Point point = GetPolarPoint(circularPlotDetails, plotGroup, dataPoint); xPosition = point.X; yPosition = point.Y; #region Generate GeometryGroup for line if (IsStartPoint) { IsStartPoint = !IsStartPoint; if (pointsList4EachBrokenLineGroup.Count > 0) { brokenLineDataPointsCollection.Add(pointsList4EachBrokenLineGroup); } pointsList4EachBrokenLineGroup = new List<DataPoint>(); } else { endPoint = new Point(xPosition, yPosition); IsStartPoint = false; } #endregion Generate GeometryGroup for line and line shadow dataPoint._visualPosition = new Point(xPosition, yPosition); pointsList4EachBrokenLineGroup.Add(dataPoint); } } brokenLineDataPointsCollection.Add(pointsList4EachBrokenLineGroup); return brokenLineDataPointsCollection; }
/// <summary> /// Get point for Polar /// </summary> /// <param name="circularPlotDetails"></param> /// <param name="plotGroup"></param> /// <param name="dp"></param> /// <returns></returns> private static Point GetPolarPoint(CircularPlotDetails circularPlotDetails, PlotGroup plotGroup, DataPoint dp) { Double yValue = dp.InternalYValue; Double yPosition = Graphics.ValueToPixelPosition(circularPlotDetails.Radius, 0, plotGroup.AxisY.InternalAxisMinimum, plotGroup.AxisY.InternalAxisMaximum, yValue); Double radius = circularPlotDetails.Radius - yPosition; Axis axisX = plotGroup.AxisX; Double minValInRadian; if (axisX.InternalAxisMinimum != 0) minValInRadian = AxisLabel.GetRadians(axisX.InternalAxisMinimum - 90); else minValInRadian = 2 * Math.PI - Math.PI / 2; Double actualAngle; if(dp.Parent.XValueType == ChartValueTypes.Time) actualAngle = Graphics.ValueToPixelPosition(minValInRadian, 2 * Math.PI + minValInRadian, AxisLabel.GetRadians(0), AxisLabel.GetRadians(360), AxisLabel.GetRadians(dp.InternalXValue)); else actualAngle = Graphics.ValueToPixelPosition(minValInRadian, 2 * Math.PI + minValInRadian, AxisLabel.GetRadians(axisX.InternalAxisMinimum), AxisLabel.GetRadians(axisX.InternalAxisMaximum), AxisLabel.GetRadians(axisX.InternalAxisMinimum + dp.InternalXValue)); Double x = radius * Math.Cos(actualAngle) + circularPlotDetails.Center.X; Double y = radius * Math.Sin(actualAngle) + circularPlotDetails.Center.Y; return new Point(x, y); }
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); } }
/// <summary> /// Creates visual object for a StackedColumn /// </summary> /// <param name="isPositive">Whether the DataPoint YValue is greater than or equals to 0.</param> /// <param name="columnCanvas"></param> /// <param name="labelCanvas"></param> /// <param name="dataPoint"></param> /// <param name="isTopOFStack"></param> /// <param name="left"></param> /// <param name="top"></param> /// <param name="bottom"></param> /// <param name="columnWidth"></param> /// <param name="depth3d"></param> /// <param name="prevSum"></param> /// <param name="positiveOrNegativeIndex"></param> /// <param name="animationEnabled"></param> private static void CreateStackedColumnVisual(Boolean isPositive, Canvas columnCanvas, Canvas labelCanvas, DataPoint dataPoint, Boolean isTopOFStack, Double left, ref Double top, ref Double bottom, Double columnWidth, Double columnHeight, Double depth3d, ref Int32 positiveOrNegativeIndex, Boolean animationEnabled, Double animationBeginTime) { PlotGroup plotGroup = dataPoint.Parent.PlotGroup; Chart chart = dataPoint.Chart as Chart; Faces column; Panel columnVisual = null; dataPoint.Parent.Faces = new Faces { Visual = columnCanvas, LabelCanvas = labelCanvas }; if (chart.View3D) { column = ColumnChart.Get3DColumn(dataPoint, columnWidth, columnHeight, depth3d, dataPoint.Color, null, null, null, (Boolean)dataPoint.LightingEnabled, (BorderStyles)dataPoint.BorderStyle, dataPoint.BorderColor, dataPoint.BorderThickness.Left); columnVisual = column.Visual as Panel; columnVisual.SetValue(Canvas.ZIndexProperty, ColumnChart.GetStackedColumnZIndex(left, top, (dataPoint.InternalYValue > 0), positiveOrNegativeIndex)); dataPoint.Faces = column; ColumnChart.ApplyOrRemoveShadow(dataPoint, true, false); } else { column = ColumnChart.Get2DColumn(dataPoint, columnWidth, columnHeight, true, false); columnVisual = column.Visual as Panel; } dataPoint.Faces = column; dataPoint.Faces.LabelCanvas = labelCanvas; columnVisual.SetValue(Canvas.LeftProperty, left); columnVisual.SetValue(Canvas.TopProperty, top); columnCanvas.Children.Add(columnVisual); dataPoint.IsTopOfStack = isTopOFStack; CreateOrUpdateMarker4VerticalChart(dataPoint, labelCanvas, new Size(columnVisual.Width, columnVisual.Height), left, top); // labelCanvas.Children.Add(GetMarker(chart, columnParams, dataPoint, left, top)); DataSeries currentDataSeries; // Apply animation if (animationEnabled) { currentDataSeries = dataPoint.Parent; if (currentDataSeries.Storyboard == null) { currentDataSeries.Storyboard = new Storyboard(); } // Apply animation to the data points dataSeriesIndex.e to the rectangles that form the columns currentDataSeries.Storyboard = ApplyStackedColumnChartAnimation(currentDataSeries, columnVisual, dataPoint.Parent.Storyboard, animationBeginTime, 0.5); } if (isPositive) { bottom = top; } else { top = bottom; } 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.AttachToolTip(chart, dataPoint, dataPoint.Faces.Visual); dataPoint.AttachHref(chart, dataPoint.Faces.Visual, dataPoint.Href, (HrefTargets)dataPoint.HrefTarget); dataPoint.SetCursor2DataPointVisualFaces(); }
internal static List <DataPoint> GetDataPointsUnderViewPort(DataSeries dataSeries, Boolean isUsedForAxisRange) { if (dataSeries.PlotGroup.AxisY.ViewportRangeEnabled) { PlotGroup plotGroup = dataSeries.PlotGroup; Axis axisX = plotGroup.AxisX; List <DataPoint> viewPortDataPoints; Double minXValueRangeOfViewPort = axisX._numericViewMinimum; Double maxXValueRangeOfViewPort = axisX._numericViewMaximum; //Double offset = Math.Abs(minXValueRangeOfViewPort - maxXValueRangeOfViewPort) * .4; //minXValueRangeOfViewPort -= offset; //maxXValueRangeOfViewPort += offset; if (!isUsedForAxisRange) { var leftDataPoints = (from dp in dataSeries.InternalDataPoints where (dp.InternalXValue < minXValueRangeOfViewPort) select dp.InternalXValue); var rightDataPoints = (from dp in dataSeries.InternalDataPoints where (dp.InternalXValue > maxXValueRangeOfViewPort) select dp.InternalXValue); if (leftDataPoints.Count() > 0) { minXValueRangeOfViewPort = leftDataPoints.Max(); } if (rightDataPoints.Count() > 0) { maxXValueRangeOfViewPort = rightDataPoints.Min(); } } viewPortDataPoints = dataSeries.InternalDataPoints .Where(d => d.InternalXValue >= minXValueRangeOfViewPort && d.InternalXValue <= maxXValueRangeOfViewPort).ToList(); if (viewPortDataPoints.Count <= 3) { var leftDataPoints = (from dp in dataSeries.InternalDataPoints where (dp.InternalXValue < minXValueRangeOfViewPort) orderby dp.InternalXValue select dp); List <DataPoint> rightDataPoints = (from dp in dataSeries.InternalDataPoints where (dp.InternalXValue > maxXValueRangeOfViewPort) orderby dp.InternalXValue select dp).ToList(); if (leftDataPoints.Count() > 0) { viewPortDataPoints.Insert(0, leftDataPoints.Last()); } if (rightDataPoints.Count > 0) { viewPortDataPoints.Add(rightDataPoints[0]); } if (rightDataPoints.Count > 1) { viewPortDataPoints.Add(rightDataPoints[1]); } if (rightDataPoints.Count > 2) { viewPortDataPoints.Add(rightDataPoints[2]); } } return(viewPortDataPoints); } else { return(dataSeries.InternalDataPoints); } }
/// <summary> /// Get broken list of polar DataPoints collection /// </summary> /// <param name="dataSeries"></param> /// <param name="circularPlotDetails"></param> /// <param name="plotGroup"></param> /// <returns></returns> private static List <List <DataPoint> > GetBrokenLineDataPointsGroup(DataSeries dataSeries, CircularPlotDetails circularPlotDetails, PlotGroup plotGroup) { Boolean IsStartPoint = true; Double xPosition; Double yPosition; Point endPoint = new Point(); List <List <DataPoint> > brokenLineDataPointsCollection = new List <List <DataPoint> >(); List <DataPoint> pointsList4EachBrokenLineGroup = new List <DataPoint>(); foreach (DataPoint dataPoint in dataSeries.InternalDataPoints) { if (dataPoint.Enabled == false) { continue; } if (Double.IsNaN(dataPoint.InternalYValue) || ((dataPoint.InternalYValue > plotGroup.AxisY.InternalAxisMaximum) || (dataPoint.InternalYValue < plotGroup.AxisY.InternalAxisMinimum))) { xPosition = Double.NaN; yPosition = Double.NaN; IsStartPoint = true; } else { Point point = GetPolarPoint(circularPlotDetails, plotGroup, dataPoint); xPosition = point.X; yPosition = point.Y; #region Generate GeometryGroup for line if (IsStartPoint) { IsStartPoint = !IsStartPoint; if (pointsList4EachBrokenLineGroup.Count > 0) { brokenLineDataPointsCollection.Add(pointsList4EachBrokenLineGroup); } pointsList4EachBrokenLineGroup = new List <DataPoint>(); } else { endPoint = new Point(xPosition, yPosition); IsStartPoint = false; } #endregion Generate GeometryGroup for line and line shadow dataPoint._visualPosition = new Point(xPosition, yPosition); pointsList4EachBrokenLineGroup.Add(dataPoint); } } brokenLineDataPointsCollection.Add(pointsList4EachBrokenLineGroup); return(brokenLineDataPointsCollection); }
/// <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); 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; Double minimumZVal, maximumZVal; CalculateMaxAndMinZValue(series, out minimumZVal, out maximumZVal); // Boolean pixelLavelShadow = false; //if (series.InternalDataPoints.Count <= 25) // pixelLavelShadow = true; foreach (DataPoint dataPoint in series.InternalDataPoints) { 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 point for Radar /// </summary> /// <param name="circularPlotDetails"></param> /// <param name="plotGroup"></param> /// <param name="dp"></param> /// <param name="dataPointIndex"></param> /// <returns></returns> private static Point GetRadarPoint(CircularPlotDetails circularPlotDetails, PlotGroup plotGroup, DataPoint dp, Double dataPointIndex) { Double yValue; if (Double.IsNaN(dp.InternalYValue)) yValue = 0; else yValue = dp.InternalYValue; Double yPosition = Graphics.ValueToPixelPosition(circularPlotDetails.Radius, 0, plotGroup.AxisY.InternalAxisMinimum, plotGroup.AxisY.InternalAxisMaximum, yValue); Double radius = circularPlotDetails.Radius - yPosition; Double minAngle = circularPlotDetails.MinAngleInDegree * dataPointIndex; Double actualAngle = AxisLabel.GetRadians(minAngle) - (Math.PI / 2); Double x = radius * Math.Cos(actualAngle) + circularPlotDetails.Center.X; Double y = radius * Math.Sin(actualAngle) + circularPlotDetails.Center.Y; return new Point(x, y); }
/// <summary> /// Calculate radar points /// </summary> /// <param name="series"></param> /// <param name="listOfRadarPoints"></param> /// <param name="plotGroup"></param> /// <param name="circularPlotDetails"></param> private static void CalculateRadarPoints(DataSeries series, ref List <Point> listOfRadarPoints, PlotGroup plotGroup, CircularPlotDetails circularPlotDetails) { DataPoint currDataPoint; DataPoint nextDataPoint; DataPoint preDataPoint = null; DataPoint firstDataPoint = series.InternalDataPoints[0]; DataPoint lastDataPoint = series.InternalDataPoints[series.InternalDataPoints.Count - 1]; for (Int32 i = 0; i < series.InternalDataPoints.Count - 1; i++) { currDataPoint = series.InternalDataPoints[i]; Double dataPointIndex = series.InternalDataPoints.IndexOf(currDataPoint); if (!(Boolean)currDataPoint.Enabled) { continue; } nextDataPoint = series.InternalDataPoints[i + 1]; Point dataPointPosition = GetRadarPoint(circularPlotDetails, plotGroup, currDataPoint, dataPointIndex); if (!Double.IsNaN(currDataPoint.InternalYValue) && (currDataPoint.InternalYValue > plotGroup.AxisY.InternalAxisMaximum || currDataPoint.InternalYValue < plotGroup.AxisY.InternalAxisMinimum)) { currDataPoint._visualPosition = new Point(Double.NaN, Double.NaN); listOfRadarPoints.Add(new Point(circularPlotDetails.Center.X, circularPlotDetails.Center.Y)); } else if (currDataPoint == firstDataPoint && (nextDataPoint != null && Double.IsNaN(nextDataPoint.InternalYValue)) && (lastDataPoint != null && !Double.IsNaN(lastDataPoint.InternalYValue))) { listOfRadarPoints.Add(dataPointPosition); currDataPoint._visualPosition = dataPointPosition; } else if (!Double.IsNaN(currDataPoint.InternalYValue) && ((preDataPoint != null && !Double.IsNaN(preDataPoint.InternalYValue)) || (nextDataPoint != null && !Double.IsNaN(nextDataPoint.InternalYValue)))) { listOfRadarPoints.Add(dataPointPosition); currDataPoint._visualPosition = dataPointPosition; } else { currDataPoint._visualPosition = new Point(Double.NaN, Double.NaN); listOfRadarPoints.Add(new Point(circularPlotDetails.Center.X, circularPlotDetails.Center.Y)); } preDataPoint = series.InternalDataPoints[i]; if (i == series.InternalDataPoints.Count - 2) // If next DataPoint is the last DataPoint { dataPointIndex = series.InternalDataPoints.IndexOf(nextDataPoint); dataPointPosition = GetRadarPoint(circularPlotDetails, plotGroup, nextDataPoint, dataPointIndex); if (!Double.IsNaN(nextDataPoint.InternalYValue) && (nextDataPoint.InternalYValue > plotGroup.AxisY.InternalAxisMaximum || nextDataPoint.InternalYValue < plotGroup.AxisY.InternalAxisMinimum)) { nextDataPoint._visualPosition = new Point(Double.NaN, Double.NaN); listOfRadarPoints.Add(new Point(circularPlotDetails.Center.X, circularPlotDetails.Center.Y)); } else if (!Double.IsNaN(nextDataPoint.InternalYValue) && (preDataPoint != null && !Double.IsNaN(preDataPoint.InternalYValue)) || (lastDataPoint != null && !Double.IsNaN(lastDataPoint.InternalYValue))) { listOfRadarPoints.Add(dataPointPosition); nextDataPoint._visualPosition = dataPointPosition; } else { nextDataPoint._visualPosition = new Point(Double.NaN, Double.NaN); listOfRadarPoints.Add(new Point(circularPlotDetails.Center.X, circularPlotDetails.Center.Y)); } if (series.InternalDataPoints.Count < circularPlotDetails.ListOfPoints4CircularAxis.Count) { listOfRadarPoints.Add(new Point(circularPlotDetails.Center.X, circularPlotDetails.Center.Y)); } } } }
/// <summary> /// Create Polar series /// </summary> /// <param name="chart"></param> /// <param name="series"></param> /// <param name="polarCanvas"></param> /// <param name="labelCanvas"></param> /// <param name="width"></param> /// <param name="height"></param> /// <param name="plotGroup"></param> /// <param name="circularPlotDetails"></param> private static void CreatePolarSeries(Chart chart, DataSeries series, Canvas polarCanvas, Canvas labelCanvas, Double width, Double height, PlotGroup plotGroup, CircularPlotDetails circularPlotDetails) { List <List <DataPoint> > brokenLineDataPointsGroup = GetBrokenLineDataPointsGroup(series, circularPlotDetails, plotGroup); foreach (List <DataPoint> dataPointList in brokenLineDataPointsGroup) { foreach (DataPoint dataPoint in dataPointList) { DrawMarker(dataPoint, labelCanvas, width, height, circularPlotDetails.Center); } DrawDataSeriesPath(series, dataPointList, polarCanvas); } }
/// <summary> /// Calculate radar points /// </summary> /// <param name="series"></param> /// <param name="listOfRadarPoints"></param> /// <param name="plotGroup"></param> /// <param name="circularPlotDetails"></param> private static void CalculateRadarPoints(DataSeries series, ref List<Point> listOfRadarPoints, PlotGroup plotGroup, CircularPlotDetails circularPlotDetails) { DataPoint currDataPoint; DataPoint nextDataPoint; DataPoint preDataPoint = null; DataPoint firstDataPoint = series.InternalDataPoints[0]; DataPoint lastDataPoint = series.InternalDataPoints[series.InternalDataPoints.Count - 1]; for (Int32 i = 0; i < series.InternalDataPoints.Count - 1; i++) { currDataPoint = series.InternalDataPoints[i]; Double dataPointIndex = series.InternalDataPoints.IndexOf(currDataPoint); if (!(Boolean)currDataPoint.Enabled) continue; nextDataPoint = series.InternalDataPoints[i + 1]; Point dataPointPosition = GetRadarPoint(circularPlotDetails, plotGroup, currDataPoint, dataPointIndex); if (!Double.IsNaN(currDataPoint.InternalYValue) && (currDataPoint.InternalYValue > plotGroup.AxisY.InternalAxisMaximum || currDataPoint.InternalYValue < plotGroup.AxisY.InternalAxisMinimum)) { currDataPoint._visualPosition = new Point(Double.NaN, Double.NaN); listOfRadarPoints.Add(new Point(circularPlotDetails.Center.X, circularPlotDetails.Center.Y)); } else if (currDataPoint == firstDataPoint && (nextDataPoint != null && Double.IsNaN(nextDataPoint.InternalYValue)) && (lastDataPoint != null && !Double.IsNaN(lastDataPoint.InternalYValue))) { listOfRadarPoints.Add(dataPointPosition); currDataPoint._visualPosition = dataPointPosition; } else if (!Double.IsNaN(currDataPoint.InternalYValue) && ((preDataPoint != null && !Double.IsNaN(preDataPoint.InternalYValue)) || (nextDataPoint != null && !Double.IsNaN(nextDataPoint.InternalYValue)))) { listOfRadarPoints.Add(dataPointPosition); currDataPoint._visualPosition = dataPointPosition; } else { currDataPoint._visualPosition = new Point(Double.NaN, Double.NaN); listOfRadarPoints.Add(new Point(circularPlotDetails.Center.X, circularPlotDetails.Center.Y)); } preDataPoint = series.InternalDataPoints[i]; if (i == series.InternalDataPoints.Count - 2) // If next DataPoint is the last DataPoint { dataPointIndex = series.InternalDataPoints.IndexOf(nextDataPoint); dataPointPosition = GetRadarPoint(circularPlotDetails, plotGroup, nextDataPoint, dataPointIndex); if (!Double.IsNaN(nextDataPoint.InternalYValue) && (nextDataPoint.InternalYValue > plotGroup.AxisY.InternalAxisMaximum || nextDataPoint.InternalYValue < plotGroup.AxisY.InternalAxisMinimum)) { nextDataPoint._visualPosition = new Point(Double.NaN, Double.NaN); listOfRadarPoints.Add(new Point(circularPlotDetails.Center.X, circularPlotDetails.Center.Y)); } else if (!Double.IsNaN(nextDataPoint.InternalYValue) && (preDataPoint != null && !Double.IsNaN(preDataPoint.InternalYValue)) || (lastDataPoint != null && !Double.IsNaN(lastDataPoint.InternalYValue))) { listOfRadarPoints.Add(dataPointPosition); nextDataPoint._visualPosition = dataPointPosition; } else { nextDataPoint._visualPosition = new Point(Double.NaN, Double.NaN); listOfRadarPoints.Add(new Point(circularPlotDetails.Center.X, circularPlotDetails.Center.Y)); } if (series.InternalDataPoints.Count < circularPlotDetails.ListOfPoints4CircularAxis.Count) listOfRadarPoints.Add(new Point(circularPlotDetails.Center.X, circularPlotDetails.Center.Y)); } } }
/// <summary> /// Update position of the DataPoint according to YValue and XValue /// </summary> /// <param name="dataPoint">DataPoint</param> /// <param name="canvasWidth">Width of the Canvas</param> /// <param name="canvasHeight">height of the Canvas</param> /// <param name="dataPointWidth">Width of the DataPoint</param> private static void UpdateYValueAndXValuePosition(DataPoint dataPoint, Double canvasWidth, Double canvasHeight, Double dataPointWidth) { Faces dpFaces = dataPoint.Faces; Double xPositionOfDataPoint, highY = 0, lowY = 0, openY = 0, closeY = 0; PlotGroup plotGroup = dataPoint.Parent.PlotGroup; SetDataPointValues(dataPoint, ref highY, ref lowY, ref openY, ref closeY); // Calculate required pixel positions xPositionOfDataPoint = Graphics.ValueToPixelPosition(0, canvasWidth, (Double)plotGroup.AxisX.InternalAxisMinimum, (Double)plotGroup.AxisX.InternalAxisMaximum, dataPoint.InternalXValue); openY = Graphics.ValueToPixelPosition(canvasHeight, 0, (Double)plotGroup.AxisY.InternalAxisMinimum, (Double)plotGroup.AxisY.InternalAxisMaximum, openY); closeY = Graphics.ValueToPixelPosition(canvasHeight, 0, (Double)plotGroup.AxisY.InternalAxisMinimum, (Double)plotGroup.AxisY.InternalAxisMaximum, closeY); highY = Graphics.ValueToPixelPosition(canvasHeight, 0, (Double)plotGroup.AxisY.InternalAxisMinimum, (Double)plotGroup.AxisY.InternalAxisMaximum, highY); lowY = Graphics.ValueToPixelPosition(canvasHeight, 0, (Double)plotGroup.AxisY.InternalAxisMinimum, (Double)plotGroup.AxisY.InternalAxisMaximum, lowY); dataPoint._isPriceUp = (openY > closeY) ? true : false; // Update size and position of visual of the DatPoint Canvas dataPointVisual = dataPoint.Faces.Visual as Canvas; dataPointVisual.Width = dataPointWidth; dataPointVisual.Height = Math.Abs(lowY - highY); dataPointVisual.SetValue(Canvas.TopProperty, (highY < lowY) ? highY : lowY); dataPointVisual.SetValue(Canvas.LeftProperty, xPositionOfDataPoint - dataPointWidth / 2); // Update size and position of High-Low line of the DatPoint Line highLowLine = dataPoint.Faces.VisualComponents[0] as Line; highLowLine.X1 = dataPointVisual.Width / 2; highLowLine.X2 = dataPointVisual.Width / 2; highLowLine.Y1 = 0; highLowLine.Y2 = dataPointVisual.Height; highLowLine.Tag = new ElementData() { Element = dataPoint, VisualElementName = "HlLine" }; // Update size and position of Open-Close rectangle of the DatPoint Rectangle openCloseRect = dpFaces.VisualComponents[1] as Rectangle; openCloseRect.Width = dataPointWidth; openCloseRect.Height = Math.Max(Math.Abs(openY - closeY), 1); openCloseRect.Tag = new ElementData() { Element = dataPoint, VisualElementName = "OcRect" }; openCloseRect.SetValue(Canvas.TopProperty, ((closeY > openY) ? openY : closeY) - ((Double)dataPointVisual.GetValue(Canvas.TopProperty))); openCloseRect.SetValue(Canvas.LeftProperty, (Double)0); // Apply color for a CandleStick ApplyOrUpdateColorForACandleStick(dataPoint); // Need to re position the shadow also ApplyOrRemoveShadow(dataPoint, dataPointWidth); // Apply or remove _axisIndicatorBorderElement ApplyOrUpdateBorder(dataPoint, dataPointWidth); // Apply or remove bevel ApplyOrRemoveBevel(dataPoint, dataPointWidth); if (dataPoint.LabelVisual != null) { SetLabelPosition(dataPoint, canvasWidth, canvasHeight); } if (dataPoint.Parent.ToolTipElement != null) { dataPoint.Parent.ToolTipElement.Hide(); } (dataPoint.Chart as Chart).ChartArea.DisableIndicators(); dataPoint._visualPosition = new Point((Double)dataPointVisual.GetValue(Canvas.LeftProperty) + dataPointVisual.Width / 2, (Double)dataPointVisual.GetValue(Canvas.TopProperty)); }
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 = CalculateDataPointWidth(dsFaces.Visual.Width, dsFaces.Visual.Height, chart); } if (property == VcProperties.Enabled || (dpFaces == null && (property == VcProperties.XValue || property == VcProperties.YValues))) { CreateOrUpdateACandleStick(dataPoint, dsFaces.Visual as Canvas, dsFaces.LabelCanvas, dsFaces.Visual.Width, dsFaces.Visual.Height, dataPointWidth); return; } if (dpFaces == null) { return; } 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: case VcProperties.StickColor: 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 = (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); 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.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) { CreateAndPositionLabel(dsFaces.LabelCanvas, dataPoint); } } if (dataPoint.Parent.SelectionEnabled && dataPoint.Selected) { dataPoint.Select(true); } break; } }
/// <summary> /// /// </summary> /// <param name="obj">Object may be DataSeries or DataPoint</param> /// <param name="property"></param> /// <param name="newValue"></param> private static void UpdateDataSeries(ObservableObject obj, VcProperties property, object newValue) { DataPoint dataPoint = null; DataSeries dataSeries = obj as DataSeries; Boolean isDataPoint = false; if (dataSeries == null) { isDataPoint = true; dataPoint = obj as DataPoint; dataSeries = dataPoint.Parent; } Chart chart = dataSeries.Chart as Chart; if (chart == null) { return; } PlotGroup plotGroup = dataSeries.PlotGroup; Canvas line2dCanvas = null; Canvas label2dCanvas = null; Path linePath = null; Path lineShadowPath = null; if (dataSeries.Faces != null) { if (dataSeries.Faces.Parts.Count > 0) { linePath = dataSeries.Faces.Parts[0] as Path; if (dataSeries.Faces.Parts.Count > 1) { lineShadowPath = dataSeries.Faces.Parts[1] as Path; } } line2dCanvas = dataSeries.Faces.Visual as Canvas; label2dCanvas = dataSeries.Faces.LabelCanvas as Canvas; } else if (dataSeries.Faces == null && property == VcProperties.Enabled && (Boolean)newValue == true) { ColumnChart.Update(chart, dataSeries.RenderAs, (from ds in chart.InternalSeries where ds.RenderAs == RenderAs.QuickLine select ds).ToList()); return; } else { return; } Double height = chart.ChartArea.ChartVisualCanvas.Height; Double width = chart.ChartArea.ChartVisualCanvas.Width; switch (property) { case VcProperties.Color: if (linePath != null) { Brush lineColorValue = (newValue != null) ? newValue as Brush : dataSeries.Color; linePath.Stroke = ((Boolean)dataSeries.LightingEnabled) ? Graphics.GetLightingEnabledBrush(lineColorValue, "Linear", new Double[] { 0.65, 0.55 }) : lineColorValue; //dataPoint.Color; } break; case VcProperties.LightingEnabled: if (linePath != null) { linePath.Stroke = ((Boolean)newValue) ? Graphics.GetLightingEnabledBrush(dataSeries.Color, "Linear", new Double[] { 0.65, 0.55 }) : dataSeries.Color; } break; case VcProperties.Opacity: if (linePath != null) { linePath.Opacity = (Double)dataSeries.Opacity; } break; case VcProperties.LineStyle: case VcProperties.LineThickness: if (lineShadowPath != null) { lineShadowPath.StrokeThickness = (Double)dataSeries.LineThickness; } if (linePath != null) { linePath.StrokeThickness = (Double)dataSeries.LineThickness; } if (lineShadowPath != null) { lineShadowPath.StrokeDashArray = ExtendedGraphics.GetDashArray(dataSeries.LineStyle); } if (linePath != null) { linePath.StrokeDashArray = ExtendedGraphics.GetDashArray(dataSeries.LineStyle); } break; case VcProperties.Enabled: if (!isDataPoint && line2dCanvas != null) { if ((Boolean)newValue == false) { line2dCanvas.Visibility = Visibility.Collapsed; label2dCanvas.Visibility = Visibility.Collapsed; } else { if (line2dCanvas.Parent == null) { ColumnChart.Update(chart, dataSeries.RenderAs, (from ds in chart.InternalSeries where ds.RenderAs == RenderAs.QuickLine select ds).ToList()); return; } line2dCanvas.Visibility = Visibility.Visible; label2dCanvas.Visibility = Visibility.Visible; } chart._toolTip.Hide(); break; } goto RENDER_SERIES; case VcProperties.ShadowEnabled: case VcProperties.DataPoints: case VcProperties.YValue: case VcProperties.YValues: case VcProperties.XValue: case VcProperties.ViewportRangeEnabled: case VcProperties.DataPointUpdate: RENDER_SERIES: LineChart.UpdateLineSeries(dataSeries, width, height, label2dCanvas); 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 GetVisualObjectForStockChart(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); } Canvas visual, labelCanvas, stockChartCanvas; RenderHelper.RepareCanvas4Drawing(preExistingPanel as Canvas, out visual, out labelCanvas, out stockChartCanvas, 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 = CandleStick.CalculateDataPointWidth(width, height, chart); foreach (DataSeries series in seriesList) { if (series.Enabled == false) { continue; } Faces dsFaces = new Faces() { Visual = stockChartCanvas, LabelCanvas = labelCanvas }; series.Faces = dsFaces; PlotGroup plotGroup = series.PlotGroup; _tempDataSeries = series; foreach (DataPoint dataPoint in series.InternalDataPoints) { CreateOrUpdateAStockDataPoint(dataPoint, stockChartCanvas, labelCanvas, width, height, dataPointWidth); } } // Apply animation to series if (animationEnabled) { if (_tempDataSeries.Storyboard == null) { _tempDataSeries.Storyboard = new Storyboard(); } _tempDataSeries.Storyboard = AnimationHelper.ApplyOpacityAnimation(stockChartCanvas, _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); } stockChartCanvas.Tag = null; // ColumnChart.CreateOrUpdatePlank(chart, seriesList[0].PlotGroup.AxisY, stockChartCanvas, 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(stockChartCanvas); } else { labelCanvas.SetValue(Canvas.ZIndexProperty, 1); visual.Children.Add(labelCanvas); visual.Children.Add(stockChartCanvas); } 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> /// Calculate width of each stacked column /// </summary> /// <param name="chart">Chart reference</param> /// <param name="plotGroup">PlotGroup</param> /// <param name="width">Width of the PlotArea</param> /// <param name="height">Width of the PlotArea</param> /// <param name="minDiff">Minimum difference between two DataPoints</param> /// <param name="maxColumnWidth">Maximum width of a StackedColumn</param> /// <returns>Width of a stacked column</returns> internal static Double CalculateWidthOfEachStackedColumn(Chart chart, PlotGroup plotGroup, Double heightOrWidth, out Double minDiff, out Double maxColumnWidth) { Double widthPerColumn; PlotDetails plotDetails = chart.PlotDetails; Double widthDivisionFactor = plotDetails.DrawingDivisionFactor; if(chart.PlotDetails.ChartOrientation == ChartOrientationType.Vertical) minDiff = plotDetails.GetMinOfMinDifferencesForXValue(RenderAs.Column, RenderAs.StackedColumn, RenderAs.StackedColumn100); else minDiff = plotDetails.GetMinOfMinDifferencesForXValue(RenderAs.Bar, RenderAs.StackedBar, RenderAs.StackedBar100); if (Double.IsPositiveInfinity(minDiff)) minDiff = 0; maxColumnWidth = Graphics.ValueToPixelPosition(0, heightOrWidth, (Double)plotGroup.AxisX.InternalAxisMinimum, (Double)plotGroup.AxisX.InternalAxisMaximum, minDiff + (Double)plotGroup.AxisX.InternalAxisMinimum) * (1 - ColumnChart.COLUMN_GAP_RATIO); widthPerColumn = maxColumnWidth / widthDivisionFactor; if (minDiff == 0) { widthPerColumn = heightOrWidth * .5 / widthDivisionFactor; maxColumnWidth = widthPerColumn * widthDivisionFactor; } else { widthPerColumn = Graphics.ValueToPixelPosition(0, heightOrWidth, plotGroup.AxisX.InternalAxisMinimum, plotGroup.AxisX.InternalAxisMaximum, minDiff + plotGroup.AxisX.InternalAxisMinimum); widthPerColumn *= (1 - ((chart.PlotDetails.ChartOrientation == ChartOrientationType.Vertical) ? ColumnChart.COLUMN_GAP_RATIO : BarChart.BAR_GAP_RATIO)); maxColumnWidth = widthPerColumn; widthPerColumn /= widthDivisionFactor; } if (!Double.IsNaN(chart.DataPointWidth)) { if (chart.DataPointWidth >= 0) { widthPerColumn = maxColumnWidth = chart.DataPointWidth / 100 * ((chart.PlotDetails.ChartOrientation == ChartOrientationType.Vertical) ? chart.PlotArea.Width: chart.PlotArea.Height); maxColumnWidth *= widthDivisionFactor; } } if (maxColumnWidth < 2) maxColumnWidth = 2; return widthPerColumn; }
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 = CandleStick.CalculateDataPointWidth(dsFaces.Visual.Width, dsFaces.Visual.Height, chart); } if (property == VcProperties.Enabled) { 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 = 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); 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.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) { CandleStick.CreateAndPositionLabel(dsFaces.LabelCanvas, dataPoint); } } if (dataPoint.Parent.SelectionEnabled && dataPoint.Selected) { dataPoint.Select(true); } break; } }
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); } }
// 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); } }