X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=dygraph.js;h=a02d919079f98662d3ec744aa127ef8a58b8c286;hb=ff91a8e4a020453eb8543f9fa866ada9eb36fd7a;hp=3de67760f0747ad5ef5deb1428de3e01513829ea;hpb=5d2acf298cb95cbcf42aaee980a516d13a961474;p=dygraphs.git diff --git a/dygraph.js b/dygraph.js index 3de6776..a02d919 100644 --- a/dygraph.js +++ b/dygraph.js @@ -963,11 +963,19 @@ Dygraph.prototype.createInterface_ = function() { }; this.mouseOutHandler_ = function(e) { - dygraph.mouseOut_(e); + // The mouse has left the chart if: + // 1. e.target is inside the chart + // 2. e.relatedTarget is outside the chart + var target = e.target || e.fromElement; + var relatedTarget = e.relatedTarget || e.toElement; + if (Dygraph.isElementContainedBy(target, dygraph.graphDiv) && + !Dygraph.isElementContainedBy(relatedTarget, dygraph.graphDiv)) { + dygraph.mouseOut_(e); + } }; + this.addEvent(window, 'mouseout', this.mouseOutHandler_); this.addEvent(this.mouseEventElement_, 'mousemove', this.mouseMoveHandler_); - this.addEvent(this.mouseEventElement_, 'mouseout', this.mouseOutHandler_); // Don't recreate and register the resize handler on subsequent calls. // This happens when the graph is resized. @@ -1005,9 +1013,9 @@ Dygraph.prototype.destroy = function() { this.registeredEvents_ = []; // remove mouse event handlers (This may not be necessary anymore) - Dygraph.removeEvent(this.mouseEventElement_, 'mouseout', this.mouseOutHandler_); + Dygraph.removeEvent(window, 'mouseout', this.mouseOutHandler_); Dygraph.removeEvent(this.mouseEventElement_, 'mousemove', this.mouseMoveHandler_); - Dygraph.removeEvent(this.mouseEventElement_, 'mousemove', this.mouseUpHandler_); + Dygraph.removeEvent(this.mouseEventElement_, 'mouseup', this.mouseUpHandler_); // remove window handlers Dygraph.removeEvent(window,'resize',this.resizeHandler_); @@ -1613,9 +1621,13 @@ Dygraph.prototype.getArea = function() { * Returns a two-element array: [X, Y]. */ Dygraph.prototype.eventToDomCoords = function(event) { - var canvasx = Dygraph.pageX(event) - Dygraph.findPosX(this.mouseEventElement_); - var canvasy = Dygraph.pageY(event) - Dygraph.findPosY(this.mouseEventElement_); - return [canvasx, canvasy]; + if (event.offsetX && event.offsetY) { + return [ event.offsetX, event.offsetY ]; + } else { + var canvasx = Dygraph.pageX(event) - Dygraph.findPosX(this.mouseEventElement_); + var canvasy = Dygraph.pageY(event) - Dygraph.findPosY(this.mouseEventElement_); + return [canvasx, canvasy]; + } }; /** @@ -3498,9 +3510,12 @@ Dygraph.prototype.annotations = function() { /** * Get the list of label names for this graph. The first column is the * x-axis, so the data series names start at index 1. + * + * Returns null when labels have not yet been defined. */ Dygraph.prototype.getLabels = function() { - return this.attr_("labels").slice(); + var labels = this.attr_("labels"); + return labels ? labels.slice() : null; }; /**