Ejemplo n.º 1
0
 private void ResetVisuals()
 {
     ChartCanvas.Children.Clear();
     slices.Clear();
     inside = null;
     mouseOverAnimationCompleted = false;
 }
Ejemplo n.º 2
0
        public PlotModel GetUgadaykaPm(int redwins, int blackwins)
        {
            var plot = new PlotModel
            {
                Title           = null,
                IsLegendVisible = false
            };
            var ps = new PieSeries
            {
                InsideLabelPosition = 0.5,
                Stroke           = OxyColors.Transparent,
                StartAngle       = 0,
                AngleSpan        = 360,
                InsideLabelColor = OxyColors.White,
                FontSize         = 10,
                TextColor        = OxyColors.White,
            };
            var redslice = new PieSlice
            {
                Label = GetLocalized("StRedSlice1") + "\n" + GetLocalized("StRedSlice2"),
                Value = redwins,
                Fill  = OxyColors.Red
            };
            var blackslice = new PieSlice
            {
                Label = GetLocalized("StBlackSlice1") + "\n" + GetLocalized("StBlackSlice2"),
                Value = blackwins,
                Fill  = OxyColors.Black,
            };

            ps.Slices.Add(redslice);
            ps.Slices.Add(blackslice);
            plot.Series.Add(ps);
            return(plot);
        }
Ejemplo n.º 3
0
        private void BuildCategoryPieChart()
        {
            Dictionary <string, decimal> categoryValuePair = DataRepository.GetTotalPerCategory(Date, (SortByType)SortBy.SortType);

            var model    = new PlotModel();
            var seriesP1 = new PieSeries
            {
                InsideLabelColor     = OxyColors.White,
                OutsideLabelFormat   = "",
                InsideLabelFormat    = "{1} {2:0}%",
                TickHorizontalLength = 0.00,
                TickRadialLength     = 0.00
            };

            foreach (var pair in categoryValuePair)
            {
                var slice = new PieSlice(pair.Key, (double)pair.Value)
                {
                    IsExploded = true,
                    Fill       = OxyColor.Parse("#3AA7F9")
                };
                seriesP1.Slices.Add(slice);
            }
            model.Series.Add(seriesP1);
            CategoryPieChart = model;
        }
Ejemplo n.º 4
0
        public void Render(StarSystem sys, DrawingContext dc, Point p, double radius)
        {
            // find amounts
            var amounts = GetAmounts(sys).ToArray();

            // find relative amount here vs. max amount in any system to determine brightness of colors
            var amountHere = amounts.Sum(t => t.Item2);

            if (amountHere == 0)
            {
                // nothing, draw a gray outline with a faint fill
                var grayTransparent = Color.FromArgb(GetAlpha(sys), Colors.Gray.R, Colors.Gray.G, Colors.Gray.B);
                dc.DrawEllipse(new SolidColorBrush(grayTransparent), new Pen(Brushes.Gray, 1), p, radius, radius);
            }
            else
            {
                // draw pie chart
                double curAngle = 0d;
                foreach (var t in amounts.OrderBy(t => t.Item2))
                {
                    var color    = t.Item1;
                    var amount   = t.Item2;
                    var arc      = 360d * amount / amountHere;
                    var brush    = new SolidColorBrush(Color.FromArgb(GetAlpha(sys), color.R, color.G, color.B));
                    var penBrush = new SolidColorBrush(color);
                    var pieSlice = new PieSlice
                    {
                        StartDegrees = curAngle,
                        DeltaDegrees = arc,
                    };
                    dc.DrawGeometry(brush, new Pen(penBrush, 1), CreateGeometry(p, radius, curAngle, arc));
                    curAngle += arc;
                }
            }
        }
Ejemplo n.º 5
0
            private Image GetPieGraph()
            {
                RandomUtil ru = new RandomUtil();
                PieGraph   pg = new PieGraph(this.Size);

                pg.Color         = Color.White;
                pg.ColorGradient = Color.Orange;

                Legend legend = new Legend(this.Width, 70);

                legend.Text = String.Empty;
                pg.Text     = _displayString + " Total: " + _totalComponents.ToString();

                ICollection keys = _componentInfoTable.Keys;
                IEnumerator ie   = keys.GetEnumerator();

                while (ie.MoveNext())
                {
                    Type          key = (Type)ie.Current;
                    ComponentInfo ci  = (ComponentInfo)_componentInfoTable[key];

                    PieSlice ps = new PieSlice(ci.Count, ci.Color);
                    pg.Slices.Add(ps);

                    LegendEntry le = new LegendEntry(ci.Color, ci.Type.Name.ToString().Trim());
                    legend.LegendEntryCollection.Add(le);
                }

                return(GraphRenderer.DrawGraphAndLegend(pg, legend, this.Size));
            }
Ejemplo n.º 6
0
        private VisualHelper GetVisual(ChartPoint point)
        {
            var map = _isPrimitive
                ? Chart.ShapesMapper.FirstOrDefault(x => x.Series.Equals(this) &&
                                                    x.ChartPoint.Key == point.Key)
                : Chart.ShapesMapper.FirstOrDefault(x => x.Series.Equals(this) &&
                                                    x.ChartPoint.Instance == point.Instance);

            var pChart = Chart as PieChart;

            if (pChart == null)
            {
                throw new InvalidCastException("Unexpected error converting chart to pie chart.");
            }

            if (map == null)
            {
                var newSlice = new PieSlice
                {
                    CentreX = 0,
                    CentreY = 0
                };

                BindingOperations.SetBinding(newSlice, Shape.StrokeProperty,
                                             new Binding {
                    Path = new PropertyPath("Stroke"), Source = this
                });
                BindingOperations.SetBinding(newSlice, Shape.FillProperty,
                                             new Binding {
                    Path = new PropertyPath("Fill"), Source = this
                });
                BindingOperations.SetBinding(newSlice, Shape.StrokeThicknessProperty,
                                             new Binding {
                    Path = new PropertyPath("StrokeThickness"), Source = this
                });
                BindingOperations.SetBinding(newSlice, VisibilityProperty,
                                             new Binding {
                    Path = new PropertyPath("Visibility"), Source = this
                });

                return(new VisualHelper
                {
                    HoverShape = newSlice,
                    PointShape = newSlice,
                    IsNew = true
                });
            }

            map.ChartPoint.X = point.X;
            map.ChartPoint.Y = point.Y;

            return(new VisualHelper
            {
                PointShape = (PieSlice)map.Shape,
                HoverShape = (PieSlice)map.HoverShape,
                IsNew = false
            });
        }
Ejemplo n.º 7
0
    public PieSlice CreatePieSlice()
    {
        PieSlice newSlice = Instantiate(pieSlicePrefab);

        newSlice.transform.SetParent(this.transform);
        newSlice.transform.localScale    = Vector3.one;
        newSlice.transform.localPosition = Vector3.zero;
        return(newSlice);
    }
Ejemplo n.º 8
0
	protected void cmdAdd_Click(object sender, System.EventArgs e)
	{
		// Create a new pie slice.
		PieSlice pieSlice = new PieSlice(txtLabel.Text, Single.Parse(txtValue.Text));
		pieSlices.Add(pieSlice);

		// Bind the list box to the new data.
		lstPieSlices.DataSource = pieSlices;
		lstPieSlices.DataBind();
	}
