this.createRollInterface_();
this.createDragInterface_();
- // connect(window, 'onload', this, function(e) { this.start_(); });
this.start_();
};
*/
Dygraph.prototype.rollPeriod = function() {
return this.rollPeriod_;
-}
+};
+
+Dygraph.addEvent = function(el, evt, fn) {
+ var normed_fn = function(e) {
+ if (!e) var e = window.event;
+ fn(e);
+ };
+ if (window.addEventListener) { // Mozilla, Netscape, Firefox
+ el.addEventListener(evt, normed_fn, false);
+ } else { // IE
+ el.attachEvent('on' + evt, normed_fn);
+ }
+};
/**
* Generates interface elements for the Dygraph: a containing div, a div to
// ... and for static parts of the chart.
this.hidden_ = this.createPlotKitCanvas_(this.canvas_);
- connect(this.hidden_, 'onmousemove', this, function(e) { this.mouseMove_(e) });
- connect(this.hidden_, 'onmouseout', this, function(e) { this.mouseOut_(e) });
+
+ var dygraph = this;
+ Dygraph.addEvent(this.hidden_, 'mousemove', function(e) {
+ dygraph.mouseMove_(e);
+ });
+ Dygraph.addEvent(this.hidden_, 'mouseout', function(e) {
+ dygraph.mouseOut_(e);
+ });
}
/**
var pa = this.graphDiv;
pa.appendChild(roller);
- connect(roller, 'onchange', this,
- function() { this.adjustRoll(roller.value); });
+ var dygraph = this;
+ roller.onchange = function() { dygraph.adjustRoll(roller.value); };
return roller;
-}
+};
+
+// These functions are taken from MochiKit.Signal
+Dygraph.pageX = function(e) {
+ if (e.pageX) {
+ return (!e.pageX || e.pageX < 0) ? 0 : e.pageX;
+ } else {
+ var de = document;
+ var b = document.body;
+ return e.clientX +
+ (de.scrollLeft || b.scrollLeft) -
+ (de.clientLeft || 0);
+ }
+};
+
+Dygraph.pageY = function(e) {
+ if (e.pageY) {
+ return (!e.pageY || e.pageY < 0) ? 0 : e.pageY;
+ } else {
+ var de = document;
+ var b = document.body;
+ return e.clientY +
+ (de.scrollTop || b.scrollTop) -
+ (de.clientTop || 0);
+ }
+};
/**
* Set up all the mouse handlers needed to capture dragging behavior for zoom
// Utility function to convert page-wide coordinates to canvas coords
var px = 0;
var py = 0;
- var getX = function(e) { return e.mouse().page.x - px };
- var getY = function(e) { return e.mouse().page.y - py };
+ var getX = function(e) { return Dygraph.pageX(e) - px };
+ var getY = function(e) { return Dygraph.pageX(e) - py };
// Draw zoom rectangles when the mouse is down and the user moves around
- connect(this.hidden_, 'onmousemove', function(event) {
+ Dygraph.addEvent(this.hidden_, 'mousemove', function(event) {
if (mouseDown) {
dragEndX = getX(event);
dragEndY = getY(event);
});
// Track the beginning of drag events
- connect(this.hidden_, 'onmousedown', function(event) {
+ Dygraph.addEvent(this.hidden_, 'mousedown', function(event) {
mouseDown = true;
px = Dygraph.findPosX(self.canvas_);
py = Dygraph.findPosY(self.canvas_);
// If the user releases the mouse button during a drag, but not over the
// canvas, then it doesn't count as a zooming action.
- connect(document, 'onmouseup', this, function(event) {
+ Dygraph.addEvent(document, 'mouseup', function(event) {
if (mouseDown) {
mouseDown = false;
dragStartX = null;
});
// Temporarily cancel the dragging event when the mouse leaves the graph
- connect(this.hidden_, 'onmouseout', this, function(event) {
+ Dygraph.addEvent(this.hidden_, 'mouseout', function(event) {
if (mouseDown) {
dragEndX = null;
dragEndY = null;
// If the mouse is released on the canvas during a drag event, then it's a
// zoom. Only do the zoom if it's over a large enough area (>= 10 pixels)
- connect(this.hidden_, 'onmouseup', this, function(event) {
+ Dygraph.addEvent(this.hidden_, 'mouseup', function(event) {
if (mouseDown) {
mouseDown = false;
dragEndX = getX(event);
});
// Double-clicking zooms back out
- connect(this.hidden_, 'ondblclick', this, function(event) {
+ Dygraph.addEvent(this.hidden_, 'dblclick', function(event) {
self.dateWindow_ = null;
self.drawGraph_(self.rawData_);
var minDate = self.rawData_[0][0];
* @private
*/
Dygraph.prototype.mouseMove_ = function(event) {
- var canvasx = event.mouse().page.x - Dygraph.findPosX(this.hidden_);
+ var canvasx = Dygraph.pageX(event) - Dygraph.findPosX(this.hidden_);
var points = this.layout_.points;
var lastx = -1;