From a4bf424f4d24e460f2c817805b56b5783b1593c7 Mon Sep 17 00:00:00 2001 From: Dan Vanderkam Date: Sun, 30 Jun 2013 23:13:49 -0400 Subject: [PATCH] annotations hide when they go off the chart --- extras/super-annotations.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/extras/super-annotations.js b/extras/super-annotations.js index de0cdfd..efc0aac 100644 --- a/extras/super-annotations.js +++ b/extras/super-annotations.js @@ -219,6 +219,8 @@ annotations.prototype.moveAnnotationToTop = function(a) { // Positions existing hairline divs. annotations.prototype.updateAnnotationDivPositions = function() { var layout = this.dygraph_.getArea(); + var chartLeft = layout.x, chartRight = layout.x + layout.w; + var chartTop = layout.y, chartBottom = layout.y + layout.h; var div = this.dygraph_.graphDiv; var box = [layout.x + Dygraph.findPosX(div), layout.y + Dygraph.findPosY(div)]; @@ -265,6 +267,10 @@ annotations.prototype.updateAnnotationDivPositions = function() { $(a.infoDiv).css({ 'bottom': (div.offsetHeight - y) + 'px' }) //.draggable("option", "containment", box); + + var visible = (x >= chartLeft && x <= chartRight) && + (pointY >= chartTop && pointY <= chartBottom); + $([a.infoDiv, a.lineDiv]).toggle(visible); } }); }; -- 2.7.4