/// <summary> /// Updates the data point's visual representation. /// </summary> /// <param name="dataPoint">The data point.</param> protected override void UpdateDataPoint(DataPoint dataPoint) { double maximumDiameter = Math.Min(PlotAreaSize.Width, PlotAreaSize.Height) * MaximumBubbleSizeAsRatioOfSmallestDimension; BubbleDataPoint bubbleDataPoint = (BubbleDataPoint)dataPoint; double ratioOfLargestBubble = (MaxOfDataPointActualSizeValues.HasValue && MaxOfDataPointActualSizeValues.Value != 0.0 && bubbleDataPoint.ActualSize >= 0.0) ? Math.Abs(bubbleDataPoint.ActualSize) / MaxOfDataPointActualSizeValues.Value : 0.0; bubbleDataPoint.Width = ratioOfLargestBubble * maximumDiameter; bubbleDataPoint.Height = ratioOfLargestBubble * maximumDiameter; // Call UpdateLayout to ensure ActualWidth/ActualHeight are correct if (bubbleDataPoint.ActualWidth == 0.0 || bubbleDataPoint.ActualHeight == 0.0) { bubbleDataPoint.UpdateLayout(); } double left = (ActualIndependentRangeAxis.GetPlotAreaCoordinate((IComparable)bubbleDataPoint.ActualIndependentValue)) - (bubbleDataPoint.Width / 2.0); double top = (PlotAreaSize.Height - (bubbleDataPoint.Height / 2.0)) - ActualDependentRangeAxis.GetPlotAreaCoordinate((IComparable)bubbleDataPoint.ActualDependentValue); if (ValueHelper.CanGraph(left) && ValueHelper.CanGraph(top)) { Canvas.SetLeft(bubbleDataPoint, left); Canvas.SetTop(bubbleDataPoint, top); } }
/// <summary> /// This method updates a single data point. /// </summary> /// <param name="dataPoint">The data point to update.</param> protected override void UpdateDataPoint(DataPoint dataPoint) { double PlotAreaHeight = ActualDependentRangeAxis.GetPlotAreaCoordinate(ActualDependentRangeAxis.Range.Maximum); double dataPointX = ActualIndependentRangeAxis.GetPlotAreaCoordinate(ValueHelper.ToComparable(dataPoint.ActualIndependentValue)); double dataPointY = ActualDependentRangeAxis.GetPlotAreaCoordinate(ValueHelper.ToDouble(dataPoint.ActualDependentValue)); if (ValueHelper.CanGraph(dataPointX) && ValueHelper.CanGraph(dataPointY)) { // Set dimensions if (!double.IsNaN(MarkerHeight)) { dataPoint.Height = MarkerHeight; } if (!double.IsNaN(MarkerWidth)) { dataPoint.Width = MarkerWidth; } // Call UpdateLayout to ensure ActualWidth/ActualHeight are correct if (dataPoint.ActualWidth == 0.0 || dataPoint.ActualHeight == 0.0) { dataPoint.UpdateLayout(); } // Set the Position Canvas.SetLeft( dataPoint, Math.Round(dataPointX - (dataPoint.ActualWidth / 2))); Canvas.SetTop( dataPoint, Math.Round(PlotAreaHeight - (dataPointY + (dataPoint.ActualHeight / 2)))); } }
/// <summary> /// Updates the point collection object. /// </summary> private void UpdatePointsCollection() { double maximum = ActualDependentRangeAxis.GetPlotAreaCoordinate(ActualDependentRangeAxis.Range.Maximum); if (ValueHelper.CanGraph(maximum)) { IEnumerable <Point> points = ActiveDataPoints .OrderBy(dataPoint => dataPoint.IndependentValue) .Select(dataPoint => new Point( ActualIndependentRangeAxis.GetPlotAreaCoordinate((IComparable)dataPoint.ActualIndependentValue), maximum - ActualDependentRangeAxis.GetPlotAreaCoordinate((IComparable)dataPoint.ActualDependentValue))); if (!points.IsEmpty()) { this.Points = new PointCollection(); foreach (Point point in points) { this.Points.Add(point); } } else { this.Points = null; } } }
/// <summary> /// Returns the style to use for all data points. /// </summary> /// <returns>The style to use for all data points.</returns> //protected override Style GetDataPointStyleFromHost() //{ // return SeriesHost.NextStyle(typeof(CandlestickDataPoint), true); //} /// <summary> /// This method updates a single data point. /// </summary> /// <param name="dataPoint">The data point to update.</param> protected override void UpdateDataPoint(DataPoint dataPoint) { CandlestickDataPoint candlestickDataPoint = (CandlestickDataPoint)dataPoint; double PlotAreaHeight = ActualDependentRangeAxis.GetPlotAreaCoordinate(ActualDependentRangeAxis.Range.Maximum).Value; double dataPointX = ActualIndependentRangeAxis.GetPlotAreaCoordinate(dataPoint.ActualIndependentValue).Value; double highPointY = ActualDependentRangeAxis.GetPlotAreaCoordinate(ValueHelper.ToDouble(candlestickDataPoint.High)).Value; double lowPointY = ActualDependentRangeAxis.GetPlotAreaCoordinate(ValueHelper.ToDouble(candlestickDataPoint.Low)).Value; double openPointY = ActualDependentRangeAxis.GetPlotAreaCoordinate(ValueHelper.ToDouble(candlestickDataPoint.Open)).Value; double closePointY = ActualDependentRangeAxis.GetPlotAreaCoordinate(ValueHelper.ToDouble(candlestickDataPoint.Close)).Value; candlestickDataPoint.UpdateBody(ActualDependentRangeAxis); if (ValueHelper.CanGraph(dataPointX)) { dataPoint.Height = Math.Abs(highPointY - lowPointY); dataPoint.Width = 5.0; if (dataPoint.ActualWidth == 0.0 || dataPoint.ActualHeight == 0.0) { dataPoint.UpdateLayout(); } Canvas.SetLeft(dataPoint, Math.Round(dataPointX - (dataPoint.ActualWidth / 2))); Canvas.SetTop(dataPoint, Math.Round(PlotAreaHeight - highPointY)); } }
/// <summary> /// This method updates a single data point. /// </summary> /// <param name="dataPoint">The data point to update.</param> protected override void UpdateDataPoint(DataPoint dataPoint) { StockBarDataPoint candlestickDataPoint = (StockBarDataPoint)dataPoint; Double PlotAreaHeight = ActualDependentRangeAxis.GetPlotAreaCoordinate(ActualDependentRangeAxis.Range.Maximum); Double dataPointX = ActualIndependentRangeAxis.GetPlotAreaCoordinate(ValueHelper.ToComparable(dataPoint.ActualIndependentValue)); Double highPointY = ActualDependentRangeAxis.GetPlotAreaCoordinate(candlestickDataPoint.High); Double lowPointY = ActualDependentRangeAxis.GetPlotAreaCoordinate(candlestickDataPoint.Low); Double openPointY = ActualDependentRangeAxis.GetPlotAreaCoordinate(candlestickDataPoint.Open); Double closePointY = ActualDependentRangeAxis.GetPlotAreaCoordinate(candlestickDataPoint.Close); if (!singleBlockWidth.HasValue) { Range <Double> doubleRange = ActualIndependentRangeAxis.Range.ToDoubleRange(); Double rangeLength = doubleRange.Maximum - doubleRange.Minimum; if (rangeLength > 0.0) { singleBlockWidth = PlotArea.Width * 1.0 / rangeLength; if (singleBlockWidth < 4.0) { singleBlockWidth = 4.0; } } else { singleBlockWidth = 4.0; } } if (ValueHelper.CanGraph(dataPointX)) { candlestickDataPoint.Background = new SolidColorBrush(Colors.Transparent); dataPoint.Height = Math.Abs(highPointY - lowPointY); dataPoint.Width = singleBlockWidth.Value * 0.8; if (dataPoint.Width > 16.0) { dataPoint.Width = 16.0; } candlestickDataPoint.UpdateBody(ActualDependentRangeAxis); //if (dataPoint.ActualWidth == 0.0 || dataPoint.ActualHeight == 0.0) { dataPoint.UpdateLayout(); } Canvas.SetLeft(dataPoint, Math.Round(dataPointX - (dataPoint.ActualWidth / 2))); Canvas.SetTop(dataPoint, Math.Round(PlotAreaHeight - highPointY)); } }
/// <summary> /// This method updates a single data point. /// </summary> /// <param name="dataPoint">The data point to update.</param> protected override void UpdateDataPoint(DataPoint dataPoint) { CandlestickDataPoint candlestickDataPoint = (CandlestickDataPoint)dataPoint; FrameworkElement fe = ActualIndependentRangeAxis as FrameworkElement; if (fe != null) { if (fe.ActualWidth == 0.0) { return; } } if (!axesHasBeenUpdated) { return; } double PlotAreaHeight = ActualDependentRangeAxis.GetPlotAreaCoordinate(ActualDependentRangeAxis.Range.Maximum); double dataPointX = ActualIndependentRangeAxis.GetPlotAreaCoordinate(ValueHelper.ToComparable(dataPoint.ActualIndependentValue)); double highPointY = ActualDependentRangeAxis.GetPlotAreaCoordinate(candlestickDataPoint.High); double lowPointY = ActualDependentRangeAxis.GetPlotAreaCoordinate(candlestickDataPoint.Low); double openPointY = ActualDependentRangeAxis.GetPlotAreaCoordinate(candlestickDataPoint.Open); double closePointY = ActualDependentRangeAxis.GetPlotAreaCoordinate(candlestickDataPoint.Close); if (closePointY > openPointY) { candlestickDataPoint.Background = positiveBrush; } else { candlestickDataPoint.Background = negativeBrush; } candlestickDataPoint.UpdateBody(ActualDependentRangeAxis); if (ValueHelper.CanGraph(dataPointX)) { dataPoint.Height = Math.Abs(highPointY - lowPointY); dataPoint.Width = 5.0; dataPoint.UpdateLayout(); Canvas.SetLeft(dataPoint, Math.Round(dataPointX - (dataPoint.ActualWidth / 2))); Canvas.SetTop(dataPoint, Math.Round(PlotAreaHeight - highPointY)); } }
/// <summary> /// Overrides the requested axis range to include the width and height /// necessary for the bubbles. /// </summary> /// <param name="rangeAxis">The range axis.</param> /// <param name="range">The data range.</param> /// <returns>The requested axis range.</returns> protected override Range <IComparable> OverrideRequestedAxisRange(IRangeAxis rangeAxis, Range <IComparable> range) { if (ActiveDataPoints.Any()) { if (rangeAxis == ActualIndependentRangeAxis) { double smallestXCoordinate = ActiveDataPoints .Select(dataPoint => ActualIndependentRangeAxis.GetPlotAreaCoordinate((IComparable)dataPoint.IndependentValue) - dataPoint.ActualWidth) .Min(); double largestXCoordinate = ActiveDataPoints .Select(dataPoint => ActualIndependentRangeAxis.GetPlotAreaCoordinate((IComparable)dataPoint.IndependentValue) + dataPoint.ActualWidth) .Max(); return(new Range <IComparable>( ActualIndependentRangeAxis.GetPlotAreaCoordinateValueRange(smallestXCoordinate).Minimum, ActualIndependentRangeAxis.GetPlotAreaCoordinateValueRange(largestXCoordinate).Maximum)); } else if (rangeAxis == ActualDependentRangeAxis) { double smallestYCoordinate = ActiveDataPoints .Select(dataPoint => ActualDependentRangeAxis.GetPlotAreaCoordinate((IComparable)dataPoint.DependentValue) - dataPoint.ActualHeight) .Min(); double largestYCoordinate = ActiveDataPoints .Select(dataPoint => ActualDependentRangeAxis.GetPlotAreaCoordinate((IComparable)dataPoint.DependentValue) + dataPoint.ActualHeight) .Max(); return(new Range <IComparable>( ActualDependentRangeAxis.GetPlotAreaCoordinateValueRange(smallestYCoordinate).Minimum, ActualDependentRangeAxis.GetPlotAreaCoordinateValueRange(largestYCoordinate).Maximum)); } } return(new Range <IComparable>()); }
/// <summary> /// Updates the visual representation of the data point. /// </summary> /// <param name="dataPoint">The data point to update.</param> protected override void UpdateDataPoint(DataPoint dataPoint) { double maximum = ActualDependentRangeAxis.GetPlotAreaCoordinate(ActualDependentRangeAxis.Range.Maximum); if (ValueHelper.CanGraph(maximum)) { double x = ActualIndependentRangeAxis.GetPlotAreaCoordinate(ValueHelper.ToComparable(dataPoint.ActualIndependentValue)); double y = ActualDependentRangeAxis.GetPlotAreaCoordinate(ValueHelper.ToDouble(dataPoint.ActualDependentValue)); if (ValueHelper.CanGraph(x) && ValueHelper.CanGraph(y)) { if (!double.IsNaN(MarkerHeight)) { dataPoint.Height = MarkerHeight; } if (!double.IsNaN(MarkerWidth)) { dataPoint.Width = MarkerWidth; } // Call UpdateLayout to ensure ActualWidth/ActualHeight are correct if (dataPoint.ActualWidth == 0.0 || dataPoint.ActualHeight == 0.0) { dataPoint.UpdateLayout(); } double coordinateY = Math.Round(maximum - (y + (dataPoint.ActualHeight / 2))); Canvas.SetTop(dataPoint, coordinateY); double coordinateX = Math.Round(x - (dataPoint.ActualWidth / 2)); Canvas.SetLeft(dataPoint, coordinateX); } if (!UpdatingAllDataPoints) { UpdatePointsCollection(); } } }
/// <summary> /// Updates each point. /// </summary> /// <param name="dataPoint">The data point to update.</param> protected override void UpdateDataPoint(DataPoint dataPoint) { if (SeriesHost == null || PlotArea == null) { return; } Object category = dataPoint.IndependentValue ?? (this.ActiveDataPoints.IndexOf(dataPoint) + 1); IComparable comparableCategory = category as IComparable; if (null == comparableCategory) { return; } if (!singleBlockWidth.HasValue) { Range <Double> doubleRange = ActualIndependentRangeAxis.Range.ToDoubleRange(); Double rangeLength = doubleRange.Maximum - doubleRange.Minimum; if (rangeLength > 0.0) { singleBlockWidth = PlotArea.Width * 1.0 / rangeLength; } else { singleBlockWidth = 1.0; } } Double pos = ActualIndependentRangeAxis.GetPlotAreaCoordinate(comparableCategory); Range <Double> coordinateRange = new Range <double>(pos - singleBlockWidth.Value / 2.0, pos + singleBlockWidth.Value / 2.0); if (!coordinateRange.HasData) { return; } double plotAreaHeight = ActualDependentRangeAxis.GetPlotAreaCoordinate(ActualDependentRangeAxis.Range.Maximum); IEnumerable <ColumnRangedSeries> columnSeries = SeriesHost.Series.OfType <ColumnRangedSeries>().Where(series => series.ActualIndependentRangeAxis == ActualIndependentRangeAxis); int numberOfSeries = columnSeries.Count(); double coordinateRangeWidth = (coordinateRange.Maximum - coordinateRange.Minimum); double segmentWidth = coordinateRangeWidth * 0.8; double columnWidth = segmentWidth / numberOfSeries; int seriesIndex = columnSeries.IndexOf(this); double dataPointY = ActualDependentRangeAxis.GetPlotAreaCoordinate(ValueHelper.ToDouble(dataPoint.ActualDependentValue)); double zeroPointY = ActualDependentRangeAxis.GetPlotAreaCoordinate(0); double offset = seriesIndex * Math.Round(columnWidth) + coordinateRangeWidth * 0.1; double dataPointX = coordinateRange.Minimum + offset; if (_categoriesWithMultipleDataPoints.ContainsKey(category)) { // Multiple DataPoints share this category; offset and overlap them appropriately IGrouping <object, DataPoint> categoryGrouping = _categoriesWithMultipleDataPoints[category]; int index = categoryGrouping.IndexOf(dataPoint); dataPointX += (index * (columnWidth * 0.2)) / (categoryGrouping.Count() - 1); columnWidth *= 0.8; Canvas.SetZIndex(dataPoint, -index); } if (!double.IsNaN(dataPointY) && !double.IsNaN(dataPointX) && !double.IsNaN(zeroPointY)) { double left = Math.Round(dataPointX); double width = Math.Round(columnWidth); double top = Math.Round(plotAreaHeight - Math.Max(dataPointY, zeroPointY) + 0.5); double bottom = Math.Round(plotAreaHeight - Math.Min(dataPointY, zeroPointY) + 0.5); double height = bottom - top + 1; Canvas.SetLeft(dataPoint, left); Canvas.SetTop(dataPoint, top); dataPoint.Width = width; dataPoint.Height = height; } }