sangltdn / flot

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

Bind "plothover" in a plugin #281

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hello,

I see the examples with the tooltip and i would like make a plugin with
that, but if I do : 

function bindEvents(plot, eventHolder) {
    eventHolder.bind('plothover', function (e) {
      alert('OK')
    });
}

// ...

plot.hooks.bindEvents.push(bindEvents);

It don't works... Sorry if I don't understand how Flot works but when I see
the other plugins it's like what I do... without 'plothover'.

Original issue reported on code.google.com by Pr.Dor...@gmail.com on 19 Dec 2009 at 9:40

GoogleCodeExporter commented 9 years ago
Ah, I think it's because you need to set options.grid.hoverable to true.

The boundaries between plugin and core Flot are still a bit fuzzy at the 
moment. I
don't consider the API finalized.

Original comment by olau%iol...@gtempaccount.com on 20 Jan 2010 at 1:08

GoogleCodeExporter commented 9 years ago
... set to true, else the event doesn't fire (take a look at the Flot code if 
in doubt).

Original comment by olau%iol...@gtempaccount.com on 20 Jan 2010 at 1:09

GoogleCodeExporter commented 9 years ago
It doesn't works with hoverable : the plugin and the html page are in 
attachements ↓ .

Original comment by Pr.Dor...@gmail.com on 20 Jan 2010 at 9:25

Attachments:

GoogleCodeExporter commented 9 years ago
Hi,

It works if you do it as shown below.

plot.hooks.bindEvents.push(function (plot, eventHolder) {
    eventHolder.mousemove(function (event) {
        console.log ("Mouse over [" + event.pageX + ", " + event.pageY + "]");
    });
});

Original comment by nadeeshy...@gmail.com on 9 Mar 2010 at 5:54

GoogleCodeExporter commented 9 years ago
Sorry, coming to think of it, it's perhaps because the eventHolder is where you
should listen for native events (it's the canvas) whereas the plot actually 
fires
events on another element, the placeholder (the initial div). You can get that
element with plot.getPlaceholder(), at least on Flot in SVN.

Sorry again. I have updated API.txt with an extra paragraph:

"Note that custom plot events generated by Flot are not generated on 
eventHolder, but
on the div placeholder supplied as first argument to the plot call. You can get 
that
with plot.getPlaceholder() - that's probably also the one you should use if you 
need
to fire a custom event."

Original comment by olau%iol...@gtempaccount.com on 15 Mar 2010 at 11:15

GoogleCodeExporter commented 9 years ago

Original comment by dnsch...@gmail.com on 1 May 2012 at 10:27