コード例 #1
0
ファイル: PiePlotter.xaml.cs プロジェクト: sree93/Directree
        /// <summary>
        /// Constructs pie pieces and adds them to the visual tree for this control's canvas
        /// </summary>
        private void ConstructPiePieces()
        {
            CollectionView myCollectionView = (CollectionView)CollectionViewSource.GetDefaultView(this.DataContext);

            if (myCollectionView == null)
            {
                return;
            }

            double halfWidth   = this.Width / 2;
            double innerRadius = halfWidth * HoleSize;

            // compute the total for the property which is being plotted
            double total = 0;

            foreach (Object item in myCollectionView)
            {
                total += GetPlottedPropertyValue(item);
            }

            // add the pie pieces
            canvas.Children.Clear();
            piePieces.Clear();

            double accumulativeAngle = 0;

            foreach (Object item in myCollectionView)
            {
                bool selectedItem = item == myCollectionView.CurrentItem;

                double wedgeAngle = GetPlottedPropertyValue(item) * 360 / total;

                PiePiece piece = new PiePiece()
                {
                    Radius        = halfWidth,
                    InnerRadius   = innerRadius,
                    CentreX       = halfWidth,
                    CentreY       = halfWidth,
                    PushOut       = (selectedItem ? 10.0 : 0),
                    WedgeAngle    = wedgeAngle,
                    PieceValue    = GetPlottedPropertyValue(item),
                    RotationAngle = accumulativeAngle,
                    Fill          = ColorSelector != null?ColorSelector.SelectBrush(item, myCollectionView.IndexOf(item)) : Brushes.Black,
                                        // record the index of the item which this pie slice represents
                                        Tag     = myCollectionView.IndexOf(item),
                                        ToolTip = new ToolTip()
                };

                piece.ToolTipOpening += new ToolTipEventHandler(PiePieceToolTipOpening);
                piece.MouseUp        += new MouseButtonEventHandler(PiePieceMouseUp);

                piePieces.Add(piece);
                canvas.Children.Insert(0, piece);

                accumulativeAngle += wedgeAngle;
            }
        }
コード例 #2
0
        private Brush GetBackgroundColor(object item)
        {
            if (item is IPieceBackgroundColor color)
            {
                return(color.GetBackgroundColor());
            }

            return(ColorSelector != null?ColorSelector.SelectBrush(item, -1) : Brushes.Black);
        }
コード例 #3
0
ファイル: PiePlotter.xaml.cs プロジェクト: brooklikeme/wantai
        private void ConstructPiePieces()
        {
            double halfWidth   = this.Width / 2;
            double innerRadius = 2;//halfWidth * HoleSize;

            // add the pie pieces
            canvas.Children.Clear();
            piePieces.Clear();

            double accumulativeAngle = 0;

            for (int item = 0; item < int.Parse(PlottedProperty); item++)
            {
                double wedgeAngle = 360 / int.Parse(PlottedProperty);

                PiePiece piece = new PiePiece()
                {
                    Radius        = halfWidth,
                    InnerRadius   = innerRadius,
                    CentreX       = halfWidth,
                    CentreY       = halfWidth,
                    PushOut       = 0,
                    WedgeAngle    = wedgeAngle,
                    PieceValue    = wedgeAngle,
                    RotationAngle = accumulativeAngle,
                    Fill          = ColorSelector != null?ColorSelector.SelectBrush(null, item) : Brushes.Black,
                                        // record the index of the item which this pie slice represents
                                        Tag     = item,
                                        ToolTip = new ToolTip()
                };

                piece.ToolTipOpening += new ToolTipEventHandler(PiePieceToolTipOpening);
                piece.MouseUp        += new MouseButtonEventHandler(PiePieceMouseUp);

                piePieces.Add(piece);
                canvas.Children.Insert(0, piece);

                accumulativeAngle += wedgeAngle;
            }
        }
コード例 #4
0
        /// <summary>
        /// Constructs pie pieces and adds them to the visual tree for this control's canvas
        /// </summary>
        private void ConstructPiePieces()
        {
            CollectionView myCollectionView = (CollectionView)CollectionViewSource.GetDefaultView(this.DataContext);

            if (myCollectionView == null)
            {
                return;
            }

            double halfWidth = ((this.ActualHeight < this.ActualWidth ? this.ActualHeight : this.ActualWidth)
                                - this.Margin.Top - this.Margin.Bottom) / 2;
            double innerRadius = halfWidth * HoleSize;

            // compute the total for the property which is being plotted
            double total = myCollectionView.Cast <object>().Sum(item => GetPlottedPropertyValue(item));

            CleanupPie();

            // add the pie pieces
            double accumulativeAngle = 0;

            foreach (Object item in myCollectionView)
            {
                bool selectedItem = item == myCollectionView.CurrentItem;

                double wedgeAngle = GetPlottedPropertyValue(item) * 360 / total;

                PiePiece piece = new PiePiece()
                {
                    Radius                                     = halfWidth,
                    InnerRadius                                = innerRadius,
                    CenterX                                    = halfWidth,
                    CenterY                                    = halfWidth,
                    PushOut                                    = (selectedItem ? 10.0 : 0),
                    WedgeAngle                                 = wedgeAngle,
                    PieceValue                                 = GetPlottedPropertyValue(item),
                    RotationAngle                              = accumulativeAngle,
                    Fill                                       = ColorSelector != null?ColorSelector.SelectBrush(item, myCollectionView.IndexOf(item)) : Brushes.Black,
                                                  PieceCaption = GetPlottedCaptionPropertyValue(item),
                                                  // record the index of the item which this pie slice represents
                                                  Tag     = myCollectionView.IndexOf(item),
                                                  ToolTip = new ToolTip()
                };

                piece.ToolTipOpening += PiePieceToolTipOpening;
                piece.MouseUp        += PiePieceMouseUp;

                piePieces.Add(piece);
                canvas.Children.Insert(0, piece);

                accumulativeAngle += wedgeAngle;
            }
        }