Example #1
0
 private void OnPieSliceClicked(object sender, ChartDataValue e)
 {
     if (e.UserData is SecurityGroup g && DrillDown != null)
     {
         // now we can drill down and show a report on just this group of investments.
         DrillDown(this, g);
     }
 }
Example #2
0
        protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
        {
            var pos   = e.GetPosition(ChartCanvas);
            var slice = FindSlice(pos);

            if (slice != null)
            {
                ChartDataValue value = slice.Data;
                if (PieSliceClicked != null)
                {
                    PieSliceClicked(this, value);
                }
            }
        }
        protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
        {
            var pos  = e.GetPosition(this);
            var info = FindColumn(pos);

            if (info != null)
            {
                ChartDataValue value = info.Data;
                if (ColumnClicked != null)
                {
                    ColumnClicked(this, value);
                }
            }
        }
Example #4
0
        public ChartColumn(ChartDataValue cv, NumberFormatInfo nfi, Color c1, double colWidth, double availableHeight, double range)
        {
            this.availableHeight = availableHeight;
            if (range == 0)
            {
                range = availableHeight;
            }
            this.range = range;

            vtext = new TextBlock();

            Binding binding = new Binding();

            binding.Source    = this;
            binding.Path      = new PropertyPath("ColumnValue");
            binding.Converter = new NumberConverter(nfi);

            vtext.SetBinding(TextBlock.TextProperty, binding);
            vtext.HorizontalAlignment = HorizontalAlignment.Center;

            r         = new Rectangle();
            r.Width   = colWidth;
            r.Height  = 0;
            r.RadiusX = r.RadiusY = 2;

            HlsColor hls = new HlsColor(c1);

            hls.Lighten(.3f);
            Color c2 = hls.Color;

            hls = new HlsColor(c1);
            hls.Darken(.3f);
            Color stroke = hls.Color;

            r.Stroke          = new SolidColorBrush(stroke);
            r.StrokeThickness = 1;
            r.Fill            = new LinearGradientBrush(c1, c2, new Point(0, 0), new Point(0, 1));

            TextBlock label = new TextBlock();

            label.Text = cv.Label;
            label.HorizontalAlignment = HorizontalAlignment.Center;

            this.Children.Add(vtext);
            this.Children.Add(r);
            this.Children.Add(label);

            this.value = cv;
            this.SetValue(ColumnValueProperty, cv.Value);
        }
Example #5
0
        private UIElement OnGenerateToolTip(ChartDataValue value)
        {
            var tip = new StackPanel()
            {
                Orientation = Orientation.Vertical
            };

            tip.Children.Add(new TextBlock()
            {
                Text = value.Label, FontWeight = FontWeights.Bold
            });
            tip.Children.Add(new TextBlock()
            {
                Text = value.Value.ToString("C0")
            });
            return(tip);
        }
Example #6
0
        private void OnHover()
        {
            var slice = this.inside;

            if (slice == null)
            {
                return;
            }

            ChartDataValue value   = slice.Data;
            var            tip     = this.ToolTip as ToolTip;
            var            content = ToolTipGenerator != null?ToolTipGenerator(value) : new TextBlock()
            {
                Text = value.Label + "\r\n" + value.Value
            };

            if (tip == null)
            {
                tip = new ToolTip()
                {
                    Placement = System.Windows.Controls.Primitives.PlacementMode.MousePoint,
                    Content   = content,
                    IsOpen    = true
                };
                this.ToolTip = tip;
            }
            else
            {
                tip.Content = content;
                tip.IsOpen  = true;
            }
            tip.Measure(new Size(100, 100));
            tip.HorizontalOffset = 0;
            tip.VerticalOffset   = -tip.ActualHeight;

            // notify any interested listeners
            var h = this.PieSliceHover;

            if (h != null)
            {
                h(this, value);
            }
        }
Example #7
0
        void UpdatePointer(Point pos)
        {
            if (data != null && data.Series.Count > 0 && scale != null && scale.ScaleX > 0)
            {
                if (selectedSeries == null)
                {
                    selectedSeries = data.Series[data.Series.Count - 1];
                }

                Point legendPos    = this.TransformToDescendant(legend).Transform(pos);
                Rect  legendArea   = new Rect(0, 0, legend.ActualWidth, legend.ActualHeight);
                bool  insideLegend = (legendArea.Contains(legendPos));

                if (pointer == null)
                {
                    PathGeometry diamond = new PathGeometry();
                    PathFigure   figure  = new PathFigure();
                    diamond.Figures.Add(figure);
                    figure.IsClosed   = true;
                    figure.IsFilled   = true;
                    figure.StartPoint = new Point(0, -5);
                    figure.Segments.Add(new LineSegment(new Point(5, 0), true));
                    figure.Segments.Add(new LineSegment(new Point(0, 5), true));
                    figure.Segments.Add(new LineSegment(new Point(-5, 0), true));

                    pointer = new Path()
                    {
                        Data = diamond,
                        Fill = Brushes.Red
                    };
                    this.Children.Add(pointer);
                }
                if (tooltip == null)
                {
                    tooltip                     = new Border();
                    tooltip.Padding             = new Thickness(2);
                    tooltip.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
                    tooltip.VerticalAlignment   = System.Windows.VerticalAlignment.Top;
                    tooltip.BorderBrush         = AppTheme.Instance.GetThemedBrush("SystemControlForegroundBaseHighBrush");
                    tooltip.BorderThickness     = new Thickness(1);
                    tooltip.Background          = AppTheme.Instance.GetThemedBrush("SystemControlBackgroundBaseLowBrush");
                    this.Children.Add(tooltip);
                }

                ChartDataSeries series = selectedSeries;
                var             values = series.Values;

                int i = (int)(pos.X / scale.ScaleX);
                if (i >= 0 && i < values.Count)
                {
                    ChartDataValue v = values[i];
                    Selected = v;

                    UIElement content = null;
                    if (this.ToolTipGenerator != null)
                    {
                        content = this.ToolTipGenerator(v);
                    }
                    else
                    {
                        var label = new TextBlock();
                        label.Foreground = Brushes.Black;
                        label.Text       = v.Label;
                        content          = label;
                    }
                    tooltip.Child = content;

                    if (insideLegend)
                    {
                        tooltip.Visibility = System.Windows.Visibility.Hidden;
                    }
                    else
                    {
                        tooltip.UpdateLayout();

                        double tipPositionX = pos.X;
                        if (tipPositionX + tooltip.ActualWidth > this.ActualWidth)
                        {
                            tipPositionX = this.ActualWidth - tooltip.ActualWidth;
                        }
                        double tipPositionY = pos.Y - tooltip.ActualHeight - 4;
                        if (tipPositionY < 0)
                        {
                            tipPositionY = 0;
                        }
                        tooltip.Margin     = new Thickness(tipPositionX, tipPositionY, 0, 0);
                        tooltip.Visibility = System.Windows.Visibility.Visible;
                    }

                    double value = v.Value;
                    if (series.Flipped)
                    {
                        value = -value;
                    }
                    Point pointerPosition = transform.Transform(new Point(i, value));
                    pointer.RenderTransform = new TranslateTransform(pointerPosition.X, pointerPosition.Y);
                    pointer.Visibility      = System.Windows.Visibility.Visible;
                }
                else
                {
                    tooltip.Visibility = System.Windows.Visibility.Hidden;
                    pointer.Visibility = System.Windows.Visibility.Hidden;
                }
            }
            else
            {
                // todo
            }
        }