Ejemplo n.º 9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Gauge"/> class.
        /// </summary>
        public Gauge()
        {
            Canvas = new Canvas();

            Content = Canvas;

            PieBack          = new PieSlice();
            Pie              = new PieSlice();
            MeasureTextBlock = new TextBlock();
            LeftLabel        = new TextBlock();
            RightLabel       = new TextBlock();

            Canvas.Children.Add(PieBack);
            Canvas.Children.Add(Pie);
            Canvas.Children.Add(MeasureTextBlock);
            Canvas.Children.Add(RightLabel);
            Canvas.Children.Add(LeftLabel);

            Canvas.SetZIndex(PieBack, 0);
            Canvas.SetZIndex(Pie, 1);

            PieBack.SetBinding(Shape.FillProperty,
                               new Binding {
                Path = new PropertyPath("GaugeBackground"), Source = this
            });
            PieBack.SetBinding(Shape.StrokeThicknessProperty,
                               new Binding {
                Path = new PropertyPath("StrokeThickness"), Source = this
            });
            PieBack.SetBinding(Shape.StrokeProperty,
                               new Binding {
                Path = new PropertyPath("Stroke"), Source = this
            });

            Pie.SetBinding(Shape.StrokeThicknessProperty,
                           new Binding {
                Path = new PropertyPath("StrokeThickness"), Source = this
            });
            Pie.Stroke = new SolidColorBrush(Colors.Transparent);

            this.SetIfNotSet(MinHeightProperty, 50d);
            this.SetIfNotSet(MinWidthProperty, 80d);

            MeasureTextBlock.FontWeight = FontWeights.Bold;

            IsNew = true;

            SizeChanged += (sender, args) =>
            {
                IsChartInitialized = true;
                Update();
            };
        }
Ejemplo n.º 10
0
 void OnExitSlice()
 {
     if (inside != null && this.mouseOverAnimationCompleted)
     {
         var duration = new Duration(TimeSpan.FromMilliseconds(AnimationColorMilliseconds));
         var brush    = (SolidColorBrush)inside.Path.Fill;
         brush.BeginAnimation(SolidColorBrush.ColorProperty, new ColorAnimation()
         {
             To = inside.Color, Duration = duration
         });
     }
     inside = null;
 }
Ejemplo n.º 11
0
    public ExerciseEditPanel CreatePanel(Exercise exercise, PieSlice pieSlice)
    {
        ExerciseEditPanel newPanel = Instantiate(panelPrefab);

        newPanel.exercise = exercise;
        newPanel.hweel    = hweel;
        newPanel.transform.SetParent(grid.transform);

        newPanel.pieSlice = pieSlice;

        panels.Add(newPanel);

        return(newPanel);
    }
Ejemplo n.º 12
0
 /// <summary>
 ///   Return the index of the foremost pie slice i.e. the one crossing
 ///   90 degrees boundary.
 /// </summary>
 /// <param name="pieSlices">
 ///   Array of <c>PieSlice</c> objects to examine.
 /// </param>
 /// <returns>
 ///   Index of the foremost pie slice.
 /// </returns>
 private int GetForemostPieSlice(PieSlice[] pieSlices)
 {
     Debug.Assert(pieSlices != null && pieSlices.Length > 0);
     for (int i = 0; i < pieSlices.Length; ++i)
     {
         PieSlice pieSlice = pieSlices[i];
         if (((pieSlice.StartAngle <= 90) && ((pieSlice.StartAngle + pieSlice.SweepAngle) >= 90)) ||
             ((pieSlice.StartAngle + pieSlice.SweepAngle > 360) && ((pieSlice.StartAngle) <= 450) && (pieSlice.StartAngle + pieSlice.SweepAngle) >= 450))
         {
             return(i);
         }
     }
     Debug.Assert(false, "Foremost pie slice not found");
     return(-1);
 }
Ejemplo n.º 13
0
        private void MakePieCharts([JetBrains.Annotations.NotNull] string fileName, [JetBrains.Annotations.NotNull] string plotName, [JetBrains.Annotations.NotNull] DirectoryInfo basisPath,
                                   [JetBrains.Annotations.NotNull] Dictionary <string, List <TagEntry> > consumption)
        {
            foreach (var pair in consumption)
            {
                var plotModel1 = new PlotModel();
                pair.Value.Sort((x, y) => x.Value.CompareTo(y.Value));
                plotModel1.LegendBorderThickness = 0;
                plotModel1.LegendOrientation     = LegendOrientation.Horizontal;
                plotModel1.LegendPlacement       = LegendPlacement.Outside;
                plotModel1.LegendPosition        = LegendPosition.BottomCenter;
                if (Parameters.ShowTitle)
                {
                    plotModel1.Title = plotName;
                }

                var pieSeries1 = new PieSeries
                {
                    InsideLabelColor      = OxyColors.White,
                    InsideLabelPosition   = 0.8,
                    StrokeThickness       = 2,
                    AreInsideLabelsAngled = true
                };
                foreach (var tuple in pair.Value)
                {
                    var name = tuple.TagName.Trim();
                    if (name.Length > 30)
                    {
                        name = name.Substring(0, 20) + "...";
                    }
                    var slice = new PieSlice(name, tuple.Value);

                    pieSeries1.Slices.Add(slice);
                }

                plotModel1.Series.Add(pieSeries1);
                var fi           = new FileInfo(fileName);
                var modifiedName = fi.Name.Substring(0, fi.Name.Length - 3) + AutomationUtili.CleanFileName(pair.Key);
                if (fi.DirectoryName == null)
                {
                    throw new LPGException("Directory name was null");
                }

                var cleanedfullname = Path.Combine(fi.DirectoryName, modifiedName);
                Save(plotModel1, plotName, cleanedfullname, basisPath, CalcOption.HouseholdContents);
            }
        }
Ejemplo n.º 14
0
        /// <summary>
        /// 创建三维饼图
        /// </summary>
        private void CreatePie3D()
        {
            _chartPie3D = new LightningChartUltimate();

            // Disable rendering, strongly recommended before updating chart properties.
            _chartPie3D.BeginUpdate();

            // Change active view to Pie3D view.
            _chartPie3D.ActiveView = ActiveView.ViewPie3D;

            _chartPie3D.Parent     = panel1;
            _chartPie3D.Dock       = DockStyle.Fill;
            _chartPie3D.Name       = "Pie3D chart";
            _chartPie3D.Title.Text = "预警模块";

            // Configure background.
            _chartPie3D.Background.GradientFill  = GradientFill.Radial;
            _chartPie3D.Background.GradientColor = Color.Black;

            // Configure 3D pie view.
            _chartPie3D.ViewPie3D.Style    = PieStyle3D.Pie;
            _chartPie3D.ViewPie3D.Rounding = 40; // Set pie rounding.


            // Configure legend.
            _chartPie3D.ViewPie3D.LegendBox3DPie.Layout   = LegendBoxLayout.HorizontalRowSpan;
            _chartPie3D.ViewPie3D.LegendBox3DPie.Position = LegendBoxPosition.BottomCenter;
            _chartPie3D.ViewPie3D.LegendBox3DPie.Visible  = false;

            // Add pie slice data.
            // By using TRUE as a last parameter, the slice will be automatically added to chart.ViewPie3D.Values collection.
            PieSlice slice1 = new PieSlice("铁水温度", Color.FromArgb(150, 255, 255, 0), 8, _chartPie3D.ViewPie3D, true);

            slice1.Title.Font = new Font("黑体", 10);
            PieSlice slice2 = new PieSlice("铁水硅含量", Color.FromArgb(150, 0, 0, 255), 6, _chartPie3D.ViewPie3D, true);

            slice2.Title.Font = new Font("黑体", 10);
            PieSlice slice3 = new PieSlice("铁水流速", Color.FromArgb(150, 0, 255, 255), 5, _chartPie3D.ViewPie3D, true);

            slice3.Title.Font = new Font("黑体", 10);
            PieSlice slice4 = new PieSlice("铁水出铁量", Color.FromArgb(150, 255, 0, 255), 2, _chartPie3D.ViewPie3D, true);

            slice4.Title.Font = new Font("黑体", 10); //slice1.Title.Color = PublicColor.FromArgb(255, Color.Black);

            _chartPie3D.EndUpdate();
        }
