- // Draw zoom rectangles when the mouse is down and the user moves around
- mousemove: function(event, g, context) {
- if (context.isZooming) {
- Dygraph.moveZoom(event, g, context);
- } else if (context.isPanning) {
- Dygraph.movePan(event, g, context);
- }
- },
+ // Note: we register mousemove/mouseup on document to allow some leeway for
+ // events to move outside of the chart. Interaction model events get
+ // registered on the canvas, which is too small to allow this.
+ var mousemove = function(event) {
+ if (context.isZooming) {
+ // When the mouse moves >200px from the chart edge, cancel the zoom.
+ var d = distanceFromChart(event, g);
+ if (d < DRAG_EDGE_MARGIN) {
+ Dygraph.moveZoom(event, g, context);
+ } else {
+ if (context.dragEndX !== null) {
+ context.dragEndX = null;
+ context.dragEndY = null;
+ g.clearZoomRect_();
+ }
+ }
+ } else if (context.isPanning) {
+ Dygraph.movePan(event, g, context);
+ }
+ };
+ var mouseup = function(event) {
+ if (context.isZooming) {
+ if (context.dragEndX !== null) {
+ Dygraph.endZoom(event, g, context);
+ } else {
+ Dygraph.Interaction.maybeTreatMouseOpAsClick(event, g, context);
+ }
+ } else if (context.isPanning) {
+ Dygraph.endPan(event, g, context);
+ }