@kevinburke/flot 5.1.1 → 5.1.3

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 (40) hide show
  1. package/CHANGELOG.md +62 -0
  2. package/dist/flot.js +47 -28
  3. package/dist/flot.min.js +1 -1
  4. package/dist/flot.min.js.map +1 -1
  5. package/dist/flot.mjs +47 -28
  6. package/dist/jquery.flot.js +94 -31
  7. package/dist/jquery.flot.min.js +1 -1
  8. package/dist/jquery.flot.min.js.map +1 -1
  9. package/dist/plugins/jquery.flot.crosshair.js +2 -2
  10. package/dist/plugins/jquery.flot.crosshair.min.js +1 -1
  11. package/dist/plugins/jquery.flot.image.js +6 -6
  12. package/dist/plugins/jquery.flot.image.min.js +1 -1
  13. package/dist/plugins/jquery.flot.image.min.js.map +1 -1
  14. package/dist/plugins/jquery.flot.pie.js +4 -4
  15. package/dist/plugins/jquery.flot.pie.min.js +1 -1
  16. package/dist/plugins/jquery.flot.pie.min.js.map +1 -1
  17. package/dist/plugins/jquery.flot.resize.js +2 -2
  18. package/dist/plugins/jquery.flot.resize.min.js +1 -1
  19. package/dist/plugins/jquery.flot.resize.min.js.map +1 -1
  20. package/dist/plugins/jquery.flot.threshold.js +2 -2
  21. package/dist/plugins/jquery.flot.threshold.min.js +1 -1
  22. package/package.json +1 -1
  23. package/source/globals.d.ts +5 -0
  24. package/source/helpers.js +16 -4
  25. package/source/jquery-adapter.js +27 -2
  26. package/source/jquery.canvaswrapper.js +8 -4
  27. package/source/jquery.flot.browser.js +1 -1
  28. package/source/jquery.flot.composeImages.js +1 -1
  29. package/source/jquery.flot.hover.js +4 -4
  30. package/source/jquery.flot.image.js +6 -1
  31. package/source/jquery.flot.js +1 -1
  32. package/source/jquery.flot.legend.js +1 -1
  33. package/source/jquery.flot.navigate.js +1 -1
  34. package/source/jquery.flot.pie.js +2 -2
  35. package/source/jquery.flot.selection.js +3 -2
  36. package/source/jquery.flot.time.js +3 -3
  37. package/source/jquery.flot.touch.js +6 -1
  38. package/source/jquery.flot.touchNavigate.js +5 -3
  39. package/types/jquery.d.ts +2 -1
  40. package/source/jquery.js +0 -9473
@@ -35,14 +35,34 @@ import {
35
35
  dateTickGenerator,
36
36
  composeImages,
37
37
  } from './index.js';
38
+ import * as helpers from './helpers.js';
39
+ var setTrigger = helpers.setTrigger;
40
+
41
+ // Route flot's internal trigger() through jQuery so plugin handlers bound
42
+ // via $(el).on(type, fn) see the same data shape as upstream flot/flot.
43
+ // Two conventions coexist in the plugins, matching upstream:
44
+ // - trigger(el, type, [arg0, arg1, ...]) → $(el).trigger(type, [args])
45
+ // jQuery spreads the array into handler positional params, so
46
+ // function(event, pos, item, items) works (plothover, plotzoom, ...).
47
+ // - trigger(el, type, <non-array>) → $.Event(type, { detail: x })
48
+ // Handlers read event.detail, matching upstream's re-center contract
49
+ // where a plain object (or Event) is attached to event.detail.
50
+ setTrigger(function(el, type, args) {
51
+ if (args === undefined || Array.isArray(args)) {
52
+ $(el).trigger(type, args || []);
53
+ return;
54
+ }
55
+ var event = $.Event(type, { detail: args });
56
+ $(el).trigger(event);
57
+ });
38
58
 
