Example #1
0
        public override void Plot(bool animate = true)
        {
            if (Visibility != Visibility.Visible) return;
            var pChart = Chart as PieChart;
            if (pChart == null) return;
            if (pChart.PieTotalSum <= 0) return;
            var rotated = 0d;

            Chart.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));

            var minDimension = Chart.PlotArea.Width < Chart.PlotArea.Height
                ? Chart.PlotArea.Width
                : Chart.PlotArea.Height;
            minDimension -= pChart.DrawPadding;
            minDimension = minDimension < pChart.DrawPadding ? pChart.DrawPadding : minDimension;

            var sliceId = 0;
            var isFist = true;

            var f = Chart.GetFormatter(Chart.AxisY);
            var pie = (PieChart) Chart;

            foreach (var point in Values.Points)
            {
                var participation = point.Y/pChart.PieTotalSum;
                if (isFist)
                {
                    rotated = participation*-.5  + (pie.PieRotation/360);
                    isFist = false;
                }

                var slice = new PieSlice
                {
                    CentreX = 0,
                    CentreY = 0,
                    RotationAngle = 360*rotated,
                    WedgeAngle = 360*participation,
                    Radius = minDimension/2,
                    InnerRadius = pChart.InnerRadius,
                    Fill = Brushes != null && Brushes.Length > sliceId
                        ? Brushes[sliceId]
                        : new SolidColorBrush(GetColorByIndex(sliceId)),
                    Stroke = Stroke,
                    StrokeThickness = pChart.SlicePadding
                };
                var wa = new DoubleAnimation
                {
                    From = 0,
                    To = slice.WedgeAngle,
                    Duration = TimeSpan.FromMilliseconds(500)
                };
                var ra = new DoubleAnimation
                {
                    From = 0,
                    To = slice.RotationAngle,
                    Duration = TimeSpan.FromMilliseconds(500)
                };

                Canvas.SetTop(slice, Chart.PlotArea.Height/2);
                Canvas.SetLeft(slice, Chart.PlotArea.Width/2);

                Chart.Canvas.Children.Add(slice);
                Shapes.Add(slice);

                if (DataLabels)
                {
                    var valueBlock = BuildATextBlock(0);
                    valueBlock.Text = f(point.Y);

                    var hypo = ((minDimension / 2) + (pChart.InnerRadius > 10 ? pChart.InnerRadius : 10)) / 2;
                    var gamma = participation * 360 / 2 + rotated * 360;
                    var cp = new Point(hypo * Math.Sin(gamma * (Math.PI / 180)), hypo * Math.Cos(gamma * (Math.PI / 180)));

                    valueBlock.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));

                    Canvas.SetTop(valueBlock, Chart.PlotArea.Height / 2 - cp.Y - valueBlock.DesiredSize.Height * .5);
                    Canvas.SetLeft(valueBlock, cp.X + Chart.PlotArea.Width / 2 - valueBlock.DesiredSize.Width * .5);
                    Panel.SetZIndex(valueBlock, int.MaxValue - 1);
                    //because math is kind of complex to detetrmine if label fits inside the slide, by now we 
                    //will just add it if participation > 5% ToDo: the math!
                    if (participation > .05 && Chart.AxisY.ShowLabels)
                    {
                        Chart.Canvas.Children.Add(valueBlock);
                        Chart.Shapes.Add(valueBlock);
                    }
                }

                if (!Chart.DisableAnimation)
                {
                    if (animate)
                    {
                        slice.BeginAnimation(PieSlice.WedgeAngleProperty, wa);
                        slice.BeginAnimation(PieSlice.RotationAngleProperty, ra);
                    }
                }

                slice.MouseDown += Chart.DataMouseDown;

                slice.MouseEnter += Chart.DataMouseEnter;
                slice.MouseLeave += Chart.DataMouseLeave;

                Chart.ShapesMapper.Add(new ShapeMap
                {
                    Series = this,
                    HoverShape = slice,
                    Shape = slice,
                    ChartPoint = point
                });


                sliceId++;
                rotated += participation;
            }
        }
