From: Dan Vanderkam Date: Mon, 1 Jul 2013 03:13:49 +0000 (-0400) Subject: annotations hide when they go off the chart X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=a4bf424f4d24e460f2c817805b56b5783b1593c7;p=dygraphs.git annotations hide when they go off the chart --- 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); } }); };