Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Tk::Chart adding data to displayed graph

by cavac (Curate)
on Oct 23, 2018 at 11:30 UTC ( #1224546=note: print w/replies, xml ) Need Help??


in reply to Tk::Chart adding data to displayed graph

You have multiple options here. For example, you could just add a cyclic callback event like this:

my $teatime = $mw->repeat(50, \&updateGraphs); ... sub updateGraphs { ... return; }

Instead of calling MainLoop, you could look into using something like DoOneEvent(), but i couldn't find it in my own codebase, so i can't be sure it works.

perl -e 'use MIME::Base64; print decode_base64("4pmsIE5ldmVyIGdvbm5hIGdpdmUgeW91IHVwCiAgTmV2ZXIgZ29ubmEgbGV0IHlvdSBkb3duLi4uIOKZqwo=");'

Replies are listed 'Best First'.
Re^2: Tk::Chart adding data to displayed graph
by tobbes (Acolyte) on Oct 23, 2018 at 11:34 UTC
    Ah thank you. But I also need to be able to click on the chart and have it react to events.

      You can still bind normal event handlers as well. Just update whatever variables you need, then call the updateGraph() function manually.

      Something like:

      my $viewbutton = $mw->Button(-text=>"Change view", -command=>\&changeV +iew); ... sub changeView { $viewmode++; if($viewmode > 3) { $viewmode = 0; } updateGraph(); return; }

      Tk::Chart is an extension of Tk::Canvas, which has support for Mouse interactions. You probably want to use $canvas->bind() or something similar to get mouse interactions with the canvas as event callbacks. To quote the documentation:

      The only events for which bindings may be specified are those related +to the mouse and keyboard (such as Enter, Leave, ButtonPress, Motion, and KeyPress) or virtual events. The handling of +events in canvases uses the current item defined in "ITEM IDS AND TAGS" above. Enter and Leave events trigger for an i +tem when it becomes the current item or ceases to be the current item; note that these events are different than Enter +and Leave events for windows. Mouse-related events are directed to the current item, if any. Keyboard-related even +ts are directed to the focus item, if any (see the focus method below for more on this). If a virtual event is used i +n a binding, that binding can trigger only if the virtual event is defined by an underlying mouse-related or keyboar +d-related event.

      Frankly, i would have to spend a few hours of reading and testing on how exactly this would all work related to your graphs (which i leave as an excersise for the reader), but it sounds promising for what you want it to do.

      perl -e 'use MIME::Base64; print decode_base64("4pmsIE5ldmVyIGdvbm5hIGdpdmUgeW91IHVwCiAgTmV2ZXIgZ29ubmEgbGV0IHlvdSBkb3duLi4uIOKZqwo=");'

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1224546]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (6)
As of 2021-03-04 18:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favorite kind of desktop background is:











    Results (107 votes). Check out past polls.

    Notices?