Exemplo n.º 1
0
        public override void DrawContent(SKCanvas canvas, int width, int height)
        {
            if (Inputs != null)
            {
                DrawCaption(canvas, width, height);
                using (new SKAutoCanvasRestore(canvas))
                {
                    canvas.Translate(width / 2, height / 2);
                    var sumValue = Inputs.Sum(x => Math.Abs(x.Value));
                    var radius   = (Math.Min(width, height) - (2 * Margin)) / 2;

                    var start = 0.0f;
                    for (int i = 0; i < Inputs.Count(); i++)
                    {
                        var input = Inputs.ElementAt(i);
                        var end   = start + ((Math.Abs(input.Value) / sumValue) * AnimationProgress);

                        // Sector
                        var path = RadialHelpers.CreateSectorPath(start, end, radius, radius * HoleRadius);
                        using (var paint = new SKPaint
                        {
                            Style = SKPaintStyle.Fill,
                            Color = input.Color,
                            IsAntialias = true,
                        })
                        {
                            canvas.DrawPath(path, paint);
                        }

                        start = end;
                    }
                }
            }
        }
Exemplo n.º 2
0
        public override void DrawContent(SKCanvas canvas, int width, int height)
        {
            this.DrawCaption(canvas, width, height);
            using (new SKAutoCanvasRestore(canvas))
            {
                canvas.Translate(width / 2, height / 2);
                var sumValue = this.Entries.Sum(x => Math.Abs(x.Value));
                var radius   = (Math.Min(width, height) - (2 * Margin)) / 2;

                var start = 0.0f;
                for (int i = 0; i < this.Entries.Count(); i++)
                {
                    var entry = this.Entries.ElementAt(i);
                    var end   = start + (Math.Abs(entry.Value) / sumValue);

                    var path = RadialHelpers.CreateSectorPath(start, end, radius, radius - this.HoleRadius);
                    using (var paint = new SKPaint
                    {
                        Style = SKPaintStyle.Fill,
                        Color = entry.Color,
                        IsAntialias = true,
                    })
                    {
                        canvas.DrawPath(path, paint);
                    }

                    start = end;
                }
            }
        }