@kevinburke/flot 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/CHANGELOG.md +1814 -0
  2. package/LICENSE.txt +22 -0
  3. package/README.md +119 -0
  4. package/dist/flot.js +9830 -0
  5. package/dist/flot.min.js +2 -0
  6. package/dist/flot.min.js.map +1 -0
  7. package/dist/flot.mjs +9805 -0
  8. package/dist/jquery.flot.js +9869 -0
  9. package/dist/jquery.flot.min.js +2 -0
  10. package/dist/jquery.flot.min.js.map +1 -0
  11. package/dist/plugins/jquery.flot.crosshair.js +207 -0
  12. package/dist/plugins/jquery.flot.crosshair.min.js +2 -0
  13. package/dist/plugins/jquery.flot.crosshair.min.js.map +1 -0
  14. package/dist/plugins/jquery.flot.image.js +261 -0
  15. package/dist/plugins/jquery.flot.image.min.js +2 -0
  16. package/dist/plugins/jquery.flot.image.min.js.map +1 -0
  17. package/dist/plugins/jquery.flot.pie.js +815 -0
  18. package/dist/plugins/jquery.flot.pie.min.js +2 -0
  19. package/dist/plugins/jquery.flot.pie.min.js.map +1 -0
  20. package/dist/plugins/jquery.flot.resize.js +62 -0
  21. package/dist/plugins/jquery.flot.resize.min.js +2 -0
  22. package/dist/plugins/jquery.flot.resize.min.js.map +1 -0
  23. package/dist/plugins/jquery.flot.threshold.js +148 -0
  24. package/dist/plugins/jquery.flot.threshold.min.js +2 -0
  25. package/dist/plugins/jquery.flot.threshold.min.js.map +1 -0
  26. package/docs/API.md +1767 -0
  27. package/docs/PLUGINS.md +143 -0
  28. package/docs/absRelTime.md +42 -0
  29. package/docs/browser.md +24 -0
  30. package/docs/canvaswrapper.md +116 -0
  31. package/docs/composeImages.md +32 -0
  32. package/docs/drawSeries.md +35 -0
  33. package/docs/hover.md +21 -0
  34. package/docs/interactions.md +57 -0
  35. package/docs/logaxis.md +27 -0
  36. package/docs/navigate.md +110 -0
  37. package/package.json +53 -0
  38. package/source/helpers.js +168 -0
  39. package/source/index.js +70 -0
  40. package/source/jquery-adapter.js +83 -0
  41. package/source/jquery.canvaswrapper.js +546 -0
  42. package/source/jquery.colorhelpers.js +198 -0
  43. package/source/jquery.flot.axislabels.js +214 -0
  44. package/source/jquery.flot.browser.js +53 -0
  45. package/source/jquery.flot.categories.js +202 -0
  46. package/source/jquery.flot.composeImages.js +327 -0
  47. package/source/jquery.flot.crosshair.js +203 -0
  48. package/source/jquery.flot.drawSeries.js +699 -0
  49. package/source/jquery.flot.errorbars.js +375 -0
  50. package/source/jquery.flot.fillbetween.js +254 -0
  51. package/source/jquery.flot.flatdata.js +47 -0
  52. package/source/jquery.flot.hover.js +354 -0
  53. package/source/jquery.flot.image.js +252 -0
  54. package/source/jquery.flot.js +2814 -0
  55. package/source/jquery.flot.legend.js +444 -0
  56. package/source/jquery.flot.logaxis.js +299 -0
  57. package/source/jquery.flot.navigate.js +842 -0
  58. package/source/jquery.flot.pie.js +811 -0
  59. package/source/jquery.flot.resize.js +57 -0
  60. package/source/jquery.flot.saturated.js +40 -0
  61. package/source/jquery.flot.selection.js +552 -0
  62. package/source/jquery.flot.stack.js +220 -0
  63. package/source/jquery.flot.symbol.js +98 -0
  64. package/source/jquery.flot.threshold.js +144 -0
  65. package/source/jquery.flot.time.js +584 -0
  66. package/source/jquery.flot.touch.js +320 -0
  67. package/source/jquery.flot.touchNavigate.js +357 -0
  68. package/source/jquery.flot.uiConstants.js +9 -0
  69. package/source/jquery.js +9473 -0
