/// <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 = (_rangeOfActualSizeValues.HasData && _rangeOfActualSizeValues.Maximum != 0.0 && bubbleDataPoint.ActualSize >= 0.0) ? Math.Abs(bubbleDataPoint.ActualSize) / _rangeOfActualSizeValues.Maximum : 0.0; bubbleDataPoint.Width = ratioOfLargestBubble * maximumDiameter; bubbleDataPoint.Height = ratioOfLargestBubble * maximumDiameter; double left = (ActualIndependentAxis.GetPlotAreaCoordinate(bubbleDataPoint.ActualIndependentValue)).Value - (bubbleDataPoint.Width / 2.0); double top = (PlotAreaSize.Height - (bubbleDataPoint.Height / 2.0)) - ActualDependentRangeAxis.GetPlotAreaCoordinate(bubbleDataPoint.ActualDependentValue).Value; if (ValueHelper.CanGraph(left) && ValueHelper.CanGraph(top)) { dataPoint.Visibility = Visibility.Visible; Canvas.SetLeft(bubbleDataPoint, left); Canvas.SetTop(bubbleDataPoint, top); } else { dataPoint.Visibility = Visibility.Collapsed; } }
/// <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> /// 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> /// Overrides the range requested from the axis. The default range is /// the range of values on to be plotted on the axis. /// </summary> /// <param name="rangeAxis">The axis to retrieve the range for.</param> /// <param name="range">The range of values that are plotted on the /// axis.</param> /// <returns>A new range.</returns> protected virtual Range <IComparable> OverrideRequestedAxisRange(IRangeAxis rangeAxis, Range <IComparable> range) { if (range.HasData) { double minimumCoordinate = rangeAxis.GetPlotAreaCoordinate(range.Minimum); double maximumCoordinate = rangeAxis.GetPlotAreaCoordinate(range.Maximum); if (ValueHelper.CanGraph(minimumCoordinate) && ValueHelper.CanGraph(maximumCoordinate)) { minimumCoordinate -= RangeAxisMargin; maximumCoordinate += RangeAxisMargin; Range <IComparable> minimumOffsetRange = rangeAxis.GetPlotAreaCoordinateValueRange(minimumCoordinate); Range <IComparable> maximumOffsetRange = rangeAxis.GetPlotAreaCoordinateValueRange(maximumCoordinate); if (minimumOffsetRange.HasData && maximumOffsetRange.HasData) { return(new Range <IComparable>( minimumOffsetRange.Minimum, maximumOffsetRange.Maximum)); } } } return(range); }
/// <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 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).Value; if (ValueHelper.CanGraph(maximum)) { double x = ActualIndependentAxis.GetPlotAreaCoordinate(dataPoint.ActualIndependentValue).Value; double y = ActualDependentRangeAxis.GetPlotAreaCoordinate(dataPoint.ActualDependentValue).Value; if (ValueHelper.CanGraph(x) && ValueHelper.CanGraph(y)) { dataPoint.Visibility = Visibility.Visible; 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); } else { dataPoint.Visibility = Visibility.Collapsed; } } if (!UpdatingDataPoints) { UpdateShape(); } }
/// <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> /// 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.ActualIndependentValue ?? (this.ActiveDataPoints.IndexOf(dataPoint) + 1); Range <UnitValue> coordinateRange = GetCategoryRange(category); if (!coordinateRange.HasData) { return; } else if (coordinateRange.Maximum.Unit != Unit.Pixels || coordinateRange.Minimum.Unit != Unit.Pixels) { throw new InvalidOperationException(Properties.Resources.DataPointSeriesWithAxes_ThisSeriesDoesNotSupportRadialAxes); } double minimum = (double)coordinateRange.Minimum.Value; double maximum = (double)coordinateRange.Maximum.Value; IEnumerable <BarSeries> barSeries = SeriesHost.Series.OfType <BarSeries>().Where(series => series.ActualIndependentAxis == ActualIndependentAxis); int numberOfSeries = barSeries.Count(); double coordinateRangeHeight = (maximum - minimum); double segmentHeight = coordinateRangeHeight * 0.8; double barHeight = segmentHeight / numberOfSeries; int seriesIndex = barSeries.IndexOf(this); double dataPointX = ActualDependentRangeAxis.GetPlotAreaCoordinate(ValueHelper.ToDouble(dataPoint.ActualDependentValue)).Value.Value; double zeroPointX = ActualDependentRangeAxis.GetPlotAreaCoordinate(ActualDependentRangeAxis.Origin).Value.Value; double offset = seriesIndex * Math.Round(barHeight) + coordinateRangeHeight * 0.1; double dataPointY = minimum + offset; if (GetIsDataPointGrouped(category)) { // Multiple DataPoints share this category; offset and overlap them appropriately IGrouping <object, DataPoint> categoryGrouping = GetDataPointGroup(category); int index = categoryGrouping.IndexOf(dataPoint); dataPointY += (index * (barHeight * 0.2)) / (categoryGrouping.Count() - 1); barHeight *= 0.8; Canvas.SetZIndex(dataPoint, -index); } if (ValueHelper.CanGraph(dataPointX) && ValueHelper.CanGraph(dataPointY) && ValueHelper.CanGraph(zeroPointX)) { double top = Math.Round(dataPointY); double height = Math.Round(barHeight); double left = Math.Round(Math.Min(dataPointX, zeroPointX) - 0.5); double right = Math.Round(Math.Max(dataPointX, zeroPointX) - 0.5); double width = right - left + 1; Canvas.SetLeft(dataPoint, left); Canvas.SetTop(dataPoint, top); dataPoint.Width = width; dataPoint.Height = height; } }
internal override void OnUpdateView(DataPoint dataPoint) { DataPointView view = dataPoint.View; if (view == null) { return; } FrameworkElement frameworkElement = view.MarkerView; bool flag = this.IsMarkerVisible(dataPoint) && ValueHelper.CanGraph(view.AnchorPoint.X) && ValueHelper.CanGraph(view.AnchorPoint.Y); if (flag && frameworkElement == null) { this.OnCreateView(dataPoint); frameworkElement = view.MarkerView; } else if (!flag && frameworkElement != null) { this.OnRemoveView(dataPoint); frameworkElement = (FrameworkElement)null; } if (frameworkElement == null) { return; } AnchorPanel.SetHideOverlapped((UIElement)frameworkElement, this.CanHideMarker(dataPoint)); AnchorPanel.SetMaximumMovingDistance((UIElement)frameworkElement, 0.0); AnchorPanel.SetAnchorPoint((UIElement)frameworkElement, view.AnchorPoint); AnchorPanel.SetContentPosition((UIElement)frameworkElement, ContentPositions.MiddleCenter); }
/// <summary> /// Updates the Series shape object. /// </summary> protected virtual void UpdateShape() { double maximum = ActualDependentRangeAxis.GetPlotAreaCoordinate(ActualDependentRangeAxis.Range.Maximum).Value; Func <DataPoint, Point> createPoint = dataPoint => new Point( ActualIndependentAxis.GetPlotAreaCoordinate(dataPoint.ActualIndependentValue).Value, maximum - ActualDependentRangeAxis.GetPlotAreaCoordinate(dataPoint.ActualDependentValue).Value); IEnumerable <Point> points = Enumerable.Empty <Point>(); if (ValueHelper.CanGraph(maximum)) { if (ActualIndependentAxis is IRangeAxis) { points = DataPointsByIndependentValue.Select(createPoint); } else { points = ActiveDataPoints .Select(createPoint) .OrderBy(point => point.X); } } UpdateShapeFromPoints(points); }
/// <summary> /// Renders the axis as an oriented axis. /// </summary> /// <param name="availableSize">The available size.</param> private void RenderOriented(Size availableSize) { _minorTickMarkPool.Reset(); _majorTickMarkPool.Reset(); _labelPool.Reset(); double length = GetLength(availableSize); try { OrientedPanel.Children.Clear(); if (ActualRange.HasData && !Object.Equals(ActualRange.Minimum, ActualRange.Maximum)) { foreach (IComparable axisValue in GetMajorTickMarkValues(availableSize)) { UnitValue coordinate = GetPlotAreaCoordinate(axisValue, length); if (ValueHelper.CanGraph(coordinate.Value)) { Line line = _majorTickMarkPool.Next(); OrientedPanel.SetCenterCoordinate(line, coordinate.Value); OrientedPanel.SetPriority(line, 0); OrientedPanel.Children.Add(line); } } foreach (IComparable axisValue in GetMinorTickMarkValues(availableSize)) { UnitValue coordinate = GetPlotAreaCoordinate(axisValue, length); if (ValueHelper.CanGraph(coordinate.Value)) { Line line = _minorTickMarkPool.Next(); OrientedPanel.SetCenterCoordinate(line, coordinate.Value); OrientedPanel.SetPriority(line, 0); OrientedPanel.Children.Add(line); } } int count = 0; foreach (IComparable axisValue in GetLabelValues(availableSize)) { UnitValue coordinate = GetPlotAreaCoordinate(axisValue, length); if (ValueHelper.CanGraph(coordinate.Value)) { Control axisLabel = _labelPool.Next(); PrepareAxisLabel(axisLabel, axisValue); OrientedPanel.SetCenterCoordinate(axisLabel, coordinate.Value); OrientedPanel.SetPriority(axisLabel, count + 1); OrientedPanel.Children.Add(axisLabel); count = (count + 1) % 2; } } } } finally { _minorTickMarkPool.Done(); _majorTickMarkPool.Done(); _labelPool.Done(); } }
internal virtual bool CanGraph(XYDataPoint dataPointXY) { if (ValueHelper.CanGraph(dataPointXY.XValueInScaleUnits) && ValueHelper.CanGraph(dataPointXY.YValueInScaleUnits) && (DoubleHelper.GreaterOrEqualWithPrecision(dataPointXY.XValueInScaleUnits, 0.0) && DoubleHelper.LessOrEqualWithPrecision(dataPointXY.XValueInScaleUnits, 1.0)) && DoubleHelper.GreaterOrEqualWithPrecision(dataPointXY.YValueInScaleUnits, 0.0)) { return(DoubleHelper.LessOrEqualWithPrecision(dataPointXY.YValueInScaleUnits, 1.0)); } return(false); }
private bool IsValidScaleUnitValue(double scaleUnitValue) { if (ValueHelper.CanGraph(scaleUnitValue) && scaleUnitValue < 100.0) { return(scaleUnitValue > -100.0); } return(false); }
/// <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> /// 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); Range <double> coordinateRange = ActualIndependentCategoryAxis.GetPlotAreaCoordinateRange(category); if (!coordinateRange.HasData) { return; } IEnumerable <BarSeries> barSeries = SeriesHost.Series.OfType <BarSeries>().Where(series => series.ActualIndependentCategoryAxis == ActualIndependentCategoryAxis); int numberOfSeries = barSeries.Count(); double coordinateRangeHeight = (coordinateRange.Maximum - coordinateRange.Minimum); double segmentHeight = coordinateRangeHeight * 0.8; double barHeight = segmentHeight / numberOfSeries; int seriesIndex = barSeries.IndexOf(this); double dataPointX = ActualDependentRangeAxis.GetPlotAreaCoordinate(ValueHelper.ToDouble(dataPoint.ActualDependentValue)); double zeroPointX = ActualDependentRangeAxis.GetPlotAreaCoordinate(0); double offset = seriesIndex * Math.Round(barHeight) + coordinateRangeHeight * 0.1; double dataPointY = 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); dataPointY += (index * (barHeight * 0.2)) / (categoryGrouping.Count() - 1); barHeight *= 0.8; Canvas.SetZIndex(dataPoint, -index); } if (ValueHelper.CanGraph(dataPointX) && ValueHelper.CanGraph(dataPointY) && ValueHelper.CanGraph(zeroPointX)) { double top = Math.Round(dataPointY); double height = Math.Round(barHeight); double left = Math.Round(Math.Min(dataPointX, zeroPointX) - 0.5); double right = Math.Round(Math.Max(dataPointX, zeroPointX) - 0.5); double width = right - left + 1; Canvas.SetLeft(dataPoint, left); Canvas.SetTop(dataPoint, top); dataPoint.Width = width; dataPoint.Height = height; } }
/// <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)); } }
internal virtual void UpdateActualLabelMargin(double markerSize) { if (ValueHelper.CanGraph(markerSize)) { double labelMargin = this.LabelMargin; if (this.MarkerType != MarkerType.None) { labelMargin += markerSize / 2.0; } this.ActualLabelMargin = labelMargin; } else { this.ActualLabelMargin = 0.0; } }
/// <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).Value.Value; double dataPointX = ActualIndependentAxis.GetPlotAreaCoordinate(dataPoint.ActualIndependentValue).Value.Value; double dataPointY = ActualDependentRangeAxis.GetPlotAreaCoordinate(dataPoint.ActualDependentValue).Value.Value; if (ValueHelper.CanGraph(dataPointX) && ValueHelper.CanGraph(dataPointY)) { // 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 Series shape object from a collection of Points. /// </summary> /// <param name="points">Collection of Points.</param> protected override void UpdateShapeFromPoints(IEnumerable <Point> points) { UnitValue originCoordinate = ActualDependentRangeAxis.GetPlotAreaCoordinate(ActualDependentRangeAxis.Origin); UnitValue maximumCoordinate = ActualDependentRangeAxis.GetPlotAreaCoordinate(ActualDependentRangeAxis.Range.Maximum); if (points.Any() && ValueHelper.CanGraph(originCoordinate.Value) && ValueHelper.CanGraph(maximumCoordinate.Value)) { double originY = Math.Floor(originCoordinate.Value); var figure = new PathFigure(); figure.IsClosed = true; figure.IsFilled = true; double maximum = maximumCoordinate.Value; Point startPoint; IEnumerator <Point> pointEnumerator = points.GetEnumerator(); pointEnumerator.MoveNext(); startPoint = new Point(pointEnumerator.Current.X, maximum - originY); figure.StartPoint = startPoint; Point lastPoint; do { lastPoint = pointEnumerator.Current; figure.Segments.Add(new LineSegment { Point = pointEnumerator.Current }); } while (pointEnumerator.MoveNext()); figure.Segments.Add(new LineSegment { Point = new Point(lastPoint.X, maximum - originY) }); if (figure.Segments.Count > 1) { var geometry = new PathGeometry(); geometry.Figures.Add(figure); Geometry = geometry; } } else { Geometry = null; } }
/// <summary> /// Gets the margin to use for an independent axis that does not implement ICategoryAxis. /// </summary> /// <param name="axis">Axis to get the margin for.</param> /// <returns>Margin for axis.</returns> private double GetMarginForNonCategoryAxis(IAxis axis) { Debug.Assert(!(axis is ICategoryAxis), "This method is unnecessary for ICategoryAxis."); // Find the smallest distance between two independent value plot area coordinates double smallestDistance = double.MaxValue; double lastCoordinate = double.NaN; foreach (double coordinate in IndependentValueGroupsOrderedByIndependentValue .Select(g => axis.GetPlotAreaCoordinate(g.IndependentValue).Value) .Where(v => ValueHelper.CanGraph(v))) { if (!double.IsNaN(lastCoordinate)) { double distance = coordinate - lastCoordinate; if (distance < smallestDistance) { smallestDistance = distance; } } lastCoordinate = coordinate; } // Return the margin if (double.MaxValue == smallestDistance) { // No smallest distance because <= 1 independent values to plot FrameworkElement element = axis as FrameworkElement; if (null != element) { // Use width of provided axis so single column scenario looks good return(element.GetMargin(axis)); } else { // No information to work with; no idea what margin to return throw new NotSupportedException(); } } else { // Found the smallest distance; margin is half of that return(smallestDistance / 2); } }
/// <summary> /// Called when the value of the OffsetRatioProperty property changes. /// </summary> /// <param name="oldValue">The value to be replaced.</param> /// <param name="newValue">The new value.</param> private void OnOffsetRatioPropertyChanged(double oldValue, double newValue) { if (ValueHelper.CanGraph(newValue)) { RoutedPropertyChangedEventHandler <double> handler = this.OffsetRatioChanged; if (handler != null) { handler(this, new RoutedPropertyChangedEventArgs <double>(oldValue, newValue)); } if (this.State == DataPointState.Created) { ActualOffsetRatio = newValue; } } else { this.OffsetRatio = 0.0; } }
/// <summary> /// Calculates the length of the data points. /// </summary> protected void CalculateDataPointLength() { if (!(ActualIndependentAxis is ICategoryAxis)) { IEnumerable <UnitValue> values = ActiveDataPoints .Select(dataPoint => ActualIndependentAxis.GetPlotAreaCoordinate(dataPoint.ActualIndependentValue)) .Where(value => ValueHelper.CanGraph(value.Value)) .OrderBy(value => value.Value) .ToList(); _dataPointlength = EnumerableFunctions.Zip( values, values.Skip(1), (left, right) => new Range <double>(left.Value, right.Value)) .Select(range => range.Maximum - range.Minimum) .MinOrNullable(); } }
/// <summary> /// Called when the value of the ActualRatioProperty property changes. /// </summary> /// <param name="oldValue">The value to be replaced.</param> /// <param name="newValue">The new value.</param> private void OnActualRatioPropertyChanged(double oldValue, double newValue) { if (ValueHelper.CanGraph(newValue)) { RoutedPropertyChangedEventHandler <double> handler = this.ActualRatioChanged; if (handler != null) { handler(this, new RoutedPropertyChangedEventArgs <double>(oldValue, newValue)); } } else { this.ActualRatio = 0.0; } if (DesignerProperties.GetIsInDesignMode(this)) { PieSeries.UpdatePieDataPointGeometry(this, ActualWidth, ActualHeight); } }
/// <summary> /// Gets a range in which to render a data point. /// </summary> /// <param name="category"> /// The category to retrieve the range for. /// </param> /// <returns>The range in which to render a data point.</returns> protected Range <UnitValue> GetCategoryRange(object category) { ICategoryAxis categoryAxis = ActualIndependentAxis as CategoryAxis; if (categoryAxis != null) { return(categoryAxis.GetPlotAreaCoordinateRange(category)); } UnitValue unitValue = ActualIndependentAxis.GetPlotAreaCoordinate(category); if (ValueHelper.CanGraph(unitValue.Value) && _dataPointlength.HasValue) { double halfLength = _dataPointlength.Value / 2.0; return(new Range <UnitValue>( new UnitValue(unitValue.Value - halfLength, unitValue.Unit), new UnitValue(unitValue.Value + halfLength, unitValue.Unit))); } return(new Range <UnitValue>()); }
/// <summary> /// Updates the ratios of each data point. /// </summary> private void UpdateRatios() { double sum = ActivePieDataPoints.Select(pieDataPoint => Math.Abs(ValueHelper.ToDouble(pieDataPoint.DependentValue))).Sum(); // Priming the loop by calculating initial value of // offset ratio and its corresponding points. double offsetRatio = 0; foreach (PieDataPoint dataPoint in ActivePieDataPoints) { double dependentValue = Math.Abs(ValueHelper.ToDouble(dataPoint.DependentValue)); double ratio = dependentValue / sum; if (!ValueHelper.CanGraph(ratio)) { ratio = 0.0; } dataPoint.Ratio = ratio; dataPoint.OffsetRatio = offsetRatio; offsetRatio += ratio; } }
/// <summary> /// Called when the value of the RatioProperty property changes. /// </summary> /// <param name="oldValue">The value to be replaced.</param> /// <param name="newValue">The new value.</param> private void OnRatioPropertyChanged(double oldValue, double newValue) { if (ValueHelper.CanGraph(newValue)) { SetFormattedProperty(FormattedRatioProperty, RatioStringFormat, newValue); RoutedPropertyChangedEventHandler <double> handler = this.RatioChanged; if (handler != null) { handler(this, new RoutedPropertyChangedEventArgs <double>(oldValue, newValue)); } if (this.State == DataPointState.Created) { ActualRatio = newValue; } } else { this.Ratio = 0.0; } }
/// <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 the point collection object. /// </summary> protected override void UpdateShape() { double maximum = ActualDependentRangeAxis.GetPlotAreaCoordinate(ActualDependentRangeAxis.Range.Maximum).Value.Value; Func <DataPoint, Point> createPoint = dataPoint => new Point( ActualIndependentAxis.GetPlotAreaCoordinate(dataPoint.ActualIndependentValue).Value.Value, maximum - ActualDependentRangeAxis.GetPlotAreaCoordinate(dataPoint.ActualDependentValue).Value.Value); IEnumerable <Point> points = null; if (ValueHelper.CanGraph(maximum)) { if (ActualIndependentAxis is IRangeAxis) { points = DataPointsByIndependentValue.Select(createPoint); } else { points = ActiveDataPoints .Select(createPoint) .OrderBy(point => point.X); } if (!points.IsEmpty()) { this.Points = new PointCollection(); foreach (Point point in points) { this.Points.Add(point); } return; } } this.Points = null; }
private List <PolylineSegmentDefinition> GetSegmentDefinitions() { List <PolylineSegmentDefinition> list = new List <PolylineSegmentDefinition>(); PolylineSegmentDefinition segmentDefinition = (PolylineSegmentDefinition)null; for (int index = 0; index < this.Points.Count; ++index) { if (ValueHelper.CanGraph(this.Points[index].X) && ValueHelper.CanGraph(this.Points[index].Y)) { if (segmentDefinition != null && this.IsSameAppearance(segmentDefinition.Appearance, this.Appearances[index])) { segmentDefinition.Points.Add(this.Points[index]); } else { segmentDefinition = new PolylineSegmentDefinition(); segmentDefinition.Appearance = this.Appearances[index]; segmentDefinition.Points.Add(this.Points[index]); list.Add(segmentDefinition); } } } return(list); }
private void ChangeDataPointSizeValue(BubbleDataPoint dataPoint, object newValue) { if (dataPoint == null) { return; } double valueInScaleUnits = dataPoint.SizeValueInScaleUnits; double num = this.ProjectSizeToPixels((DataPoint)dataPoint, ValueHelper.ToDouble(newValue)); dataPoint.SizeValueInScaleUnitsWithoutAnimation = num; if (valueInScaleUnits == num) { return; } if (ValueHelper.CanGraph(valueInScaleUnits) && ValueHelper.CanGraph(num) && (this.IsSeriesAnimationEnabled && this.ChartArea != null)) { DependencyPropertyAnimationHelper.BeginAnimation(this.ChartArea, "SizeValueInScaleUnits", (object)valueInScaleUnits, (object)num, (Action <object, object>)((value1, value2) => dataPoint.SizeValueInScaleUnits = (double)value2), dataPoint.Storyboards, this.Series.ActualTransitionDuration, this.Series.ActualTransitionEasingFunction); } else { this.SkipToFillValueAnimation((XYDataPoint)dataPoint, "SizeValueInScaleUnits"); dataPoint.SizeValueInScaleUnits = num; } }