@kevinburke/flot 5.1.1 → 5.1.2

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.
package/CHANGELOG.md CHANGED
@@ -5,6 +5,30 @@ All notable changes to this project will be documented in this file.
5
5
  Starting with 5.0.0, this changelog tracks the @kevinburke/flot fork.
6
6
  For earlier upstream history, see the [flot/flot repository](https://github.com/flot/flot).
7
7
 
8
+ ## [5.1.2] - 2026-04-22
9
+
10
+ ### Fixed
11
+
12
+ - `jquery-adapter.js`: restore upstream flot/flot event-dispatch
13
+ semantics for consumers using `@kevinburke/flot/jquery` (or the
14
+ `jquery.flot.min.js` bundle). In 5.0.0, the fork's core switched to
15
+ native `CustomEvent` with extra args stashed on `event.detail`. That
16
+ is correct for the jQuery-free core, but broke every handler bound
17
+ through jQuery — `$(el).on("plothover", function(event, pos, item))`
18
+ silently received `undefined` for `pos` and `item`, because native
19
+ `dispatchEvent` does not spread args into jQuery handler positional
20
+ parameters. Same for `plotclick`, `plotselected`, `plotunselected`,
21
+ `plotselecting`, `plotzoom`, `plotpan`, `plotactivated`, and the pie
22
+ plugin's events.
23
+ Fixed by adding a `setTrigger()` hook in `helpers.js` and having the
24
+ jQuery adapter install a jQuery-aware trigger: arrays are dispatched
25
+ as `$(el).trigger(type, args)` (spreading into handler params);
26
+ non-array args are wrapped in a `$.Event` with `detail`, matching
27
+ upstream's `re-center` contract. The jQuery-free core path is
28
+ unchanged.
29
+ Added a browser regression test (`plothover handler receives pos
30
+ and item positional args`) that would have caught this.
31
+
8
32
  ## [5.1.1] - 2026-04-15
9
33
 
10
34
  ### Fixed
package/dist/flot.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! @kevinburke/flot v5.1.1 | MIT License | https://github.com/kevinburke/flot */
1
+ /*! @kevinburke/flot v5.1.2 | MIT License | https://github.com/kevinburke/flot */
2
2
  var Flot = (function (exports) {
3
3
  'use strict';
4
4
 
@@ -24,7 +24,7 @@ var Flot = (function (exports) {
24
24
  isSafari: function() {
25
25
  var top = window.top;
26
26
  if (!top) return false;
27
- return /constructor/i.test(top.HTMLElement) || (function (p) { return p.toString() === "[object SafariRemoteNotification]"; })(!top['safari'] || (typeof top.safari !== 'undefined' && top.safari.pushNotification));
27
+ 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));
28
28
  },
29
29
 
30
30
  isMobileSafari: function() {
@@ -105,6 +105,9 @@ var Flot = (function (exports) {
105
105
  var keys = Object.keys(src);
106
106
  for (var k = 0; k < keys.length; k++) {
107
107
  var key = keys[k];
108
+ if (key === '__proto__' || key === 'constructor') {
109
+ continue;
110
+ }
108
111
  var val = src[key];
109
112
  if (val === undefined) {
110
113
  continue;
@@ -171,10 +174,11 @@ var Flot = (function (exports) {
171
174
  }
172
175
  }
173
176
 
174
- // Trigger a custom event on an element. Extra args are passed as the
175
- // event's `detail` property (an array). For jQuery adapter compatibility,
176
- // the adapter re-dispatches these as jQuery events so $(el).on() works.
177
- function trigger(el, type, args) {
177
+ // Default trigger: dispatches a native CustomEvent with extra args stashed
178
+ // on `event.detail` (an array). The jQuery adapter overrides this via
179
+ // setTrigger so handlers bound with $(el).on(type, fn) receive the extra
180
+ // args as positional parameters, matching upstream flot/flot behavior.
181
+ var triggerImpl = function(el, type, args) {
178
182
  var event = new CustomEvent(type, {
179
183
  detail: args || [],
180
184
  bubbles: true,
@@ -182,6 +186,10 @@ var Flot = (function (exports) {
182
186
  });
183
187
  el.dispatchEvent(event);
184
188
  return event;
189
+ };
190
+
191
+ function trigger(el, type, args) {
192
+ return triggerImpl(el, type, args);
185
193
  }
186
194
 
187
195
  // Bind an event listener, tracking it so unbindAll can remove it later.
@@ -444,7 +452,9 @@ var Flot = (function (exports) {
444
452
  layer.style.left = '0px';
445
453
  layer.style.bottom = '0px';
446
454
  layer.style.right = '0px';
447
- svgElement.appendChild(layer);
455
+ if (svgElement) {
456
+ svgElement.appendChild(layer);
457
+ }
448
458
  this.SVG[classes] = layer;
449
459
  }
450
460
 
@@ -538,8 +548,8 @@ var Flot = (function (exports) {
538
548
 
539
549
  element.style.position = 'absolute';
540
550
  element.style.maxWidth = width;
541
- element.setAttributeNS(null, 'x', -9999);
542
- element.setAttributeNS(null, 'y', -9999);
551
+ element.setAttributeNS(null, 'x', String(-9999));
552
+ element.setAttributeNS(null, 'y', String(-9999));
543
553
 
544
554
  if (typeof font === 'object') {
545
555
  element.style.font = textStyle;
@@ -563,7 +573,9 @@ var Flot = (function (exports) {
563
573
  while (element.firstChild) {
564
574
  element.removeChild(element.firstChild);
565
575
  }
566
- element.parentNode.removeChild(element);
576
+ if (element.parentNode) {
577
+ element.parentNode.removeChild(element);
578
+ }
567
579
  }
568
580
 
569
581
  info.measured = true;
@@ -4521,7 +4533,7 @@ var Flot = (function (exports) {
4521
4533
  // Plugin registry. Plugins push to this array to register themselves.
4522
4534
  var plugins = [];
4523
4535
 
4524
- var version = "5.1.1";
4536
+ var version = "5.1.2";
4525
4537
 
4526
4538
  // The main plot function.
4527
4539
  function plot(placeholder, data, options) {
@@ -6017,7 +6029,7 @@ var Flot = (function (exports) {
6017
6029
  ctx.lineJoin = "round";
6018
6030
  var startx = Math.round(panHint.start.x),
6019
6031
  starty = Math.round(panHint.start.y),
6020
- endx, endy;
6032
+ endx = 0, endy = 0;
6021
6033
 
6022
6034
  if (panAxes) {
6023
6035
  if (panAxes[0].direction === 'x') {
@@ -6782,13 +6794,14 @@ var Flot = (function (exports) {
6782
6794
  }
6783
6795
 
6784
6796
  function initTouchNavigation$1(plot, options) {
6797
+ /** @type {{ zoomEnable: boolean, prevDistance: number | null, prevTapTime: number, prevPanPosition: {x: number, y: number}, prevTapPosition: {x: number, y: number} }} */
6785
6798
  var gestureState = {
6786
6799
  zoomEnable: false,
6787
6800
  prevDistance: null,
6788
- prevTapTime: 0,
6789
6801
  prevPanPosition: { x: 0, y: 0 },
6790
6802
  prevTapPosition: { x: 0, y: 0 }
6791
6803
  },
6804
+ /** @type {{ prevTouchedAxis: string, currentTouchedAxis: string, touchedAxis: any, navigationConstraint: string, initialState: any }} */
6792
6805
  navigationState = {
6793
6806
  prevTouchedAxis: 'none',
6794
6807
  currentTouchedAxis: 'none',
@@ -6845,7 +6858,7 @@ var Flot = (function (exports) {
6845
6858
  drag: function(e) {
6846
6859
  presetNavigationState(e, 'pan');
6847
6860
 
6848
- if (useSmartPan) {
6861
+ if (useSmartPan && navigationState.initialState) {
6849
6862
  var point = getPoint(e, 'pan');
6850
6863
  plot.smartPan({
6851
6864
  x: navigationState.initialState.startPageX - point.x,
@@ -6869,7 +6882,7 @@ var Flot = (function (exports) {
6869
6882
  }
6870
6883
 
6871
6884
  if (wasPinchEvent(e, gestureState)) {
6872
- updateprevPanPosition(e, 'pan', gestureState, navigationState);
6885
+ updatePrevPanPosition(e, 'pan', gestureState, navigationState);
6873
6886
  }
6874
6887
  }
6875
6888
  };
@@ -6901,7 +6914,7 @@ var Flot = (function (exports) {
6901
6914
 
6902
6915
  var dist = pinchDistance(e);
6903
6916
 
6904
- if (gestureState.zoomEnable || Math.abs(dist - gestureState.prevDistance) > ZOOM_DISTANCE_MARGIN) {
6917
+ if (gestureState.zoomEnable || (gestureState.prevDistance != null && Math.abs(dist - gestureState.prevDistance) > ZOOM_DISTANCE_MARGIN)) {
6905
6918
  zoomPlot(plot, e, gestureState, navigationState);
6906
6919
 
6907
6920
  //activate zoom mode
@@ -7161,10 +7174,10 @@ var Flot = (function (exports) {
7161
7174
  newEvent = new CustomEvent('mouseevent');
7162
7175
 
7163
7176
  //transform from touch event to mouse event format
7164
- newEvent.pageX = e.detail.changedTouches[0].pageX;
7165
- newEvent.pageY = e.detail.changedTouches[0].pageY;
7166
- newEvent.clientX = e.detail.changedTouches[0].clientX;
7167
- newEvent.clientY = e.detail.changedTouches[0].clientY;
7177
+ /** @type {any} */ (newEvent).pageX = e.detail.changedTouches[0].pageX;
7178
+ /** @type {any} */ (newEvent).pageY = e.detail.changedTouches[0].pageY;
7179
+ /** @type {any} */ (newEvent).clientX = e.detail.changedTouches[0].clientX;
7180
+ /** @type {any} */ (newEvent).clientY = e.detail.changedTouches[0].clientY;
7168
7181
 
7169
7182
  if (o.grid.hoverable) {
7170
7183
  doTriggerClickHoverEvent(newEvent, eventType.hover, 30);
@@ -7443,6 +7456,7 @@ var Flot = (function (exports) {
7443
7456
  }
7444
7457
 
7445
7458
  function initTouchNavigation(plot, options) {
7459
+ /** @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 }} */
7446
7460
  var gestureState = {
7447
7461
  twoTouches: false,
7448
7462
  currentTapStart: { x: 0, y: 0 },
@@ -7596,6 +7610,7 @@ var Flot = (function (exports) {
7596
7610
  },
7597
7611
 
7598
7612
  isLongTap: function(e) {
7613
+ if (gestureState.tapStartTime == null) return false;
7599
7614
  var currentTime = new Date().getTime(),
7600
7615
  tapDuration = currentTime - gestureState.tapStartTime;
7601
7616
  if (tapDuration >= minLongTapDuration && !gestureState.interceptedLongTap) {
@@ -7636,6 +7651,7 @@ var Flot = (function (exports) {
7636
7651
  },
7637
7652
 
7638
7653
  isTap: function(e) {
7654
+ if (gestureState.tapStartTime == null) return false;
7639
7655
  var currentTime = new Date().getTime(),
7640
7656
  tapDuration = currentTime - gestureState.tapStartTime;
7641
7657
  if (tapDuration <= pressedTapDuration) {
@@ -7684,7 +7700,9 @@ var Flot = (function (exports) {
7684
7700
  }
7685
7701
  function isDoubleTap(e) {
7686
7702
  var currentTime = new Date().getTime(),
7687
- intervalBetweenTaps = currentTime - gestureState.prevTapTime;
7703
+ intervalBetweenTaps = gestureState.prevTapTime != null
7704
+ ? currentTime - gestureState.prevTapTime
7705
+ : Infinity;
7688
7706
 
7689
7707
  if (intervalBetweenTaps >= 0 && intervalBetweenTaps < maxIntervalBetweenTaps) {
7690
7708
  if (distance(gestureState.prevTap.x, gestureState.prevTap.y, gestureState.currentTap.x, gestureState.currentTap.y) < maxDistanceBetweenTaps) {
@@ -8071,9 +8089,9 @@ var Flot = (function (exports) {
8071
8089
  }
8072
8090
 
8073
8091
  for (var i = 0; i < spec.length - 1; ++i) {
8074
- if (axis.delta < (spec[i][0] * timeUnitSize[spec[i][1]] +
8075
- spec[i + 1][0] * timeUnitSize[spec[i + 1][1]]) / 2 &&
8076
- spec[i][0] * timeUnitSize[spec[i][1]] >= minSize) {
8092
+ if (axis.delta < (Number(spec[i][0]) * timeUnitSize[spec[i][1]] +
8093
+ Number(spec[i + 1][0]) * timeUnitSize[spec[i + 1][1]]) / 2 &&
8094
+ Number(spec[i][0]) * timeUnitSize[spec[i][1]] >= minSize) {
8077
8095
  break;
8078
8096
  }
8079
8097
  }
@@ -8736,6 +8754,7 @@ var Flot = (function (exports) {
8736
8754
  }
8737
8755
 
8738
8756
  function triggerSelectedEvent() {
8757
+ /** @type {any} */
8739
8758
  var r = getSelection();
8740
8759
 
8741
8760
  trigger(plot.getPlaceholder(), "plotselected", [ r ]);
@@ -8818,7 +8837,7 @@ var Flot = (function (exports) {
8818
8837
 
8819
8838
  // function taken from markings support in Flot
8820
8839
  function extractRange(ranges, coord) {
8821
- var axis, from, to, key, axes = plot.getAxes();
8840
+ var axis, from, to, /** @type {string|undefined} */ key, axes = plot.getAxes();
8822
8841
 
8823
8842
  for (var k in axes) {
8824
8843
  axis = axes[k];
@@ -8838,7 +8857,7 @@ var Flot = (function (exports) {
8838
8857
  }
8839
8858
 
8840
8859
  // backwards-compat stuff - to be removed in future
8841
- if (!ranges[key]) {
8860
+ if (key && !ranges[key]) {
8842
8861
  axis = coord === "x" ? plot.getXAxes()[0] : plot.getYAxes()[0];
8843
8862
  from = ranges[coord + "1"];
8844
8863
  to = ranges[coord + "2"];
@@ -9247,7 +9266,7 @@ var Flot = (function (exports) {
9247
9266
  const utf8Array = new Uint8Array(arrayBuffer);
9248
9267
  const blockSize = 16384;
9249
9268
  for (var i = 0; i < utf8Array.length; i = i + blockSize) {
9250
- const binarySubString = String.fromCharCode.apply(null, utf8Array.subarray(i, i + blockSize));
9269
+ const binarySubString = String.fromCharCode.apply(null, /** @type {any} */ (utf8Array.subarray(i, i + blockSize)));
9251
9270
  binaryString = binaryString + binarySubString;
9252
9271
  }
9253
9272
  return binaryString;
@@ -9462,7 +9481,7 @@ var Flot = (function (exports) {
9462
9481
 
9463
9482
  var left = 0;
9464
9483
  var columnWidths = [];
9465
- var style = window.getComputedStyle(document.querySelector('body'));
9484
+ var style = window.getComputedStyle(document.body);
9466
9485
  for (i = 0; i < entries.length; ++i) {
9467
9486
  let columnIndex = i % options.legend.noColumns;
9468
9487
  entry = entries[i];