Example #2
0
        public override void Plot(bool animate = true)
        {
            var pChart = Chart as PieChart;
            if (pChart == null) return;
            if (pChart.PieTotalSum <= 0) return;
            var rotated = 90d;

            Chart.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));

            var minDimension = Chart.PlotArea.Width < Chart.PlotArea.Height
                ? Chart.PlotArea.Width
                : Chart.PlotArea.Height;
            minDimension -= pChart.DrawPadding;
            minDimension = minDimension < pChart.DrawPadding ? pChart.DrawPadding : minDimension;

            var sliceId = 0;
            var isFist = true;
            foreach (var point in Values.Points)
            {
                var participation = point.Y/pChart.PieTotalSum;
                if (isFist)
                {
                    rotated = participation*-.5;
                    isFist = false;
                }

                var slice = new PieSlice
                {
                    CentreX = 0,
                    CentreY = 0,
                    RotationAngle = 360*rotated,
                    WedgeAngle = 360*participation,
                    Radius = minDimension/2,
                    InnerRadius = pChart.InnerRadius,
                    Fill = Brushes != null && Brushes.Length > sliceId
                        ? Brushes[sliceId]
                        : new SolidColorBrush(GetColorByIndex(sliceId)),
                    Stroke = Chart.Background,
                    StrokeThickness = pChart.SlicePadding
                };
                var wa = new DoubleAnimation
                {
                    From = 0,
                    To = slice.WedgeAngle,
                    Duration = TimeSpan.FromMilliseconds(500)
                };
                var ra = new DoubleAnimation
                {
                    From = 0,
                    To = slice.RotationAngle,
                    Duration = TimeSpan.FromMilliseconds(500)
                };

                Canvas.SetTop(slice, Chart.PlotArea.Height/2);
                Canvas.SetLeft(slice, Chart.PlotArea.Width/2);

                Chart.Canvas.Children.Add(slice);
                Shapes.Add(slice);

                var valueBlock = new TextBlock
                {
                    Text = Chart.AxisY.LabelFormatter == null
                        ? point.Y.ToString(CultureInfo.InvariantCulture)
                        : Chart.AxisY.LabelFormatter(point.Y),
                    FontFamily = Chart.AxisY.FontFamily,
                    FontSize = Chart.AxisY.FontSize,
                    FontStretch = Chart.AxisY.FontStretch,
                    FontStyle = Chart.AxisY.FontStyle,
                    FontWeight = Chart.AxisY.FontWeight,
                    Foreground = System.Windows.Media.Brushes.White
                };

                var hypo = ((minDimension/2) + (pChart.InnerRadius > 10 ? pChart.InnerRadius : 10))/2;
                var gamma = participation*360/2 + rotated*360;
                var cp = new Point(hypo*Math.Sin(gamma*(Math.PI/180)), hypo*Math.Cos(gamma*(Math.PI/180)));

                valueBlock.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));

                Canvas.SetTop(valueBlock, Chart.PlotArea.Height/2 - cp.Y - valueBlock.DesiredSize.Height*.5);
                Canvas.SetLeft(valueBlock, cp.X + Chart.PlotArea.Width/2 - valueBlock.DesiredSize.Width*.5);
                Panel.SetZIndex(valueBlock, int.MaxValue - 1);
                //because math is kind of complex to detetrmine if label fits inside the slide, by now we 
                //will just add it if participation > 5% ToDo: the math!
                if (participation > .05 && Chart.AxisY.ShowLabels)
                {
                    Chart.Canvas.Children.Add(valueBlock);
                    Chart.Shapes.Add(valueBlock);
                }

                if (!Chart.DisableAnimation)
                {
                    if (animate)
                    {
                        slice.BeginAnimation(PieSlice.WedgeAngleProperty, wa);
                        slice.BeginAnimation(PieSlice.RotationAngleProperty, ra);
                    }
                }

                slice.MouseDown += Chart.DataMouseDown;

                slice.MouseEnter += Chart.DataMouseEnter;
                slice.MouseLeave += Chart.DataMouseLeave;

                Chart.HoverableShapes.Add(new HoverableShape
                {
                    Series = this,
                    Shape = slice,
                    Target = slice,
                    Value = point,
                    Label = Labels != null && Labels.Count > point.X ? Labels[(int) point.X] : ""
                });


                sliceId++;
                rotated += participation;
            }
        }
