Skip to content

BlazorPlot: update events to use the new user input processor #4480

@Saklut

Description

@Saklut

Question: In ScottPlot 5.28, I was able to replicate the WinForm "MouseTracker" demo in Blazor WebAssembly, but now in ScottPlot 5.44, I can't figure out how to do that.
I don't know if I must use UserInputProcessor or how to use it.
On ScottPlot 5.28 there where the BlazorPlotBase.HandlerPointerMoved that is not on ScottPlot 5.44
Same thing with HandlerPointerPressed and HandlerPointerReleased used on the Demos DraggableAxisLines and DraggableDataPoint

ScottPlot Version: ScottPlot 5.44

Code Sample: This code is a Page on ScottPlot 5.28 that replicates the WinForm demo MouseTracker:

@page "/mousetracker"
@using ScottPlot
@using ScottPlot.Blazor
@rendermode InteractiveWebAssembly
@implements IDisposable

<h3>Mouse Tracker</h3>
<p>Demonstrates how to interact with the mouse and convert between screen units (pixels) and axis units (coordinates)</p>
<BlazorPlot @ref=blazorPlot Style="width: 400px; height: 300px;" />
@position
@code {
    BlazorPlot blazorPlot { get; set; } = new();
    ScottPlot.Plottables.Crosshair CH;
    string position = "";

   protected override void OnAfterRender(bool firstRender)
    {
        if (firstRender)
        {
            CH = blazorPlot.Plot.Add.Crosshair(0, 0);
            CH.TextColor = Colors.White;
            CH.TextBackgroundColor = CH.HorizontalLine.Color;
            CH.LineWidth = 1;
            blazorPlot.Plot.Add.Signal(Generate.Sin());
            blazorPlot.HandlerPointerMoved += OnMouseMoved;
        }
    }

    private void OnMouseMoved(object? sender, PointerEventArgs args)
    {
        Pixel mousePixel = new(args.OffsetX, args.OffsetY);
        Coordinates mouseCoordinates = blazorPlot.Plot.GetCoordinates(mousePixel);
        position = $"X={mouseCoordinates.X:N3}, Y={mouseCoordinates.Y:N3}";
        CH.Position = mouseCoordinates;
        CH.VerticalLine.Text = $"{mouseCoordinates.X:N3}";
        CH.HorizontalLine.Text = $"{mouseCoordinates.Y:N3}";
        blazorPlot.Refresh();
        StateHasChanged();
    }

    public void Dispose()
    {
        blazorPlot.HandlerPointerMoved -= OnMouseMoved;
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions