/**
* Add an event handler. This smooths a difference between IE and the rest of
* the world.
- * @param { !Element } elem The element to add the event to.
- * @param { string } type The type of the event, e.g. 'click' or 'mousemove'.
- * @param { function(Event):(boolean|undefined) } fn The function to call
+ * @param {!Node} elem The element to add the event to.
+ * @param {string} type The type of the event, e.g. 'click' or 'mousemove'.
+ * @param {function(Event):(boolean|undefined)} fn The function to call
* on the event. The function takes one parameter: the event object.
* @private
*/
* Add an event handler. This event handler is kept until the graph is
* destroyed with a call to graph.destroy().
*
- * @param { !Element } elem The element to add the event to.
- * @param { string } type The type of the event, e.g. 'click' or 'mousemove'.
- * @param { function(Event):(boolean|undefined) } fn The function to call
+ * @param {!Node} elem The element to add the event to.
+ * @param {string} type The type of the event, e.g. 'click' or 'mousemove'.
+ * @param {function(Event):(boolean|undefined)} fn The function to call
* on the event. The function takes one parameter: the event object.
* @private
*/
/**
* Remove an event handler. This smooths a difference between IE and the rest
* of the world.
- * @param {!Element} elem The element to add the event to.
+ * @param {!Node} elem The element to remove the event from.
* @param {string} type The type of the event, e.g. 'click' or 'mousemove'.
* @param {function(?Event):(boolean|undefined)} fn The function to call
* on the event. The function takes one parameter: the event object.
* browser actions, e.g. highlighting text on a double-click.
* Based on the article at
* http://www.switchonthecode.com/tutorials/javascript-tutorial-the-scroll-wheel
- * @param { !Event } e The event whose normal behavior should be canceled.
+ * @param {!Event} e The event whose normal behavior should be canceled.
* @private
*/
Dygraph.cancelEvent = function(e) {
var enclosing = this.maindiv_;
/** @type {!HTMLDivElement} */
- this.graphDiv = document.createElement("div");
+ this.graphDiv = /**@type{!HTMLDivElement}*/(document.createElement("div"));
// TODO(danvk): any other styles that are useful to set here?
this.graphDiv.style.textAlign = 'left'; // This is a CSS "reset"
// The interactive parts of the graph are drawn on top of the chart.
this.graphDiv.appendChild(this.hidden_);
this.graphDiv.appendChild(this.canvas_);
+
+ /** @type {!Element} */
this.mouseEventElement_ = this.createMouseEventElement_();
/** @type {DygraphLayout} */
}
};
- this.addAndTrackEvent(window, 'mouseout', this.mouseOutHandler_);
+ this.addAndTrackEvent(document, 'mouseout', this.mouseOutHandler_);
this.addAndTrackEvent(this.mouseEventElement_, 'mousemove', this.mouseMoveHandler_);
// Don't recreate and register the resize handler on subsequent calls.
// Update when the window is resized.
// TODO(danvk): drop frames depending on complexity of the chart.
- this.addAndTrackEvent(window, 'resize', this.resizeHandler_);
+ this.addAndTrackEvent(document, 'resize', this.resizeHandler_);
}
};
this.removeTrackedEvents_();
// remove mouse event handlers (This may not be necessary anymore)
- Dygraph.removeEvent(window, 'mouseout', this.mouseOutHandler_);
+ Dygraph.removeEvent(document, 'mouseout', this.mouseOutHandler_);
Dygraph.removeEvent(this.mouseEventElement_, 'mousemove', this.mouseMoveHandler_);
// remove window handlers
- Dygraph.removeEvent(window,'resize',this.resizeHandler_);
+ Dygraph.removeEvent(document, 'resize', this.resizeHandler_);
this.resizeHandler_ = null;
removeRecursive(this.maindiv_);
/**
* Creates an overlay element used to handle mouse events.
- * @return {Object} The mouse event element.
+ * @return {!Element} The mouse event element.
* @private
*/
Dygraph.prototype.createMouseEventElement_ = function() {
};
/**
+ * Fires the zoomCallback callback.
+ * @param {number} minDate The minimum date to pass to the callback.
+ * @param {number} maxDate The maximum date to pass to the callback.
+ * @private
+ */
+Dygraph.prototype.fireZoomCallback = function(minDate, maxDate) {
+ var zoomCallback =
+ /**@type{?function(number,number,!Array.<!Array.<number>>)}*/(
+ this.attr_('zoomCallback'));
+ if (zoomCallback) {
+ zoomCallback(minDate, maxDate, this.yAxisRanges());
+ }
+};
+
+/**
* Zoom to something containing [minDate, maxDate] values. Don't confuse this
* method with doZoomX which accepts pixel coordinates. This function redraws
* the graph.
var old_window = this.xAxisRange();
var new_window = [minDate, maxDate];
this.zoomed_x_ = true;
+
var that = this;
this.doAnimatedZoom(old_window, new_window, null, null, function() {
- if (that.attr_("zoomCallback")) {
- that.attr_("zoomCallback")(minDate, maxDate, that.yAxisRanges());
- }
+ that.fireZoomCallback(minDate, maxDate);
});
};
this.zoomed_y_ = true;
var that = this;
this.doAnimatedZoom(null, null, oldValueRanges, newValueRanges, function() {
- if (that.attr_("zoomCallback")) {
- var xRange = that.xAxisRange();
- that.attr_("zoomCallback")(xRange[0], xRange[1], that.yAxisRanges());
- }
+ var xRange = that.xAxisRange();
+ that.fireZoomCallback(xRange[0], xRange[1]);
});
};
}
}
this.drawGraph_();
- if (this.attr_("zoomCallback")) {
- this.attr_("zoomCallback")(minDate, maxDate, this.yAxisRanges());
- }
+ this.fireZoomCallback(minDate, maxDate);
return;
}
delete that.axes_[i].valueWindow;
}
}
- if (that.attr_("zoomCallback")) {
- that.attr_("zoomCallback")(minDate, maxDate, that.yAxisRanges());
- }
+ this.fireZoomCallback(minDate, maxDate);
});
}
};