From: Dan Vanderkam Date: Sat, 11 Sep 2010 05:45:10 +0000 (-0700) Subject: all required events working X-Git-Tag: v1.0.0~673 X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=70aa907273dfc66e0da5948bf14086152138fcd6;p=dygraphs.git all required events working --- diff --git a/dygraph-canvas.js b/dygraph-canvas.js index 66888ee..acb1266 100644 --- a/dygraph-canvas.js +++ b/dygraph-canvas.js @@ -531,14 +531,10 @@ DygraphCanvasRenderer.prototype._renderAnnotations = function() { div.style.color = this.colors[p.name]; div.style.borderColor = this.colors[p.name]; - var self = this; - Dygraph.addEvent(div, 'click', function(p, self) { return function(e) { - if (p.annotation.hasOwnProperty('clickHandler')) { - p.annotation.clickHandler(p.annotation, p, self.dygraph_, e); - } else if (self.dygraph_.attr_('annotationClickHandler')) { - self.dygraph_.attr_('annotationClickHandler')(p.annotation, p, self.dygraph_, e); - } }; }(p, self) - ); + Dygraph.addEvent(div, 'click', bindEvt('clickHandler', 'annotationClickHandler', p, this)); + Dygraph.addEvent(div, 'mouseover', bindEvt('mouseOverHandler', 'annotationMouseOverHandler', p, this)); + Dygraph.addEvent(div, 'mouseout', bindEvt('mouseOutHandler', 'annotationMouseOutHandler', p, this)); + Dygraph.addEvent(div, 'dblclick', bindEvt('dblClickHandler', 'annotationDblClickHandler', p, this)); this.container.appendChild(div); this.annotations.push(div); diff --git a/tests/annotation.html b/tests/annotation.html index 7d61736..cb7a95d 100644 --- a/tests/annotation.html +++ b/tests/annotation.html @@ -15,6 +15,8 @@ + +
@@ -86,14 +88,24 @@ g.setAnnotations(annotations); } + var eventDiv = document.getElementById("events"); + function nameAnnotation(ann) { + return "(" + ann.series + ", " + ann.x + ")"; + } g.updateOptions( { annotationClickHandler: function(ann, point, dg, event) { - document.getElementById("events").innerHTML += "click: (" + ann.series + ", " + ann.x + ")
"; + eventDiv.innerHTML += "click: " + nameAnnotation(ann) + "
"; + }, + annotationDblClickHandler: function(ann, point, dg, event) { + eventDiv.innerHTML += "dblclick: " + nameAnnotation(ann) + "
"; + }, + annotationMouseOverHandler: function(ann, point, dg, event) { + eventDiv.innerHTML += "mouseenter: " + nameAnnotation(ann) + "
"; + }, + annotationMouseOutHandler: function(ann, point, dg, event) { + eventDiv.innerHTML += "mouseout: " + nameAnnotation(ann) + "
"; } }); - - -