From 70aa907273dfc66e0da5948bf14086152138fcd6 Mon Sep 17 00:00:00 2001 From: Dan Vanderkam Date: Fri, 10 Sep 2010 22:45:10 -0700 Subject: [PATCH] all required events working --- dygraph-canvas.js | 12 ++++-------- tests/annotation.html | 20 ++++++++++++++++---- 2 files changed, 20 insertions(+), 12 deletions(-) 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) + "
"; } }); - - -
-- 2.7.4