Exemple #1
0
        public override void DataMouseEnter(object sender, MouseEventArgs e)
        {
            if (DataToolTip == null)
            {
                return;
            }

            DataToolTip.Visibility = Visibility.Visible;
            TooltipTimer.Stop();

            var senderShape = HoverableShapes.FirstOrDefault(s => Equals(s.Shape, sender));

            if (senderShape == null)
            {
                return;
            }

            senderShape.Target.Stroke = senderShape.Series.Stroke;
            senderShape.Target.Fill   = new SolidColorBrush {
                Color = PointHoverColor
            };

            var scatterToolTip = DataToolTip as ScatterTooltip;

            if (scatterToolTip != null)
            {
                scatterToolTip.PrimaryAxisTitle = PrimaryAxis.Title;
                scatterToolTip.PrimaryValue     = PrimaryAxis.LabelFormatter == null
                                                              ? senderShape.Value.Y.ToString(CultureInfo.InvariantCulture)
                                                              : PrimaryAxis.LabelFormatter(senderShape.Value.Y);

                scatterToolTip.SecondaryAxisTitle = SecondaryAxis.Title;
                scatterToolTip.SecondaryValue     = SecondaryAxis.LabelFormatter == null
                                                                ? senderShape.Value.X.ToString(CultureInfo.InvariantCulture)
                                                                : SecondaryAxis.LabelFormatter(senderShape.Value.X);
            }
            var p = GetToolTipPosition(senderShape, null);

            DataToolTip.BeginAnimation(Canvas.LeftProperty, new DoubleAnimation
            {
                To       = p.X,
                Duration = TimeSpan.FromMilliseconds(200)
            });
            DataToolTip.BeginAnimation(Canvas.TopProperty, new DoubleAnimation
            {
                To       = p.Y,
                Duration = TimeSpan.FromMilliseconds(200)
            });
        }
Exemple #2
0
        public virtual void DataMouseEnter(object sender, MouseEventArgs e)
        {
            if (DataToolTip == null)
            {
                return;
            }

            DataToolTip.Visibility = Visibility.Visible;
            TooltipTimer.Stop();

            var senderShape = HoverableShapes.FirstOrDefault(s => Equals(s.Shape, sender));

            if (senderShape == null)
            {
                return;
            }
            var sibilings = HoverableShapes
                            .Where(s => Math.Abs(s.Value.X - senderShape.Value.X) < S.X * .001).ToList();

            var first  = sibilings.Count > 0 ? sibilings[0] : null;
            var labels = SecondaryAxis.Labels != null?SecondaryAxis.Labels.ToArray() : null;

            var vx = first != null ? first.Value.X : 0;

            vx = AlphaLabel ? (int)(vx / (360d / Series.First().PrimaryValues.Count)) : vx;

            foreach (var sibiling in sibilings)
            {
                if (ShapeHoverBehavior == ShapeHoverBehavior.Dot)
                {
                    sibiling.Target.Stroke = sibiling.Series.Stroke;
                    sibiling.Target.Fill   = new SolidColorBrush {
                        Color = PointHoverColor
                    };
                }
                else
                {
                    sibiling.Target.Opacity = .8;
                }
            }

            var indexedToolTip = DataToolTip as IndexedTooltip;

            if (indexedToolTip != null)
            {
                indexedToolTip.Header = labels == null
                                                ? (SecondaryAxis.LabelFormatter == null
                                                        ? vx.ToString(CultureInfo.InvariantCulture)
                                                        : SecondaryAxis.LabelFormatter(vx))
                                                : (labels.Length > vx
                                                        ? labels[(int)vx]
                                                        : "");
                indexedToolTip.Data = sibilings.Select(x => new IndexedTooltipData
                {
                    Index  = Series.IndexOf(x.Series),
                    Series = x.Series,
                    Point  = x.Value,
                    Value  = PrimaryAxis.LabelFormatter == null
                                    ? x.Value.Y.ToString(CultureInfo.InvariantCulture)
                                    : PrimaryAxis.LabelFormatter(x.Value.Y)
                }).ToArray();
            }

            var p = GetToolTipPosition(senderShape, sibilings);

            DataToolTip.BeginAnimation(Canvas.LeftProperty, new DoubleAnimation
            {
                To       = p.X,
                Duration = TimeSpan.FromMilliseconds(200)
            });
            DataToolTip.BeginAnimation(Canvas.TopProperty, new DoubleAnimation
            {
                To       = p.Y,
                Duration = TimeSpan.FromMilliseconds(200)
            });
        }