39
59
  // Register $.plot and $.color on the jQuery object.
40
- $.plot = function(placeholder, data, options) {
60
+ $.plot = /** @type {typeof $.plot} */ (function(placeholder, data, options) {
41
61
  var el = typeof placeholder === 'string'
42
62
  ? document.querySelector(placeholder)
43
63
  : (placeholder instanceof $ ? placeholder[0] : placeholder);
44
64
  return plot(el, data, options);
45
- };
65
+ });
46
66
 
47
67
  $.plot.plugins = plugins;
48
68
  $.plot.version = version;
@@ -80,4 +100,9 @@ if (typeof window !== 'undefined') {
80
100
  window.Flot = {};
81
101
  }
82
102
  window.Flot.Canvas = Canvas;
103
+ // Exposed so standalone plugin bundles (dist/plugins/*.js) can resolve
104
+ // their `import { plugins } from './jquery.flot.js'` and
105
+ // `import { ... } from './helpers.js'` to live objects on this global.
106
+ window.Flot.plugins = plugins;
107
+ window.Flot.helpers = helpers;
83
108
  }
@@ -221,7 +221,9 @@ var Canvas = function(cls, container) {
221
221
  layer.style.left = '0px';
222
222
  layer.style.bottom = '0px';
223
223
  layer.style.right = '0px';
224
- svgElement.appendChild(layer);
224
+ if (svgElement) {
225
+ svgElement.appendChild(layer);
226
+ }
225
227
  this.SVG[classes] = layer;
226
228
  }
227
229
 
