return null;
};
+
+/**
+ * Is one element contained by another?
+ * @param {Element} containee The contained element.
+ * @param {Element} container The container element.
+ * @return {boolean} Whether containee is inside (or equal to) container.
+ * @private
+ */
+Dygraph.isElementContainedBy = function(containee, container) {
+ if (container === null || containee === null) {
+ return false;
+ }
+ while (containee && containee !== container) {
+ containee = containee.parentNode;
+ }
+ return (containee === container);
+};
};
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.
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_);