@@ -0,0 +1,842 @@
1
+ /* Flot plugin for adding the ability to pan and zoom the plot.
2
+
3
+ Copyright (c) 2007-2014 IOLA and Ole Laursen.
4
+ Copyright (c) 2016 Ciprian Ceteras.
5
+ Copyright (c) 2017 Raluca Portase.
6
+ Licensed under the MIT license.
7
+
8
+ */
9
+
10
+ /**
11
+ ## jquery.flot.navigate.js
12
+
13
+ This flot plugin is used for adding the ability to pan and zoom the plot.
14
+ A higher level overview is available at [interactions](interactions.md) documentation.
15
+
16
+ The default behaviour is scrollwheel up/down to zoom in, drag
17
+ to pan. The plugin defines plot.zoom({ center }), plot.zoomOut() and
18
+ plot.pan( offset ) so you easily can add custom controls. It also fires
19
+ "plotpan" and "plotzoom" events, useful for synchronizing plots.
20
+
21
+ The plugin supports these options:
22
+ ```js
23
+ zoom: {
24
+ interactive: false,
25
+ active: false,
26
+ amount: 1.5 // 2 = 200% (zoom in), 0.5 = 50% (zoom out)
27
+ }
28
+
29
+ pan: {
30
+ interactive: false,
31
+ active: false,
32
+ cursor: "move", // CSS mouse cursor value used when dragging, e.g. "pointer"
33
+ frameRate: 60,
34
+ mode: "smart" // enable smart pan mode
35
+ }
36
+
37
+ xaxis: {
38
+ axisZoom: true, //zoom axis when mouse over it is allowed
39
+ plotZoom: true, //zoom axis is allowed for plot zoom
40
+ axisPan: true, //pan axis when mouse over it is allowed
41
+ plotPan: true, //pan axis is allowed for plot pan
42
+ panRange: [undefined, undefined], // no limit on pan range, or [min, max] in axis units
43
+ zoomRange: [undefined, undefined], // no limit on zoom range, or [closest zoom, furthest zoom] in axis units
44
+ }
45
+
46
+ yaxis: {
47
+ axisZoom: true, //zoom axis when mouse over it is allowed
48
+ plotZoom: true, //zoom axis is allowed for plot zoom
49
+ axisPan: true, //pan axis when mouse over it is allowed
50
+ plotPan: true //pan axis is allowed for plot pan
51
+ panRange: [undefined, undefined], // no limit on pan range, or [min, max] in axis units
52
+ zoomRange: [undefined, undefined], // no limit on zoom range, or [closest zoom, furthest zoom] in axis units
53
+ }
54
+ ```
55
+ **interactive** enables the built-in drag/click behaviour. If you enable
56
+ interactive for pan, then you'll have a basic plot that supports moving
57
+ around; the same for zoom.
58
+
59
+ **active** is true after a touch tap on plot. This enables plot navigation.
60
+ Once activated, zoom and pan cannot be deactivated. When the plot becomes active,
61
+ "plotactivated" event is triggered.
62
+
63
+ **amount** specifies the default amount to zoom in (so 1.5 = 150%) relative to
64
+ the current viewport.
65
+
66
+ **cursor** is a standard CSS mouse cursor string used for visual feedback to the
67
+ user when dragging.
68
+
69
+ **frameRate** specifies the maximum number of times per second the plot will
70
+ update itself while the user is panning around on it (set to null to disable
71
+ intermediate pans, the plot will then not update until the mouse button is
72
+ released).
73
+
74
+ **mode** a string specifies the pan mode for mouse interaction. Accepted values:
75
+ 'manual': no pan hint or direction snapping;
76
+ 'smart': The graph shows pan hint bar and the pan movement will snap
77
+ to one direction when the drag direction is close to it;
78
+ 'smartLock'. The graph shows pan hint bar and the pan movement will always
79
+ snap to a direction that the drag diorection started with.
80
+
81
+ Example API usage:
82
+ ```js
83
+ plot = $.plot(...);
84
+
85
+ // zoom default amount in on the pixel ( 10, 20 )
86
+ plot.zoom({ center: { left: 10, top: 20 } });
87
+
88
+ // zoom out again
89
+ plot.zoomOut({ center: { left: 10, top: 20 } });
90
+
91
+ // zoom 200% in on the pixel (10, 20)
92
+ plot.zoom({ amount: 2, center: { left: 10, top: 20 } });
93
+
94
+ // pan 100 pixels to the left (changing x-range in a positive way) and 20 down
95
+ plot.pan({ left: -100, top: 20 })
96
+ ```
97
+
98
+ Here, "center" specifies where the center of the zooming should happen. Note
99
+ that this is defined in pixel space, not the space of the data points (you can
100
+ use the p2c helpers on the axes in Flot to help you convert between these).
101
+
102
+ **amount** is the amount to zoom the viewport relative to the current range, so
103
+ 1 is 100% (i.e. no change), 1.5 is 150% (zoom in), 0.7 is 70% (zoom out). You
104
+ can set the default in the options.
105
+ */
106
+
107
+ /* eslint-enable */
108
+ import { plugins } from './jquery.flot.js';
109
+ import { saturated } from './jquery.flot.saturated.js';
110
+ import { browser } from './jquery.flot.browser.js';
111
+ import { uiConstants } from './jquery.flot.uiConstants.js';
112
+ import { bind, unbind, trigger, css } from './helpers.js';
113
+
114
+ 'use strict';
115
+
116
+ var options = {
117
+ zoom: {
118
+ interactive: false,
119
+ active: false,
120
+ amount: 1.5 // how much to zoom relative to current position, 2 = 200% (zoom in), 0.5 = 50% (zoom out)
121
+ },
122
+ pan: {
123
+ interactive: false,
124
+ active: false,
125
+ cursor: "move",
126
+ frameRate: 60,
127
+ mode: 'smart'
128
+ },
129
+ recenter: {
130
+ interactive: true
131
+ },
132
+ xaxis: {
133
+ axisZoom: true, //zoom axis when mouse over it is allowed
134
+ plotZoom: true, //zoom axis is allowed for plot zoom
135
+ axisPan: true, //pan axis when mouse over it is allowed
136
+ plotPan: true, //pan axis is allowed for plot pan
137
+ panRange: [undefined, undefined], // no limit on pan range, or [min, max] in axis units
138
+ zoomRange: [undefined, undefined] // no limit on zoom range, or [closest zoom, furthest zoom] in axis units
139
+ },
140
+ yaxis: {
141
+ axisZoom: true,
142
+ plotZoom: true,
143
+ axisPan: true,
144
+ plotPan: true,
145
+ panRange: [undefined, undefined], // no limit on pan range, or [min, max] in axis units
146
+ zoomRange: [undefined, undefined] // no limit on zoom range, or [closest zoom, furthest zoom] in axis units
147
+ }
148
+ };
149
+
150
+ var SNAPPING_CONSTANT = uiConstants.SNAPPING_CONSTANT;
151
+ var PANHINT_LENGTH_CONSTANT = uiConstants.PANHINT_LENGTH_CONSTANT;
152
+
153
+ function init(plot) {
154
+ plot.hooks.processOptions.push(initNevigation);
155
+ }
156
+
157
+ function initNevigation(plot, options) {
158
+ var panAxes = null;
159
+ var canDrag = false;
160
+ var useManualPan = options.pan.mode === 'manual',
161
+ smartPanLock = options.pan.mode === 'smartLock',
162
+ useSmartPan = smartPanLock || options.pan.mode === 'smart';
163
+
164
+ function onZoomClick(e, zoomOut, amount) {
165
+ var page = browser.getPageXY(e);
166
+
167
+ var c = plot.offset();
168
+ c.left = page.X - c.left;
169
+ c.top = page.Y - c.top;
170
+
171
+ var placeholderRect = plot.getPlaceholder().getBoundingClientRect();
172
+ var ec = { left: placeholderRect.left + window.scrollX, top: placeholderRect.top + window.scrollY };
173
+ ec.left = page.X - ec.left;
174
+ ec.top = page.Y - ec.top;
175
+
176
+ var axes = plot.getXAxes().concat(plot.getYAxes()).filter(function (axis) {
177
+ var box = axis.box;
178
+ if (box !== undefined) {
179
+ return (ec.left > box.left) && (ec.left < box.left + box.width) &&
180
+ (ec.top > box.top) && (ec.top < box.top + box.height);
181
+ }
182
+ });
183
+
184
+ if (axes.length === 0) {
185
+ axes = undefined;
186
+ }
187
+
188
+ if (zoomOut) {
189
+ plot.zoomOut({
190
+ center: c,
191
+ axes: axes,
192
+ amount: amount
193
+ });
194
+ } else {
195
+ plot.zoom({
196
+ center: c,
197
+ axes: axes,
198
+ amount: amount
199
+ });
200
+ }
201
+ }
202
+
203
+ var prevCursor = 'default',
204
+ panHint = null,
205
+ panTimeout = null,
206
+ plotState,
207
+ prevDragPosition = { x: 0, y: 0 },
208
+ isPanAction = false;
209
+
210
+ function onMouseWheel(e) {
211
+ var delta = -e.deltaY;
212
+ var maxAbsoluteDeltaOnMac = 1,
213
+ isMacScroll = Math.abs(e.deltaY) <= maxAbsoluteDeltaOnMac,
214
+ defaultNonMacScrollAmount = null,
215
+ macMagicRatio = 50,
216
+ amount = isMacScroll ? 1 + Math.abs(e.deltaY) / macMagicRatio : defaultNonMacScrollAmount;
217
+
218
+ if (isPanAction) {
219
+ onDragEnd(e);
220
+ }
221
+
222
+ if (plot.getOptions().zoom.active) {
223
+ e.preventDefault();
224
+ onZoomClick(e, delta < 0, amount);
225
+ return false;
226
+ }
227
+ }
228
+
229
+ plot.navigationState = function(startPageX, startPageY) {
230
+ var axes = this.getAxes();
231
+ var result = {};
232
+ Object.keys(axes).forEach(function(axisName) {
233
+ var axis = axes[axisName];
234
+ result[axisName] = {
235
+ navigationOffset: { below: axis.options.offset.below || 0,
236
+ above: axis.options.offset.above || 0},
237
+ axisMin: axis.min,
238
+ axisMax: axis.max,
239
+ diagMode: false
240
+ }
241
+ });
242
+
243
+ result.startPageX = startPageX || 0;
244
+ result.startPageY = startPageY || 0;
245
+ return result;
246
+ }
247
+
248
+ function onDragStart(e) {
249
+
250
+ isPanAction = true;
251
+ var page = browser.getPageXY(e);
252
+
253
+ var placeholderRect = plot.getPlaceholder().getBoundingClientRect();
254
+ var ec = { left: placeholderRect.left + window.scrollX, top: placeholderRect.top + window.scrollY };
255
+ ec.left = page.X - ec.left;
256
+ ec.top = page.Y - ec.top;
257
+
258
+ panAxes = plot.getXAxes().concat(plot.getYAxes()).filter(function (axis) {
259
+ var box = axis.box;
260
+ if (box !== undefined) {
261
+ return (ec.left > box.left) && (ec.left < box.left + box.width) &&
262
+ (ec.top > box.top) && (ec.top < box.top + box.height);
263
+ }
264
+ });
265
+
266
+ if (panAxes.length === 0) {
267
+ panAxes = undefined;
268
+ }
269
+
270
+ var c = css(plot.getPlaceholder(), 'cursor');
271
+ if (c) {
272
+ prevCursor = c;
273
+ }
274
+
275
+ css(plot.getPlaceholder(), 'cursor', plot.getOptions().pan.cursor);
276
+
277
+ if (useSmartPan) {
278
+ plotState = plot.navigationState(page.X, page.Y);
279
+ } else if (useManualPan) {
280
+ prevDragPosition.x = page.X;
281
+ prevDragPosition.y = page.Y;
282
+ }
283
+ }
284
+
285
+ function onDrag(e) {
286
+ if (!isPanAction) {
287
+ return;
288
+ }
289
+
290
+ var page = browser.getPageXY(e);
291
+ var frameRate = plot.getOptions().pan.frameRate;
292
+
293
+ if (frameRate === -1) {
294
+ if (useSmartPan) {
295
+ plot.smartPan({
296
+ x: plotState.startPageX - page.X,
297
+ y: plotState.startPageY - page.Y
298
+ }, plotState, panAxes, false, smartPanLock);
299
+ } else if (useManualPan) {
300
+ plot.pan({
301
+ left: prevDragPosition.x - page.X,
302
+ top: prevDragPosition.y - page.Y,
303
+ axes: panAxes
304
+ });
305
+ prevDragPosition.x = page.X;
306
+ prevDragPosition.y = page.Y;
307
+ }
308
+ return;
309
+ }
310
+
311
+ if (panTimeout || !frameRate) return;
312
+
313
+ panTimeout = window.setTimeout(function() {
314
+ if (useSmartPan) {
315
+ plot.smartPan({
316
+ x: plotState.startPageX - page.X,
317
+ y: plotState.startPageY - page.Y
318
+ }, plotState, panAxes, false, smartPanLock);
319
+ } else if (useManualPan) {
320
+ plot.pan({
321
+ left: prevDragPosition.x - page.X,
322
+ top: prevDragPosition.y - page.Y,
323
+ axes: panAxes
324
+ });
325
+ prevDragPosition.x = page.X;
326
+ prevDragPosition.y = page.Y;
327
+ }
328
+
329
+ panTimeout = null;
330
+ }, 1 / frameRate * 1000);
331
+ }
332
+
333
+ function onDragEnd(e) {
334
+ if (!isPanAction) {
335
+ return;
336
+ }
337
+
338
+ if (panTimeout) {
339
+ window.clearTimeout(panTimeout);
340
+ panTimeout = null;
341
+ }
342
+
343
+ isPanAction = false;
344
+ var page = browser.getPageXY(e);
345
+
346
+ css(plot.getPlaceholder(), 'cursor', prevCursor);
347
+
348
+ if (useSmartPan) {
349
+ plot.smartPan({
350
+ x: plotState.startPageX - page.X,
351
+ y: plotState.startPageY - page.Y
352
+ }, plotState, panAxes, false, smartPanLock);
353
+ plot.smartPan.end();
354
+ } else if (useManualPan) {
355
+ plot.pan({
356
+ left: prevDragPosition.x - page.X,
357
+ top: prevDragPosition.y - page.Y,
358
+ axes: panAxes
359
+ });
360
+ prevDragPosition.x = 0;
361
+ prevDragPosition.y = 0;
362
+ }
363
+ }
364
+
365
+ function onDblClick(e) {
366
+ plot.activate();
367
+ var o = plot.getOptions()
368
+
369
+ if (!o.recenter.interactive) { return; }
370
+
371
+ var axes = plot.getTouchedAxis(e.clientX, e.clientY);
372
+
373
+ plot.recenter({ axes: axes[0] ? axes : null });
374
+
375
+ if (axes[0]) {
376
+ trigger(plot.getPlaceholder(), 're-center', { axisTouched: axes[0] });
377
+ } else {
378
+ trigger(plot.getPlaceholder(), 're-center', e);
379
+ }
380
+ }
381
+
382
+ function onClick(e) {
383
+ plot.activate();
384
+
385
+ if (isPanAction) {
386
+ onDragEnd(e);
387
+ }
388
+
389
+ return false;
390
+ }
391
+
392
+ plot.activate = function() {
393
+ var o = plot.getOptions();
394
+ if (!o.pan.active || !o.zoom.active) {
395
+ o.pan.active = true;
396
+ o.zoom.active = true;
397
+ trigger(plot.getPlaceholder(), "plotactivated", [plot]);
398
+ }
399
+ }
400
+
401
+ function onPointerDown(e) {
402
+ if (e.button !== 0) return;
403
+ var el = e.currentTarget;
404
+ canDrag = true;
405
+ onDragStart(e);
406
+
407
+ function onPointerMove(e) {
408
+ onDrag(e);
409
+ }
410
+
411
+ function onPointerUp(e) {
412
+ onDragEnd(e);
413
+ canDrag = false;
414
+ el.removeEventListener("pointermove", onPointerMove);
415
+ el.removeEventListener("pointerup", onPointerUp);
416
+ el.removeEventListener("pointercancel", onPointerUp);
417
+ el.releasePointerCapture(e.pointerId);
418
+ }
419
+
420
+ el.setPointerCapture(e.pointerId);
421
+ el.addEventListener("pointermove", onPointerMove);
422
+ el.addEventListener("pointerup", onPointerUp);
423
+ el.addEventListener("pointercancel", onPointerUp);
424
+ }
425
+
426
+ function bindEvents(plot, eventHolder) {
427
+ var o = plot.getOptions();
428
+ if (o.zoom.interactive) {
429
+ bind(eventHolder, "wheel", onMouseWheel);
430
+ }
431
+
432
+ if (o.pan.interactive) {
433
+ bind(eventHolder, "pointerdown", onPointerDown);
434
+ }
435
+
436
+ bind(eventHolder, "dblclick", onDblClick);
437
+ bind(eventHolder, "click", onClick);
438
+ }
439
+
440
+ plot.zoomOut = function(args) {
441
+ if (!args) {
442
+ args = {};
443
+ }
444
+
445
+ if (!args.amount) {
446
+ args.amount = plot.getOptions().zoom.amount;
447
+ }
448
+
449
+ args.amount = 1 / args.amount;
450
+ plot.zoom(args);
451
+ };
452
+
453
+ plot.zoom = function(args) {
454
+ if (!args) {
455
+ args = {};
456
+ }
457
+
458
+ var c = args.center,
459
+ amount = args.amount || plot.getOptions().zoom.amount,
460
+ w = plot.width(),
461
+ h = plot.height(),
462
+ axes = args.axes || plot.getAxes();
463
+
464
+ if (!c) {
465
+ c = {
466
+ left: w / 2,
467
+ top: h / 2
468
+ };
469
+ }
470
+
471
+ var xf = c.left / w,
472
+ yf = c.top / h,
473
+ minmax = {
474
+ x: {
475
+ min: c.left - xf * w / amount,
476
+ max: c.left + (1 - xf) * w / amount
477
+ },
478
+ y: {
479
+ min: c.top - yf * h / amount,
480
+ max: c.top + (1 - yf) * h / amount
481
+ }
482
+ };
483
+
484
+ for (var key in axes) {
485
+ if (!axes.hasOwnProperty(key)) {
486
+ continue;
487
+ }
488
+
489
+ var axis = axes[key],
490
+ opts = axis.options,
491
+ min = minmax[axis.direction].min,
492
+ max = minmax[axis.direction].max,
493
+ navigationOffset = axis.options.offset;
494
+
495
+ //skip axis without axisZoom when zooming only on certain axis or axis without plotZoom for zoom on entire plot
496
+ if ((!opts.axisZoom && args.axes) || (!args.axes && !opts.plotZoom)) {
497
+ continue;
498
+ }
499
+
500
+ min = saturated.saturate(axis.c2p(min));
501
+ max = saturated.saturate(axis.c2p(max));
502
+ if (min > max) {
503
+ // make sure min < max
504
+ var tmp = min;
505
+ min = max;
506
+ max = tmp;
507
+ }
508
+
509
+ // test for zoom limits zoomRange: [min,max]
510
+ if (opts.zoomRange) {
511
+ // zoomed in too far
512
+ if (max - min < opts.zoomRange[0]) {
513
+ continue;
514
+ }
515
+ // zoomed out to far
516
+ if (max - min > opts.zoomRange[1]) {
517
+ continue;
518
+ }
519
+ }
520
+
521
+ var offsetBelow = saturated.saturate(navigationOffset.below - (axis.min - min));
522
+ var offsetAbove = saturated.saturate(navigationOffset.above - (axis.max - max));
523
+ opts.offset = { below: offsetBelow, above: offsetAbove };
524
+ };
525
+
526
+ plot.setupGrid(true);
527
+ plot.draw();
528
+
529
+ if (!args.preventEvent) {
530
+ trigger(plot.getPlaceholder(), "plotzoom", [plot, args]);
531
+ }
532
+ };
533
+
534
+ plot.pan = function(args) {
535
+ var delta = {
536
+ x: +args.left,
537
+ y: +args.top
538
+ };
539
+
540
+ if (isNaN(delta.x)) delta.x = 0;
541
+ if (isNaN(delta.y)) delta.y = 0;
542
+
543
+ var panAxesOrAll = args.axes || plot.getAxes();
544
+ Object.keys(panAxesOrAll).forEach(function(key) {
545
+ var axis = panAxesOrAll[key];
546
+ var opts = axis.options,
547
+ d = delta[axis.direction];
548
+
549
+ //skip axis without axisPan when panning only on certain axis or axis without plotPan for pan the entire plot
550
+ if ((!opts.axisPan && args.axes) || (!opts.plotPan && !args.axes)) {
551
+ return;
552
+ }
553
+
554
+ // calc min delta (revealing left edge of plot)
555
+ var minD = axis.p2c(opts.panRange[0]) - axis.p2c(axis.min);
556
+ // calc max delta (revealing right edge of plot)
557
+ var maxD = axis.p2c(opts.panRange[1]) - axis.p2c(axis.max);
558
+ // limit delta to min or max if enabled
559
+ if (opts.panRange[0] !== undefined && d >= maxD) d = maxD;
560
+ if (opts.panRange[1] !== undefined && d <= minD) d = minD;
561
+
562
+ if (d !== 0) {
563
+ var navigationOffsetBelow = saturated.saturate(axis.c2p(axis.p2c(axis.min) + d) - axis.c2p(axis.p2c(axis.min))),
564
+ navigationOffsetAbove = saturated.saturate(axis.c2p(axis.p2c(axis.max) + d) - axis.c2p(axis.p2c(axis.max)));
565
+
566
+ if (!isFinite(navigationOffsetBelow)) {
567
+ navigationOffsetBelow = 0;
568
+ }
569
+
570
+ if (!isFinite(navigationOffsetAbove)) {
571
+ navigationOffsetAbove = 0;
572
+ }
573
+
574
+ opts.offset = {
575
+ below: saturated.saturate(navigationOffsetBelow + (opts.offset.below || 0)),
576
+ above: saturated.saturate(navigationOffsetAbove + (opts.offset.above || 0))
577
+ };
578
+ }
579
+ });
580
+
581
+ plot.setupGrid(true);
582
+ plot.draw();
583
+ if (!args.preventEvent) {
584
+ trigger(plot.getPlaceholder(), "plotpan", [plot, args]);
585
+ }
586
+ };
587
+
588
+ plot.recenter = function(args) {
589
+ var recenterAxes = args.axes || plot.getAxes();
590
+ Object.keys(recenterAxes).forEach(function(key) {
591
+ var axis = recenterAxes[key];
592
+ if (args.axes) {
593
+ if (axis.direction === 'x') {
594
+ axis.options.offset = { below: 0 };
595
+ } else if (axis.direction === 'y') {
596
+ axis.options.offset = { above: 0 };
597
+ }
598
+ } else {
599
+ axis.options.offset = { below: 0, above: 0 };
600
+ }
601
+ });
602
+ plot.setupGrid(true);
603
+ plot.draw();
604
+ };
605
+
606
+ var shouldSnap = function(delta) {
607
+ return (Math.abs(delta.y) < SNAPPING_CONSTANT && Math.abs(delta.x) >= SNAPPING_CONSTANT) ||
608
+ (Math.abs(delta.x) < SNAPPING_CONSTANT && Math.abs(delta.y) >= SNAPPING_CONSTANT);
609
+ }
610
+
611
+ // adjust delta so the pan action is constrained on the vertical or horizontal direction
612
+ // it the movements in the other direction are small
613
+ var adjustDeltaToSnap = function(delta) {
614
+ if (Math.abs(delta.x) < SNAPPING_CONSTANT && Math.abs(delta.y) >= SNAPPING_CONSTANT) {
615
+ return {x: 0, y: delta.y};
616
+ }
617
+
618
+ if (Math.abs(delta.y) < SNAPPING_CONSTANT && Math.abs(delta.x) >= SNAPPING_CONSTANT) {
619
+ return {x: delta.x, y: 0};
620
+ }
621
+
622
+ return delta;
623
+ }
624
+
625
+ var lockedDirection = null;
626
+ var lockDeltaDirection = function(delta) {
627
+ if (!lockedDirection && Math.max(Math.abs(delta.x), Math.abs(delta.y)) >= SNAPPING_CONSTANT) {
628
+ lockedDirection = Math.abs(delta.x) < Math.abs(delta.y) ? 'y' : 'x';
629
+ }
630
+
631
+ switch (lockedDirection) {
632
+ case 'x':
633
+ return { x: delta.x, y: 0 };
634
+ case 'y':
635
+ return { x: 0, y: delta.y };
636
+ default:
637
+ return { x: 0, y: 0 };
638
+ }
639
+ }
640
+
641
+ var isDiagonalMode = function(delta) {
642
+ if (Math.abs(delta.x) > 0 && Math.abs(delta.y) > 0) {
643
+ return true;
644
+ }
645
+ return false;
646
+ }
647
+
648
+ var restoreAxisOffset = function(axes, initialState, delta) {
649
+ var axis;
650
+ Object.keys(axes).forEach(function(axisName) {
651
+ axis = axes[axisName];
652
+ if (delta[axis.direction] === 0) {
653
+ axis.options.offset.below = initialState[axisName].navigationOffset.below;
654
+ axis.options.offset.above = initialState[axisName].navigationOffset.above;
655
+ }
656
+ });
657
+ }
658
+
659
+ var prevDelta = { x: 0, y: 0 };
660
+ plot.smartPan = function(delta, initialState, panAxes, preventEvent, smartLock) {
661
+ var snap = smartLock ? true : shouldSnap(delta),
662
+ axes = plot.getAxes(),
663
+ opts;
664
+ delta = smartLock ? lockDeltaDirection(delta) : adjustDeltaToSnap(delta);
665
+
666
+ if (isDiagonalMode(delta)) {
667
+ initialState.diagMode = true;
668
+ }
669
+
670
+ if (snap && initialState.diagMode === true) {
671
+ initialState.diagMode = false;
672
+ restoreAxisOffset(axes, initialState, delta);
673
+ }
674
+
675
+ if (snap) {
676
+ panHint = {
677
+ start: {
678
+ x: initialState.startPageX - plot.offset().left + plot.getPlotOffset().left,
679
+ y: initialState.startPageY - plot.offset().top + plot.getPlotOffset().top
680
+ },
681
+ end: {
682
+ x: initialState.startPageX - delta.x - plot.offset().left + plot.getPlotOffset().left,
683
+ y: initialState.startPageY - delta.y - plot.offset().top + plot.getPlotOffset().top
684
+ }
685
+ }
686
+ } else {
687
+ panHint = {
688
+ start: {
689
+ x: initialState.startPageX - plot.offset().left + plot.getPlotOffset().left,
690
+ y: initialState.startPageY - plot.offset().top + plot.getPlotOffset().top
691
+ },
692
+ end: false
693
+ }
694
+ }
695
+
696
+ if (isNaN(delta.x)) delta.x = 0;
697
+ if (isNaN(delta.y)) delta.y = 0;
698
+
699
+ if (panAxes) {
700
+ axes = panAxes;
701
+ }
702
+
703
+ var axis, axisMin, axisMax, p, d;
704
+ Object.keys(axes).forEach(function(axisName) {
705
+ axis = axes[axisName];
706
+ axisMin = axis.min;
707
+ axisMax = axis.max;
708
+ opts = axis.options;
709
+
710
+ d = delta[axis.direction];
711
+ p = prevDelta[axis.direction];
712
+
713
+ //skip axis without axisPan when panning only on certain axis or axis without plotPan for pan the entire plot
714
+ if ((!opts.axisPan && panAxes) || (!panAxes && !opts.plotPan)) {
715
+ return;
716
+ }
717
+
718
+ // calc min delta (revealing left edge of plot)
719
+ var minD = p + axis.p2c(opts.panRange[0]) - axis.p2c(axisMin);
720
+ // calc max delta (revealing right edge of plot)
721
+ var maxD = p + axis.p2c(opts.panRange[1]) - axis.p2c(axisMax);
722
+ // limit delta to min or max if enabled
723
+ if (opts.panRange[0] !== undefined && d >= maxD) d = maxD;
724
+ if (opts.panRange[1] !== undefined && d <= minD) d = minD;
725
+
726
+ if (d !== 0) {
727
+ var navigationOffsetBelow = saturated.saturate(axis.c2p(axis.p2c(axisMin) - (p - d)) - axis.c2p(axis.p2c(axisMin))),
728
+ navigationOffsetAbove = saturated.saturate(axis.c2p(axis.p2c(axisMax) - (p - d)) - axis.c2p(axis.p2c(axisMax)));
729
+
730
+ if (!isFinite(navigationOffsetBelow)) {
731
+ navigationOffsetBelow = 0;
732
+ }
733
+
734
+ if (!isFinite(navigationOffsetAbove)) {
735
+ navigationOffsetAbove = 0;
736
+ }
737
+
738
+ axis.options.offset.below = saturated.saturate(navigationOffsetBelow + (axis.options.offset.below || 0));
739
+ axis.options.offset.above = saturated.saturate(navigationOffsetAbove + (axis.options.offset.above || 0));
740
+ }
741
+ });
742
+
743
+ prevDelta = delta;
744
+ plot.setupGrid(true);
745
+ plot.draw();
746
+
747
+ if (!preventEvent) {
748
+ trigger(plot.getPlaceholder(), "plotpan", [plot, delta, panAxes, initialState]);
749
+ }
750
+ };
751
+
752
+ plot.smartPan.end = function() {
753
+ panHint = null;
754
+ lockedDirection = null;
755
+ prevDelta = { x: 0, y: 0 };
756
+ plot.triggerRedrawOverlay();
757
+ }
758
+
759
+ function shutdown(plot, eventHolder) {
760
+ unbind(eventHolder, "wheel", onMouseWheel);
761
+ unbind(eventHolder, "pointerdown", onPointerDown);
762
+ unbind(eventHolder, "dblclick", onDblClick);
763
+ unbind(eventHolder, "click", onClick);
764
+
765
+ if (panTimeout) window.clearTimeout(panTimeout);
766
+ }
767
+
768
+ function drawOverlay(plot, ctx) {
769
+ if (panHint) {
770
+ ctx.strokeStyle = 'rgba(96, 160, 208, 0.7)';
771
+ ctx.lineWidth = 2;
772
+ ctx.lineJoin = "round";
773
+ var startx = Math.round(panHint.start.x),
774
+ starty = Math.round(panHint.start.y),
775
+ endx, endy;
776
+
777
+ if (panAxes) {
778
+ if (panAxes[0].direction === 'x') {
779
+ endy = Math.round(panHint.start.y);
780
+ endx = Math.round(panHint.end.x);
781
+ } else if (panAxes[0].direction === 'y') {
782
+ endx = Math.round(panHint.start.x);
783
+ endy = Math.round(panHint.end.y);
784
+ }
785
+ } else {
786
+ endx = Math.round(panHint.end.x);
787
+ endy = Math.round(panHint.end.y);
788
+ }
789
+
790
+ ctx.beginPath();
791
+
792
+ if (panHint.end === false) {
793
+ ctx.moveTo(startx, starty - PANHINT_LENGTH_CONSTANT);
794
+ ctx.lineTo(startx, starty + PANHINT_LENGTH_CONSTANT);
795
+
796
+ ctx.moveTo(startx + PANHINT_LENGTH_CONSTANT, starty);
797
+ ctx.lineTo(startx - PANHINT_LENGTH_CONSTANT, starty);
798
+ } else {
799
+ var dirX = starty === endy;
800
+
801
+ ctx.moveTo(startx - (dirX ? 0 : PANHINT_LENGTH_CONSTANT), starty - (dirX ? PANHINT_LENGTH_CONSTANT : 0));
802
+ ctx.lineTo(startx + (dirX ? 0 : PANHINT_LENGTH_CONSTANT), starty + (dirX ? PANHINT_LENGTH_CONSTANT : 0));
803
+
804
+ ctx.moveTo(startx, starty);
805
+ ctx.lineTo(endx, endy);
806
+
807
+ ctx.moveTo(endx - (dirX ? 0 : PANHINT_LENGTH_CONSTANT), endy - (dirX ? PANHINT_LENGTH_CONSTANT : 0));
808
+ ctx.lineTo(endx + (dirX ? 0 : PANHINT_LENGTH_CONSTANT), endy + (dirX ? PANHINT_LENGTH_CONSTANT : 0));
809
+ }
810
+
811
+ ctx.stroke();
812
+ }
813
+ }
814
+
815
+ plot.getTouchedAxis = function(touchPointX, touchPointY) {
816
+ var placeholderRect = plot.getPlaceholder().getBoundingClientRect();
817
+ var ec = { left: placeholderRect.left + window.scrollX, top: placeholderRect.top + window.scrollY };
818
+ ec.left = touchPointX - ec.left;
819
+ ec.top = touchPointY - ec.top;
820
+
821
+ var axis = plot.getXAxes().concat(plot.getYAxes()).filter(function (axis) {
822
+ var box = axis.box;
823
+ if (box !== undefined) {
824
+ return (ec.left > box.left) && (ec.left < box.left + box.width) &&
825
+ (ec.top > box.top) && (ec.top < box.top + box.height);
826
+ }
827
+ });
828
+
829
+ return axis;
830
+ }
831
+
832
+ plot.hooks.drawOverlay.push(drawOverlay);
833
+ plot.hooks.bindEvents.push(bindEvents);
834
+ plot.hooks.shutdown.push(shutdown);
835
+ }
836
+
837
+ plugins.push({
838
+ init: init,
839
+ options: options,
840
+ name: 'navigate',
841
+ version: '1.3'
842
+ });