BLT-newbie - barchart: How to display value under mouse cursor 
Author Message
 BLT-newbie - barchart: How to display value under mouse cursor

I'm displaying a histogram (vectors X,Y) with BLT's barchart.

# X,Y are some data lists

        barchart .bar -plotbackground white
        .bar element create e1 -xdata $X -ydata $Y

Does somebody has an idea how to display the corresponding
data (x,y) values when the mouse cursor is moved over the barchart ?
Something like

        bind $bar <Motion> {show %x %y}
        proc show {x y} {
                ... ??? ...
                puts stderr "show($x,$y) = "
        }

Any hint is welcome.
Thanks,
Rolf.

---------------------------------------------------------------
Rolf Schroedter
German Aerospace Center
Institute of Space Sensor Technology and Planetary Exploration
D-12489 Berlin, Rutherfordstrasse 2
Tel/Fax:  (+49) (30) 67055-416/384



Sun, 05 Dec 2004 21:45:07 GMT  
 BLT-newbie - barchart: How to display value under mouse cursor

Quote:

> I'm displaying a histogram (vectors X,Y) with BLT's barchart.
> # X,Y are some data lists
>        barchart .bar -plotbackground white
>        .bar element create e1 -xdata $X -ydata $Y
> Does somebody has an idea how to display the corresponding
> data (x,y) values when the mouse cursor is moved over the barchart ?
> Something like
>        bind $bar <Motion> {show %x %y}
>        proc show {x y} {
>                ... ??? ...
>                puts stderr "show($x,$y) = "
>        }

I'm guessing that what you want is the X-Y coordinates of a bar
segment as the mouse passes over it.

        .bar element bind all <Enter> {
            .bar element closest %x %y info
            puts stderr "$info(x) $info(y)"
        }

Note that this is using the "element bind" operation, not Tk's bind
command.  [The "element bind" operation works a lot like the canvas'
"bind" operation of canvas items.]

Whenever the pointer enters a bar segment, you can check for the
closest element.  There must be one, since you've entered an element.
The X,Y coordinates are returned through the array variable than you
provided as an argument (in this example, it's called "info").

If you want to X-Y graph coordinates of the mouse pointer, where ever
the mouse moves, track Motion events on the barchart.

        bind .bar <Motion> {
            if { [.bar inside %x %y] } {
                set x [.bar axis invtransform x %x]
                set y [.bar axis invtransform y %y]
                puts stderr "$x $y"
            }
        }

Verify that the pointer is inside the plotting area with the "inside"
operation and then transform the mouse screen coordinates to graph
coordinates.

If you want the X-Y coordinates of the closest bar segment from the
mouse pointer, where ever the mouse is

        bind .bar <Motion> {
            if { [.bar element closest %x %y info] } {
                puts stderr "$info(x) $info(y)"
            }
        }

use the "element closest" operation.  It returns 1 if there is an
element within the threshold distance (see -halo option) and 0
otherwise.

--gah



Mon, 06 Dec 2004 06:45:49 GMT  
 BLT-newbie - barchart: How to display value under mouse cursor
Thank a lot George,
that's what I'm was looking for.

Regards, Rolf.

Quote:

> I'm guessing that what you want is the X-Y coordinates of a bar
> segment as the mouse passes over it.

>         .bar element bind all <Enter> {
>             .bar element closest %x %y info
>             puts stderr "$info(x) $info(y)"
>         }

> Note that this is using the "element bind" operation, not Tk's bind
> command.  [The "element bind" operation works a lot like the canvas'
> "bind" operation of canvas items.]
> ...

---------------------------------------------------------------
Rolf Schroedter
German Aerospace Center
Institute of Space Sensor Technology and Planetary Exploration
D-12489 Berlin, Rutherfordstrasse 2
Tel/Fax:  (+49) (30) 67055-416/384



Mon, 06 Dec 2004 22:10:37 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Mouse Cursor Co-ordinate Display For a Beginner

2. display the data values at cursor position

3. Move mouse-cursor and send mouse-click

4. BLT barchart -title

5. BLT barchart labels

6. Using BLT barchart effectively

7. BLT barchart, using logarithmic scale

8. BLT barchart element bind command does not work?

9. BLT barchart update speed???

10. BLT 2.1 barchart patch available

11. BLT barchart tags

12. xdata for BLT barchart, adding a grid

 

 
Powered by phpBB® Forum Software