zhaoweikai / flot

Automatically exported from code.google.com/p/flot
MIT License
0 stars 0 forks source link

allow direct access to 'eventHolder' object for custom events #738

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
feature request:
allow direct, arbitrary access to the 'eventHolder' canvas object

currently, it is a somewhat clumsy task to try to get the 'eventHolder' object:
1) hack into the flot source code & manually expose it:
plot.eventHolder=eventHolder;

2) use the 'bindEvents' hook to 'grab&save' a reference to the object:
var eHolder=null;
var pltOpts={};
...
pltOpts.hooks={bindEvents:[function(p,e){eHolder=e;}]};
...
$.plot(obj,data,pltOpts);
...
//do stuff with eHolder, since it should now be defined
//reason this might be necessary is for 'delayed/postponed event 
binding&unbinding'
//i.e., cases where you dont want or cant define event handlers using the 
'bindEvents' hooks

3) manually try to 'select' the eventHolder object (which is ugly & might be 
unreliable?)
var eventHolder=$("#plot_div canvas.overlay");

solution: 
add a simple 'getter' function that returns the internal 'eventHolder' canvas 
object; 
For event-binding safety, I guess you could do a simple internal test to see 
'bindEvents' has already been executed, and return 'false' if not; otherwise, 
return the canvas obj. But realistically, I dont think this would be a problem. 
thoughts/feedback?

var eventsDone_=false;

function bindEvents(){
...
    executeHooks(hooks.bindEvents,[plot.eventHolder]);
    eventsDone_=true;
}
plot.getEventHolder=function(){
    return (eventsDone_)?eventHolder:false;
} 

Original issue reported on code.google.com by changos...@gmail.com on 14 Aug 2012 at 7:07