Ejemplo n.º 15
0
        private void CreatePlotModel(int redWin, int blackWin, int playersCount)
        {
            var plot = new PlotModel
            {
                Title                    = null,
                TitleColor               = OxyColor.FromRgb(255, 255, 255),
                TitlePadding             = 0,
                PlotAreaBorderThickness  = new OxyThickness(0, 0, 0, 0),
                TitleHorizontalAlignment = TitleHorizontalAlignment.CenteredWithinPlotArea,
                IsLegendVisible          = false,
            };
            var ps = new PieSeries
            {
                InsideLabelPosition = 0.5,
                StrokeThickness     = 1,
                StartAngle          = 0,
                AngleSpan           = 360,
                OutsideLabelFormat  = "",
                InsideLabelColor    = OxyColor.FromRgb(255, 255, 255),
                FontSize            = 28,
                TickLabelDistance   = 0,
                Stroke    = OxyColors.Transparent,
                TextColor = OxyColors.White,
            };
            var redslice = new PieSlice
            {
                Label = $"{redWin}",
                Value = redWin,
                Fill  = OxyColors.Red
            };
            var blackslice = new PieSlice
            {
                Label = $"{blackWin}",
                Value = blackWin,
                Fill  = OxyColors.Black,
            };

            ps.Slices.Add(redslice);
            ps.Slices.Add(blackslice);
            plot.Series.Add(ps);
            GamesForWeek = plot;
            PlayersCount = playersCount;
        }
Ejemplo n.º 16
0
        /// <summary>
        ///   Return the index of the foremost pie slice i.e. the one crossing
        ///   90 degrees boundary.
        /// </summary>
        /// <param name="pieSlices">
        ///   Array of <c>PieSlice</c> objects to examine.
        /// </param>
        /// <returns>
        ///   Index of the foremost pie slice.
        /// </returns>
        private static int GetForemostPieSlice(IList <PieSlice> pieSlices)
        {
            if (pieSlices == null || pieSlices.Count <= 0)
            {
                return(-1);
            }

            for (int i = 0; i < pieSlices.Count; ++i)
            {
                PieSlice pieSlice = pieSlices[i];
                if (((pieSlice.StartAngle <= 90) && (pieSlice.StartAngle + pieSlice.SweepAngle >= 90)) ||
                    ((pieSlice.StartAngle + pieSlice.SweepAngle > 360) && (pieSlice.StartAngle <= 450) &&
                     pieSlice.StartAngle + pieSlice.SweepAngle >= 450))
                {
                    return(i);
                }
            }

            return(-1);
        }
Ejemplo n.º 17
0
        void AnimateSlice(Storyboard sb, PieSlice slice, double a1, double a2, double a3, double a4, Color c)
        {
            var duration1 = new Duration(TimeSpan.FromMilliseconds(AnimationGrowthMilliseconds));

            var animation1 = new DoubleAnimation()
            {
                From           = a1,
                To             = a2,
                Duration       = duration1,
                EasingFunction = new ExponentialEase()
                {
                    Exponent = 0.6, EasingMode = EasingMode.EaseIn
                }
            };

            sb.Children.Add(animation1);
            Storyboard.SetTarget(animation1, slice);
            Storyboard.SetTargetProperty(animation1, new PropertyPath(PieSlice.StartAngleProperty)); // start of the slice

            var animation2 = new DoubleAnimation()
            {
                From           = a3,
                To             = a4,
                Duration       = duration1,
                EasingFunction = new ExponentialEase()
                {
                    Exponent = 0.6, EasingMode = EasingMode.EaseIn
                }
            };

            sb.Children.Add(animation2);
            Storyboard.SetTarget(animation2, slice);
            Storyboard.SetTargetProperty(animation2, new PropertyPath(PieSlice.EndAngleProperty)); // end of the slice.

            var             duration2 = new Duration(TimeSpan.FromMilliseconds(AnimationColorMilliseconds));
            SolidColorBrush stroke    = (SolidColorBrush)slice.Path.Stroke;
            SolidColorBrush fill      = (SolidColorBrush)slice.Path.Fill;

            stroke.BeginAnimation(SolidColorBrush.ColorProperty, new ColorAnimation(c, duration2));
            fill.BeginAnimation(SolidColorBrush.ColorProperty, new ColorAnimation(c, duration2));
        }
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Create your application here
            SetContentView(Resource.Layout.PieGraph);

            PieGraph pg    = FindViewById <PieGraph> (Resource.Id.piegraph);        //(PieGraph)v.findViewById(R.id.piegraph);
            PieSlice slice = new PieSlice();

            slice.setColor(Color.ParseColor("#99CC00"));
            slice.setValue(2);
            pg.addSlice(slice);
            slice = new PieSlice();
            slice.setColor(Color.ParseColor("#FFBB33"));
            slice.setValue(3);
            pg.addSlice(slice);
            slice = new PieSlice();
            slice.setColor(Color.ParseColor("#AA66CC"));
            slice.setValue(8);
            pg.addSlice(slice);
        }
Ejemplo n.º 19
0
        private static PlotModel WinLoseSet(IRating player)
        {
            var win  = player?.Win ?? 0;
            var lose = player?.Lose ?? 0;
            var plot = new PlotModel
            {
                Title           = null,
                IsLegendVisible = false
            };
            var ps = new PieSeries
            {
                InsideLabelPosition = 0.5,
                Stroke           = OxyColors.Transparent,
                StartAngle       = 0,
                AngleSpan        = 360,
                InsideLabelColor = OxyColors.White,
                FontSize         = 10,
                TextColor        = OxyColors.White,
            };
            var redslice = new PieSlice
            {
                Label = GetLocalized("InfoWinLabel"),
                Value = win,
                Fill  = OxyColors.Red
            };
            var blackslice = new PieSlice
            {
                Label = GetLocalized("InfoLoseLabel"),
                Value = lose,
                Fill  = OxyColors.Black,
            };

            ps.Slices.Add(redslice);
            ps.Slices.Add(blackslice);
            plot.Series.Add(ps);
            return(plot);
        }
