1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | "use strict";
|
15 |
|
16 | import * as utils from './dygraph-utils';
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | var DRAG_EDGE_MARGIN = 100;
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 | var DygraphInteraction = {};
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 | DygraphInteraction.maybeTreatMouseOpAsClick = function(event, g, context) {
|
41 | context.dragEndX = utils.dragGetX_(event, context);
|
42 | context.dragEndY = utils.dragGetY_(event, context);
|
43 | var regionWidth = Math.abs(context.dragEndX - context.dragStartX);
|
44 | var regionHeight = Math.abs(context.dragEndY - context.dragStartY);
|
45 |
|
46 | if (regionWidth < 2 && regionHeight < 2 &&
|
47 | g.lastx_ !== undefined && g.lastx_ !== null) {
|
48 | DygraphInteraction.treatMouseOpAsClick(g, event, context);
|
49 | }
|
50 |
|
51 | context.regionWidth = regionWidth;
|
52 | context.regionHeight = regionHeight;
|
53 | };
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 | DygraphInteraction.startPan = function(event, g, context) {
|
70 | var i, axis;
|
71 | context.isPanning = true;
|
72 | var xRange = g.xAxisRange();
|
73 |
|
74 | if (g.getOptionForAxis("logscale", "x")) {
|
75 | context.initialLeftmostDate = utils.log10(xRange[0]);
|
76 | context.dateRange = utils.log10(xRange[1]) - utils.log10(xRange[0]);
|
77 | } else {
|
78 | context.initialLeftmostDate = xRange[0];
|
79 | context.dateRange = xRange[1] - xRange[0];
|
80 | }
|
81 | context.xUnitsPerPixel = context.dateRange / (g.plotter_.area.w - 1);
|
82 |
|
83 | if (g.getNumericOption("panEdgeFraction")) {
|
84 | var maxXPixelsToDraw = g.width_ * g.getNumericOption("panEdgeFraction");
|
85 | var xExtremes = g.xAxisExtremes();
|
86 |
|
87 | var boundedLeftX = g.toDomXCoord(xExtremes[0]) - maxXPixelsToDraw;
|
88 | var boundedRightX = g.toDomXCoord(xExtremes[1]) + maxXPixelsToDraw;
|
89 |
|
90 | var boundedLeftDate = g.toDataXCoord(boundedLeftX);
|
91 | var boundedRightDate = g.toDataXCoord(boundedRightX);
|
92 | context.boundedDates = [boundedLeftDate, boundedRightDate];
|
93 |
|
94 | var boundedValues = [];
|
95 | var maxYPixelsToDraw = g.height_ * g.getNumericOption("panEdgeFraction");
|
96 |
|
97 | for (i = 0; i < g.axes_.length; i++) {
|
98 | axis = g.axes_[i];
|
99 | var yExtremes = axis.extremeRange;
|
100 |
|
101 | var boundedTopY = g.toDomYCoord(yExtremes[0], i) + maxYPixelsToDraw;
|
102 | var boundedBottomY = g.toDomYCoord(yExtremes[1], i) - maxYPixelsToDraw;
|
103 |
|
104 | var boundedTopValue = g.toDataYCoord(boundedTopY, i);
|
105 | var boundedBottomValue = g.toDataYCoord(boundedBottomY, i);
|
106 |
|
107 | boundedValues[i] = [boundedTopValue, boundedBottomValue];
|
108 | }
|
109 | context.boundedValues = boundedValues;
|
110 | } else {
|
111 |
|
112 | context.boundedDates = null;
|
113 | context.boundedValues = null;
|
114 | }
|
115 |
|
116 |
|
117 |
|
118 |
|
119 |
|
120 |
|
121 | context.is2DPan = false;
|
122 | context.axes = [];
|
123 | for (i = 0; i < g.axes_.length; i++) {
|
124 | axis = g.axes_[i];
|
125 | var axis_data = {};
|
126 | var yRange = g.yAxisRange(i);
|
127 |
|
128 |
|
129 | var logscale = g.attributes_.getForAxis("logscale", i);
|
130 | if (logscale) {
|
131 | axis_data.initialTopValue = utils.log10(yRange[1]);
|
132 | axis_data.dragValueRange = utils.log10(yRange[1]) - utils.log10(yRange[0]);
|
133 | } else {
|
134 | axis_data.initialTopValue = yRange[1];
|
135 | axis_data.dragValueRange = yRange[1] - yRange[0];
|
136 | }
|
137 | axis_data.unitsPerPixel = axis_data.dragValueRange / (g.plotter_.area.h - 1);
|
138 | context.axes.push(axis_data);
|
139 |
|
140 |
|
141 | if (axis.valueRange) context.is2DPan = true;
|
142 | }
|
143 | };
|
144 |
|
145 |
|
146 |
|
147 |
|
148 |
|
149 |
|
150 |
|
151 |
|
152 |
|
153 |
|
154 |
|
155 |
|
156 |
|
157 |
|
158 |
|
159 | DygraphInteraction.movePan = function(event, g, context) {
|
160 | context.dragEndX = utils.dragGetX_(event, context);
|
161 | context.dragEndY = utils.dragGetY_(event, context);
|
162 |
|
163 | var minDate = context.initialLeftmostDate -
|
164 | (context.dragEndX - context.dragStartX) * context.xUnitsPerPixel;
|
165 | if (context.boundedDates) {
|
166 | minDate = Math.max(minDate, context.boundedDates[0]);
|
167 | }
|
168 | var maxDate = minDate + context.dateRange;
|
169 | if (context.boundedDates) {
|
170 | if (maxDate > context.boundedDates[1]) {
|
171 |
|
172 | minDate = minDate - (maxDate - context.boundedDates[1]);
|
173 | maxDate = minDate + context.dateRange;
|
174 | }
|
175 | }
|
176 |
|
177 | if (g.getOptionForAxis("logscale", "x")) {
|
178 | g.dateWindow_ = [ Math.pow(utils.LOG_SCALE, minDate),
|
179 | Math.pow(utils.LOG_SCALE, maxDate) ];
|
180 | } else {
|
181 | g.dateWindow_ = [minDate, maxDate];
|
182 | }
|
183 |
|
184 |
|
185 | if (context.is2DPan) {
|
186 |
|
187 | var pixelsDragged = context.dragEndY - context.dragStartY;
|
188 |
|
189 |
|
190 | for (var i = 0; i < g.axes_.length; i++) {
|
191 | var axis = g.axes_[i];
|
192 | var axis_data = context.axes[i];
|
193 | var unitsDragged = pixelsDragged * axis_data.unitsPerPixel;
|
194 |
|
195 | var boundedValue = context.boundedValues ? context.boundedValues[i] : null;
|
196 |
|
197 |
|
198 | var maxValue = axis_data.initialTopValue + unitsDragged;
|
199 | if (boundedValue) {
|
200 | maxValue = Math.min(maxValue, boundedValue[1]);
|
201 | }
|
202 | var minValue = maxValue - axis_data.dragValueRange;
|
203 | if (boundedValue) {
|
204 | if (minValue < boundedValue[0]) {
|
205 |
|
206 | maxValue = maxValue - (minValue - boundedValue[0]);
|
207 | minValue = maxValue - axis_data.dragValueRange;
|
208 | }
|
209 | }
|
210 | if (g.attributes_.getForAxis("logscale", i)) {
|
211 | axis.valueRange = [ Math.pow(utils.LOG_SCALE, minValue),
|
212 | Math.pow(utils.LOG_SCALE, maxValue) ];
|
213 | } else {
|
214 | axis.valueRange = [ minValue, maxValue ];
|
215 | }
|
216 | }
|
217 | }
|
218 |
|
219 | g.drawGraph_(false);
|
220 | };
|
221 |
|
222 |
|
223 |
|
224 |
|
225 |
|
226 |
|
227 |
|
228 |
|
229 |
|
230 |
|
231 |
|
232 |
|
233 |
|
234 |
|
235 |
|
236 | DygraphInteraction.endPan = DygraphInteraction.maybeTreatMouseOpAsClick;
|
237 |
|
238 |
|
239 |
|
240 |
|
241 |
|
242 |
|
243 |
|
244 |
|
245 |
|
246 |
|
247 |
|
248 |
|
249 |
|
250 |
|
251 |
|
252 | DygraphInteraction.startZoom = function(event, g, context) {
|
253 | context.isZooming = true;
|
254 | context.zoomMoved = false;
|
255 | };
|
256 |
|
257 |
|
258 |
|
259 |
|
260 |
|
261 |
|
262 |
|
263 |
|
264 |
|
265 |
|
266 |
|
267 |
|
268 |
|
269 |
|
270 |
|
271 | DygraphInteraction.moveZoom = function(event, g, context) {
|
272 | context.zoomMoved = true;
|
273 | context.dragEndX = utils.dragGetX_(event, context);
|
274 | context.dragEndY = utils.dragGetY_(event, context);
|
275 |
|
276 | var xDelta = Math.abs(context.dragStartX - context.dragEndX);
|
277 | var yDelta = Math.abs(context.dragStartY - context.dragEndY);
|
278 |
|
279 |
|
280 | context.dragDirection = (xDelta < yDelta / 2) ? utils.VERTICAL : utils.HORIZONTAL;
|
281 |
|
282 | g.drawZoomRect_(
|
283 | context.dragDirection,
|
284 | context.dragStartX,
|
285 | context.dragEndX,
|
286 | context.dragStartY,
|
287 | context.dragEndY,
|
288 | context.prevDragDirection,
|
289 | context.prevEndX,
|
290 | context.prevEndY);
|
291 |
|
292 | context.prevEndX = context.dragEndX;
|
293 | context.prevEndY = context.dragEndY;
|
294 | context.prevDragDirection = context.dragDirection;
|
295 | };
|
296 |
|
297 |
|
298 |
|
299 |
|
300 |
|
301 |
|
302 |
|
303 | DygraphInteraction.treatMouseOpAsClick = function(g, event, context) {
|
304 | var clickCallback = g.getFunctionOption('clickCallback');
|
305 | var pointClickCallback = g.getFunctionOption('pointClickCallback');
|
306 |
|
307 | var selectedPoint = null;
|
308 |
|
309 |
|
310 | var closestIdx = -1;
|
311 | var closestDistance = Number.MAX_VALUE;
|
312 |
|
313 |
|
314 | for (var i = 0; i < g.selPoints_.length; i++) {
|
315 | var p = g.selPoints_[i];
|
316 | var distance = Math.pow(p.canvasx - context.dragEndX, 2) +
|
317 | Math.pow(p.canvasy - context.dragEndY, 2);
|
318 | if (!isNaN(distance) &&
|
319 | (closestIdx == -1 || distance < closestDistance)) {
|
320 | closestDistance = distance;
|
321 | closestIdx = i;
|
322 | }
|
323 | }
|
324 |
|
325 |
|
326 | var radius = g.getNumericOption('highlightCircleSize') + 2;
|
327 | if (closestDistance <= radius * radius) {
|
328 | selectedPoint = g.selPoints_[closestIdx];
|
329 | }
|
330 |
|
331 | if (selectedPoint) {
|
332 | var e = {
|
333 | cancelable: true,
|
334 | point: selectedPoint,
|
335 | canvasx: context.dragEndX,
|
336 | canvasy: context.dragEndY
|
337 | };
|
338 | var defaultPrevented = g.cascadeEvents_('pointClick', e);
|
339 | if (defaultPrevented) {
|
340 |
|
341 | return;
|
342 | }
|
343 | if (pointClickCallback) {
|
344 | pointClickCallback.call(g, event, selectedPoint);
|
345 | }
|
346 | }
|
347 |
|
348 | var e = {
|
349 | cancelable: true,
|
350 | xval: g.lastx_,
|
351 | pts: g.selPoints_,
|
352 | canvasx: context.dragEndX,
|
353 | canvasy: context.dragEndY
|
354 | };
|
355 | if (!g.cascadeEvents_('click', e)) {
|
356 | if (clickCallback) {
|
357 |
|
358 | clickCallback.call(g, event, g.lastx_, g.selPoints_);
|
359 | }
|
360 | }
|
361 | };
|
362 |
|
363 |
|
364 |
|
365 |
|
366 |
|
367 |
|
368 |
|
369 |
|
370 |
|
371 |
|
372 |
|
373 |
|
374 |
|
375 |
|
376 |
|
377 |
|
378 | DygraphInteraction.endZoom = function(event, g, context) {
|
379 | g.clearZoomRect_();
|
380 | context.isZooming = false;
|
381 | DygraphInteraction.maybeTreatMouseOpAsClick(event, g, context);
|
382 |
|
383 |
|
384 |
|
385 |
|
386 | var plotArea = g.getArea();
|
387 | if (context.regionWidth >= 10 &&
|
388 | context.dragDirection == utils.HORIZONTAL) {
|
389 | var left = Math.min(context.dragStartX, context.dragEndX),
|
390 | right = Math.max(context.dragStartX, context.dragEndX);
|
391 | left = Math.max(left, plotArea.x);
|
392 | right = Math.min(right, plotArea.x + plotArea.w);
|
393 | if (left < right) {
|
394 | g.doZoomX_(left, right);
|
395 | }
|
396 | context.cancelNextDblclick = true;
|
397 | } else if (context.regionHeight >= 10 &&
|
398 | context.dragDirection == utils.VERTICAL) {
|
399 | var top = Math.min(context.dragStartY, context.dragEndY),
|
400 | bottom = Math.max(context.dragStartY, context.dragEndY);
|
401 | top = Math.max(top, plotArea.y);
|
402 | bottom = Math.min(bottom, plotArea.y + plotArea.h);
|
403 | if (top < bottom) {
|
404 | g.doZoomY_(top, bottom);
|
405 | }
|
406 | context.cancelNextDblclick = true;
|
407 | }
|
408 | context.dragStartX = null;
|
409 | context.dragStartY = null;
|
410 | };
|
411 |
|
412 |
|
413 |
|
414 |
|
415 | DygraphInteraction.startTouch = function(event, g, context) {
|
416 | event.preventDefault();
|
417 | if (event.touches.length > 1) {
|
418 |
|
419 | context.startTimeForDoubleTapMs = null;
|
420 | }
|
421 |
|
422 | var touches = [];
|
423 | for (var i = 0; i < event.touches.length; i++) {
|
424 | var t = event.touches[i];
|
425 | var rect = t.target.getBoundingClientRect()
|
426 |
|
427 | touches.push({
|
428 | pageX: t.pageX,
|
429 | pageY: t.pageY,
|
430 | dataX: g.toDataXCoord(t.clientX - rect.left),
|
431 | dataY: g.toDataYCoord(t.clientY - rect.top)
|
432 |
|
433 | });
|
434 | }
|
435 | context.initialTouches = touches;
|
436 |
|
437 | if (touches.length == 1) {
|
438 |
|
439 | context.initialPinchCenter = touches[0];
|
440 | context.touchDirections = { x: true, y: true };
|
441 | } else if (touches.length >= 2) {
|
442 |
|
443 |
|
444 |
|
445 |
|
446 | context.initialPinchCenter = {
|
447 | pageX: 0.5 * (touches[0].pageX + touches[1].pageX),
|
448 | pageY: 0.5 * (touches[0].pageY + touches[1].pageY),
|
449 |
|
450 |
|
451 | dataX: 0.5 * (touches[0].dataX + touches[1].dataX),
|
452 | dataY: 0.5 * (touches[0].dataY + touches[1].dataY)
|
453 | };
|
454 |
|
455 |
|
456 | var initialAngle = 180 / Math.PI * Math.atan2(
|
457 | context.initialPinchCenter.pageY - touches[0].pageY,
|
458 | touches[0].pageX - context.initialPinchCenter.pageX);
|
459 |
|
460 |
|
461 | initialAngle = Math.abs(initialAngle);
|
462 | if (initialAngle > 90) initialAngle = 90 - initialAngle;
|
463 |
|
464 | context.touchDirections = {
|
465 | x: (initialAngle < (90 - 45/2)),
|
466 | y: (initialAngle > 45/2)
|
467 | };
|
468 | }
|
469 |
|
470 |
|
471 | context.initialRange = {
|
472 | x: g.xAxisRange(),
|
473 | y: g.yAxisRange()
|
474 | };
|
475 | };
|
476 |
|
477 |
|
478 |
|
479 |
|
480 | DygraphInteraction.moveTouch = function(event, g, context) {
|
481 |
|
482 | context.startTimeForDoubleTapMs = null;
|
483 |
|
484 | var i, touches = [];
|
485 | for (i = 0; i < event.touches.length; i++) {
|
486 | var t = event.touches[i];
|
487 | touches.push({
|
488 | pageX: t.pageX,
|
489 | pageY: t.pageY
|
490 | });
|
491 | }
|
492 | var initialTouches = context.initialTouches;
|
493 |
|
494 | var c_now;
|
495 |
|
496 |
|
497 | var c_init = context.initialPinchCenter;
|
498 | if (touches.length == 1) {
|
499 | c_now = touches[0];
|
500 | } else {
|
501 | c_now = {
|
502 | pageX: 0.5 * (touches[0].pageX + touches[1].pageX),
|
503 | pageY: 0.5 * (touches[0].pageY + touches[1].pageY)
|
504 | };
|
505 | }
|
506 |
|
507 |
|
508 |
|
509 | var swipe = {
|
510 | pageX: c_now.pageX - c_init.pageX,
|
511 | pageY: c_now.pageY - c_init.pageY
|
512 | };
|
513 | var dataWidth = context.initialRange.x[1] - context.initialRange.x[0];
|
514 | var dataHeight = context.initialRange.y[0] - context.initialRange.y[1];
|
515 | swipe.dataX = (swipe.pageX / g.plotter_.area.w) * dataWidth;
|
516 | swipe.dataY = (swipe.pageY / g.plotter_.area.h) * dataHeight;
|
517 | var xScale, yScale;
|
518 |
|
519 |
|
520 |
|
521 | if (touches.length == 1) {
|
522 | xScale = 1.0;
|
523 | yScale = 1.0;
|
524 | } else if (touches.length >= 2) {
|
525 | var initHalfWidth = (initialTouches[1].pageX - c_init.pageX);
|
526 | xScale = (touches[1].pageX - c_now.pageX) / initHalfWidth;
|
527 |
|
528 | var initHalfHeight = (initialTouches[1].pageY - c_init.pageY);
|
529 | yScale = (touches[1].pageY - c_now.pageY) / initHalfHeight;
|
530 | }
|
531 |
|
532 |
|
533 | xScale = Math.min(8, Math.max(0.125, xScale));
|
534 | yScale = Math.min(8, Math.max(0.125, yScale));
|
535 |
|
536 | var didZoom = false;
|
537 | if (context.touchDirections.x) {
|
538 | var cFactor = c_init.dataX - swipe.dataX / xScale;
|
539 | g.dateWindow_ = [
|
540 | cFactor + (context.initialRange.x[0] - c_init.dataX) / xScale,
|
541 | cFactor + (context.initialRange.x[1] - c_init.dataX) / xScale
|
542 | ];
|
543 | didZoom = true;
|
544 | }
|
545 |
|
546 | if (context.touchDirections.y) {
|
547 | for (i = 0; i < 1 ; i++) {
|
548 | var axis = g.axes_[i];
|
549 | var logscale = g.attributes_.getForAxis("logscale", i);
|
550 | if (logscale) {
|
551 |
|
552 | } else {
|
553 | var cFactor = c_init.dataY - swipe.dataY / yScale;
|
554 | axis.valueRange = [
|
555 | cFactor + (context.initialRange.y[0] - c_init.dataY) / yScale,
|
556 | cFactor + (context.initialRange.y[1] - c_init.dataY) / yScale
|
557 | ];
|
558 | didZoom = true;
|
559 | }
|
560 | }
|
561 | }
|
562 |
|
563 | g.drawGraph_(false);
|
564 |
|
565 |
|
566 | if (didZoom && touches.length > 1 && g.getFunctionOption('zoomCallback')) {
|
567 | var viewWindow = g.xAxisRange();
|
568 | g.getFunctionOption("zoomCallback").call(g, viewWindow[0], viewWindow[1], g.yAxisRanges());
|
569 | }
|
570 | };
|
571 |
|
572 |
|
573 |
|
574 |
|
575 | DygraphInteraction.endTouch = function(event, g, context) {
|
576 | if (event.touches.length !== 0) {
|
577 |
|
578 | DygraphInteraction.startTouch(event, g, context);
|
579 | } else if (event.changedTouches.length == 1) {
|
580 |
|
581 |
|
582 |
|
583 | var now = new Date().getTime();
|
584 | var t = event.changedTouches[0];
|
585 | if (context.startTimeForDoubleTapMs &&
|
586 | now - context.startTimeForDoubleTapMs < 500 &&
|
587 | context.doubleTapX && Math.abs(context.doubleTapX - t.screenX) < 50 &&
|
588 | context.doubleTapY && Math.abs(context.doubleTapY - t.screenY) < 50) {
|
589 | g.resetZoom();
|
590 | } else {
|
591 | context.startTimeForDoubleTapMs = now;
|
592 | context.doubleTapX = t.screenX;
|
593 | context.doubleTapY = t.screenY;
|
594 | }
|
595 | }
|
596 | };
|
597 |
|
598 |
|
599 | var distanceFromInterval = function(x, left, right) {
|
600 | if (x < left) {
|
601 | return left - x;
|
602 | } else if (x > right) {
|
603 | return x - right;
|
604 | } else {
|
605 | return 0;
|
606 | }
|
607 | };
|
608 |
|
609 |
|
610 |
|
611 |
|
612 |
|
613 | var distanceFromChart = function(event, g) {
|
614 | var chartPos = utils.findPos(g.canvas_);
|
615 | var box = {
|
616 | left: chartPos.x,
|
617 | right: chartPos.x + g.canvas_.offsetWidth,
|
618 | top: chartPos.y,
|
619 | bottom: chartPos.y + g.canvas_.offsetHeight
|
620 | };
|
621 |
|
622 | var pt = {
|
623 | x: utils.pageX(event),
|
624 | y: utils.pageY(event)
|
625 | };
|
626 |
|
627 | var dx = distanceFromInterval(pt.x, box.left, box.right),
|
628 | dy = distanceFromInterval(pt.y, box.top, box.bottom);
|
629 | return Math.max(dx, dy);
|
630 | };
|
631 |
|
632 |
|
633 |
|
634 |
|
635 |
|
636 |
|
637 |
|
638 |
|
639 |
|
640 |
|
641 | DygraphInteraction.defaultModel = {
|
642 |
|
643 | mousedown: function(event, g, context) {
|
644 |
|
645 | if (event.button && event.button == 2) return;
|
646 |
|
647 | context.initializeMouseDown(event, g, context);
|
648 |
|
649 | if (event.altKey || event.shiftKey) {
|
650 | DygraphInteraction.startPan(event, g, context);
|
651 | } else {
|
652 | DygraphInteraction.startZoom(event, g, context);
|
653 | }
|
654 |
|
655 |
|
656 |
|
657 |
|
658 | var mousemove = function(event) {
|
659 | if (context.isZooming) {
|
660 |
|
661 | var d = distanceFromChart(event, g);
|
662 | if (d < DRAG_EDGE_MARGIN) {
|
663 | DygraphInteraction.moveZoom(event, g, context);
|
664 | } else {
|
665 | if (context.dragEndX !== null) {
|
666 | context.dragEndX = null;
|
667 | context.dragEndY = null;
|
668 | g.clearZoomRect_();
|
669 | }
|
670 | }
|
671 | } else if (context.isPanning) {
|
672 | DygraphInteraction.movePan(event, g, context);
|
673 | }
|
674 | };
|
675 | var mouseup = function(event) {
|
676 | if (context.isZooming) {
|
677 | if (context.dragEndX !== null) {
|
678 | DygraphInteraction.endZoom(event, g, context);
|
679 | } else {
|
680 | DygraphInteraction.maybeTreatMouseOpAsClick(event, g, context);
|
681 | }
|
682 | } else if (context.isPanning) {
|
683 | DygraphInteraction.endPan(event, g, context);
|
684 | }
|
685 |
|
686 | utils.removeEvent(document, 'mousemove', mousemove);
|
687 | utils.removeEvent(document, 'mouseup', mouseup);
|
688 | context.destroy();
|
689 | };
|
690 |
|
691 | g.addAndTrackEvent(document, 'mousemove', mousemove);
|
692 | g.addAndTrackEvent(document, 'mouseup', mouseup);
|
693 | },
|
694 | willDestroyContextMyself: true,
|
695 |
|
696 | touchstart: function(event, g, context) {
|
697 | DygraphInteraction.startTouch(event, g, context);
|
698 | },
|
699 | touchmove: function(event, g, context) {
|
700 | DygraphInteraction.moveTouch(event, g, context);
|
701 | },
|
702 | touchend: function(event, g, context) {
|
703 | DygraphInteraction.endTouch(event, g, context);
|
704 | },
|
705 |
|
706 |
|
707 | dblclick: function(event, g, context) {
|
708 | if (context.cancelNextDblclick) {
|
709 | context.cancelNextDblclick = false;
|
710 | return;
|
711 | }
|
712 |
|
713 |
|
714 | var e = {
|
715 | canvasx: context.dragEndX,
|
716 | canvasy: context.dragEndY,
|
717 | cancelable: true,
|
718 | };
|
719 | if (g.cascadeEvents_('dblclick', e)) {
|
720 | return;
|
721 | }
|
722 |
|
723 | if (event.altKey || event.shiftKey) {
|
724 | return;
|
725 | }
|
726 | g.resetZoom();
|
727 | }
|
728 | };
|
729 |
|
730 |
|
731 |
|
732 |
|
733 |
|
734 |
|
735 |
|
736 |
|
737 |
|
738 |
|
739 |
|
740 |
|
741 |
|
742 |
|
743 | DygraphInteraction.nonInteractiveModel_ = {
|
744 | mousedown: function(event, g, context) {
|
745 | context.initializeMouseDown(event, g, context);
|
746 | },
|
747 | mouseup: DygraphInteraction.maybeTreatMouseOpAsClick
|
748 | };
|
749 |
|
750 |
|
751 | DygraphInteraction.dragIsPanInteractionModel = {
|
752 | mousedown: function(event, g, context) {
|
753 | context.initializeMouseDown(event, g, context);
|
754 | DygraphInteraction.startPan(event, g, context);
|
755 | },
|
756 | mousemove: function(event, g, context) {
|
757 | if (context.isPanning) {
|
758 | DygraphInteraction.movePan(event, g, context);
|
759 | }
|
760 | },
|
761 | mouseup: function(event, g, context) {
|
762 | if (context.isPanning) {
|
763 | DygraphInteraction.endPan(event, g, context);
|
764 | }
|
765 | }
|
766 | };
|
767 |
|
768 | export default DygraphInteraction;
|