Example #3
0
        public override void Plot(bool animate = true)
        {
            var pChart = Chart as PieChart;
            if (pChart == null) return;
            if (pChart.PieTotalSum <= 0) return;
            var rotated = 0d;

            Chart.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));

            var minDimension = Chart.DesiredSize.Width < Chart.DesiredSize.Height
                ? Chart.DesiredSize.Width : Chart.DesiredSize.Height;
            minDimension -= pChart.DrawPadding;
            minDimension = minDimension < pChart.DrawPadding ? pChart.DrawPadding : minDimension;

            var sliceId = 0;
            for (var index = 0; index < PrimaryValues.Count; index++)
            {
                var value = PrimaryValues[index];
                var participation = value/pChart.PieTotalSum;
                if (index == 0) rotated = participation *-.5;

                var slice = new PieSlice
                {
                    CentreX = 0,
                    CentreY = 0,
                    RotationAngle = 360 * rotated,
                    WedgeAngle = 360 * participation,
                    Radius = minDimension / 2,
                    InnerRadius = pChart.InnerRadius,
                    Fill = new SolidColorBrush {Color = GetColorByIndex(sliceId), Opacity = .8},
                    Stroke = Chart.Background,
                    StrokeThickness = pChart.SlicePadding
                };

                var wa = new DoubleAnimation
                {
                    From = 0,
                    To = slice.WedgeAngle,
                    Duration = TimeSpan.FromMilliseconds(300)
                };
                var ra = new DoubleAnimation
                {
                    From = 0,
                    To = slice.RotationAngle,
                    Duration = TimeSpan.FromMilliseconds(300)
                };

                Canvas.SetTop(slice, Chart.ActualHeight/2);
                Canvas.SetLeft(slice, Chart.ActualWidth/2);

                Chart.Canvas.Children.Add(slice);
                Shapes.Add(slice);

                var valueBlock = new TextBlock
                {
                    Text = Chart.PrimaryAxis.LabelFormatter == null
                        ? value.ToString(CultureInfo.InvariantCulture)
                        : Chart.PrimaryAxis.LabelFormatter(value),
                    FontFamily = Chart.PrimaryAxis.FontFamily,
                    FontSize = Chart.PrimaryAxis.FontSize,
                    FontStretch = Chart.PrimaryAxis.FontStretch,
                    FontStyle = Chart.PrimaryAxis.FontStyle,
                    FontWeight = Chart.PrimaryAxis.FontWeight,
                    Foreground = Brushes.White
                };

                var hypo = ((minDimension/2) + (pChart.InnerRadius > 10 ? pChart.InnerRadius : 10))/2;
                var gamma = participation*360/2 + rotated*360;
                var cp = new Point(hypo*Math.Sin(gamma*(Math.PI/180)), hypo*Math.Cos(gamma*(Math.PI/180)));

                valueBlock.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));

                Canvas.SetTop(valueBlock, Chart.ActualHeight/2 -cp.Y - valueBlock.DesiredSize.Height*.5);
                Canvas.SetLeft(valueBlock, cp.X + Chart.ActualWidth/2 - valueBlock.DesiredSize.Width*.5);
                Panel.SetZIndex(valueBlock, int.MaxValue);
                //because math is kind of complex to detetrmine if label fits inside the slide, by now we
                //will just add it if participation > 5% ToDo: the math!
                if (participation > .05 && Chart.PrimaryAxis.PrintLabels)
                {
                    Chart.Canvas.Children.Add(valueBlock);
                    Chart.AxisLabels.Add(valueBlock);
                }

                if (!Chart.DisableAnimation)
                {
                    if (animate)
                    {
                        slice.BeginAnimation(PieSlice.WedgeAngleProperty, wa);
                        slice.BeginAnimation(PieSlice.RotationAngleProperty, ra);
                    }
                }

                if (Chart.Hoverable)
                {
                    slice.MouseEnter += Chart.OnDataMouseEnter;
                    slice.MouseLeave += Chart.OnDataMouseLeave;
                    Chart.HoverableShapes.Add(new HoverableShape
                    {
                        Serie = this,
                        Shape = slice,
                        Target = slice,
                        Value = new Point(0, value),
                        Label = Labels.Length > index ? Labels[index] : ""
                    });
                }

                sliceId++;
                rotated += participation;
            }
        }