@@ -315,8 +317,8 @@ var Canvas = function(cls, container) {
315
317
 
316
318
  element.style.position = 'absolute';
317
319
  element.style.maxWidth = width;
318
- element.setAttributeNS(null, 'x', -9999);
319
- element.setAttributeNS(null, 'y', -9999);
320
+ element.setAttributeNS(null, 'x', String(-9999));
321
+ element.setAttributeNS(null, 'y', String(-9999));
320
322
 
321
323
  if (typeof font === 'object') {
322
324
  element.style.font = textStyle;
@@ -340,7 +342,9 @@ var Canvas = function(cls, container) {
340
342
  while (element.firstChild) {
341
343
  element.removeChild(element.firstChild);
342
344
  }
343
- element.parentNode.removeChild(element);
345
+ if (element.parentNode) {
346
+ element.parentNode.removeChild(element);
347
+ }
344
348
  }
345
349
 
346
350
  info.measured = true;
@@ -22,7 +22,7 @@ export var browser = {
22
22
  isSafari: function() {
23
23
  var top = window.top;
24
24
  if (!top) return false;
25
- return /constructor/i.test(top.HTMLElement) || (function (p) { return p.toString() === "[object SafariRemoteNotification]"; })(!top['safari'] || (typeof top.safari !== 'undefined' && top.safari.pushNotification));
25
+ return /constructor/i.test(/** @type {any} */ (top.HTMLElement)) || (function (/** @type {any} */ p) { return p.toString() === "[object SafariRemoteNotification]"; })(!(/** @type {any} */ (top))['safari'] || (typeof (/** @type {any} */ (top)).safari !== 'undefined' && (/** @type {any} */ (top)).safari.pushNotification));
26
26
  },
27
27
 
28
28
  isMobileSafari: function() {
@@ -165,7 +165,7 @@ import { browser } from './jquery.flot.browser.js';
165
165
  const utf8Array = new Uint8Array(arrayBuffer);
166
166
  const blockSize = 16384;
167
167
  for (var i = 0; i < utf8Array.length; i = i + blockSize) {
168
- const binarySubString = String.fromCharCode.apply(null, utf8Array.subarray(i, i + blockSize));
168
+ const binarySubString = String.fromCharCode.apply(null, /** @type {any} */ (utf8Array.subarray(i, i + blockSize)));
169
169
  binaryString = binaryString + binarySubString;
170
170
  }
171
171
  return binaryString;
@@ -80,10 +80,10 @@ import { bind, unbind, trigger } from './helpers.js';
80
80
  newEvent = new CustomEvent('mouseevent');
81
81
 
82
82
  //transform from touch event to mouse event format
83
- newEvent.pageX = e.detail.changedTouches[0].pageX;
84
- newEvent.pageY = e.detail.changedTouches[0].pageY;
85
- newEvent.clientX = e.detail.changedTouches[0].clientX;
86
- newEvent.clientY = e.detail.changedTouches[0].clientY;
83
+ /** @type {any} */ (newEvent).pageX = e.detail.changedTouches[0].pageX;
84
+ /** @type {any} */ (newEvent).pageY = e.detail.changedTouches[0].pageY;
85
+ /** @type {any} */ (newEvent).clientX = e.detail.changedTouches[0].clientX;
86
+ /** @type {any} */ (newEvent).clientY = e.detail.changedTouches[0].clientY;
87
87
 
88
88
  if (o.grid.hoverable) {
89
89
  doTriggerClickHoverEvent(newEvent, eventType.hover, 30);
@@ -52,6 +52,7 @@ Google Maps).
52
52
 
53
53
  */
54
54
 
55
+ import $ from 'jquery';
55
56
  import { plugins } from './jquery.flot.js';
56
57
 
57
58
  var options = {
@@ -64,7 +65,7 @@ import { plugins } from './jquery.flot.js';
64
65
  }
65
66
  };
66
67
 
67
- export var image = {};
68
+ var image = {};
68
69
 
69
70
  image.loadDataImages = function (series, options, callback) {
70
71
  var urls = [], points = [];
@@ -250,3 +251,7 @@ import { plugins } from './jquery.flot.js';
250
251
  name: 'image',
251
252
  version: '1.1'
252
253
  });
254
+
255
+ // Expose the image helpers as $.plot.image so example code can call
256
+ // $.plot.image.loadDataImages(...) / $.plot.image.load(...).
257
+ $.plot.image = image;
@@ -2822,7 +2822,7 @@ import { drawSeries as drawSeriesModule } from './jquery.flot.drawSeries.js';
2822
2822
  // Plugin registry. Plugins push to this array to register themselves.
2823
2823
  export var plugins = [];
2824
2824
 
2825
- export var version = "5.1.1";
2825
+ export var version = "5.1.3";
2826
2826
 
2827
2827
  // The main plot function.
2828
2828
  export function plot(placeholder, data, options) {
@@ -54,7 +54,7 @@ import { plugins } from './jquery.flot.js';
54
54
 
55
55
  var left = 0;
56
56
  var columnWidths = [];
57
- var style = window.getComputedStyle(document.querySelector('body'));
57
+ var style = window.getComputedStyle(document.body);
58
58
  for (i = 0; i < entries.length; ++i) {
59
59
  let columnIndex = i % options.legend.noColumns;
60
60
  entry = entries[i];
@@ -790,7 +790,7 @@ import { bind, unbind, trigger, css } from './helpers.js';
790
790
  ctx.lineJoin = "round";
791
791
  var startx = Math.round(panHint.start.x),
792
792
  starty = Math.round(panHint.start.y),
793
- endx, endy;
793
+ endx = 0, endy = 0;
794
794
 
795
795
  if (panAxes) {
796
796
  if (panAxes[0].direction === 'x') {
@@ -660,8 +660,8 @@ import { extend, bind, unbind, trigger, width, height } from './helpers.js';
660
660
  // event fires before processDatapoints has run.
661
661
  var options = plot.getOptions();
662
662
  var offset = plot.offset();
663
- var canvasX = parseInt(e.pageX - offset.left);
664
- var canvasY = parseInt(e.pageY - offset.top);
663
+ var canvasX = parseInt(String(e.pageX - offset.left));
664
+ var canvasY = parseInt(String(e.pageY - offset.top));
665
665
  var item = findNearbySlice(canvasX, canvasY);
666
666
 
667
667
  if (options.grid.autoHighlight) {
@@ -203,6 +203,7 @@ import { bind, trigger, unbind } from './helpers.js';
203
203
  }
204
204
 
205
205
  function triggerSelectedEvent() {
206
+ /** @type {any} */
206
207
  var r = getSelection();
207
208
 
208
209
  trigger(plot.getPlaceholder(), "plotselected", [ r ]);
@@ -285,7 +286,7 @@ import { bind, trigger, unbind } from './helpers.js';
285
286
 
286
287
  // function taken from markings support in Flot
287
288
  function extractRange(ranges, coord) {
288
- var axis, from, to, key, axes = plot.getAxes();
289
+ var axis, from, to, /** @type {string|undefined} */ key, axes = plot.getAxes();
289
290
 
290
291
  for (var k in axes) {
291
292
  axis = axes[k];
@@ -305,7 +306,7 @@ import { bind, trigger, unbind } from './helpers.js';
305
306
  }
306
307
 
307
308
  // backwards-compat stuff - to be removed in future
308
- if (!ranges[key]) {
309
+ if (key && !ranges[key]) {
309
310
  axis = coord === "x" ? plot.getXAxes()[0] : plot.getYAxes()[0];
310
311
  from = ranges[coord + "1"];
311
312
  to = ranges[coord + "2"];
@@ -329,9 +329,9 @@ import { saturated } from './jquery.flot.saturated.js';
329
329
  }
330
330
 
331
331
  for (var i = 0; i < spec.length - 1; ++i) {
332
- if (axis.delta < (spec[i][0] * timeUnitSize[spec[i][1]] +
333
- spec[i + 1][0] * timeUnitSize[spec[i + 1][1]]) / 2 &&
334
- spec[i][0] * timeUnitSize[spec[i][1]] >= minSize) {
332
+ if (axis.delta < (Number(spec[i][0]) * timeUnitSize[spec[i][1]] +
333
+ Number(spec[i + 1][0]) * timeUnitSize[spec[i + 1][1]]) / 2 &&
334
+ Number(spec[i][0]) * timeUnitSize[spec[i][1]] >= minSize) {
335
335
  break;
336
336
  }
337
337
  }
@@ -14,6 +14,7 @@ import { plugins } from './jquery.flot.js';
14
14
  }
15
15
 
16
16
  function initTouchNavigation(plot, options) {
17
+ /** @type {{ twoTouches: boolean, currentTapStart: {x: number, y: number}, currentTapEnd: {x: number, y: number}, prevTap: {x: number, y: number}, currentTap: {x: number, y: number}, interceptedLongTap: boolean, isUnsupportedGesture: boolean, prevTapTime: number | null, tapStartTime: number | null, longTapTriggerId: ReturnType<typeof setTimeout> | null }} */
17
18
  var gestureState = {
18
19
  twoTouches: false,
19
20
  currentTapStart: { x: 0, y: 0 },
@@ -167,6 +168,7 @@ import { plugins } from './jquery.flot.js';
167
168
  },
168
169
 
169
170
  isLongTap: function(e) {
171
+ if (gestureState.tapStartTime == null) return false;
170
172
  var currentTime = new Date().getTime(),
171
173
  tapDuration = currentTime - gestureState.tapStartTime;
172
174
  if (tapDuration >= minLongTapDuration && !gestureState.interceptedLongTap) {
@@ -207,6 +209,7 @@ import { plugins } from './jquery.flot.js';
207
209
  },
208
210
 
209
211
  isTap: function(e) {
212
+ if (gestureState.tapStartTime == null) return false;
210
213
  var currentTime = new Date().getTime(),
211
214
  tapDuration = currentTime - gestureState.tapStartTime;
212
215
  if (tapDuration <= pressedTapDuration) {
@@ -259,7 +262,9 @@ import { plugins } from './jquery.flot.js';
259
262
 
260
263
  function isDoubleTap(e) {
261
264
  var currentTime = new Date().getTime(),
262
- intervalBetweenTaps = currentTime - gestureState.prevTapTime;
265
+ intervalBetweenTaps = gestureState.prevTapTime != null
266
+ ? currentTime - gestureState.prevTapTime
267
+ : Infinity;
263
268
 
264
269
  if (intervalBetweenTaps >= 0 && intervalBetweenTaps < maxIntervalBetweenTaps) {
265
270
  if (distance(gestureState.prevTap.x, gestureState.prevTap.y, gestureState.currentTap.x, gestureState.currentTap.y) < maxDistanceBetweenTaps) {
@@ -24,6 +24,7 @@ import { trigger } from './helpers.js';
24
24
  }
25
25
 
26
26
  function initTouchNavigation(plot, options) {
27
+ /** @type {{ zoomEnable: boolean, prevDistance: number | null, prevTapTime: number, prevPanPosition: {x: number, y: number}, prevTapPosition: {x: number, y: number} }} */
27
28
  var gestureState = {
28
29
  zoomEnable: false,
29
30
  prevDistance: null,
@@ -31,6 +32,7 @@ import { trigger } from './helpers.js';
31
32
  prevPanPosition: { x: 0, y: 0 },
32
33
  prevTapPosition: { x: 0, y: 0 }
33
34
  },
35
+ /** @type {{ prevTouchedAxis: string, currentTouchedAxis: string, touchedAxis: any, navigationConstraint: string, initialState: any }} */
34
36
  navigationState = {
35
37
  prevTouchedAxis: 'none',
36
38
  currentTouchedAxis: 'none',
@@ -87,7 +89,7 @@ import { trigger } from './helpers.js';
87
89
  drag: function(e) {
88
90
  presetNavigationState(e, 'pan', gestureState);
89
91
 
90
- if (useSmartPan) {
92
+ if (useSmartPan && navigationState.initialState) {
91
93
  var point = getPoint(e, 'pan');
92
94
  plot.smartPan({
93
95
  x: navigationState.initialState.startPageX - point.x,
@@ -111,7 +113,7 @@ import { trigger } from './helpers.js';
111
113
  }
112
114
 
113
115
  if (wasPinchEvent(e, gestureState)) {
114
- updateprevPanPosition(e, 'pan', gestureState, navigationState);
116
+ updatePrevPanPosition(e, 'pan', gestureState, navigationState);
115
117
  }
116
118
  }
117
119
  };
@@ -143,7 +145,7 @@ import { trigger } from './helpers.js';
143
145
 
144
146
  var dist = pinchDistance(e);
145
147
 
146
- if (gestureState.zoomEnable || Math.abs(dist - gestureState.prevDistance) > ZOOM_DISTANCE_MARGIN) {
148
+ if (gestureState.zoomEnable || (gestureState.prevDistance != null && Math.abs(dist - gestureState.prevDistance) > ZOOM_DISTANCE_MARGIN)) {
147
149
  zoomPlot(plot, e, gestureState, navigationState);
148
150
 
149
151
  //activate zoom mode
package/types/jquery.d.ts CHANGED
@@ -23,11 +23,12 @@ declare global {
23
23
  dateGenerator: unknown;
24
24
  dateTickGenerator: unknown;
25
25
  composeImages: unknown;
26
+ image?: unknown;
26
27
  };
27
28
  color: {
28
29
  make(r: number, g: number, b: number, a?: number): unknown;
29
30
  parse(str: string): unknown;
30
- extract(elem: JQuery, cssProp: string): unknown;
31
+ extract(elem: HTMLElement | JQuery, cssProp: string): unknown;
31
32
  };
32
33
  }
33
34