Example #1
0
        /// <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);
        }
Example #2
0
        /// <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);
        }
        /// <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 = Translate(offsetRatioPoint, 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 =
                        Translate(currentRatioPoint, 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);
                    }
                }
            }
        }
Example #6
0
        /// <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 = Translate(offsetRatioPoint, 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 =
                        Translate(currentRatioPoint, 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);
                    }
                }
            }
        }