Ejemplo n.º 20
0
        private void OnEnterSlice(PieSlice slice)
        {
            if (slice != null)
            {
                var brush = (SolidColorBrush)slice.Path.Fill;
                var color = slice.Color;
                if (inside == null || slice != inside)
                {
                    if (inside != null)
                    {
                        OnExitSlice();
                    }

                    var duration           = new Duration(TimeSpan.FromMilliseconds(AnimationColorMilliseconds));
                    var highlight          = GetMouseOverColor(color);
                    var mouseOverAnimation = new ColorAnimation()
                    {
                        To = highlight, Duration = duration
                    };
                    mouseOverAnimation.Completed += (s, e) =>
                    {
                        this.mouseOverAnimationCompleted = true;
                        if (slice != inside)
                        {
                            brush.BeginAnimation(SolidColorBrush.ColorProperty, new ColorAnimation()
                            {
                                To = color, Duration = duration
                            });
                        }
                    };
                    this.mouseOverAnimationCompleted = false;
                    brush.BeginAnimation(SolidColorBrush.ColorProperty, mouseOverAnimation);
                    inside = slice;
                }
            }
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Gauge"/> class.
        /// </summary>
        public AuGauge()
        {
            //var fontFamily = new FontFamily("Microsoft YaHei UI");
            //(FontFamily)this.FindResource("SourceHanSansTC");
            //this.FontFamily = fontFamily;

            Canvas  = new Canvas();
            Content = Canvas;

            PieBack          = new PieSlice();
            Pie              = new PieSlice();
            MeasureTextBlock = new TextBlock();
            LeftLabel        = new TextBlock();
            RightLabel       = new TextBlock();
            //August

            MeasureTextBlockUnit            = new TextBlock();
            MeasureTextBlockUnit.Foreground = _titleColor;
            Title = new TextBlock();
            //Title.FontFamily = fontFamily;
            Title.Foreground = _titleColor;

            Canvas.Children.Add(PieBack);
            Canvas.Children.Add(Pie);
            Canvas.Children.Add(MeasureTextBlock);
            //August
            Canvas.Children.Add(MeasureTextBlockUnit);
            Canvas.Children.Add(Title);

            #region Grid
            //Grid Left
            GridLeft      = new Grid();
            GridleftRowUp = new RowDefinition
            {
                Height = new GridLength(50, GridUnitType.Star)
            };
            GridleftRowDown = new RowDefinition
            {
                Height = new GridLength(50, GridUnitType.Star)
            };
            GridLeft.RowDefinitions.Add(GridleftRowUp);
            GridLeft.RowDefinitions.Add(GridleftRowDown);
            //Grid Right
            GridRight      = new Grid();
            GridRightRowUp = new RowDefinition
            {
                Height = new GridLength(50, GridUnitType.Star)
            };
            GridRightRowDown = new RowDefinition
            {
                Height = new GridLength(150, GridUnitType.Star)
            };
            GridRight.RowDefinitions.Add(GridRightRowUp);
            GridRight.RowDefinitions.Add(GridRightRowDown);

            //Label Max/Min
            Max = new TextBlock
            {
                Foreground = _titleColor,
                Text       = " Max ",
                //FontFamily = new FontFamily("Microsoft YaHei UI")//(FontFamily)this.FindResource("SourceHanSansTC")
            };
            Min = new TextBlock
            {
                Foreground = _titleColor,
                Text       = " Min "
            };
            GridLeft.Children.Add(Min);
            GridRight.Children.Add(Max);

            //Grid Barder
            GridLeftBoarder = new Border
            {
                BorderThickness = new Thickness(0, 1, 0, 0),
                BorderBrush     = _titleColor
            };
            GridLeft.Children.Add(GridLeftBoarder);
            GridRightBoarder = new Border
            {
                BorderThickness = new Thickness(0, 1, 0, 0),
                BorderBrush     = _titleColor
            };
            GridRight.Children.Add(GridRightBoarder);

            //Label Left/Right
            GridLeft.Children.Add(LeftLabel);
            LeftLabel.Foreground          = _titleColor;
            LeftLabel.HorizontalAlignment = HorizontalAlignment.Center;

            GridRight.Children.Add(RightLabel);
            RightLabel.Foreground          = _titleColor;
            RightLabel.HorizontalAlignment = HorizontalAlignment.Center;

            GridLeftBoarder.SetValue(Grid.RowProperty, 1);
            GridRightBoarder.SetValue(Grid.RowProperty, 1);

            Min.SetValue(Grid.RowProperty, 1);
            Max.SetValue(Grid.RowProperty, 1);
            LeftLabel.SetValue(Grid.RowProperty, 0);
            RightLabel.SetValue(Grid.RowProperty, 0);

            Canvas.Children.Add(GridLeft);
            Canvas.Children.Add(GridRight);
            Panel.SetZIndex(GridLeft, 1);
            Panel.SetZIndex(GridRight, 1);
            #endregion
            //RightLabel.TextDecorations = System.Windows.TextDecorations.Underline;
            //LeftLabel.TextDecorations = System.Windows.TextDecorations.Underline;

            //Canvas.Children.Add(RightLabel);
            //Canvas.Children.Add(LeftLabel);

            Panel.SetZIndex(MeasureTextBlock, 1);
            Panel.SetZIndex(RightLabel, 1);
            Panel.SetZIndex(LeftLabel, 1);

            Panel.SetZIndex(PieBack, 0);
            Panel.SetZIndex(Pie, 1);

            Canvas.SetBinding(WidthProperty,
                              new Binding {
                Path = new PropertyPath(WidthProperty), Source = this
            });
            Canvas.SetBinding(HeightProperty,
                              new Binding {
                Path = new PropertyPath(HeightProperty), Source = this
            });

            PieBack.SetBinding(Shape.FillProperty,
                               new Binding {
                Path = new PropertyPath(GaugeBackgroundProperty), Source = this
            });
            PieBack.SetBinding(Shape.StrokeThicknessProperty,
                               new Binding {
                Path = new PropertyPath(StrokeThicknessProperty), Source = this
            });
            PieBack.SetBinding(Shape.StrokeProperty,
                               new Binding {
                Path = new PropertyPath(StrokeProperty), Source = this
            });
            PieBack.SetBinding(RenderTransformProperty,
                               new Binding {
                Path = new PropertyPath(GaugeRenderTransformProperty), Source = this
            });

            Pie.SetBinding(Shape.StrokeThicknessProperty,
                           new Binding {
                Path = new PropertyPath(StrokeThicknessProperty), Source = this
            });
            Pie.SetBinding(RenderTransformProperty,
                           new Binding {
                Path = new PropertyPath(GaugeRenderTransformProperty), Source = this
            });
            Pie.Stroke = Brushes.Transparent;

            SetCurrentValue(GaugeBackgroundProperty, new SolidColorBrush(Color.FromRgb(21, 101, 191))
            {
                Opacity = .1
            });
            SetCurrentValue(StrokeThicknessProperty, 0d);
            SetCurrentValue(StrokeProperty, new SolidColorBrush(Color.FromRgb(222, 222, 222)));

            SetCurrentValue(FromColorProperty, Color.FromRgb(100, 180, 245));
            SetCurrentValue(ToColorProperty, Color.FromRgb(21, 101, 191));

            SetCurrentValue(MinHeightProperty, 20d);
            SetCurrentValue(MinWidthProperty, 20d);

            SetCurrentValue(AnimationsSpeedProperty, TimeSpan.FromMilliseconds(800));

            //MeasureTextBlock.FontWeight = FontWeights.Bold;

            IsNew = true;

            SizeChanged += (sender, args) =>
            {
                IsChartInitialized = true;
                Update();
            };
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Gauge"/> class.
        /// </summary>
        public Gauge()
        {
            Canvas  = new Canvas();
            Content = Canvas;

            PieBack          = new PieSlice();
            Pie              = new PieSlice();
            MeasureTextBlock = new TextBlock();
            LeftLabel        = new TextBlock();
            RightLabel       = new TextBlock();

            Canvas.Children.Add(PieBack);
            Canvas.Children.Add(Pie);
            Canvas.Children.Add(MeasureTextBlock);
            Canvas.Children.Add(RightLabel);
            Canvas.Children.Add(LeftLabel);

            Panel.SetZIndex(MeasureTextBlock, 1);
            Panel.SetZIndex(RightLabel, 1);
            Panel.SetZIndex(LeftLabel, 1);

            Panel.SetZIndex(PieBack, 0);
            Panel.SetZIndex(Pie, 1);

            Canvas.SetBinding(WidthProperty,
                              new Binding {
                Path = new PropertyPath(WidthProperty), Source = this
            });
            Canvas.SetBinding(HeightProperty,
                              new Binding {
                Path = new PropertyPath(HeightProperty), Source = this
            });

            PieBack.SetBinding(Shape.FillProperty,
                               new Binding {
                Path = new PropertyPath(GaugeBackgroundProperty), Source = this
            });
            PieBack.SetBinding(Shape.StrokeThicknessProperty,
                               new Binding {
                Path = new PropertyPath(StrokeThicknessProperty), Source = this
            });
            PieBack.SetBinding(Shape.StrokeProperty,
                               new Binding {
                Path = new PropertyPath(StrokeProperty), Source = this
            });
            PieBack.SetBinding(RenderTransformProperty,
                               new Binding {
                Path = new PropertyPath(GaugeRenderTransformProperty), Source = this
            });

            Pie.SetBinding(Shape.StrokeThicknessProperty,
                           new Binding {
                Path = new PropertyPath(StrokeThicknessProperty), Source = this
            });
            Pie.SetBinding(RenderTransformProperty,
                           new Binding {
                Path = new PropertyPath(GaugeRenderTransformProperty), Source = this
            });
            Pie.Stroke = Brushes.Transparent;

            SetCurrentValue(GaugeBackgroundProperty, new SolidColorBrush(Color.FromRgb(21, 101, 191))
            {
                Opacity = .1
            });
            SetCurrentValue(StrokeThicknessProperty, 0d);
            SetCurrentValue(StrokeProperty, new SolidColorBrush(Color.FromRgb(222, 222, 222)));

            SetCurrentValue(FromColorProperty, Color.FromRgb(100, 180, 245));
            SetCurrentValue(ToColorProperty, Color.FromRgb(21, 101, 191));

            SetCurrentValue(MinHeightProperty, 20d);
            SetCurrentValue(MinWidthProperty, 20d);

            SetCurrentValue(AnimationsSpeedProperty, TimeSpan.FromMilliseconds(800));

            MeasureTextBlock.FontWeight = FontWeights.Bold;

            IsNew = true;

            SizeChanged += (sender, args) =>
            {
                IsChartInitialized = true;
                Update();
            };
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="AngularGaugeWithPointer"/> class.
        /// </summary>
        public AngularGaugeWithPointer()
        {
            Canvas  = new Canvas();
            Content = Canvas;

            PieBack          = new PieSlice();
            Pie              = new PieSlice();
            MeasureTextBlock = new TextBlock();
            LeftLabel        = new TextBlock();
            RightLabel       = new TextBlock();

            StickRotateTransform = new RotateTransform(180);
            Stick = new Path
            {
                Data    = Geometry.Parse("m0,90 a5,5 0 0 0 20,0 l-8,-88 a2,2 0 0 0 -4 0 z"),
                Fill    = Brushes.CornflowerBlue,
                Stretch = Stretch.Fill,
                RenderTransformOrigin = new Point(0.5, 0.9),
                RenderTransform       = StickRotateTransform
            };
            Canvas.Children.Add(Stick);
            Panel.SetZIndex(Stick, 1);

            Canvas.Children.Add(PieBack);
            Canvas.Children.Add(Pie);
            Canvas.Children.Add(MeasureTextBlock);
            Canvas.Children.Add(RightLabel);
            Canvas.Children.Add(LeftLabel);

            Panel.SetZIndex(MeasureTextBlock, 1);
            Panel.SetZIndex(RightLabel, 1);
            Panel.SetZIndex(LeftLabel, 1);

            Panel.SetZIndex(PieBack, 0);
            Panel.SetZIndex(Pie, 1);

            Canvas.SetBinding(WidthProperty,
                              new Binding {
                Path = new PropertyPath(WidthProperty), Source = this
            });
            Canvas.SetBinding(HeightProperty,
                              new Binding {
                Path = new PropertyPath(HeightProperty), Source = this
            });

            PieBack.SetBinding(Shape.FillProperty,
                               new Binding {
                Path = new PropertyPath(GaugeBackgroundProperty), Source = this
            });
            PieBack.SetBinding(Shape.StrokeThicknessProperty,
                               new Binding {
                Path = new PropertyPath(StrokeThicknessProperty), Source = this
            });
            PieBack.SetBinding(Shape.StrokeProperty,
                               new Binding {
                Path = new PropertyPath(StrokeProperty), Source = this
            });
            PieBack.SetBinding(RenderTransformProperty,
                               new Binding {
                Path = new PropertyPath(GaugeRenderTransformProperty), Source = this
            });

            Pie.SetBinding(Shape.StrokeThicknessProperty,
                           new Binding {
                Path = new PropertyPath(StrokeThicknessProperty), Source = this
            });
            Pie.SetBinding(RenderTransformProperty,
                           new Binding {
                Path = new PropertyPath(GaugeRenderTransformProperty), Source = this
            });
            Pie.Stroke = Brushes.Transparent;

            Stick.SetCurrentValue(Shape.FillProperty, new SolidColorBrush(Color.FromRgb(69, 90, 100)));

            SetCurrentValue(GaugeBackgroundProperty, new SolidColorBrush(Color.FromRgb(21, 101, 191))
            {
                Opacity = .1
            });
            SetCurrentValue(StrokeThicknessProperty, 0d);
            SetCurrentValue(StrokeProperty, new SolidColorBrush(Color.FromRgb(222, 222, 222)));

            SetCurrentValue(FromColorProperty, Color.FromRgb(100, 180, 245));
            SetCurrentValue(ToColorProperty, Color.FromRgb(21, 101, 191));

            SetCurrentValue(MinHeightProperty, 20d);
            SetCurrentValue(MinWidthProperty, 20d);

            SetCurrentValue(AnimationsSpeedProperty, TimeSpan.FromMilliseconds(800));

            MeasureTextBlock.FontWeight = FontWeights.Bold;

            IsNew = true;

            SizeChanged += (sender, args) =>
            {
                IsChartInitialized = true;
                Update();
            };
        }
Ejemplo n.º 24
0
        protected override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
            _slice = GetTemplateChild("Slice") as PieSlice;
            _circle = GetTemplateChild("Circle") as Canvas;
            _slider = GetTemplateChild("Slider") as Rectangle;
            _invisibleEllipse = GetTemplateChild("InvisibleEllipse") as Ellipse;

            if (_circle != null)
            {
                _transform.CenterX = _circle.Width / 2.0;
                _transform.CenterY = _circle.Height / 2.0;
                _circle.RenderTransform = _transform;
            }

            if (this.Maximum == 0)
            {
                this.Maximum = 1;
            }
            double angle = (this.Value * (double)360) / Maximum;
            this.UpdateLayout(angle, false);
        }
Ejemplo n.º 25
0
        internal void Draw()
        {
            if (!IsControlLaoded)
            {
                return;
            }

            //No cache for you gauge :( kill and redraw please
            foreach (var child in Canvas.Children
                     .Where(x => !Equals(x, Stick) && !(x is AngularSection) && !(x is PieSlice)).ToArray())
            {
                Canvas.Children.Remove(child);
            }

            Wedge = Wedge > 360 ? 360 : (Wedge < 0 ? 0 : Wedge);

            var fromAlpha = (360 - Wedge) * .5;
            var toAlpha   = 360 - fromAlpha;

            var d = ActualWidth < ActualHeight ? ActualWidth : ActualHeight;

            Stick.Height = d * .5 * .8;
            Stick.Width  = Stick.Height * .2;

            Canvas.SetLeft(Stick, ActualWidth * .5 - Stick.Width * .5);
            Canvas.SetTop(Stick, ActualHeight * .5 - Stick.Height * .9);

            var ticksHi  = d * .5;
            var ticksHj  = d * .47;
            var labelsHj = d * .44;

            foreach (var section in Sections)
            {
                PieSlice slice;
                section.Owner = this;

                if (!Slices.TryGetValue(section, out slice))
                {
                    slice           = new PieSlice();
                    Slices[section] = slice;
                }

                var p = (Canvas)section.Parent;
                p?.Children.Remove(section);
                Canvas.Children.Add(section);
                var ps = (Canvas)slice.Parent;
                ps?.Children.Remove(slice);
                Canvas.Children.Add(slice);
            }

            UpdateSections();

            for (var i = FromValue; i <= ToValue; i += TicksStep)
            {
                var alpha = LinearInterpolation(fromAlpha, toAlpha, FromValue, ToValue, i) + 90;

                var tick = new Line
                {
                    X1 = ActualWidth * .5 + ticksHi * Math.Cos(alpha * Math.PI / 180),
                    X2 = ActualWidth * .5 + ticksHj * Math.Cos(alpha * Math.PI / 180),
                    Y1 = ActualHeight * .5 + ticksHi * Math.Sin(alpha * Math.PI / 180),
                    Y2 = ActualHeight * .5 + ticksHj * Math.Sin(alpha * Math.PI / 180)
                };
                Canvas.Children.Add(tick);
                tick.SetBinding(Shape.StrokeProperty,
                                new Binding {
                    Path = new PropertyPath("TicksForeground"), Source = this
                });
                tick.SetBinding(Shape.StrokeThicknessProperty,
                                new Binding {
                    Path = new PropertyPath("TicksStrokeThickness"), Source = this
                });
            }

            for (var i = FromValue; i <= ToValue; i += LabelsStep)
            {
                var alpha = LinearInterpolation(fromAlpha, toAlpha, FromValue, ToValue, i) + 90;

                var tick = new Line
                {
                    X1 = ActualWidth * .5 + ticksHi * Math.Cos(alpha * Math.PI / 180),
                    X2 = ActualWidth * .5 + labelsHj * Math.Cos(alpha * Math.PI / 180),
                    Y1 = ActualHeight * .5 + ticksHi * Math.Sin(alpha * Math.PI / 180),
                    Y2 = ActualHeight * .5 + labelsHj * Math.Sin(alpha * Math.PI / 180)
                };

                Canvas.Children.Add(tick);
                var label = new TextBlock
                {
                    Text = LabelFormatter(i)
                };

                //label.SetBinding(EffectProperty,
                //new Binding {Path = new PropertyPath("LabelsEffect"), Source = this});

                Canvas.Children.Add(label);
                label.UpdateLayout();
                Canvas.SetLeft(label, alpha < 270
                    ? tick.X2
                    : (Math.Abs(alpha - 270) < 4
                        ? tick.X2 - label.ActualWidth * .5
                        : tick.X2 - label.ActualWidth));
                Canvas.SetTop(label, tick.Y2);
                tick.SetBinding(Shape.StrokeProperty,
                                new Binding {
                    Path = new PropertyPath("TicksForeground"), Source = this
                });
                tick.SetBinding(Shape.StrokeThicknessProperty,
                                new Binding {
                    Path = new PropertyPath("TicksStrokeThickness"), Source = this
                });
            }
            MoveStick();
        }
Ejemplo n.º 26
0
        internal void Draw()
        {
            if (!IsControlLaoded) return;

            //No cache for you gauge :( kill and redraw please
            foreach (var child in Canvas.Children.Cast<UIElement>()
                .Where(x => !Equals(x, Stick) && !(x is AngularSection) && !(x is PieSlice)).ToArray())
                Canvas.Children.Remove(child);

            Wedge = Wedge > 360 ? 360 : (Wedge < 0 ? 0 : Wedge);

            var fromAlpha = (360-Wedge)*.5;
            var toAlpha = 360 - fromAlpha;

            var d = ActualWidth < ActualHeight ? ActualWidth : ActualHeight;

            Stick.Height = d*.5*.8;
            Stick.Width = Stick.Height*.2;

            Canvas.SetLeft(Stick, ActualWidth*.5 - Stick.Width*.5);
            Canvas.SetTop(Stick, ActualHeight*.5 - Stick.Height*.9);

            var ticksHi = d*.5;
            var ticksHj = d*.47;
            var labelsHj = d*.44;

            foreach (var section in Sections)
            {
                PieSlice slice;

                section.Owner = this;

                if (!Slices.TryGetValue(section, out slice))
                {
                    slice = new PieSlice();
                    Slices[section] = slice;
                }

                var p = (Canvas)section.Parent;
                if (p != null) p.Children.Remove(section);
                Canvas.Children.Add(section);
                var ps = (Canvas)slice.Parent;
                if (ps != null) ps.Children.Remove(slice);
                Canvas.Children.Add(slice);
            }

            UpdateSections();

            var ts = double.IsNaN(TicksStep) ? DecideInterval((ToValue - FromValue)/5) : TicksStep;
            if (ts / (FromValue - ToValue) > 300)
                throw new LiveChartsException("TicksStep property is too small compared with the range in " +
                                              "the gauge, to avoid performance issues, please increase it.");

            for (var i = FromValue; i <= ToValue; i += ts)
            {
                var alpha = LinearInterpolation(fromAlpha, toAlpha, FromValue, ToValue, i) + 90;

                var tick = new Line
                {
                    X1 = ActualWidth*.5 + ticksHi*Math.Cos(alpha*Math.PI/180),
                    X2 = ActualWidth*.5 + ticksHj*Math.Cos(alpha*Math.PI/180),
                    Y1 = ActualHeight*.5 + ticksHi*Math.Sin(alpha*Math.PI/180),
                    Y2 = ActualHeight*.5 + ticksHj*Math.Sin(alpha*Math.PI/180)
                };
                Canvas.Children.Add(tick);
                tick.SetBinding(Shape.StrokeProperty,
                    new Binding {Path = new PropertyPath(TicksForegroundProperty), Source = this});
                tick.SetBinding(Shape.StrokeThicknessProperty,
                    new Binding { Path = new PropertyPath(TicksStrokeThicknessProperty), Source = this });
            }

            var ls = double.IsNaN(LabelsStep) ? DecideInterval((ToValue - FromValue) / 5) : LabelsStep;
            if (ls / (FromValue - ToValue) > 300)
                throw new LiveChartsException("LabelsStep property is too small compared with the range in " +
                                              "the gauge, to avoid performance issues, please increase it.");

            for (var i = FromValue; i <= ToValue; i += ls)
            {
                var alpha = LinearInterpolation(fromAlpha, toAlpha, FromValue, ToValue, i) + 90;

                var tick = new Line
                {
                    X1 = ActualWidth*.5 + ticksHi*Math.Cos(alpha*Math.PI/180),
                    X2 = ActualWidth*.5 + labelsHj*Math.Cos(alpha*Math.PI/180),
                    Y1 = ActualHeight*.5 + ticksHi*Math.Sin(alpha*Math.PI/180),
                    Y2 = ActualHeight*.5 + labelsHj*Math.Sin(alpha*Math.PI/180)
                };

                Canvas.Children.Add(tick);
                var label = new TextBlock
                {
                    Text = LabelFormatter(i)
                };

                label.SetBinding(EffectProperty,
                    new Binding {Path = new PropertyPath(LabelsEffectProperty), Source = this});

                Canvas.Children.Add(label);
                label.UpdateLayout();
                Canvas.SetLeft(label, alpha < 270
                    ? tick.X2
                    : (Math.Abs(alpha - 270) < 4
                        ? tick.X2 - label.ActualWidth*.5
                        : tick.X2 - label.ActualWidth));
                Canvas.SetTop(label, tick.Y2);
                tick.SetBinding(Shape.StrokeProperty,
                    new Binding { Path = new PropertyPath(TicksForegroundProperty), Source = this });
                tick.SetBinding(Shape.StrokeThicknessProperty,
                    new Binding { Path = new PropertyPath(TicksStrokeThicknessProperty), Source = this });
            }
            MoveStick();
        }
Ejemplo n.º 27
0
			private Image GetPieGraph()
			{
				RandomUtil ru = new RandomUtil();
				PieGraph pg = new PieGraph(this.Size);

				pg.Color = Color.White;
				pg.ColorGradient = Color.Orange; 

				Legend legend = new Legend(this.Width, 70);

				legend.Text = String.Empty;
				pg.Text = _displayString + " Total: " + _totalComponents.ToString();

				ICollection keys = _componentInfoTable.Keys;
				IEnumerator ie = keys.GetEnumerator();
				while (ie.MoveNext())
				{
					Type key = (Type)ie.Current;
					ComponentInfo ci = (ComponentInfo)_componentInfoTable[key];

					PieSlice ps = new PieSlice(ci.Count, ci.Color);
					pg.Slices.Add(ps);

					LegendEntry le = new LegendEntry(ci.Color, ci.Type.Name.ToString().Trim());
					legend.LegendEntryCollection.Add(le);
				}

				return GraphRenderer.DrawGraphAndLegend(pg, legend, this.Size);
			}
Ejemplo n.º 28
0
        /// <summary>
        ///   Draws outer peripheries of all slices.
        /// </summary>
        /// <param name="graphics">
        ///   <c>Graphics</c> used for drawing.
        /// </param>
        private void DrawSliceSides(Graphics graphics)
        {
            ArrayList pieSlicesList = new ArrayList(m_pieSlices);
            PieSlice  ps;

            // if the first pie slice (crossing 270 i.e. back) is crossing 90
            // (front) axis too, we have to split it
            if ((m_pieSlices[0].StartAngle > 90) && (m_pieSlices[0].StartAngle <= 270) &&
                (m_pieSlices[0].StartAngle + m_pieSlices[0].SweepAngle > 450))
            {
                ps = (PieSlice)pieSlicesList[0];
                // this one is split at 0 deg to avoid line of split to be
                // visible on the periphery
                PieSlice[] splitSlices = ps.Split(0F);
                pieSlicesList[0] = splitSlices[0];
                if (splitSlices[1].SweepAngle > 0F)
                {
                    pieSlicesList.Insert(1, splitSlices[1]);
                }
            }
            else if (((m_pieSlices[0].StartAngle > 270) && (m_pieSlices[0].StartAngle + m_pieSlices[0].SweepAngle > 450)) ||
                     ((m_pieSlices[0].StartAngle < 90) && (m_pieSlices[0].StartAngle + m_pieSlices[0].SweepAngle > 270)))
            {
                ps = (PieSlice)pieSlicesList[0];
                // this one is split at 180 deg to avoid line of split to be
                // visible on the periphery
                PieSlice[] splitSlices = ps.Split(180F);
                pieSlicesList[0] = splitSlices[1];
                if (splitSlices[1].SweepAngle > 0F)
                {
                    pieSlicesList.Add(splitSlices[0]);
                }
            }
            // first draw the backmost pie slice
            ps = (PieSlice)pieSlicesList[0];
            ps.DrawSides(graphics);
            // draw pie slices from the backmost to forward
            int incrementIndex = 1;
            int decrementIndex = pieSlicesList.Count - 1;

            while (incrementIndex < decrementIndex)
            {
                PieSlice sliceLeft = (PieSlice)pieSlicesList[decrementIndex];
                float    angle1    = sliceLeft.StartAngle - 90;
                if (angle1 > 180 || angle1 < 0)
                {
                    angle1 = 0;
                }
                PieSlice sliceRight = (PieSlice)pieSlicesList[incrementIndex];
                float    angle2     = (450 - sliceRight.EndAngle) % 360;
                if (angle2 > 180 || angle2 < 0)
                {
                    angle2 = 0;
                }
                Debug.Assert(angle1 >= 0);
                Debug.Assert(angle2 >= 0);
                if (angle2 >= angle1)
                {
                    sliceRight.DrawSides(graphics);
                    ++incrementIndex;
                }
                else if (angle2 < angle1)
                {
                    sliceLeft.DrawSides(graphics);
                    --decrementIndex;
                }
            }
            ps = (PieSlice)pieSlicesList[decrementIndex];
            ps.DrawSides(graphics);
        }
Ejemplo n.º 29
0
        private void UpdateChart()
        {
            if (double.IsNaN(this.ActualWidth))
            {
                return;
            }
            double w = this.ActualWidth - (this.Padding.Left + this.Padding.Right);
            double h = this.ActualHeight - (this.Padding.Top + this.Padding.Bottom);

            if (w < 0 || h < 0 || this.Visibility != Visibility.Visible)
            {
                return;
            }

            double m = Math.Min(w, h);
            double c = Math.Floor(m / 2);

            double total = (from d in this.Series.Values where !d.Hidden select d.Value).Sum();

            Point      center = new Point(c + (w - m) / 2, c + (h - m) / 2);
            Size       size   = new Size(c, c);
            Storyboard sb     = new Storyboard();

            double sum      = 0;
            int    i        = 0;
            double oldStart = 0;
            double oldEnd   = 0;

            foreach (var item in this.Series.Values)
            {
                PieSlice slice = null;
                if (i < slices.Count)
                {
                    slice        = slices[i];
                    oldStart     = slice.StartAngle;
                    oldEnd       = slice.EndAngle;
                    slice.Center = center;
                    slice.Size   = size;
                }
                else
                {
                    slice = new PieSlice(ChartCanvas, Colors.Transparent, center, size);
                    slices.Add(slice);
                }

                if (item.Hidden)
                {
                    // we need the slice to be added, but it needs to be hidden.
                    slice.Visibility = Visibility.Collapsed;
                    continue;
                }
                else
                {
                    slice.Visibility = Visibility.Visible;
                }

                slice.Data  = item;
                slice.Color = item.Color.Value;
                double start = total == 0 ? 0 : (sum * 360) / total;
                double end   = total == 0 ? 360 : ((sum + item.Value) * 360) / total;
                if (end == 360)
                {
                    end = 359.99;
                }
                AnimateSlice(sb, slice, oldStart, start, oldEnd, end, item.Color.Value);
                sum += item.Value;
                i++;
            }

            while (slices.Count > i)
            {
                ChartCanvas.Children.Remove(slices[i].Path);
                slices.RemoveAt(i);
            }

            this.BeginStoryboard(sb);
        }
Ejemplo n.º 30
0
        /// <summary>
        ///   Searches the chart to find the index of the pie slice which
        ///   contains point given. Search order goes in the direction opposite
        ///   to drawing order.
        /// </summary>
        /// <param name="point">
        ///   <c>PointF</c> point for which pie slice is searched for.
        /// </param>
        /// <returns>
        ///   Index of the corresponding pie slice, or -1 if none is found.
        /// </returns>
        public int FindPieSliceUnderPoint(PointF point)
        {
            // first check tops
            for (int i = 0; i < m_pieSlices.Length; ++i)
            {
                PieSlice slice = m_pieSlices[i];
                if (slice.PieSliceContainsPoint(point))
                {
                    return((int)m_pieSlicesMapping[i]);
                }
            }
            // split the backmost (at 270 degrees) pie slice
            ArrayList pieSlicesList = new ArrayList(m_pieSlices);

            PieSlice[] splitSlices = m_pieSlices[0].Split(270F);
            if (splitSlices.Length > 1)
            {
                pieSlicesList[0] = splitSlices[1];
                if (splitSlices[0].SweepAngle > 0F)
                {
                    pieSlicesList.Add(splitSlices[0]);
                }
            }
            PieSlice[] pieSlices  = (PieSlice[])pieSlicesList.ToArray(typeof(PieSlice));
            int        indexFound = -1;
            // if not found yet, then check for periferies
            int incrementIndex = 0;
            int decrementIndex = pieSlices.Length - 1;

            while (incrementIndex <= decrementIndex)
            {
                PieSlice sliceLeft  = pieSlices[decrementIndex];
                float    angle1     = 270 - sliceLeft.StartAngle;
                PieSlice sliceRight = pieSlices[incrementIndex];
                float    angle2     = (sliceRight.EndAngle + 90) % 360;
                Debug.Assert(angle2 >= 0);
                if (angle2 < angle1)
                {
                    if (sliceRight.PeripheryContainsPoint(point))
                    {
                        indexFound = incrementIndex;
                    }
                    ++incrementIndex;
                }
                else
                {
                    if (sliceLeft.PeripheryContainsPoint(point))
                    {
                        indexFound = decrementIndex;
                    }
                    --decrementIndex;
                }
            }
            // check for start/stop sides, starting from the foremost
            if (indexFound < 0)
            {
                int foremostPieIndex = GetForemostPieSlice(pieSlices);
                if (foremostPieIndex == -1)
                {
                    Debug.Assert(false, "Foremost pie slice not found");
                }

                // check for start sides from the foremost slice to the left
                // side
                int i = foremostPieIndex;
                while (i < pieSlices.Length)
                {
                    PieSlice sliceLeft = pieSlices[i];
                    if (sliceLeft.StartSideContainsPoint(point))
                    {
                        indexFound = i;
                        break;
                    }
                    ++i;
                }
                // if not found yet, check end sides from the foremost to the right
                // side
                if (indexFound < 0)
                {
                    i = foremostPieIndex;
                    while (i >= 0)
                    {
                        PieSlice sliceLeft = pieSlices[i];
                        if (sliceLeft.EndSideContainsPoint(point))
                        {
                            indexFound = i;
                            break;
                        }
                        --i;
                    }
                }
            }
            // finally search for bottom sides
            if (indexFound < 0)
            {
                for (int i = 0; i < m_pieSlices.Length; ++i)
                {
                    PieSlice slice = m_pieSlices[i];
                    if (slice.BottomSurfaceSectionContainsPoint(point))
                    {
                        return((int)m_pieSlicesMapping[i]);
                    }
                }
            }
            if (indexFound <= -1)
            {
                return(-1);
            }

            indexFound %= m_pieSlicesMapping.Count;
            return((int)m_pieSlicesMapping[indexFound]);
        }
Ejemplo n.º 31
0
        private static PlotModel RolesStatSet(IRating player)
        {
            var red = player != null?player.WinRed.GetValueOrDefault() + player.LoseRed.GetValueOrDefault() : 0;

            var black = player != null?player.WinBlack.GetValueOrDefault() + player.LoseBlack.GetValueOrDefault() : 0;

            var sheriff = player != null?player.WinSheriff.GetValueOrDefault() + player.LoseSheriff.GetValueOrDefault() : 0;

            var don = player != null?player.WinDon.GetValueOrDefault() + player.LoseDon.GetValueOrDefault() : 0;

            var plot = new PlotModel
            {
                Title           = null,
                IsLegendVisible = false
            };
            var ps = new PieSeries
            {
                InsideLabelPosition = 0.6,
                Stroke           = OxyColors.Transparent,
                StartAngle       = 0,
                AngleSpan        = 360,
                InsideLabelColor = OxyColors.White,
                FontSize         = 8,
                TextColor        = OxyColors.White,
            };
            var redslice = new PieSlice
            {
                Label = GetLocalized("InfoRedSlice"),
                Value = red,
                Fill  = OxyColors.Red
            };
            var blackslice = new PieSlice
            {
                Label = GetLocalized("InfoBlackSlice"),
                Value = black,
                Fill  = OxyColors.Black,
            };
            var sheriffslice = new PieSlice
            {
                Label = GetLocalized("InfoSheriffSlice"),
                Value = sheriff,
                Fill  = OxyColor.FromRgb(255, 100, 100)
            };
            var donslice = new PieSlice
            {
                Label = GetLocalized("InfoDonSlice"),
                Value = don,
                Fill  = OxyColor.FromRgb(50, 50, 50)
            };

            if (red != 0)
            {
                ps.Slices.Add(redslice);
            }
            if (black != 0)
            {
                ps.Slices.Add(blackslice);
            }
            if (don != 0)
            {
                ps.Slices.Add(donslice);
            }
            if (sheriff != 0)
            {
                ps.Slices.Add(sheriffslice);
            }
            plot.Series.Add(ps);
            return(plot);
        }
Ejemplo n.º 32
0
        /// <summary>
        ///   Initializes pies.
        /// </summary>
        /// Creates a list of pies, starting with the pie that is crossing the
        /// 270 degrees boundary, i.e. "backmost" pie that always has to be
        /// drawn first to ensure correct surface overlapping.
        private void InitializePieSlices()
        {
            // calculates the sum of values required to evaluate sweep angles
            // for individual pies
            double sum = m_values.Sum(itemValue => (double)itemValue);

            // some values and indices that will be used in the loop
            SizeF     topEllipeSize = TopEllipseSize;
            SizeF     largestDisplacementEllipseSize = LargestDisplacementEllipseSize;
            int       maxDisplacementIndex           = m_sliceRelativeDisplacements.Length - 1;
            float     largestDisplacement            = LargestDisplacement;
            ArrayList listPieSlices = new ArrayList();

            m_pieSlicesMapping.Clear();
            int    colorIndex        = 0;
            int    backPieIndex      = -1;
            int    displacementIndex = 0;
            double startAngle        = m_initialAngle;

            for (int i = 0; i < m_values.Length; ++i)
            {
                decimal itemValue  = m_values[i];
                double  sweepAngle = (double)itemValue / sum * 360;
                // displacement from the center of the ellipse
                float xDisplacement = m_sliceRelativeDisplacements[displacementIndex];
                float yDisplacement = m_sliceRelativeDisplacements[displacementIndex];
                if (xDisplacement > 0F)
                {
                    Debug.Assert(largestDisplacement > 0F);
                    SizeF pieDisplacement = GetSliceDisplacement((float)(startAngle + sweepAngle / 2),
                                                                 m_sliceRelativeDisplacements[displacementIndex]);
                    xDisplacement = pieDisplacement.Width;
                    yDisplacement = pieDisplacement.Height;
                }
                PieSlice slice;
                if (i == m_highlightedIndex)
                {
                    using (PieSlice pieSlice =
                               CreatePieSliceHighlighted(m_left + largestDisplacementEllipseSize.Width / 2 + xDisplacement,
                                                         m_top + largestDisplacementEllipseSize.Height / 2 + yDisplacement,
                                                         topEllipeSize.Width, topEllipeSize.Height, PieHeight,
                                                         (float)startAngle, (float)sweepAngle, m_colors[colorIndex],
                                                         m_shadowStyle, m_edgeColorType, m_edgeLineWidth))
                    {
                        slice = (PieSlice)pieSlice.Clone();
                    }
                }
                else
                {
                    using (PieSlice pieSlice = CreatePieSlice(m_left + largestDisplacementEllipseSize.Width / 2 + xDisplacement,
                                                              m_top + largestDisplacementEllipseSize.Height / 2 + yDisplacement,
                                                              topEllipeSize.Width, topEllipeSize.Height, PieHeight,
                                                              (float)startAngle, (float)sweepAngle, m_colors[colorIndex],
                                                              m_shadowStyle, m_edgeColorType, m_edgeLineWidth))
                    {
                        slice = (PieSlice)pieSlice.Clone();
                    }
                }
                slice.Text = m_texts[i];
                // the backmost pie is inserted to the front of the list for correct drawing
                if (backPieIndex > -1 || ((startAngle <= 270) && (startAngle + sweepAngle > 270)) ||
                    ((startAngle >= 270) && (startAngle + sweepAngle > 630)))
                {
                    ++backPieIndex;
                    listPieSlices.Insert(backPieIndex, slice);
                    m_pieSlicesMapping.Insert(backPieIndex, i);
                }
                else
                {
                    listPieSlices.Add(slice);
                    m_pieSlicesMapping.Add(i);
                }
                // increment displacementIndex only if there are more displacements available
                if (displacementIndex < maxDisplacementIndex)
                {
                    ++displacementIndex;
                }
                ++colorIndex;
                // if all colors have been exhausted, reset color index
                if (colorIndex >= m_colors.Length)
                {
                    colorIndex = 0;
                }
                // prepare for the next pie slice
                startAngle += sweepAngle;
                if (startAngle > 360)
                {
                    startAngle -= 360;
                }
            }
            m_pieSlices = (PieSlice[])listPieSlices.ToArray(typeof(PieSlice));
        }
Ejemplo n.º 33
0
 public void Add(PieSlice pieSlice)
 {
     m_values.Add(pieSlice);
 }