3 * Copyright 2011 Robert Konigsberg (konigsberg@google.com)
4 * MIT-licensed (http://opensource.org/licenses/MIT)
8 * @fileoverview The default interaction model for Dygraphs. This is kept out
9 * of dygraph.js for better navigability.
10 * @author Robert Konigsberg (konigsberg@google.com)
13 /*jshint globalstrict: true */
14 /*global Dygraph:false */
18 * A collection of functions to facilitate build custom interaction models.
21 Dygraph
.Interaction
= {};
24 * Called in response to an interaction model operation that
25 * should start the default panning behavior.
27 * It's used in the default callback for "mousedown" operations.
28 * Custom interaction model builders can use it to provide the default
31 * @param {Event} event the event object which led to the startPan call.
32 * @param {Dygraph} g The dygraph on which to act.
33 * @param {Object} context The dragging context object (with
34 * dragStartX/dragStartY/etc. properties). This function modifies the
37 Dygraph
.Interaction
.startPan
= function(event
, g
, context
) {
39 context
.isPanning
= true;
40 var xRange
= g
.xAxisRange();
42 if (g
.getOptionForAxis("logscale", "x")) {
43 context
.initialLeftmostDate
= Dygraph
.log10(xRange
[0]);
44 context
.dateRange
= Dygraph
.log10(xRange
[1]) - Dygraph
.log10(xRange
[0]);
46 context
.initialLeftmostDate
= xRange
[0];
47 context
.dateRange
= xRange
[1] - xRange
[0];
49 context
.xUnitsPerPixel
= context
.dateRange
/ (g
.plotter_
.area
.w
- 1);
51 if (g
.getNumericOption("panEdgeFraction")) {
52 var maxXPixelsToDraw
= g
.width_
* g
.getNumericOption("panEdgeFraction");
53 var xExtremes
= g
.xAxisExtremes(); // I REALLY WANT TO CALL THIS xTremes!
55 var boundedLeftX
= g
.toDomXCoord(xExtremes
[0]) - maxXPixelsToDraw
;
56 var boundedRightX
= g
.toDomXCoord(xExtremes
[1]) + maxXPixelsToDraw
;
58 var boundedLeftDate
= g
.toDataXCoord(boundedLeftX
);
59 var boundedRightDate
= g
.toDataXCoord(boundedRightX
);
60 context
.boundedDates
= [boundedLeftDate
, boundedRightDate
];
62 var boundedValues
= [];
63 var maxYPixelsToDraw
= g
.height_
* g
.getNumericOption("panEdgeFraction");
65 for (i
= 0; i
< g
.axes_
.length
; i
++) {
67 var yExtremes
= axis
.extremeRange
;
69 var boundedTopY
= g
.toDomYCoord(yExtremes
[0], i
) + maxYPixelsToDraw
;
70 var boundedBottomY
= g
.toDomYCoord(yExtremes
[1], i
) - maxYPixelsToDraw
;
72 var boundedTopValue
= g
.toDataYCoord(boundedTopY
, i
);
73 var boundedBottomValue
= g
.toDataYCoord(boundedBottomY
, i
);
75 boundedValues
[i
] = [boundedTopValue
, boundedBottomValue
];
77 context
.boundedValues
= boundedValues
;
80 // Record the range of each y-axis at the start of the drag.
81 // If any axis has a valueRange or valueWindow, then we want a 2D pan.
82 // We can't store data directly in g.axes_, because it does not belong to us
83 // and could change out from under us during a pan (say if there's a data
85 context
.is2DPan
= false;
87 for (i
= 0; i
< g
.axes_
.length
; i
++) {
90 var yRange
= g
.yAxisRange(i
);
91 // TODO(konigsberg): These values should be in |context|.
92 // In log scale, initialTopValue, dragValueRange and unitsPerPixel are log scale.
93 var logscale
= g
.attributes_
.getForAxis("logscale", i
);
95 axis_data
.initialTopValue
= Dygraph
.log10(yRange
[1]);
96 axis_data
.dragValueRange
= Dygraph
.log10(yRange
[1]) - Dygraph
.log10(yRange
[0]);
98 axis_data
.initialTopValue
= yRange
[1];
99 axis_data
.dragValueRange
= yRange
[1] - yRange
[0];
101 axis_data
.unitsPerPixel
= axis_data
.dragValueRange
/ (g
.plotter_
.area
.h
- 1);
102 context
.axes
.push(axis_data
);
104 // While calculating axes, set 2dpan.
105 if (axis
.valueWindow
|| axis
.valueRange
) context
.is2DPan
= true;
110 * Called in response to an interaction model operation that
111 * responds to an event that pans the view.
113 * It's used in the default callback for "mousemove" operations.
114 * Custom interaction model builders can use it to provide the default
117 * @param {Event} event the event object which led to the movePan call.
118 * @param {Dygraph} g The dygraph on which to act.
119 * @param {Object} context The dragging context object (with
120 * dragStartX/dragStartY/etc. properties). This function modifies the
123 Dygraph
.Interaction
.movePan
= function(event
, g
, context
) {
124 context
.dragEndX
= Dygraph
.dragGetX_(event
, context
);
125 context
.dragEndY
= Dygraph
.dragGetY_(event
, context
);
127 var minDate
= context
.initialLeftmostDate
-
128 (context
.dragEndX
- context
.dragStartX
) * context
.xUnitsPerPixel
;
129 if (context
.boundedDates
) {
130 minDate
= Math
.max(minDate
, context
.boundedDates
[0]);
132 var maxDate
= minDate
+ context
.dateRange
;
133 if (context
.boundedDates
) {
134 if (maxDate
> context
.boundedDates
[1]) {
135 // Adjust minDate, and recompute maxDate.
136 minDate
= minDate
- (maxDate
- context
.boundedDates
[1]);
137 maxDate
= minDate
+ context
.dateRange
;
141 if (g
.getOptionForAxis("logscale", "x")) {
142 g
.dateWindow_
= [ Math
.pow(Dygraph
.LOG_SCALE
, minDate
),
143 Math
.pow(Dygraph
.LOG_SCALE
, maxDate
) ];
145 g
.dateWindow_
= [minDate
, maxDate
];
148 // y-axis scaling is automatic unless this is a full 2D pan.
149 if (context
.is2DPan
) {
151 var pixelsDragged
= context
.dragEndY
- context
.dragStartY
;
153 // Adjust each axis appropriately.
154 for (var i
= 0; i
< g
.axes_
.length
; i
++) {
155 var axis
= g
.axes_
[i
];
156 var axis_data
= context
.axes
[i
];
157 var unitsDragged
= pixelsDragged
* axis_data
.unitsPerPixel
;
159 var boundedValue
= context
.boundedValues
? context
.boundedValues
[i
] : null;
161 // In log scale, maxValue and minValue are the logs of those values.
162 var maxValue
= axis_data
.initialTopValue
+ unitsDragged
;
164 maxValue
= Math
.min(maxValue
, boundedValue
[1]);
166 var minValue
= maxValue
- axis_data
.dragValueRange
;
168 if (minValue
< boundedValue
[0]) {
169 // Adjust maxValue, and recompute minValue.
170 maxValue
= maxValue
- (minValue
- boundedValue
[0]);
171 minValue
= maxValue
- axis_data
.dragValueRange
;
174 if (g
.attributes_
.getForAxis("logscale", i
)) {
175 axis
.valueWindow
= [ Math
.pow(Dygraph
.LOG_SCALE
, minValue
),
176 Math
.pow(Dygraph
.LOG_SCALE
, maxValue
) ];
178 axis
.valueWindow
= [ minValue
, maxValue
];
187 * Called in response to an interaction model operation that
188 * responds to an event that ends panning.
190 * It's used in the default callback for "mouseup" operations.
191 * Custom interaction model builders can use it to provide the default
194 * @param {Event} event the event object which led to the endPan call.
195 * @param {Dygraph} g The dygraph on which to act.
196 * @param {Object} context The dragging context object (with
197 * dragStartX/dragStartY/etc. properties). This function modifies the
200 Dygraph
.Interaction
.endPan
= function(event
, g
, context
) {
201 context
.dragEndX
= Dygraph
.dragGetX_(event
, context
);
202 context
.dragEndY
= Dygraph
.dragGetY_(event
, context
);
204 var regionWidth
= Math
.abs(context
.dragEndX
- context
.dragStartX
);
205 var regionHeight
= Math
.abs(context
.dragEndY
- context
.dragStartY
);
207 if (regionWidth
< 2 && regionHeight
< 2 &&
208 g
.lastx_
!== undefined
&& g
.lastx_
!= -1) {
209 Dygraph
.Interaction
.treatMouseOpAsClick(g
, event
, context
);
212 // TODO(konigsberg): mouseup should just delete the
213 // context object, and mousedown should create a new one.
214 context
.isPanning
= false;
215 context
.is2DPan
= false;
216 context
.initialLeftmostDate
= null;
217 context
.dateRange
= null;
218 context
.valueRange
= null;
219 context
.boundedDates
= null;
220 context
.boundedValues
= null;
225 * Called in response to an interaction model operation that
226 * responds to an event that starts zooming.
228 * It's used in the default callback for "mousedown" operations.
229 * Custom interaction model builders can use it to provide the default
232 * @param {Event} event the event object which led to the startZoom call.
233 * @param {Dygraph} g The dygraph on which to act.
234 * @param {Object} context The dragging context object (with
235 * dragStartX/dragStartY/etc. properties). This function modifies the
238 Dygraph
.Interaction
.startZoom
= function(event
, g
, context
) {
239 context
.isZooming
= true;
240 context
.zoomMoved
= false;
244 * Called in response to an interaction model operation that
245 * responds to an event that defines zoom boundaries.
247 * It's used in the default callback for "mousemove" operations.
248 * Custom interaction model builders can use it to provide the default
251 * @param {Event} event the event object which led to the moveZoom call.
252 * @param {Dygraph} g The dygraph on which to act.
253 * @param {Object} context The dragging context object (with
254 * dragStartX/dragStartY/etc. properties). This function modifies the
257 Dygraph
.Interaction
.moveZoom
= function(event
, g
, context
) {
258 context
.zoomMoved
= true;
259 context
.dragEndX
= Dygraph
.dragGetX_(event
, context
);
260 context
.dragEndY
= Dygraph
.dragGetY_(event
, context
);
262 var xDelta
= Math
.abs(context
.dragStartX
- context
.dragEndX
);
263 var yDelta
= Math
.abs(context
.dragStartY
- context
.dragEndY
);
265 // drag direction threshold for y axis is twice as large as x axis
266 context
.dragDirection
= (xDelta
< yDelta
/ 2) ? Dygraph
.VERTICAL
: Dygraph
.HORIZONTAL
;
269 context
.dragDirection
,
274 context
.prevDragDirection
,
278 context
.prevEndX
= context
.dragEndX
;
279 context
.prevEndY
= context
.dragEndY
;
280 context
.prevDragDirection
= context
.dragDirection
;
284 * TODO(danvk): move this logic into dygraph.js
286 * @param {Event} event
287 * @param {Object} context
289 Dygraph
.Interaction
.treatMouseOpAsClick
= function(g
, event
, context
) {
290 var clickCallback
= g
.getFunctionOption('clickCallback');
291 var pointClickCallback
= g
.getFunctionOption('pointClickCallback');
293 var selectedPoint
= null;
295 // Find out if the click occurs on a point.
297 var closestDistance
= Number
.MAX_VALUE
;
299 // check if the click was on a particular point.
300 for (var i
= 0; i
< g
.selPoints_
.length
; i
++) {
301 var p
= g
.selPoints_
[i
];
302 var distance
= Math
.pow(p
.canvasx
- context
.dragEndX
, 2) +
303 Math
.pow(p
.canvasy
- context
.dragEndY
, 2);
304 if (!isNaN(distance
) &&
305 (closestIdx
== -1 || distance
< closestDistance
)) {
306 closestDistance
= distance
;
311 // Allow any click within two pixels of the dot.
312 var radius
= g
.getNumericOption('highlightCircleSize') + 2;
313 if (closestDistance
<= radius
* radius
) {
314 selectedPoint
= g
.selPoints_
[closestIdx
];
320 point
: selectedPoint
,
321 canvasx
: context
.dragEndX
,
322 canvasy
: context
.dragEndY
324 var defaultPrevented
= g
.cascadeEvents_('pointClick', e
);
325 if (defaultPrevented
) {
326 // Note: this also prevents click / clickCallback from firing
.
329 if (pointClickCallback
) {
330 pointClickCallback
.call(g
, event
, selectedPoint
);
336 xval
: g
.lastx_
, // closest point by x value
338 canvasx
: context
.dragEndX
,
339 canvasy
: context
.dragEndY
341 if (!g
.cascadeEvents_('click', e
)) {
343 // TODO(danvk): pass along more info about the points, e.g. 'x'
344 clickCallback
.call(g
, event
, g
.lastx_
, g
.selPoints_
);
350 * Called in response to an interaction model operation that
351 * responds to an event that performs a zoom based on previously defined
354 * It's used in the default callback for "mouseup" operations.
355 * Custom interaction model builders can use it to provide the default
358 * @param {Event} event the event object which led to the endZoom call.
359 * @param {Dygraph} g The dygraph on which to end the zoom.
360 * @param {Object} context The dragging context object (with
361 * dragStartX/dragStartY/etc. properties). This function modifies the
364 Dygraph
.Interaction
.endZoom
= function(event
, g
, context
) {
365 context
.isZooming
= false;
366 context
.dragEndX
= Dygraph
.dragGetX_(event
, context
);
367 context
.dragEndY
= Dygraph
.dragGetY_(event
, context
);
368 var regionWidth
= Math
.abs(context
.dragEndX
- context
.dragStartX
);
369 var regionHeight
= Math
.abs(context
.dragEndY
- context
.dragStartY
);
371 if (regionWidth
< 2 && regionHeight
< 2 &&
372 g
.lastx_
!== undefined
&& g
.lastx_
!= -1) {
373 Dygraph
.Interaction
.treatMouseOpAsClick(g
, event
, context
);
376 // The zoom rectangle is visibly clipped to the plot area, so its behavior
377 // should be as well.
378 // See http://code.google.com/p/dygraphs/issues/detail
?id
=280
379 var plotArea
= g
.getArea();
380 if (regionWidth
>= 10 && context
.dragDirection
== Dygraph
.HORIZONTAL
) {
381 var left
= Math
.min(context
.dragStartX
, context
.dragEndX
),
382 right
= Math
.max(context
.dragStartX
, context
.dragEndX
);
383 left
= Math
.max(left
, plotArea
.x
);
384 right
= Math
.min(right
, plotArea
.x
+ plotArea
.w
);
386 g
.doZoomX_(left
, right
);
388 context
.cancelNextDblclick
= true;
389 } else if (regionHeight
>= 10 && context
.dragDirection
== Dygraph
.VERTICAL
) {
390 var top
= Math
.min(context
.dragStartY
, context
.dragEndY
),
391 bottom
= Math
.max(context
.dragStartY
, context
.dragEndY
);
392 top
= Math
.max(top
, plotArea
.y
);
393 bottom
= Math
.min(bottom
, plotArea
.y
+ plotArea
.h
);
395 g
.doZoomY_(top
, bottom
);
397 context
.cancelNextDblclick
= true;
399 if (context
.zoomMoved
) g
.clearZoomRect_();
401 context
.dragStartX
= null;
402 context
.dragStartY
= null;
408 Dygraph
.Interaction
.startTouch
= function(event
, g
, context
) {
409 event
.preventDefault(); // touch browsers are all nice.
410 if (event
.touches
.length
> 1) {
411 // If the user ever puts two fingers down, it's not a double tap.
412 context
.startTimeForDoubleTapMs
= null;
416 for (var i
= 0; i
< event
.touches
.length
; i
++) {
417 var t
= event
.touches
[i
];
418 // we dispense with 'dragGetX_' because all touchBrowsers support pageX
422 dataX
: g
.toDataXCoord(t
.pageX
),
423 dataY
: g
.toDataYCoord(t
.pageY
)
424 // identifier: t.identifier
427 context
.initialTouches
= touches
;
429 if (touches
.length
== 1) {
430 // This is just a swipe.
431 context
.initialPinchCenter
= touches
[0];
432 context
.touchDirections
= { x
: true, y
: true };
433 } else if (touches
.length
>= 2) {
434 // It's become a pinch!
435 // In case there are 3+ touches, we ignore all but the "first" two.
437 // only screen coordinates can be averaged (data coords could be log scale).
438 context
.initialPinchCenter
= {
439 pageX
: 0.5 * (touches
[0].pageX
+ touches
[1].pageX
),
440 pageY
: 0.5 * (touches
[0].pageY
+ touches
[1].pageY
),
442 // TODO(danvk): remove
443 dataX
: 0.5 * (touches
[0].dataX
+ touches
[1].dataX
),
444 dataY
: 0.5 * (touches
[0].dataY
+ touches
[1].dataY
)
447 // Make pinches in a 45-degree swath around either axis 1-dimensional zooms.
448 var initialAngle
= 180 / Math
.PI
* Math
.atan2(
449 context
.initialPinchCenter
.pageY
- touches
[0].pageY
,
450 touches
[0].pageX
- context
.initialPinchCenter
.pageX
);
452 // use symmetry to get it into the first quadrant.
453 initialAngle
= Math
.abs(initialAngle
);
454 if (initialAngle
> 90) initialAngle
= 90 - initialAngle
;
456 context
.touchDirections
= {
457 x
: (initialAngle
< (90 - 45/2)),
458 y
: (initialAngle
> 45/2)
462 // save the full x & y ranges.
463 context
.initialRange
= {
472 Dygraph
.Interaction
.moveTouch
= function(event
, g
, context
) {
473 // If the tap moves, then it's definitely not part of a double-tap.
474 context
.startTimeForDoubleTapMs
= null;
477 for (i
= 0; i
< event
.touches
.length
; i
++) {
478 var t
= event
.touches
[i
];
484 var initialTouches
= context
.initialTouches
;
488 // old and new centers.
489 var c_init
= context
.initialPinchCenter
;
490 if (touches
.length
== 1) {
494 pageX
: 0.5 * (touches
[0].pageX
+ touches
[1].pageX
),
495 pageY
: 0.5 * (touches
[0].pageY
+ touches
[1].pageY
)
499 // this is the "swipe" component
500 // we toss it out for now, but could use it in the future.
502 pageX
: c_now
.pageX
- c_init
.pageX
,
503 pageY
: c_now
.pageY
- c_init
.pageY
505 var dataWidth
= context
.initialRange
.x
[1] - context
.initialRange
.x
[0];
506 var dataHeight
= context
.initialRange
.y
[0] - context
.initialRange
.y
[1];
507 swipe
.dataX
= (swipe
.pageX
/ g
.plotter_
.area
.w
) * dataWidth
;
508 swipe
.dataY
= (swipe
.pageY
/ g
.plotter_
.area
.h
) * dataHeight
;
511 // The residual bits are usually split into scale & rotate bits, but we split
512 // them into x-scale and y-scale bits.
513 if (touches
.length
== 1) {
516 } else if (touches
.length
>= 2) {
517 var initHalfWidth
= (initialTouches
[1].pageX
- c_init
.pageX
);
518 xScale
= (touches
[1].pageX
- c_now
.pageX
) / initHalfWidth
;
520 var initHalfHeight
= (initialTouches
[1].pageY
- c_init
.pageY
);
521 yScale
= (touches
[1].pageY
- c_now
.pageY
) / initHalfHeight
;
524 // Clip scaling to [1/8, 8] to prevent too much blowup
.
525 xScale
= Math
.min(8, Math
.max(0.125, xScale
));
526 yScale
= Math
.min(8, Math
.max(0.125, yScale
));
529 if (context
.touchDirections
.x
) {
531 c_init
.dataX
- swipe
.dataX
+ (context
.initialRange
.x
[0] - c_init
.dataX
) / xScale
,
532 c_init
.dataX
- swipe
.dataX
+ (context
.initialRange
.x
[1] - c_init
.dataX
) / xScale
537 if (context
.touchDirections
.y
) {
538 for (i
= 0; i
< 1 /*g.axes_.length*/; i
++) {
539 var axis
= g
.axes_
[i
];
540 var logscale
= g
.attributes_
.getForAxis("logscale", i
);
542 // TODO(danvk): implement
545 c_init
.dataY
- swipe
.dataY
+ (context
.initialRange
.y
[0] - c_init
.dataY
) / yScale
,
546 c_init
.dataY
- swipe
.dataY
+ (context
.initialRange
.y
[1] - c_init
.dataY
) / yScale
555 // We only call zoomCallback on zooms, not pans, to mirror desktop behavior.
556 if (didZoom
&& touches
.length
> 1 && g
.getFunctionOption('zoomCallback')) {
557 var viewWindow
= g
.xAxisRange();
558 g
.getFunctionOption("zoomCallback").call(g
, viewWindow
[0], viewWindow
[1], g
.yAxisRanges());
565 Dygraph
.Interaction
.endTouch
= function(event
, g
, context
) {
566 if (event
.touches
.length
!== 0) {
567 // this is effectively a "reset"
568 Dygraph
.Interaction
.startTouch(event
, g
, context
);
569 } else if (event
.changedTouches
.length
== 1) {
570 // Could be part of a "double tap"
571 // The heuristic here is that it's a double-tap if the two touchend events
572 // occur within 500ms and within a 50x50 pixel box.
573 var now
= new Date().getTime();
574 var t
= event
.changedTouches
[0];
575 if (context
.startTimeForDoubleTapMs
&&
576 now
- context
.startTimeForDoubleTapMs
< 500 &&
577 context
.doubleTapX
&& Math
.abs(context
.doubleTapX
- t
.screenX
) < 50 &&
578 context
.doubleTapY
&& Math
.abs(context
.doubleTapY
- t
.screenY
) < 50) {
581 context
.startTimeForDoubleTapMs
= now
;
582 context
.doubleTapX
= t
.screenX
;
583 context
.doubleTapY
= t
.screenY
;
589 * Default interation model for dygraphs. You can refer to specific elements of
590 * this when constructing your own interaction model, e.g.:
592 * interactionModel: {
593 * mousedown: Dygraph.defaultInteractionModel.mousedown
597 Dygraph
.Interaction
.defaultModel
= {
598 // Track the beginning of drag events
599 mousedown
: function(event
, g
, context
) {
600 // Right-click should not initiate a zoom.
601 if (event
.button
&& event
.button
== 2) return;
603 context
.initializeMouseDown(event
, g
, context
);
605 if (event
.altKey
|| event
.shiftKey
) {
606 Dygraph
.startPan(event
, g
, context
);
608 Dygraph
.startZoom(event
, g
, context
);
612 // Draw zoom rectangles when the mouse is down and the user moves around
613 mousemove
: function(event
, g
, context
) {
614 if (context
.isZooming
) {
615 Dygraph
.moveZoom(event
, g
, context
);
616 } else if (context
.isPanning
) {
617 Dygraph
.movePan(event
, g
, context
);
621 mouseup
: function(event
, g
, context
) {
622 if (context
.isZooming
) {
623 Dygraph
.endZoom(event
, g
, context
);
624 } else if (context
.isPanning
) {
625 Dygraph
.endPan(event
, g
, context
);
629 touchstart
: function(event
, g
, context
) {
630 Dygraph
.Interaction
.startTouch(event
, g
, context
);
632 touchmove
: function(event
, g
, context
) {
633 Dygraph
.Interaction
.moveTouch(event
, g
, context
);
635 touchend
: function(event
, g
, context
) {
636 Dygraph
.Interaction
.endTouch(event
, g
, context
);
639 // Temporarily cancel the dragging event when the mouse leaves the graph
640 mouseout
: function(event
, g
, context
) {
641 if (context
.isZooming
) {
642 context
.dragEndX
= null;
643 context
.dragEndY
= null;
648 // Disable zooming out if panning.
649 dblclick
: function(event
, g
, context
) {
650 if (context
.cancelNextDblclick
) {
651 context
.cancelNextDblclick
= false;
655 // Give plugins a chance to grab this event.
657 canvasx
: context
.dragEndX
,
658 canvasy
: context
.dragEndY
660 if (g
.cascadeEvents_('dblclick', e
)) {
664 if (event
.altKey
|| event
.shiftKey
) {
671 Dygraph
.DEFAULT_ATTRS
.interactionModel
= Dygraph
.Interaction
.defaultModel
;
673 // old ways of accessing these methods/properties
674 Dygraph
.defaultInteractionModel
= Dygraph
.Interaction
.defaultModel
;
675 Dygraph
.endZoom
= Dygraph
.Interaction
.endZoom
;
676 Dygraph
.moveZoom
= Dygraph
.Interaction
.moveZoom
;
677 Dygraph
.startZoom
= Dygraph
.Interaction
.startZoom
;
678 Dygraph
.endPan
= Dygraph
.Interaction
.endPan
;
679 Dygraph
.movePan
= Dygraph
.Interaction
.movePan
;
680 Dygraph
.startPan
= Dygraph
.Interaction
.startPan
;
682 Dygraph
.Interaction
.nonInteractiveModel_
= {
683 mousedown
: function(event
, g
, context
) {
684 context
.initializeMouseDown(event
, g
, context
);
686 mouseup
: function(event
, g
, context
) {
687 // TODO(danvk): this logic is repeated in Dygraph.Interaction.endZoom
688 context
.dragEndX
= Dygraph
.dragGetX_(event
, context
);
689 context
.dragEndY
= Dygraph
.dragGetY_(event
, context
);
690 var regionWidth
= Math
.abs(context
.dragEndX
- context
.dragStartX
);
691 var regionHeight
= Math
.abs(context
.dragEndY
- context
.dragStartY
);
693 if (regionWidth
< 2 && regionHeight
< 2 &&
694 g
.lastx_
!== undefined
&& g
.lastx_
!= -1) {
695 Dygraph
.Interaction
.treatMouseOpAsClick(g
, event
, context
);
700 // Default interaction model when using the range selector.
701 Dygraph
.Interaction
.dragIsPanInteractionModel
= {
702 mousedown
: function(event
, g
, context
) {
703 context
.initializeMouseDown(event
, g
, context
);
704 Dygraph
.startPan(event
, g
, context
);
706 mousemove
: function(event
, g
, context
) {
707 if (context
.isPanning
) {
708 Dygraph
.movePan(event
, g
, context
);
711 mouseup
: function(event
, g
, context
) {
712 if (context
.isPanning
) {
713 Dygraph
.endPan(event
, g
, context
);