hairlines hide when they go off the chart
authorDan Vanderkam <danvdk@gmail.com>
Mon, 1 Jul 2013 03:10:04 +0000 (23:10 -0400)
committerDan Vanderkam <danvdk@gmail.com>
Mon, 1 Jul 2013 03:10:04 +0000 (23:10 -0400)
extras/hairlines.js

index 2d72036..0a4cd40 100644 (file)
@@ -155,6 +155,7 @@ hairlines.prototype.moveHairlineToTop = function(h) {
 hairlines.prototype.updateHairlineDivPositions = function() {
   var g = this.dygraph_;
   var layout = this.dygraph_.getArea();
+  var chartLeft = layout.x, chartRight = layout.x + layout.w;
   var div = this.dygraph_.graphDiv;
   var box = [layout.x + Dygraph.findPosX(div),
              layout.y + Dygraph.findPosY(div)];
@@ -173,6 +174,9 @@ hairlines.prototype.updateHairlineDivPositions = function() {
       'left': left + 'px',
       'top': layout.y + 'px',
     }).draggable("option", "containment", box);
+
+    var visible = (left >= chartLeft && left <= chartRight);
+    $([h.infoDiv, h.lineDiv]).toggle(visible);
   });
 };