| Re: Button_events and data [message #11179 is a reply to message #10980] |
Wed, 25 February 1998 00:00  |
David L. Windt
Messages: 9 Registered: June 1997
|
Junior Member |
|
|
<HTML>
<P>Bernard Puc wrote:
<BLOCKQUOTE TYPE=CITE>Hello,
<P> I'm looking for pointers
on how to do the following: I have a line
<BR>plot in a draw widget. I want to click the pointer on the plot
and have
<BR>a vertical line drawn at the nearest datapoint to the mouseclick.
<BR> widget_draw returns the
cursor location in device coordinates and I
<BR>need to translate that into dataspace coordinates.
<BR> Going one step further,
ideally, I'd like to have a vertical line
<BR>follow the cursor around the draw widget at all times, jumping from
<BR>datapoint to datapoint. I suspect someone has already written
such a
<BR>thing...
<P>Any help appreciated.
<P>-Bernard Puc
<BR>puc@gsfc.nasa.gov</BLOCKQUOTE>
Assuming you're plotting X vs Y, and have captured a draw widget
event
<BR>called EVENT...
<P>You can use CONVERT_COORD to first convert the draw widget event to
<BR>data coordinates:
<P>CC=CONVERT_COORD(EVENT.X,EVENT.Y,/DEVICE,/TO_DATA)
<P>You might then try my VALUE_TO_INDEX function to get the x data index
<BR>corresponding to the x value closest to the widget event (i.e., the
<BR>mouse click):
<P>X_INDEX=VALUE_TO_INDEX(X,CC(0))
<P>and then plot the vertical line using PLOTS:
<P>PLOTS,[0,0]+X(X_INDEX),!Y.CRANGE
<P>(Or if you like, this can all be done in one line, as in:
<BR>PLOTS,[0,0]+ $
<BR> X(VALUE_TO_INDEX(X,(CONVERT_COORD(EVENT.X,EVENT.Y,
$
<BR>
/DEVICE,/TO_DATA))(0))), $
<BR> !Y.CRANGE
<BR>)
<P>To have a vertical line that follows the mouse around will require
<BR>a bit more work, but it could make use of the same methods as above.
<P>VALUE_TO_INDEX, as well as all my other thrilling idl programs can be
<BR>found at <A HREF="http://www.bell-labs.com/user/windt/idl">www.bell-labs.com/user/windt/idl</A>.
In particular, you might
<BR>also be interested in TRACK_PLOT - it doesn't draw lines, but it
<BR>provides live X and Y values in a text widget as you move the mouse
<BR>over an x,y plot. It might make a reasonable starting point for
<BR>doing what you want to do with vertical lines.
<P>David Windt
<BR>windt@bell-labs.com
<BR> </HTML>
|
|
|
|