@kevinburke/flot 5.1.2 → 5.1.4

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.
@@ -1,4 +1,4 @@
1
- /*! @kevinburke/flot v5.1.2 | MIT License | https://github.com/kevinburke/flot */
1
+ /*! @kevinburke/flot v5.1.4 | MIT License | https://github.com/kevinburke/flot */
2
2
  (function ($) {
3
3
  'use strict';
4
4
 
@@ -168,8 +168,10 @@
168
168
  function removeData(el, key) {
169
169
  var store = dataStore.get(el);
170
170
  if (store) {
171
- {
171
+ if (key) {
172
172
  delete store[key];
173
+ } else {
174
+ dataStore.delete(el);
173
175
  }
174
176
  }
175
177
  }
@@ -192,7 +194,7 @@
192
194
  return triggerImpl(el, type, args);
193
195
  }
194
196
 
195
- function setTrigger(fn) {
197
+ function setTrigger$1(fn) {
196
198
  triggerImpl = fn;
197
199
  }
198
200
 
@@ -235,6 +237,20 @@
235
237
  }
236
238
  }
237
239
 
240
+ var helpers = /*#__PURE__*/Object.freeze({
241
+ __proto__: null,
242
+ bind: bind,
243
+ css: css,
244
+ data: data,
245
+ extend: extend,
246
+ height: height,
247
+ removeData: removeData,
248
+ setTrigger: setTrigger$1,
249
+ trigger: trigger,
250
+ unbind: unbind,
251
+ width: width
252
+ });
253
+
238
254
  /** ## jquery.flot.canvaswrapper
239
255
 
240
256
  This plugin contains the function for creating and manipulating both the canvas
@@ -1739,6 +1755,120 @@
1739
1755
  */
1740
1756
 
1741
1757
 
1758
+ /**
1759
+ * @typedef {{ [key: string]: any }} PluginOptions
1760
+ */
1761
+
1762
+ /**
1763
+ * @typedef {PluginOptions & {
1764
+ * points: PluginOptions,
1765
+ * lines: PluginOptions,
1766
+ * bars: PluginOptions,
1767
+ * shadowSize: number,
1768
+ * highlightColor: string | null
1769
+ * }} InternalSeriesOptions
1770
+ */
1771
+
1772
+ /**
1773
+ * @typedef {PluginOptions & {
1774
+ * position?: string,
1775
+ * color?: string | number | null,
1776
+ * tickColor?: string | number | null,
1777
+ * font?: PluginOptions | null,
1778
+ * autoScale?: string,
1779
+ * offset?: PluginOptions,
1780
+ * boxPosition?: AxisBoxPosition
1781
+ * }} InternalAxisOptions
1782
+ */
1783
+
1784
+ /**
1785
+ * @typedef {{ top: number, right: number, bottom: number, left: number }} BorderWidth
1786
+ */
1787
+
1788
+ /**
1789
+ * @typedef {{ top: string, right: string, bottom: string, left: string }} BorderColor
1790
+ */
1791
+
1792
+ /**
1793
+ * @typedef {{ left: number, top: number, width: number, height: number, padding: number }} AxisBox
1794
+ */
1795
+
1796
+ /**
1797
+ * @typedef {{ centerX: number, centerY: number }} AxisBoxPosition
1798
+ */
1799
+
1800
+ /**
1801
+ * @typedef {PluginOptions & {
1802
+ * n: number,
1803
+ * direction: "x" | "y",
1804
+ * options: InternalAxisOptions,
1805
+ * used: boolean,
1806
+ * show: boolean,
1807
+ * reserveSpace: boolean,
1808
+ * labelWidth: number,
1809
+ * labelHeight: number,
1810
+ * box: AxisBox,
1811
+ * boxPosition: AxisBoxPosition,
1812
+ * min: number,
1813
+ * max: number,
1814
+ * datamin: number | null,
1815
+ * datamax: number | null,
1816
+ * scale: number,
1817
+ * tickSize: number,
1818
+ * tickDecimals: number,
1819
+ * ticks: Array<PluginOptions>,
1820
+ * p2c: function(string | number): number,
1821
+ * c2p: function(string | number): number
1822
+ * }} InternalAxis
1823
+ */
1824
+
1825
+ /**
1826
+ * @typedef {PluginOptions & {
1827
+ * show: boolean,
1828
+ * aboveData: boolean,
1829
+ * color: string,
1830
+ * backgroundColor: string | PluginOptions | null,
1831
+ * borderColor: string | BorderColor | null,
1832
+ * tickColor: string | null,
1833
+ * margin: number | PluginOptions,
1834
+ * borderWidth: number | BorderWidth,
1835
+ * minBorderMargin: number | null,
1836
+ * markings: any,
1837
+ * markingsColor: string,
1838
+ * markingsLineWidth: number,
1839
+ * clickable: boolean,
1840
+ * hoverable: boolean,
1841
+ * autoHighlight: boolean,
1842
+ * mouseActiveRadius: number
1843
+ * }} InternalGridOptions
1844
+ */
1845
+
1846
+ /**
1847
+ * @typedef {PluginOptions & {
1848
+ * colors: string[],
1849
+ * xaxis: InternalAxisOptions,
1850
+ * yaxis: InternalAxisOptions,
1851
+ * xaxes: InternalAxisOptions[],
1852
+ * yaxes: InternalAxisOptions[],
1853
+ * series: InternalSeriesOptions,
1854
+ * grid: InternalGridOptions,
1855
+ * interaction: PluginOptions,
1856
+ * hooks: PluginOptions
1857
+ * }} InternalOptions
1858
+ */
1859
+
1860
+ /**
1861
+ * @typedef {{ [key: string]: Array<function(...any): any> }} HookRegistry
1862
+ */
1863
+
1864
+ /**
1865
+ * @typedef {PluginOptions} InternalPlot
1866
+ */
1867
+
1868
+ /**
1869
+ * @typedef {{ from?: number, to?: number, axis: InternalAxis }} ExtractedRange
1870
+ */
1871
+
1742
1872
  function defaultTickGenerator(axis) {
1743
1873
  var ticks = [],
1744
1874
  start = saturated.saturate(saturated.floorInBase(axis.min, axis.tickSize)),
@@ -1827,6 +1957,7 @@
1827
1957
  // or { data: [ [x1, y1], [x2, y2], ... ], label: "some label", ... }
1828
1958
 
1829
1959
  var series = [],
1960
+ /** @type {InternalOptions} */
1830
1961
  options = {
1831
1962
  // the color theme used for graphs
1832
1963
  colors: ["#edc240", "#afd8f8", "#cb4b4b", "#4da74d", "#9440ed"],
@@ -1939,7 +2070,9 @@
1939
2070
  eventHolder = null, // DOM element that events should be bound to
1940
2071
  ctx = null,
1941
2072
  octx = null,
2073
+ /** @type {InternalAxis[]} */
1942
2074
  xaxes = [],
2075
+ /** @type {InternalAxis[]} */
1943
2076
  yaxes = [],
1944
2077
  plotOffset = {
1945
2078
  left: 0,
@@ -1949,6 +2082,7 @@
1949
2082
  },
1950
2083
  plotWidth = 0,
1951
2084
  plotHeight = 0,
2085
+ /** @type {HookRegistry} */
1952
2086
  hooks = {
1953
2087
  processOptions: [],
1954
2088
  processRawData: [],
@@ -1968,6 +2102,7 @@
1968
2102
  resize: [],
1969
2103
  shutdown: []
1970
2104
  },
2105
+ /** @type {InternalPlot} */
1971
2106
  plot = this;
1972
2107
 
1973
2108
  var eventManager = {};
@@ -2034,8 +2169,8 @@
2034
2169
  plot.triggerRedrawOverlay = triggerRedrawOverlay;
2035
2170
  plot.pointOffset = function(point) {
2036
2171
  return {
2037
- left: parseInt(xaxes[axisNumber(point, "x") - 1].p2c(+point.x) + plotOffset.left, 10),
2038
- top: parseInt(yaxes[axisNumber(point, "y") - 1].p2c(+point.y) + plotOffset.top, 10)
2172
+ left: parseInt(String(xaxes[axisNumber(point, "x") - 1].p2c(+point.x) + plotOffset.left), 10),
2173
+ top: parseInt(String(yaxes[axisNumber(point, "y") - 1].p2c(+point.y) + plotOffset.top), 10)
2039
2174
  };
2040
2175
  };
2041
2176
  plot.shutdown = shutdown;
@@ -2045,6 +2180,7 @@
2045
2180
  placeholder.innerHTML = '';
2046
2181
 
2047
2182
  series = [];
2183
+ // @ts-expect-error destroy clears closure references after shutdown.
2048
2184
  options = null;
2049
2185
  surface = null;
2050
2186
  overlay = null;
@@ -2053,7 +2189,9 @@
2053
2189
  octx = null;
2054
2190
  xaxes = [];
2055
2191
  yaxes = [];
2192
+ // @ts-expect-error destroy clears closure references after shutdown.
2056
2193
  hooks = null;
2194
+ // @ts-expect-error destroy clears closure references after shutdown.
2057
2195
  plot = null;
2058
2196
  };
2059
2197
 
@@ -2282,6 +2420,9 @@
2282
2420
  return a;
2283
2421
  }
2284
2422
 
2423
+ /**
2424
+ * @returns {InternalAxis[]}
2425
+ */
2285
2426
  function allAxes() {
2286
2427
  // return flat array without annoying null entries
2287
2428
  return xaxes.concat(yaxes).filter(function(a) {
@@ -2360,16 +2501,23 @@
2360
2501
 
2361
2502
  function getOrCreateAxis(axes, number) {
2362
2503
  if (!axes[number - 1]) {
2363
- axes[number - 1] = {
2504
+ axes[number - 1] = /** @type {InternalAxis} */ (/** @type {unknown} */ ({
2364
2505
  n: number, // save the number for future reference
2365
2506
  direction: axes === xaxes ? "x" : "y",
2366
2507
  options: extend(true, {}, axes === xaxes ? options.xaxis : options.yaxis)
2367
- };
2508
+ }));
2368
2509
  }
2369
2510
 
2370
2511
  return axes[number - 1];
2371
2512
  }
2372
2513
 
2514
+ function firstAxis(axes) {
2515
+ if (!axes[0]) {
2516
+ throw new Error("missing first axis");
2517
+ }
2518
+ return axes[0];
2519
+ }
2520
+
2373
2521
  function fillInSeriesOptions() {
2374
2522
  var neededColors = series.length,
2375
2523
  maxIndex = -1,
@@ -2792,8 +2940,13 @@
2792
2940
  function measureTickLabels(axis) {
2793
2941
  var opts = axis.options,
2794
2942
  ticks = opts.showTickLabels !== 'none' && axis.ticks ? axis.ticks : [],
2795
- showMajorTickLabels = opts.showTickLabels === 'major' || opts.showTickLabels === 'all',
2796
- showEndpointsTickLabels = opts.showTickLabels === 'endpoints' || opts.showTickLabels === 'all',
2943
+ // Mirror drawAxisLabels: 'major' and 'all' draw every tick;
2944
+ // only 'endpoints' skips middle ticks. Measurement must cover
2945
+ // every label that will be drawn, otherwise labelWidth can be
2946
+ // too small for the widest one — e.g. a top tick of 100 next
2947
+ // to 70/80/90 gets clipped to "00" because the axis box was
2948
+ // sized for 2-char labels. See flot/flot#1729, flot/flot#1788.
2949
+ endpointsOnly = opts.showTickLabels === 'endpoints',
2797
2950
  labelWidth = opts.labelWidth || 0,
2798
2951
  labelHeight = opts.labelHeight || 0,
2799
2952
  legacyStyles = axis.direction + "Axis " + axis.direction + axis.n + "Axis",
@@ -2804,9 +2957,7 @@
2804
2957
  var t = ticks[i];
2805
2958
  var label = t.label;
2806
2959
 
2807
- if (!t.label ||
2808
- (showMajorTickLabels === false && i > 0 && i < ticks.length - 1) ||
2809
- (showEndpointsTickLabels === false && (i === 0 || i === ticks.length - 1))) {
2960
+ if (!t.label || (endpointsOnly && i > 0 && i < ticks.length - 1)) {
2810
2961
  continue;
2811
2962
  }
2812
2963
 
@@ -3130,9 +3281,11 @@
3130
3281
  if (delta === 0.0) {
3131
3282
  // degenerate case
3132
3283
  var widen = max === 0 ? 1 : 0.01;
3133
- var wmin = null;
3284
+ var wmin = 0;
3285
+ var wminSet = false;
3134
3286
  if (min == null) {
3135
- wmin -= widen;
3287
+ wmin = -widen;
3288
+ wminSet = true;
3136
3289
  }
3137
3290
 
3138
3291
  // always widen max if we couldn't widen min to ensure we
@@ -3141,7 +3294,7 @@
3141
3294
  max += widen;
3142
3295
  }
3143
3296
 
3144
- if (wmin != null) {
3297
+ if (wminSet) {
3145
3298
  min = wmin;
3146
3299
  }
3147
3300
  }
@@ -3537,8 +3690,13 @@
3537
3690
  triggerRedrawOverlay();
3538
3691
  }
3539
3692
 
3693
+ /**
3694
+ * @returns {ExtractedRange}
3695
+ */
3540
3696
  function extractRange(ranges, coord) {
3541
- var axis, from, to, key, axes = allAxes();
3697
+ var axis, from, to, axes = allAxes();
3698
+ var key = "";
3699
+ var keyFound = false;
3542
3700
 
3543
3701
  for (var i = 0; i < axes.length; ++i) {
3544
3702
  axis = axes[i];
@@ -3550,6 +3708,7 @@
3550
3708
  }
3551
3709
 
3552
3710
  if (ranges[key]) {
3711
+ keyFound = true;
3553
3712
  from = ranges[key].from;
3554
3713
  to = ranges[key].to;
3555
3714
  break;
@@ -3558,8 +3717,8 @@
3558
3717
  }
3559
3718
 
3560
3719
  // backwards-compat stuff - to be removed in future
3561
- if (!ranges[key]) {
3562
- axis = coord === "x" ? xaxes[0] : yaxes[0];
3720
+ if (!keyFound) {
3721
+ axis = firstAxis(coord === "x" ? xaxes : yaxes);
3563
3722
  from = ranges[coord + "1"];
3564
3723
  to = ranges[coord + "2"];
3565
3724
  }
@@ -3574,7 +3733,7 @@
3574
3733
  return {
3575
3734
  from: from,
3576
3735
  to: to,
3577
- axis: axis
3736
+ axis: /** @type {InternalAxis} */ (axis)
3578
3737
  };
3579
3738
  }
3580
3739
 
@@ -3824,7 +3983,8 @@
3824
3983
  // check if the line will be overlapped with a border
3825
3984
  var overlappedWithBorder = function (value) {
3826
3985
  var bw = options.grid.borderWidth;
3827
- return (((typeof bw === "object" && bw[axis.position] > 0) || bw > 0) && (value === axis.min || value === axis.max));
3986
+ var overlapsBorder = typeof bw === "object" ? bw[axis.position] > 0 : bw > 0;
3987
+ return overlapsBorder && (value === axis.min || value === axis.max);
3828
3988
  };
3829
3989
 
3830
3990
  ctx.strokeStyle = options.grid.tickColor;
@@ -3870,6 +4030,10 @@
3870
4030
  var bw = options.grid.borderWidth,
3871
4031
  bc = options.grid.borderColor;
3872
4032
 
4033
+ if (bc == null) {
4034
+ bc = options.grid.color;
4035
+ }
4036
+
3873
4037
  if (typeof bw === "object" || typeof bc === "object") {
3874
4038
  if (typeof bw !== "object") {
3875
4039
  bw = {
@@ -4247,10 +4411,14 @@
4247
4411
  smallestDistance = radius * radius + 1;
4248
4412
 
4249
4413
  for (i = series.length - 1; i >= 0; --i) {
4250
- if (!seriesFilter(i)) continue;
4414
+ if (!seriesFilter(i)) {
4415
+ continue;
4416
+ }
4251
4417
 
4252
4418
  var s = series[i];
4253
- if (!s.datapoints) return;
4419
+ if (!s.datapoints) {
4420
+ continue;
4421
+ }
4254
4422
 
4255
4423
  var foundPoint = false;
4256
4424
  if (s.lines.show || s.points.show) {
@@ -4537,7 +4705,7 @@
4537
4705
  // Plugin registry. Plugins push to this array to register themselves.
4538
4706
  var plugins = [];
4539
4707
 
4540
- var version = "5.1.2";
4708
+ var version = "5.1.4";
4541
4709
 
4542
4710
  // The main plot function.
4543
4711
  function plot(placeholder, data, options) {
@@ -9921,6 +10089,7 @@
9921
10089
  // import '@kevinburke/flot/jquery';
9922
10090
  // $.plot("#placeholder", data, options);
9923
10091
 
10092
+ var setTrigger = setTrigger$1;
9924
10093
 
9925
10094
  // Route flot's internal trigger() through jQuery so plugin handlers bound
9926
10095
  // via $(el).on(type, fn) see the same data shape as upstream flot/flot.
@@ -9940,13 +10109,15 @@
9940
10109
  $(el).trigger(event);
9941
10110
  });
9942
10111
 
9943
- // Register $.plot and $.color on the jQuery object.
9944
- $.plot = function(placeholder, data, options) {
10112
+ function jqueryPlot(placeholder, data, options) {
9945
10113
  var el = typeof placeholder === 'string'
9946
10114
  ? document.querySelector(placeholder)
9947
10115
  : (placeholder instanceof $ ? placeholder[0] : placeholder);
9948
10116
  return plot(el, data, options);
9949
- };
10117
+ }
10118
+
10119
+ // Register $.plot and $.color on the jQuery object.
10120
+ $.plot = /** @type {typeof $.plot} */ (/** @type {unknown} */ (jqueryPlot));
9950
10121
 
9951
10122
  $.plot.plugins = plugins;
9952
10123
  $.plot.version = version;
@@ -9968,7 +10139,9 @@
9968
10139
  var origExtract = color.extract;
9969
10140
  $.color = Object.create(color);
9970
10141
  $.color.extract = function(elem, cssProp) {
9971
- if (elem instanceof $ && elem.length) elem = elem[0];
10142
+ if (elem instanceof $) {
10143
+ elem = elem[0];
10144
+ }
9972
10145
  return origExtract(elem, cssProp);
9973
10146
  };
9974
10147
 
@@ -9984,6 +10157,11 @@
9984
10157
  window.Flot = {};
9985
10158
  }
9986
10159
  window.Flot.Canvas = Canvas;
10160
+ // Exposed so standalone plugin bundles (dist/plugins/*.js) can resolve
10161
+ // their `import { plugins } from './jquery.flot.js'` and
10162
+ // `import { ... } from './helpers.js'` to live objects on this global.
10163
+ window.Flot.plugins = plugins;
10164
+ window.Flot.helpers = helpers;
9987
10165
  }
9988
10166
 
9989
10167
  })(jQuery);