Exemple #1
0
        void Update(CallTreeNodeViewModel item)
        {
            Debug.WriteLine("RingDiagram.Update: new root = " + item);

            this.task.Cancel();

            Debug.WriteLine("hierarchyStack count: " + this.hierarchyStack.Count);

            while (this.hierarchyStack.Count > 0 && !hierarchyStack.Peek().IsAncestorOf(item))
            {
                this.hierarchyStack.Pop();
            }

            Debug.Assert(hierarchyStack.Count == 0 || hierarchyStack.Peek().IsAncestorOf(item));

            this.Children.Clear();

            if (item == null)
            {
                return;
            }

            List <Shape> newItems = new List <Shape>();

            Ellipse ell = new Ellipse();

            ell.Width               = 40;
            ell.Height              = 40;
            ell.VerticalAlignment   = VerticalAlignment.Center;
            ell.HorizontalAlignment = HorizontalAlignment.Center;
            ell.Fill    = Brushes.Gray;
            ell.Stroke  = Brushes.Black;
            ell.ToolTip = item.CreateToolTip(Translation);
            ell.Tag     = item;

            ell.MouseLeftButtonDown += (sender, e) =>
            {
                if (this.hierarchyStack.Count > 1 && this.hierarchyStack.Peek().Level > 1)
                {
                    var oldItem = this.hierarchyStack.Pop();
                    this.SelectedRoot            = this.hierarchyStack.Peek();
                    this.SelectedRoot.IsSelected = true;
                    this.SelectedRoot.IsExpanded = true;
                    oldItem.IsSelected           = false;
                }
            };

            if (hierarchyStack.Count == 0 || hierarchyStack.Peek() != item)
            {
                this.hierarchyStack.Push(item);
            }

            List <PiePieceDescriptor> pieces = new List <PiePieceDescriptor>();

            this.task.Execute(
                () => {
                if (item.CpuCyclesSpent > 0)
                {
                    CreateTree(pieces, item, 0, item.CpuCyclesSpent, 0);
                }
            },
                () => {
                this.Children.Add(ell);
                this.Children.AddRange(pieces.Select(p => CreatePiePiece(p.Radius, p.WedgeAngle, p.RotationAngle, p.Level, p.Node)));
                item.BringIntoView();
            },
                delegate { }
                );
        }
Exemple #2
0
        private PiePiece CreatePiePiece(int rad, double wedgeAngle, double rotationAngle, int level, CallTreeNodeViewModel node)
        {
            // prevent exception when ProfilerHook screws up and children are larger than their parent (e.g. when process is killed)
            if (rotationAngle > 360)
            {
                rotationAngle %= 360;
            }

            PiePiece p = new PiePiece();

            p.Radius              = 20 + level * rad;
            p.InnerRadius         = level * rad;
            p.WedgeAngle          = wedgeAngle;
            p.RotationAngle       = rotationAngle;
            p.Stroke              = Brushes.Black;
            p.ToolTip             = node.CreateToolTip(Translation);
            p.VerticalAlignment   = VerticalAlignment.Center;
            p.HorizontalAlignment = HorizontalAlignment.Center;
            p.Tag = node;

            p.MouseLeftButtonDown += new MouseButtonEventHandler(
                delegate(object sender, MouseButtonEventArgs e) {
                node.IsExpanded    = true;
                node.IsSelected    = true;                      // expand the path to the node so that the treeview can select it
                var oldNode        = this.SelectedRoot;
                this.SelectedRoot  = node;
                oldNode.IsSelected = false;
            }
                );

            HSVColor hsv = new HSVColor {
                Hue        = (float)rotationAngle,
                Saturation = 0.5f,
                Value      = 0.6f - level / 50f
            };

            SolidColorBrush brush = new SolidColorBrush();

            p.Fill = brush;

            Color normalColor = hsv.ToColor();

            hsv.Value = 0.8f;
            Color highlightColor = hsv.ToColor();

            brush.Color = normalColor;

            p.IsMouseDirectlyOverChanged += (sender, e) => {
                if (p.IsMouseDirectlyOver)
                {
                    brush.BeginAnimation(SolidColorBrush.ColorProperty,
                                         new ColorAnimation(highlightColor, new Duration(TimeSpan.FromSeconds(0.5)),
                                                            FillBehavior.HoldEnd));
                }
                else
                {
                    brush.BeginAnimation(SolidColorBrush.ColorProperty,
                                         new ColorAnimation(normalColor, new Duration(TimeSpan.FromSeconds(0.5)),
                                                            FillBehavior.Stop));
                }
            };

            return(p);
        }