From ab5e5c7548f975820f6b469886d15ff5bc1b8477 Mon Sep 17 00:00:00 2001 From: Dan Vanderkam Date: Fri, 10 Sep 2010 22:36:52 -0700 Subject: [PATCH] event works --- dygraph-canvas.js | 21 +++++++++++++++++++++ tests/annotation.html | 12 +++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/dygraph-canvas.js b/dygraph-canvas.js index 4f5bd6c..66888ee 100644 --- a/dygraph-canvas.js +++ b/dygraph-canvas.js @@ -499,6 +499,17 @@ DygraphCanvasRenderer.prototype._renderAnnotations = function() { "overflow": "hidden", }; + var bindEvt = function(eventName, classEventName, p, self) { + return function(e) { + var a = p.annotation; + if (a.hasOwnProperty(eventName)) { + a[eventName](a, p, self.dygraph_, e); + } else if (self.dygraph_.attr_(classEventName)) { + self.dygraph_.attr_(classEventName)(a, p, self.dygraph_,e ); + } + }; + } + // Get a list of point with annotations. var points = this.layout.annotated_points; for (var i = 0; i < points.length; i++) { @@ -519,6 +530,16 @@ DygraphCanvasRenderer.prototype._renderAnnotations = function() { div.title = p.annotation.text; 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) + ); + this.container.appendChild(div); this.annotations.push(div); } diff --git a/tests/annotation.html b/tests/annotation.html index 100334b..7d61736 100644 --- a/tests/annotation.html +++ b/tests/annotation.html @@ -66,7 +66,10 @@ x: "20061013", shortText: 'X', text: 'Another one', - cssClass: 'annotation' + cssClass: 'annotation', + clickHandler: function() { + document.getElementById("events").innerHTML += "special handler
"; + } } ); g.setAnnotations(annotations); @@ -82,8 +85,15 @@ last_ann = x; g.setAnnotations(annotations); } + + g.updateOptions( { + annotationClickHandler: function(ann, point, dg, event) { + document.getElementById("events").innerHTML += "click: (" + ann.series + ", " + ann.x + ")
"; + } + }); +
-- 2.7.4