Exemple #3
0
        protected virtual void DrawAxis()
        {
            foreach (var l in Shapes)
            {
                Canvas.Children.Remove(l);
            }
            //Titles
            var titleY = 0d;

            if (!string.IsNullOrWhiteSpace(PrimaryAxis.Title))
            {
                var ty     = GetLabelSize(PrimaryAxis, PrimaryAxis.Title);
                var yLabel = new TextBlock
                {
                    FontFamily      = PrimaryAxis.FontFamily,
                    FontSize        = PrimaryAxis.FontSize,
                    FontStretch     = PrimaryAxis.FontStretch,
                    FontStyle       = PrimaryAxis.FontStyle,
                    FontWeight      = PrimaryAxis.FontWeight,
                    Foreground      = PrimaryAxis.Foreground,
                    RenderTransform = new RotateTransform(-90)
                };
                var binding = new Binding
                {
                    Path   = new PropertyPath("Title"),
                    Source = PrimaryAxis
                };
                BindingOperations.SetBinding(yLabel, TextBlock.TextProperty, binding);
                Shapes.Add(yLabel);
                Canvas.Children.Add(yLabel);
                Canvas.SetLeft(yLabel, 5);
                Canvas.SetTop(yLabel, Canvas.DesiredSize.Height * .5 + ty.X * .5);
                titleY += ty.Y + 5;
            }
            var titleX = 0d;

            if (!string.IsNullOrWhiteSpace(SecondaryAxis.Title))
            {
                var tx     = GetLabelSize(SecondaryAxis, SecondaryAxis.Title);
                var yLabel = new TextBlock
                {
                    FontFamily  = SecondaryAxis.FontFamily,
                    FontSize    = SecondaryAxis.FontSize,
                    FontStretch = SecondaryAxis.FontStretch,
                    FontStyle   = SecondaryAxis.FontStyle,
                    FontWeight  = SecondaryAxis.FontWeight,
                    Foreground  = SecondaryAxis.Foreground
                };
                var binding = new Binding
                {
                    Path   = new PropertyPath("Title"),
                    Source = SecondaryAxis
                };
                BindingOperations.SetBinding(yLabel, TextBlock.TextProperty, binding);
                Shapes.Add(yLabel);
                Canvas.Children.Add(yLabel);
                Canvas.SetLeft(yLabel, Canvas.DesiredSize.Width * .5 - tx.X * .5);
                Canvas.SetTop(yLabel, Canvas.DesiredSize.Height - tx.Y - 5);
                titleX += tx.Y;
            }

            PlotArea.X      += titleY;
            PlotArea.Width  -= titleY;
            PlotArea.Height -= titleX;

            //drawing primary axis
            var ly = PrimaryAxis.Separator.Enabled || PrimaryAxis.PrintLabels
                                ? Max.Y
                                : Min.Y - 1;
            var longestYLabelSize = GetLongestLabelSize(PrimaryAxis);

            for (var i = Min.Y; i <= ly; i += S.Y)
            {
                var y = ToPlotArea(i, AxisTags.Y);
                if (PrimaryAxis.Separator.Enabled)
                {
                    var l = new Line
                    {
                        Stroke = new SolidColorBrush {
                            Color = PrimaryAxis.Separator.Color
                        },
                        StrokeThickness = PrimaryAxis.Separator.Thickness,
                        X1 = ToPlotArea(Min.X, AxisTags.X),
                        Y1 = y,
                        X2 = ToPlotArea(Max.X, AxisTags.X),
                        Y2 = y
                    };
                    Canvas.Children.Add(l);
                    Shapes.Add(l);
                }

                if (PrimaryAxis.PrintLabels)
                {
                    var t = PrimaryAxis.LabelFormatter == null
                                                ? i.ToString(CultureInfo.InvariantCulture)
                                                : PrimaryAxis.LabelFormatter(i);

                    var label = new TextBlock
                    {
                        FontFamily  = PrimaryAxis.FontFamily,
                        FontSize    = PrimaryAxis.FontSize,
                        FontStretch = PrimaryAxis.FontStretch,
                        FontStyle   = PrimaryAxis.FontStyle,
                        FontWeight  = PrimaryAxis.FontWeight,
                        Foreground  = PrimaryAxis.Foreground,
                        Text        = t
                    };
                    var fl = new FormattedText(t, CultureInfo.CurrentUICulture, FlowDirection.LeftToRight,
                                               new Typeface(PrimaryAxis.FontFamily, PrimaryAxis.FontStyle, PrimaryAxis.FontWeight,
                                                            PrimaryAxis.FontStretch), PrimaryAxis.FontSize, Brushes.Black);
                    Canvas.Children.Add(label);
                    Shapes.Add(label);
                    Canvas.SetLeft(label, titleY + (5 + longestYLabelSize.X) - fl.Width);
                    Canvas.SetTop(label, ToPlotArea(i, AxisTags.Y) - longestYLabelSize.Y * .5);
                }
            }

            //drawing secondary axis
            var lx = SecondaryAxis.Separator.Enabled || SecondaryAxis.PrintLabels
                                ? Max.X + (IgnoresLastLabel ? -1 : 0)
                                : Min.X - 1;

            for (var i = Min.X; i <= lx; i += S.X)
            {
                var x = ToPlotArea(i, AxisTags.X);
                if (SecondaryAxis.Separator.Enabled)
                {
                    var l = new Line
                    {
                        Stroke = new SolidColorBrush {
                            Color = SecondaryAxis.Separator.Color
                        },
                        StrokeThickness = SecondaryAxis.Separator.Thickness,
                        X1 = x,
                        Y1 = ToPlotArea(Max.Y, AxisTags.Y),
                        X2 = x,
                        Y2 = ToPlotArea(Min.Y, AxisTags.Y)
                    };
                    Canvas.Children.Add(l);
                    Shapes.Add(l);
                }

                if (SecondaryAxis.PrintLabels)
                {
                    var labels = SecondaryAxis.Labels != null?SecondaryAxis.Labels.ToArray() : null;

                    var t = labels == null
                                                ? (SecondaryAxis.LabelFormatter == null
                                                        ? i.ToString(CultureInfo.InvariantCulture)
                                                        : SecondaryAxis.LabelFormatter(i))
                                                : (labels.Length > i
                                                        ? labels[(int)i]
                                                        : "");
                    var label = new TextBlock
                    {
                        FontFamily  = SecondaryAxis.FontFamily,
                        FontSize    = SecondaryAxis.FontSize,
                        FontStretch = SecondaryAxis.FontStretch,
                        FontStyle   = SecondaryAxis.FontStyle,
                        FontWeight  = SecondaryAxis.FontWeight,
                        Foreground  = SecondaryAxis.Foreground,
                        Text        = t
                    };
                    var fl = new FormattedText(t, CultureInfo.CurrentUICulture, FlowDirection.LeftToRight,
                                               new Typeface(SecondaryAxis.FontFamily, SecondaryAxis.FontStyle, SecondaryAxis.FontWeight,
                                                            SecondaryAxis.FontStretch), SecondaryAxis.FontSize, Brushes.Black);
                    Canvas.Children.Add(label);
                    Shapes.Add(label);
                    Canvas.SetLeft(label, ToPlotArea(i, AxisTags.X) - fl.Width * .5 + XOffset);
                    Canvas.SetTop(label, PlotArea.Y + PlotArea.Height + 5);
                }
            }

            //drawing ceros.
            if (Max.Y >= 0 && Min.Y <= 0 && PrimaryAxis.IsEnabled)
            {
                var l = new Line
                {
                    Stroke = new SolidColorBrush {
                        Color = PrimaryAxis.Color
                    },
                    StrokeThickness = PrimaryAxis.Thickness,
                    X1 = ToPlotArea(Min.X, AxisTags.X),
                    Y1 = ToPlotArea(0, AxisTags.Y),
                    X2 = ToPlotArea(Max.X, AxisTags.X),
                    Y2 = ToPlotArea(0, AxisTags.Y)
                };
                Canvas.Children.Add(l);
                Shapes.Add(l);
            }

            if (Max.X >= 0 && Min.X <= 0 && SecondaryAxis.IsEnabled)
            {
                var l = new Line
                {
                    Stroke = new SolidColorBrush {
                        Color = SecondaryAxis.Color
                    },
                    StrokeThickness = SecondaryAxis.Thickness,
                    X1 = ToPlotArea(0, AxisTags.X),
                    Y1 = ToPlotArea(Min.Y, AxisTags.Y),
                    X2 = ToPlotArea(0, AxisTags.X),
                    Y2 = ToPlotArea(Max.Y, AxisTags.Y)
                };
                Canvas.Children.Add(l);
                Shapes.Add(l);
            }
        }
Exemple #4
0
        public virtual void OnDataMouseEnter(object sender, MouseEventArgs e)
        {
            var b = new Border
            {
                BorderThickness = TooltipBorderThickness ?? new Thickness(0),
                Background      = TooltipBackground ?? new SolidColorBrush {
                    Color = Color.FromRgb(30, 30, 30), Opacity = .8
                },
                CornerRadius = TooltipCornerRadius ?? new CornerRadius(2),
                BorderBrush  = TooltipBorderBrush ?? Brushes.Transparent
            };
            var sp = new StackPanel
            {
                Orientation = Orientation.Vertical
            };

            var senderShape = HoverableShapes.FirstOrDefault(s => Equals(s.Shape, sender));

            if (senderShape == null)
            {
                return;
            }
            var sibilings = HoverableShapes
                            .Where(s => Math.Abs(s.Value.X - senderShape.Value.X) < .01 * Min.X).ToList();

            var first  = sibilings.Count > 0 ? sibilings[0] : null;
            var last   = sibilings.Count > 0 ? sibilings[sibilings.Count - 1] : null;
            var labels = SecondaryAxis.Labels?.ToArray();
            var vx     = first?.Value.X ?? 0;

            vx = AlphaLabel ? (int)(vx / (360d / Series.First().PrimaryValues.Count)) : vx;

            sp.Children.Add(new TextBlock
            {
                Margin = new Thickness(10, 5, 10, 0),
                HorizontalAlignment = HorizontalAlignment.Center,
                TextAlignment       = TextAlignment.Center,
                Text = labels == null
                ? (SecondaryAxis.LabelFormatter == null
                    ? vx.ToString(CultureInfo.InvariantCulture)
                    : SecondaryAxis.LabelFormatter(vx))
                : (labels.Length > vx
                    ? labels[(int)vx]
                    : ""),
                VerticalAlignment = VerticalAlignment.Center,
                FontFamily        = new FontFamily("Calibri"),
                FontSize          = 11,
                Foreground        = TooltipForegroung ?? Brushes.White
            });

            foreach (var sibiling in sibilings)
            {
                if (ShapeHoverBehavior == ShapeHoverBehavior.Dot)
                {
                    sibiling.Target.Stroke = new SolidColorBrush {
                        Color = sibiling.Serie.Color
                    };
                    sibiling.Target.Fill = new SolidColorBrush {
                        Color = PointHoverColor
                    };
                }
                else
                {
                    sibiling.Target.Opacity = .8;
                }

                sp.Children.Add(new StackPanel
                {
                    Orientation = Orientation.Horizontal,
                    Margin      = new Thickness(10, 0, 10, (sibiling == last ? 5 : 0)),
                    Children    =
                    {
                        new Border
                        {
                            Background = new SolidColorBrush{
                                Color = sibiling.Serie.Color
                            },
                            Height          = 10,
                            Width           = 10,
                            CornerRadius    = new CornerRadius(5),
                            BorderThickness = new Thickness(0)
                        },
                        new TextBlock
                        {
                            Text = PrimaryAxis.LabelFormatter == null
                                ? sibiling.Value.Y.ToString(CultureInfo.InvariantCulture)
                                : PrimaryAxis.LabelFormatter(sibiling.Value.Y),
                            Margin            = new Thickness(5, 0, 5, 0),
                            VerticalAlignment = VerticalAlignment.Center,
                            FontFamily        = new FontFamily("Calibri"),
                            FontSize          = 11,
                            Foreground        = TooltipForegroung ?? Brushes.White
                        }
                    }
                });
            }

            b.Child = sp;
            Canvas.Children.Add(b);

            b.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
            var p = GetToolTipPosition(senderShape, sibilings, b);

            Canvas.SetLeft(b, p.X);
            Canvas.SetTop(b, p.Y);

            CurrentToolTip = b;
        }
