I am trying to use a flot in a coffeescript .The returned javascript wraps all the methods in a function call and because of that I am not able to use the .bind event. $(this).bind 'plothover', (event, pos, item) -> is not getting called when my mouse moves
$ ->
$("#flot-placeholder1").text("Amit")
plot = $.plot($("#flot-placeholder1"), dataset, options)
$("#flot-placeholder1").UseTooltip()
$.fn.UseTooltip = ->
alert "UseTooltip"
**$(this).bind 'plothover', (event, pos, item) ->**
alert "UseTooltip"
if item
if (previousLabel isnt item.series.label) or (previousPoint isnt item.dataIndex)
previousPoint = item.dataIndex
previousLabel = item.series.label
$("#tooltip").remove()
x = item.datapoint[0]
y = item.datapoint[1]
color = item.series.color
month = new Date(x).getMonth()
if item.seriesIndex is 0 or item.seriesIndex is 2
showTooltip item.pageX, item.pageY, color, "<strong>" + item.series.label + "</strong><br>" + monthNames[month] + " : <strong>" + y + "</strong>(USD)"
else
showTooltip item.pageX, item.pageY, color, "<strong>" + item.series.label + "</strong><br>" + monthNames[month] + " : <strong>" + y + "</strong>(%)"
else
$("#tooltip").remove()
previousPoint = null
In the
flot/examples/interacting/index.html
I replaced the script withwhere
interact.js
is the compiled version of this coffeescript file:It functions just like the original. With the
grid
set tohoverable
,$(this).bind "plothover", (event, pos, item) ->
works just fine.