5-to-9
5-to-9

Reputation: 649

Dynamic-Data-Display / Getting x-coordinate of user input

My program is basically about analyzing videos. A major part is to plot a diagram showing (f.e.) brightness per frame on y-axis and every frame number on x-axis. Because the program is written in C# and uses WPF, D³ was the way to go for plotting.

Now the user might see a peak signal in the diagram and wants to look on that single frame to understand why it's so bright (it might be just natural, or an encoding-artifact).

There comes my question: The most intuitive way for the user to click on the diagram where the peak is, which jumps the video preview (other GUI element) right to that frame. So I need the x-coordinate (=frame number) of the user click on the diagram.

It is possible to manually analyze the mouse-input event, but that would take much work (because the x-axis is different for each video and the entire diagram can be resized, so absolute coordinates are a no go). But maybe something similar is already implemented by D³. I searched the documentary, but didn't find anything useful. The only piece of information was using a "DraggablePoint", but that's where the trail goes cold. Does someone of you know how to get the x-coordinate without much work?

Upvotes: 2

Views: 2201

Answers (1)

Jason Higgins
Jason Higgins

Reputation: 1526

It sure is possible! The way that I have done it in the past is to add a CursorCoordinateGraph object to my plotters children, and it automatically tracks the mouse position on the graph in relation to the data. You can turn off the visual features of the CursorCoordinateGraph and use it for tracking only. Here's what it would look like:

CursorCoordinateGraph mouseTrack;
plotter.Children.Add(mouseTrack);
mouseTrack.ShowHorizontalLine = false;
mouseTrack.ShowVerticalLine = false;

And your mouse click event would look like this:

private void plotter_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) 
{
    Point mousePos = mouseTrack.Position;
    var transform = plotter.Viewport.Transform;
    Point mousePosInData = mousePos.ScreenToData(transform);
    double xValue = mousePosInData.X;
}

You can then use xValue and manipulate it however you would like to achieve your desired effect.

Upvotes: 3

Related Questions