Exemple #5
0
        protected virtual void DrawAxis()
        {
            foreach (var l in AxisLabels)
            {
                Canvas.Children.Remove(l);
            }
            foreach (var s in AxisShapes)
            {
                Canvas.Children.Remove(s);
            }

            AxisLabels.Clear();
            AxisShapes.Clear();

            //Calculating labels length
            var yLabel = "";

            if (PrimaryAxis.PrintLabels)
            {
                for (var i = Min.Y; i <= Max.Y; i += S.Y)
                {
                    var iL = PrimaryAxis.LabelFormatter == null
                        ? i.ToString(CultureInfo.InvariantCulture)
                        : PrimaryAxis.LabelFormatter(i);

                    if (yLabel.Length < iL.Length)
                    {
                        yLabel = iL;
                    }
                }
            }

            var longestYLabel = new FormattedText(yLabel, CultureInfo.CurrentUICulture, FlowDirection.LeftToRight, new Typeface(SecondaryAxis.FontFamily, SecondaryAxis.FontStyle, SecondaryAxis.FontWeight, SecondaryAxis.FontStretch), SecondaryAxis.FontSize, Brushes.Black);

            var labels = SecondaryAxis.Labels?.ToArray();
            var fx     = labels == null
                ? (SecondaryAxis.LabelFormatter == null
                    ? Min.X.ToString(CultureInfo.InvariantCulture)
                    : SecondaryAxis.LabelFormatter(Min.X))
                : (labels.Length > Min.X
                    ? labels[(int)Min.X]
                    : "");

            fx = SecondaryAxis.PrintLabels ? fx : "";
            var vx   = Math.Truncate((Max.X - Min.X) / S.X) * S.X;
            var labx = labels == null
                ? (SecondaryAxis.LabelFormatter == null
                    ? vx.ToString(CultureInfo.InvariantCulture)
                    : SecondaryAxis.LabelFormatter(vx))
                : (labels.Length > vx && vx >= 0
                    ? labels[(int)vx]
                    : "");

            labx = SecondaryAxis.PrintLabels ? labx : "";
            var firstXLabel = new FormattedText(fx, CultureInfo.CurrentUICulture, FlowDirection.LeftToRight, new Typeface(PrimaryAxis.FontFamily, PrimaryAxis.FontStyle, PrimaryAxis.FontWeight, PrimaryAxis.FontStretch), PrimaryAxis.FontSize, Brushes.Black);
            var lastXLabel  = new FormattedText(labx, CultureInfo.CurrentUICulture, FlowDirection.LeftToRight, new Typeface(PrimaryAxis.FontFamily, PrimaryAxis.FontStyle, PrimaryAxis.FontWeight, PrimaryAxis.FontStretch), PrimaryAxis.FontSize, Brushes.Black);

            Canvas.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));

            PlotArea.X = 5 + (longestYLabel.Width > firstXLabel.Width * .5 ? longestYLabel.Width : firstXLabel.Width * .5) + 5;
            var distanceToEnd      = ToPlotArea(Max.X - vx, AxisTags.X) - PlotArea.X;
            var lastXLabelOverFlow = distanceToEnd > lastXLabel.Width * .5
                ? (lastXLabel.Width * .5 - distanceToEnd > 0
                    ? lastXLabel.Width * .5 - distanceToEnd
                    : 0)
                : lastXLabel.Width * .5;
            var w = Canvas.DesiredSize.Width - PlotArea.X - lastXLabelOverFlow - 5;

            PlotArea.Width = w > 0 ? w : 10;
            PlotArea.Y     = longestYLabel.Height * .5 + 5;
            var h = Canvas.DesiredSize.Height - PlotArea.Y - firstXLabel.Height - 10;

            PlotArea.Height = h > 0 ? h : 10;

            //drawing primary axis
            var ly = PrimaryAxis.Separator.Enabled || PrimaryAxis.PrintLabels
                ? Max.Y
                : Min.Y - 1;

            for (var i = Min.Y; i <= ly; i += S.Y)
            {
                var y = ToPlotArea(i, AxisTags.Y);
                if (PrimaryAxis.Separator.Enabled)
                {
                    var l = new Line
                    {
                        Stroke = new SolidColorBrush {
                            Color = PrimaryAxis.Separator.Color
                        },
                        StrokeThickness = PrimaryAxis.Separator.Thickness,
                        X1 = ToPlotArea(Min.X, AxisTags.X),
                        Y1 = y,
                        X2 = ToPlotArea(Max.X, AxisTags.X),
                        Y2 = y
                    };
                    Canvas.Children.Add(l);
                    AxisShapes.Add(l);
                }

                if (PrimaryAxis.PrintLabels)
                {
                    var t = PrimaryAxis.LabelFormatter == null
                        ? i.ToString(CultureInfo.InvariantCulture)
                        : PrimaryAxis.LabelFormatter(i);

                    var label = new TextBlock
                    {
                        FontFamily  = PrimaryAxis.FontFamily,
                        FontSize    = PrimaryAxis.FontSize,
                        FontStretch = PrimaryAxis.FontStretch,
                        FontStyle   = PrimaryAxis.FontStyle,
                        FontWeight  = PrimaryAxis.FontWeight,
                        Foreground  = new SolidColorBrush {
                            Color = PrimaryAxis.TextColor
                        },
                        Text = t
                    };
                    var fl = new FormattedText(t, CultureInfo.CurrentUICulture, FlowDirection.LeftToRight,
                                               new Typeface(PrimaryAxis.FontFamily, PrimaryAxis.FontStyle, PrimaryAxis.FontWeight,
                                                            PrimaryAxis.FontStretch), PrimaryAxis.FontSize, Brushes.Black);
                    Canvas.Children.Add(label);
                    AxisLabels.Add(label);
                    Canvas.SetLeft(label, (5 + longestYLabel.Width) - fl.Width);
                    Canvas.SetTop(label, ToPlotArea(i, AxisTags.Y) - longestYLabel.Height * .5);
                }
            }

            //drawing secondary axis
            var lx = SecondaryAxis.Separator.Enabled || SecondaryAxis.PrintLabels
                ? Max.X
                : Min.X - 1;

            for (var i = Min.X; i <= lx; i += S.X)
            {
                var x = ToPlotArea(i, AxisTags.X);
                if (SecondaryAxis.Separator.Enabled)
                {
                    var l = new Line
                    {
                        Stroke = new SolidColorBrush {
                            Color = SecondaryAxis.Separator.Color
                        },
                        StrokeThickness = SecondaryAxis.Separator.Thickness,
                        X1 = x,
                        Y1 = ToPlotArea(Max.Y, AxisTags.Y),
                        X2 = x,
                        Y2 = ToPlotArea(Min.Y, AxisTags.Y)
                    };
                    Canvas.Children.Add(l);
                    AxisShapes.Add(l);
                }

                if (SecondaryAxis.PrintLabels)
                {
                    var t = labels == null
                        ? (SecondaryAxis.LabelFormatter == null
                            ? i.ToString(CultureInfo.InvariantCulture)
                            : SecondaryAxis.LabelFormatter(i))
                        : (labels.Length > i
                            ? labels[(int)i]
                            : "");
                    var label = new TextBlock
                    {
                        FontFamily  = SecondaryAxis.FontFamily,
                        FontSize    = SecondaryAxis.FontSize,
                        FontStretch = SecondaryAxis.FontStretch,
                        FontStyle   = SecondaryAxis.FontStyle,
                        FontWeight  = SecondaryAxis.FontWeight,
                        Foreground  = new SolidColorBrush {
                            Color = SecondaryAxis.TextColor
                        },
                        Text = t
                    };
                    var fl = new FormattedText(t, CultureInfo.CurrentUICulture, FlowDirection.LeftToRight,
                                               new Typeface(SecondaryAxis.FontFamily, SecondaryAxis.FontStyle, SecondaryAxis.FontWeight,
                                                            SecondaryAxis.FontStretch), SecondaryAxis.FontSize, Brushes.Black);
                    Canvas.Children.Add(label);
                    AxisLabels.Add(label);
                    Canvas.SetLeft(label, ToPlotArea(i, AxisTags.X) - fl.Width * .5 + LabelOffset);
                    Canvas.SetTop(label, PlotArea.Y + PlotArea.Height + 5);
                }
            }

            //drawing ceros.
            if (Max.Y >= 0 && Min.Y <= 0 && PrimaryAxis.Enabled)
            {
                var l = new Line
                {
                    Stroke = new SolidColorBrush {
                        Color = PrimaryAxis.Color
                    },
                    StrokeThickness = PrimaryAxis.Thickness,
                    X1 = ToPlotArea(Min.X, AxisTags.X),
                    Y1 = ToPlotArea(0, AxisTags.Y),
                    X2 = ToPlotArea(Max.X, AxisTags.X),
                    Y2 = ToPlotArea(0, AxisTags.Y)
                };
                Canvas.Children.Add(l);
                AxisShapes.Add(l);
            }

            if (Max.X >= 0 && Min.X <= 0 && SecondaryAxis.Enabled)
            {
                var l = new Line
                {
                    Stroke = new SolidColorBrush {
                        Color = SecondaryAxis.Color
                    },
                    StrokeThickness = SecondaryAxis.Thickness,
                    X1 = ToPlotArea(0, AxisTags.X),
                    Y1 = ToPlotArea(Min.Y, AxisTags.Y),
                    X2 = ToPlotArea(0, AxisTags.X),
                    Y2 = ToPlotArea(Max.Y, AxisTags.Y)
                };
                Canvas.Children.Add(l);
                AxisShapes.Add(l);
            }
        }
