示例#1
0
        private void wpfPlot1_MouseMove(object sender, MouseEventArgs e)
        {
            // determine point nearest the cursor
            (double mouseCoordX, double mouseCoordY) = wpfPlot1.GetMouseCoordinates();
            double xyRatio = wpfPlot1.Plot.XAxis.Dims.PxPerUnit / wpfPlot1.Plot.YAxis.Dims.PxPerUnit;

            (double pointX, double pointY, int pointIndex) = MyScatterPlot.GetPointNearest(mouseCoordX, mouseCoordY, xyRatio);

            // place the highlight over the point of interest
            HighlightedPoint.X         = pointX;
            HighlightedPoint.Y         = pointY;
            HighlightedPoint.IsVisible = true;

            // render if the highlighted point chnaged
            if (LastHighlightedIndex != pointIndex)
            {
                LastHighlightedIndex = pointIndex;
                wpfPlot1.Refresh();
            }

            // update the GUI to describe the highlighted point
            double mouseX = e.GetPosition(this).X;
            double mouseY = e.GetPosition(this).Y;

            label1.Content = $"Closest point to ({mouseX:N2}, {mouseY:N2}) " +
                             $"is index {pointIndex} ({pointX:N2}, {pointY:N2})";
        }
示例#2
0
        private void MouseMove(object sender, PointerEventArgs e)
        {
            // determine point nearest the cursor
            (double mouseCoordX, double mouseCoordY) = avaPlot1.GetMouseCoordinates();
            double xyRatio = avaPlot1.Plot.XAxis.Dims.PxPerUnit / avaPlot1.Plot.YAxis.Dims.PxPerUnit;

            (double pointX, double pointY, int pointIndex) = MyScatterPlot.GetPointNearest(mouseCoordX, mouseCoordY, xyRatio);

            // place the highlight over the point of interest
            HighlightedPoint.Xs[0]     = pointX;
            HighlightedPoint.Ys[0]     = pointY;
            HighlightedPoint.IsVisible = true;

            // render if the highlighted point chnaged
            if (LastHighlightedIndex != pointIndex)
            {
                LastHighlightedIndex = pointIndex;
                avaPlot1.Render();
            }

            // update the GUI to describe the highlighted point
            (double mouseX, double mouseY)       = avaPlot1.GetMouseCoordinates();
            this.Find <TextBlock>("label1").Text = $"Closest point to ({mouseX:N0}, {mouseY:N0}) " +
                                                   $"is index {pointIndex} ({pointX:N2}, {pointY:N2})";
        }