private void DataMouseDown(object sender, MouseEventArgs e) { var result = ActualSeries.SelectMany(x => x.ActualValues.GetPoints(x)) .FirstOrDefault(x => { var pointView = x.View as PointView; return(pointView != null && Equals(pointView.HoverShape, sender)); }); OnDataClick(sender, result); }
private void DataMouseLeave(object sender, EventArgs e) { TooltipTimeoutTimer.Stop(); TooltipTimeoutTimer.Start(); var source = ActualSeries.SelectMany(x => x.ActualValues.GetPoints(x)); var senderPoint = source.FirstOrDefault(x => x.View != null && Equals(((PointView)x.View).HoverShape, sender)); if (senderPoint == null) { return; } if (Hoverable) { senderPoint.View.OnHoverLeave(senderPoint); } }
private void DataMouseEnter(object sender, EventArgs e) { TooltipTimeoutTimer.Stop(); var source = ActualSeries.SelectMany(x => x.ActualValues.GetPoints(x)).ToList(); var senderPoint = source.FirstOrDefault(x => x.View != null && Equals(((PointView)x.View).HoverShape, sender)); if (senderPoint == null) { return; } if (Hoverable) { senderPoint.View.OnHover(senderPoint); } if (DataTooltip != null) { if (DataTooltip.Parent == null) { Panel.SetZIndex(DataTooltip, int.MaxValue); AddToView(DataTooltip); Canvas.SetTop(DataTooltip, 0d); Canvas.SetLeft(DataTooltip, 0d); } ActiveTooltip = DataTooltip; var lcTooltip = DataTooltip as IChartTooltip; if (lcTooltip == null) { throw new LiveChartsException("The current tooltip is not valid, ensure it implements IChartsTooltip"); } if (lcTooltip.SelectionMode == null) { lcTooltip.SelectionMode = senderPoint.SeriesView.Model.PreferredSelectionMode; } var coreModel = ChartFunctions.GetTooltipData(senderPoint, Model, lcTooltip.SelectionMode.Value); lcTooltip.Data = new TooltipData { XFormatter = coreModel.XFormatter, YFormatter = coreModel.YFormatter, SharedValue = coreModel.Shares, SelectionMode = lcTooltip.SelectionMode ?? TooltipSelectionMode.OnlySender, Points = coreModel.Points.Select(x => new DataPointViewModel { Series = new SeriesViewModel { PointGeometry = ((Series)x.SeriesView).PointGeometry ?? Geometry.Parse("M 0,0.5 h 1,0.5 Z"), Fill = ((Series)x.SeriesView) is IFondeable ? ((IFondeable)x.SeriesView).PointForeround : ((Series)x.SeriesView).Fill, Stroke = ((Series)x.SeriesView).Stroke, StrokeThickness = ((Series)x.SeriesView).StrokeThickness, Title = ((Series)x.SeriesView).Title, }, ChartPoint = x }).ToList() }; DataTooltip.Visibility = Visibility.Visible; DataTooltip.UpdateLayout(); var location = GetTooltipPosition(senderPoint); location = new Point(Canvas.GetLeft(DrawMargin) + location.X, Canvas.GetTop(DrawMargin) + location.Y); if (lcTooltip.IsWrapped) { var container = (FrameworkElement)DataTooltip.Parent; var positionTransform = TransformToAncestor(container); var pos = positionTransform.Transform(new Point(0, 0)); location.X += pos.X; location.Y += pos.Y; if (location.X < 0) { location.X = 0; } if (location.X + DataTooltip.ActualWidth > container.ActualWidth) { var dif = container.ActualWidth - (location.X + DataTooltip.ActualWidth); dif *= container.ActualWidth / 2 > senderPoint.ChartLocation.X ? 1 : -1; location.X += dif; } } if (DisableAnimations) { Canvas.SetLeft(DataTooltip, location.X); Canvas.SetTop(DataTooltip, location.Y); } else { DataTooltip.BeginAnimation(Canvas.LeftProperty, new DoubleAnimation(location.X, TimeSpan.FromMilliseconds(200))); DataTooltip.BeginAnimation(Canvas.TopProperty, new DoubleAnimation(location.Y, TimeSpan.FromMilliseconds(200))); } } }
private void DataMouseEnter(object sender, PointerRoutedEventArgs e) { TooltipTimeoutTimer.Stop(); var source = ActualSeries.SelectMany(x => x.ActualValues.GetPoints(x)).ToList(); var senderPoint = source.FirstOrDefault(x => x.View != null && Equals(((PointView)x.View).HoverShape, sender)); if (senderPoint == null) { return; } if (Hoverable) { senderPoint.View.OnHover(senderPoint); } if (DataTooltip != null) { if (DataTooltip.Parent == null) { Canvas.SetZIndex(DataTooltip, short.MaxValue); AddToView(DataTooltip); Canvas.SetTop(DataTooltip, 0d); Canvas.SetLeft(DataTooltip, 0d); } if (ActiveTooltip != null) { ActiveTooltip.Visibility = Visibility.Collapsed; } ActiveTooltip = DataTooltip; var lcTooltip = DataTooltip as IChartTooltip; if (lcTooltip == null) { throw new LiveChartsException( "The current tooltip is not valid, ensure it implements IChartsTooltip"); } if (lcTooltip.SelectionMode == TooltipSelectionMode.Auto) { lcTooltip.SelectionMode = senderPoint.SeriesView.Model.PreferredSelectionMode; } var coreModel = ChartFunctions.GetTooltipData(senderPoint, Model, lcTooltip.SelectionMode); lcTooltip.Data = new TooltipData { XFormatter = coreModel.XFormatter, YFormatter = coreModel.YFormatter, SharedValue = coreModel.Shares, SelectionMode = lcTooltip.SelectionMode == TooltipSelectionMode.Auto ? TooltipSelectionMode.OnlySender : lcTooltip.SelectionMode, Points = coreModel.Points.Select(x => new DataPointViewModel { Series = new SeriesViewModel { PointGeometry = ((Series)x.SeriesView).PointGeometry == DefaultGeometries.None ? new PointGeometry("M 0, 0.5 h 1, 0.5 Z").Parse() : ((Series)x.SeriesView).PointGeometry.Parse(), Fill = ((Series)x.SeriesView) is IFondeable && !(x.SeriesView is IVerticalStackedAreaSeriesView || x.SeriesView is IStackedAreaSeriesView) ? ((IFondeable)x.SeriesView).PointForeround : ((Series)x.SeriesView).Fill, Stroke = ((Series)x.SeriesView).Stroke, StrokeThickness = ((Series)x.SeriesView).StrokeThickness, Title = ((Series)x.SeriesView).Title, }, ChartPoint = x }).ToList() }; DataTooltip.Visibility = Visibility.Visible; DataTooltip.UpdateLayout(); var location = GetTooltipPosition(senderPoint); location = new Point(Canvas.GetLeft(DrawMargin) + location.X, Canvas.GetTop(DrawMargin) + location.Y); if (lcTooltip.IsWrapped) { var container = (FrameworkElement)DataTooltip.Parent; var positionTransform = TransformToVisual(container); var pos = positionTransform.TransformPoint(new Point(0, 0)); location.X += pos.X; location.Y += pos.Y; if (location.X < 0) { location.X = 0; } if (location.X + DataTooltip.ActualWidth > container.ActualWidth) { var dif = container.ActualWidth - (location.X + DataTooltip.ActualWidth); dif *= container.ActualWidth / 2 > senderPoint.ChartLocation.X ? 1 : -1; location.X += dif; } } if (DisableAnimations) { Canvas.SetLeft(DataTooltip, location.X); Canvas.SetTop(DataTooltip, location.Y); } else { var storyBoard = new Storyboard(); var xAnimation = new DoubleAnimation() { To = location.X, Duration = TimeSpan.FromMilliseconds(200) }; var yAnimation = new DoubleAnimation() { To = location.Y, Duration = TimeSpan.FromMilliseconds(200) }; storyBoard.Children.Add(xAnimation); storyBoard.Children.Add(yAnimation); Storyboard.SetTarget(xAnimation, DataTooltip); Storyboard.SetTargetProperty(xAnimation, "(Canvas.Left)"); Storyboard.SetTarget(yAnimation, DataTooltip); Storyboard.SetTargetProperty(yAnimation, "(Canvas.Top)"); storyBoard.Begin(); } } }