Exemple #6
0
        public override void OnDataMouseEnter(object sender, MouseEventArgs e)
        {
            var b = new Border
            {
                BorderThickness = TooltipBorderThickness ?? new Thickness(0),
                Background      = TooltipBackground ?? new SolidColorBrush {
                    Color = Color.FromRgb(30, 30, 30), Opacity = .8
                },
                CornerRadius = TooltipCornerRadius ?? new CornerRadius(1),
                BorderBrush  = TooltipBorderBrush ?? Brushes.Transparent
            };
            var sp = new StackPanel
            {
                Orientation = Orientation.Vertical
            };

            var senderShape = HoverableShapes.FirstOrDefault(s => Equals(s.Shape, sender));

            if (senderShape == null)
            {
                return;
            }

            senderShape.Target.Stroke = new SolidColorBrush {
                Color = senderShape.Serie.Color
            };
            senderShape.Target.Fill = new SolidColorBrush {
                Color = PointHoverColor
            };

            sp.Children.Add(new TextBlock
            {
                Text = "X:" +
                       (PrimaryAxis.LabelFormatter == null
                           ? senderShape.Value.X.ToString(CultureInfo.InvariantCulture)
                           : PrimaryAxis.LabelFormatter(senderShape.Value.X)) +
                       " Y: " +
                       (SecondaryAxis.LabelFormatter == null
                           ? senderShape.Value.Y.ToString(CultureInfo.InvariantCulture)
                           : SecondaryAxis.LabelFormatter(senderShape.Value.Y)),
                Margin            = new Thickness(5),
                VerticalAlignment = VerticalAlignment.Center,
                FontFamily        = new FontFamily("Calibri"),
                FontSize          = 11,
                Foreground        = TooltipForegroung ?? Brushes.White
            });

            b.Child = sp;
            Canvas.Children.Add(b);

            b.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
            var x = senderShape.Value.X > (Min.X + Max.X) / 2
                ? ToPlotArea(senderShape.Value.X, AxisTags.X) - 10 - b.DesiredSize.Width
                : ToPlotArea(senderShape.Value.X, AxisTags.X) + 10;
            var y = senderShape.Value.Y > (Min.Y + Max.Y) / 2
                ? ToPlotArea(senderShape.Value.Y, AxisTags.Y) + 10
                : ToPlotArea(senderShape.Value.Y, AxisTags.Y) - 10 - b.DesiredSize.Height;

            Canvas.SetLeft(b, x);
            Canvas.SetTop(b, y);
            Panel.SetZIndex(b, int.MaxValue - 1);
            CurrentToolTip = b;
        }