/// <summary> /// Called when the value of the RatioStringFormatProperty property changes. /// </summary> /// <param name="d">PieDataPoint that changed its RatioStringFormat.</param> /// <param name="e">Event arguments.</param> private static void OnRatioStringFormatPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { PieDataPoint source = d as PieDataPoint; string newValue = e.NewValue as string; source.OnRatioStringFormatPropertyChanged(newValue); }
/// <summary> /// Called when the value of the RatioProperty property changes. /// </summary> /// <param name="d">PieDataPoint that changed its Ratio.</param> /// <param name="e">Event arguments.</param> private static void OnRatioPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { PieDataPoint source = (PieDataPoint)d; double oldValue = (double)e.OldValue; double newValue = (double)e.NewValue; source.OnRatioPropertyChanged(oldValue, newValue); }
/// <summary> /// Updates a data point. /// </summary> /// <param name="dataPoint">The data point to update.</param> protected override void UpdateDataPoint(DataPoint dataPoint) { PieDataPoint pieDataPoint = (PieDataPoint)dataPoint; pieDataPoint.Width = ActualWidth; pieDataPoint.Height = ActualHeight; UpdatePieDataPointGeometry(pieDataPoint, ActualWidth, ActualHeight); Canvas.SetLeft(pieDataPoint, 0); Canvas.SetTop(pieDataPoint, 0); }
/// <summary> /// Detaches event handlers from a data point. /// </summary> /// <param name="dataPoint">The data point.</param> protected override void DetachEventHandlersFromDataPoint(DataPoint dataPoint) { PieDataPoint pieDataPoint = dataPoint as PieDataPoint; pieDataPoint.ActualRatioChanged -= OnPieDataPointActualRatioChanged; pieDataPoint.ActualOffsetRatioChanged -= OnPieDataPointActualOffsetRatioChanged; pieDataPoint.RatioChanged -= OnPieDataPointRatioChanged; pieDataPoint.OffsetRatioChanged -= OnPieDataPointOffsetRatioChanged; base.DetachEventHandlersFromDataPoint(dataPoint); }
public void GotoDataPointSelected(PieDataPoint dp) { PieSeries pieSeries = (PieChart.Series[0] as PieSeries); if (dp != null) { var render = pieSeries.PlotArea.RenderTransform as CompositeTransform; if (render != null) { Storyboard sb = new Storyboard(); sb.CreateRotetionAnimation(pieSeries.PlotArea, render.Rotation, dp.MiddleRadius, 0.5); sb.Begin(); } } }
private void PieSeries_DataPointSelected(object sender, WinRTXamlToolkit.Controls.RotedEventArgs<DataPoint> e) { PieDataPoint pieDataPoint = e.Value as PieDataPoint; PieSeries pieSeries = (PieChart.Series[0] as PieSeries); if (pieDataPoint != null) { //pieDataPoint.DiameterScale = 0.98; Storyboard sb = new Storyboard(); sb.CreatDoubleAnimation(pieDataPoint, "DiameterScale", 0.9, 0.98, 0.5); sb.Begin(); if (_current != null && !_current.Equals(pieDataPoint)) { _current.DiameterScale = 0.9; } _current = pieDataPoint; } GotoDataPointSelected(_current); }
/// <summary> /// Creates a legend item for each data point. /// </summary> /// <param name="dataPoint">The data point added.</param> protected override void AddDataPoint(DataPoint dataPoint) { base.AddDataPoint(dataPoint); PieDataPoint pieDataPoint = (PieDataPoint)dataPoint; int index = ActiveDataPoints.IndexOf(dataPoint) + 1; LegendItem legendItem = CreatePieLegendItem(dataPoint, index); // Grab a style enumerator if we don't have one already. if (_resourceDictionaryEnumerator == null) { _resourceDictionaryEnumerator = GetResourceDictionaryWithTargetType(this, typeof(PieDataPoint), true); } if (_resourceDictionaryEnumerator.MoveNext()) { ResourceDictionary paletteResources = _resourceDictionaryEnumerator.Current.ShallowCopy(); pieDataPoint.PaletteResources = paletteResources; pieDataPoint.Resources.MergedDictionaries.Add(paletteResources); } else { pieDataPoint.PaletteResources = null; } pieDataPoint.ActualDataPointStyle = DataPointStyle ?? pieDataPoint.Resources[DataPointStyleName] as Style; pieDataPoint.SetBinding(PieDataPoint.StyleProperty, new Binding { Path = new PropertyPath(PieDataPoint.ActualDataPointStyleName), Source = pieDataPoint }); if (LegendItemStyle != null || pieDataPoint.Resources.ContainsKey(LegendItemStyleName)) { pieDataPoint.ActualLegendItemStyle = LegendItemStyle ?? (pieDataPoint.Resources[LegendItemStyleName] as Style); } legendItem.SetBinding(LegendItem.StyleProperty, new Binding { Path = new PropertyPath(ActualLegendItemStyleName), Source = pieDataPoint }); _dataPointLegendItems[dataPoint] = legendItem; LegendItems.Add(legendItem); UpdateLegendItemIndexes(); }
/// <summary> /// Updates the PieDataPoint's Geometry property. /// </summary> /// <param name="pieDataPoint">PieDataPoint instance.</param> /// <param name="plotAreaWidth">PlotArea width.</param> /// <param name="plotAreaHeight">PlotArea height.</param> internal static void UpdatePieDataPointGeometry(PieDataPoint pieDataPoint, double plotAreaWidth, double plotAreaHeight) { double diameter = (plotAreaWidth < plotAreaHeight) ? plotAreaWidth : plotAreaHeight; diameter *= 0.95; double plotAreaRadius = diameter / 2; double maxDistanceFromCenter = 0.0; double sliceRadius = plotAreaRadius - maxDistanceFromCenter; Point translatePoint = new Point(plotAreaWidth / 2, plotAreaHeight / 2); if (pieDataPoint.ActualRatio == 1) { foreach (DependencyProperty dependencyProperty in new DependencyProperty[] { PieDataPoint.GeometryProperty, PieDataPoint.GeometrySelectionProperty, PieDataPoint.GeometryHighlightProperty }) { Geometry geometry = new EllipseGeometry { Center = translatePoint, RadiusX = sliceRadius, RadiusY = sliceRadius }; pieDataPoint.SetValue(dependencyProperty, geometry); } } else { if (pieDataPoint.ActualRatio == 0.0) { pieDataPoint.Geometry = null; pieDataPoint.GeometryHighlight = null; pieDataPoint.GeometrySelection = null; } else { double ratio = pieDataPoint.ActualRatio; double offsetRatio = pieDataPoint.ActualOffsetRatio; double currentRatio = offsetRatio + ratio; Point offsetRatioPoint = ConvertRatioOfRotationToPoint(offsetRatio, sliceRadius, sliceRadius); Point adjustedOffsetRatioPoint = offsetRatioPoint.Translate(translatePoint); // Calculate the last clockwise point in the pie slice Point currentRatioPoint = ConvertRatioOfRotationToPoint(currentRatio, sliceRadius, sliceRadius); // Adjust point using center of plot area as origin // instead of 0,0 Point adjustedCurrentRatioPoint = currentRatioPoint.Translate(translatePoint); foreach (DependencyProperty dependencyProperty in new DependencyProperty[] { PieDataPoint.GeometryProperty, PieDataPoint.GeometrySelectionProperty, PieDataPoint.GeometryHighlightProperty }) { // Creating the pie slice geometry object PathFigure pathFigure = new PathFigure { IsClosed = true }; pathFigure.StartPoint = translatePoint; pathFigure.Segments.Add(new LineSegment { Point = adjustedOffsetRatioPoint }); bool isLargeArc = (currentRatio - offsetRatio) > 0.5; pathFigure.Segments.Add( new ArcSegment { Point = adjustedCurrentRatioPoint, IsLargeArc = isLargeArc, Size = new Size(sliceRadius, sliceRadius), SweepDirection = SweepDirection.Clockwise }); PathGeometry pathGeometry = new PathGeometry(); pathGeometry.Figures.Add(pathFigure); pieDataPoint.SetValue(dependencyProperty, pathGeometry); } } } }
/// <summary> /// Updates the PieDataPoint's Geometry property. /// </summary> /// <param name="pieDataPoint">PieDataPoint instance.</param> /// <param name="plotAreaWidth">PlotArea width.</param> /// <param name="plotAreaHeight">PlotArea height.</param> internal static void UpdatePieDataPointGeometry(PieDataPoint pieDataPoint, double plotAreaWidth, double plotAreaHeight) { double diameter = (plotAreaWidth < plotAreaHeight) ? plotAreaWidth : plotAreaHeight; diameter *= 0.95; double plotAreaRadius = diameter / 2; double maxDistanceFromCenter = 0.0; double sliceRadius = plotAreaRadius - maxDistanceFromCenter; Point translatePoint = new Point(plotAreaWidth / 2, plotAreaHeight / 2); if (pieDataPoint.ActualRatio == 1) { foreach (DependencyProperty dependencyProperty in new DependencyProperty[] { PieDataPoint.GeometryProperty, PieDataPoint.GeometrySelectionProperty, PieDataPoint.GeometryHighlightProperty }) { Geometry geometry = new EllipseGeometry { Center = translatePoint, RadiusX = sliceRadius, RadiusY = sliceRadius }; pieDataPoint.SetValue(dependencyProperty, geometry); } } else { if (pieDataPoint.ActualRatio == 0.0) { pieDataPoint.Geometry = null; pieDataPoint.GeometryHighlight = null; pieDataPoint.GeometrySelection = null; } else { double ratio = pieDataPoint.ActualRatio; double offsetRatio = pieDataPoint.ActualOffsetRatio; double currentRatio = offsetRatio + ratio; Point offsetRatioPoint = ConvertRatioOfRotationToPoint(offsetRatio, sliceRadius, sliceRadius); Point adjustedOffsetRatioPoint = offsetRatioPoint.Translate(translatePoint); // Calculate the last clockwise point in the pie slice Point currentRatioPoint = ConvertRatioOfRotationToPoint(currentRatio, sliceRadius, sliceRadius); // Adjust point using center of plot area as origin // instead of 0,0 Point adjustedCurrentRatioPoint = currentRatioPoint.Translate(translatePoint); foreach (DependencyProperty dependencyProperty in new DependencyProperty[] { PieDataPoint.GeometryProperty, PieDataPoint.GeometrySelectionProperty, PieDataPoint.GeometryHighlightProperty }) { // Creating the pie slice geometry object PathFigure pathFigure = new PathFigure { IsClosed = true }; pathFigure.StartPoint = translatePoint; pathFigure.Segments.Add(new LineSegment { Point = adjustedOffsetRatioPoint }); bool isLargeArc = (currentRatio - offsetRatio) > 0.5; pathFigure.Segments.Add( new ArcSegment { Point = adjustedCurrentRatioPoint, IsLargeArc = isLargeArc, Size = new Size(sliceRadius, sliceRadius), SweepDirection = SweepDirection.Clockwise }); PathGeometry pathGeometry = new PathGeometry(); pathGeometry.Figures.Add(pathFigure); pieDataPoint.SetValue(dependencyProperty, pathGeometry); } } } }