private void OnHighlightIDChanged() { HighlightIDChanged?.Invoke(this, null); CanvasPlot.Children.Clear(); if (Points == null || HighlightID < 0 || HighlightID >= Points.Count || double.IsNaN(Points[HighlightID].Value)) { return; } Ellipse PointOutline = new Ellipse { Width = PointRadius * 2 + 4, Height = PointRadius * 2 + 4, Stroke = Brushes.Gray, StrokeThickness = 3, IsHitTestVisible = false }; CanvasPlot.Children.Add(PointOutline); Canvas.SetLeft(PointOutline, PointCenters[HighlightID].X - PointRadius - 2); Canvas.SetTop(PointOutline, PointCenters[HighlightID].Y - PointRadius - 2); if (Zoom > 1 && !IsMouseOver) { double ScrollFraction = PointCenters[HighlightID].X / ImagePlot.ActualWidth; ScrollViewerPlot.ScrollToHorizontalOffset(ScrollFraction * ScrollViewerPlot.ScrollableWidth); } }
private void ImagePlot_OnMouseMove(object sender, MouseEventArgs e) { if (Zoom > 1) { System.Windows.Point ViewportPoint = e.GetPosition(ScrollViewerPlot); double ScrollFraction = ViewportPoint.X / ScrollViewerPlot.ActualWidth; ScrollViewerPlot.ScrollToHorizontalOffset(ScrollFraction * ScrollViewerPlot.ScrollableWidth); } if (Points == null || Points.Count == 0 || PointCenters == null || PointCenters.Length == 0) { HighlightID = -1; return; } System.Windows.Point MousePoint = e.GetPosition(ImagePlot); int ClosestID = GetClosestPoint(MousePoint); List <int> Neighbors = Helper.ArrayOfSequence(Math.Max(0, ClosestID - 5), Math.Min(PointCenters.Length, ClosestID + 5), 1).ToList(); Neighbors.Sort((a, b) => (PointCenters[a] - MousePoint).Length.CompareTo((PointCenters[b] - MousePoint).Length)); ClosestID = Neighbors.First(); System.Windows.Point Closest = PointCenters[ClosestID]; double Dist = (Closest - MousePoint).Length; if (Dist > PointRadius * Zoom * 2) { if (ImagePlot.ToolTip != null) { ((ToolTip)ImagePlot.ToolTip).IsOpen = false; } //ImagePlot.ToolTip = null; HighlightID = -1; return; } HighlightID = ClosestID; //if (ImagePlot.ToolTip == null || ImagePlot.ToolTip.GetType() != typeof(ToolTip)) // ImagePlot.ToolTip = new ToolTip(); ((ToolTip)ImagePlot.ToolTip).Content = (ClosestID + 1) + ": " + (Points[ClosestID].Context != null ? Points[ClosestID].Context.RootName + ", " : "") + Points[ClosestID].Value.ToString("F3", CultureInfo.InvariantCulture); ((ToolTip)ImagePlot.ToolTip).IsOpen = false; ((ToolTip)ImagePlot.ToolTip).IsOpen = true; }