@kevinburke/flot 5.1.3 → 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.3 | 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
 
@@ -1755,6 +1755,120 @@
1755
1755
  */
1756
1756
 
1757
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
+
1758
1872
  function defaultTickGenerator(axis) {
1759
1873
  var ticks = [],
1760
1874
  start = saturated.saturate(saturated.floorInBase(axis.min, axis.tickSize)),
@@ -1843,6 +1957,7 @@
1843
1957
  // or { data: [ [x1, y1], [x2, y2], ... ], label: "some label", ... }
1844
1958
 
1845
1959
  var series = [],
1960
+ /** @type {InternalOptions} */
1846
1961
  options = {
1847
1962
  // the color theme used for graphs
1848
1963
  colors: ["#edc240", "#afd8f8", "#cb4b4b", "#4da74d", "#9440ed"],
@@ -1955,7 +2070,9 @@
1955
2070
  eventHolder = null, // DOM element that events should be bound to
1956
2071
  ctx = null,
1957
2072
  octx = null,
2073
+ /** @type {InternalAxis[]} */
1958
2074
  xaxes = [],
2075
+ /** @type {InternalAxis[]} */
1959
2076
  yaxes = [],
1960
2077
  plotOffset = {
1961
2078
  left: 0,
@@ -1965,6 +2082,7 @@
1965
2082
  },
1966
2083
  plotWidth = 0,
1967
2084
  plotHeight = 0,
2085
+ /** @type {HookRegistry} */
1968
2086
  hooks = {
1969
2087
  processOptions: [],
1970
2088
  processRawData: [],
@@ -1984,6 +2102,7 @@
1984
2102
  resize: [],
1985
2103
  shutdown: []
1986
2104
  },
2105
+ /** @type {InternalPlot} */
1987
2106
  plot = this;
1988
2107
 
1989
2108
  var eventManager = {};
@@ -2050,8 +2169,8 @@
2050
2169
  plot.triggerRedrawOverlay = triggerRedrawOverlay;
2051
2170
  plot.pointOffset = function(point) {
2052
2171
  return {
2053
- left: parseInt(xaxes[axisNumber(point, "x") - 1].p2c(+point.x) + plotOffset.left, 10),
2054
- 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)
2055
2174
  };
2056
2175
  };
2057
2176
  plot.shutdown = shutdown;
@@ -2061,6 +2180,7 @@
2061
2180
  placeholder.innerHTML = '';
2062
2181
 
2063
2182
  series = [];
2183
+ // @ts-expect-error destroy clears closure references after shutdown.
2064
2184
  options = null;
2065
2185
  surface = null;
2066
2186
  overlay = null;
@@ -2069,7 +2189,9 @@
2069
2189
  octx = null;
2070
2190
  xaxes = [];
2071
2191
  yaxes = [];
2192
+ // @ts-expect-error destroy clears closure references after shutdown.
2072
2193
  hooks = null;
2194
+ // @ts-expect-error destroy clears closure references after shutdown.
2073
2195
  plot = null;
2074
2196
  };
2075
2197
 
@@ -2298,6 +2420,9 @@
2298
2420
  return a;
2299
2421
  }
2300
2422
 
2423
+ /**
2424
+ * @returns {InternalAxis[]}
2425
+ */
2301
2426
  function allAxes() {
2302
2427
  // return flat array without annoying null entries
2303
2428
  return xaxes.concat(yaxes).filter(function(a) {
@@ -2376,16 +2501,23 @@
2376
2501
 
2377
2502
  function getOrCreateAxis(axes, number) {
2378
2503
  if (!axes[number - 1]) {
2379
- axes[number - 1] = {
2504
+ axes[number - 1] = /** @type {InternalAxis} */ (/** @type {unknown} */ ({
2380
2505
  n: number, // save the number for future reference
2381
2506
  direction: axes === xaxes ? "x" : "y",
2382
2507
  options: extend(true, {}, axes === xaxes ? options.xaxis : options.yaxis)
2383
- };
2508
+ }));
2384
2509
  }
2385
2510
 
2386
2511
  return axes[number - 1];
2387
2512
  }
2388
2513
 
2514
+ function firstAxis(axes) {
2515
+ if (!axes[0]) {
2516
+ throw new Error("missing first axis");
2517
+ }
2518
+ return axes[0];
2519
+ }
2520
+
2389
2521
  function fillInSeriesOptions() {
2390
2522
  var neededColors = series.length,
2391
2523
  maxIndex = -1,
@@ -2808,8 +2940,13 @@
2808
2940
  function measureTickLabels(axis) {
2809
2941
  var opts = axis.options,
2810
2942
  ticks = opts.showTickLabels !== 'none' && axis.ticks ? axis.ticks : [],
2811
- showMajorTickLabels = opts.showTickLabels === 'major' || opts.showTickLabels === 'all',
2812
- 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',
2813
2950
  labelWidth = opts.labelWidth || 0,
2814
2951
  labelHeight = opts.labelHeight || 0,
2815
2952
  legacyStyles = axis.direction + "Axis " + axis.direction + axis.n + "Axis",
@@ -2820,9 +2957,7 @@
2820
2957
  var t = ticks[i];
2821
2958
  var label = t.label;
2822
2959
 
2823
- if (!t.label ||
2824
- (showMajorTickLabels === false && i > 0 && i < ticks.length - 1) ||
2825
- (showEndpointsTickLabels === false && (i === 0 || i === ticks.length - 1))) {
2960
+ if (!t.label || (endpointsOnly && i > 0 && i < ticks.length - 1)) {
2826
2961
  continue;
2827
2962
  }
2828
2963
 
@@ -3146,9 +3281,11 @@
3146
3281
  if (delta === 0.0) {
3147
3282
  // degenerate case
3148
3283
  var widen = max === 0 ? 1 : 0.01;
3149
- var wmin = null;
3284
+ var wmin = 0;
3285
+ var wminSet = false;
3150
3286
  if (min == null) {
3151
- wmin -= widen;
3287
+ wmin = -widen;
3288
+ wminSet = true;
3152
3289
  }
3153
3290
 
3154
3291
  // always widen max if we couldn't widen min to ensure we
@@ -3157,7 +3294,7 @@
3157
3294
  max += widen;
3158
3295
  }
3159
3296
 
3160
- if (wmin != null) {
3297
+ if (wminSet) {
3161
3298
  min = wmin;
3162
3299
  }
3163
3300
  }
@@ -3553,8 +3690,13 @@
3553
3690
  triggerRedrawOverlay();
3554
3691
  }
3555
3692
 
3693
+ /**
3694
+ * @returns {ExtractedRange}
3695
+ */
3556
3696
  function extractRange(ranges, coord) {
3557
- var axis, from, to, key, axes = allAxes();
3697
+ var axis, from, to, axes = allAxes();
3698
+ var key = "";
3699
+ var keyFound = false;
3558
3700
 
3559
3701
  for (var i = 0; i < axes.length; ++i) {
3560
3702
  axis = axes[i];
@@ -3566,6 +3708,7 @@
3566
3708
  }
3567
3709
 
3568
3710
  if (ranges[key]) {
3711
+ keyFound = true;
3569
3712
  from = ranges[key].from;
3570
3713
  to = ranges[key].to;
3571
3714
  break;
@@ -3574,8 +3717,8 @@
3574
3717
  }
3575
3718
 
3576
3719
  // backwards-compat stuff - to be removed in future
3577
- if (!ranges[key]) {
3578
- axis = coord === "x" ? xaxes[0] : yaxes[0];
3720
+ if (!keyFound) {
3721
+ axis = firstAxis(coord === "x" ? xaxes : yaxes);
3579
3722
  from = ranges[coord + "1"];
3580
3723
  to = ranges[coord + "2"];
3581
3724
  }
@@ -3590,7 +3733,7 @@
3590
3733
  return {
3591
3734
  from: from,
3592
3735
  to: to,
3593
- axis: axis
3736
+ axis: /** @type {InternalAxis} */ (axis)
3594
3737
  };
3595
3738
  }
3596
3739
 
@@ -3840,7 +3983,8 @@
3840
3983
  // check if the line will be overlapped with a border
3841
3984
  var overlappedWithBorder = function (value) {
3842
3985
  var bw = options.grid.borderWidth;
3843
- 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);
3844
3988
  };
3845
3989
 
3846
3990
  ctx.strokeStyle = options.grid.tickColor;
@@ -3886,6 +4030,10 @@
3886
4030
  var bw = options.grid.borderWidth,
3887
4031
  bc = options.grid.borderColor;
3888
4032
 
4033
+ if (bc == null) {
4034
+ bc = options.grid.color;
4035
+ }
4036
+
3889
4037
  if (typeof bw === "object" || typeof bc === "object") {
3890
4038
  if (typeof bw !== "object") {
3891
4039
  bw = {
@@ -4263,10 +4411,14 @@
4263
4411
  smallestDistance = radius * radius + 1;
4264
4412
 
4265
4413
  for (i = series.length - 1; i >= 0; --i) {
4266
- if (!seriesFilter(i)) continue;
4414
+ if (!seriesFilter(i)) {
4415
+ continue;
4416
+ }
4267
4417
 
4268
4418
  var s = series[i];
4269
- if (!s.datapoints) return;
4419
+ if (!s.datapoints) {
4420
+ continue;
4421
+ }
4270
4422
 
4271
4423
  var foundPoint = false;
4272
4424
  if (s.lines.show || s.points.show) {
@@ -4553,7 +4705,7 @@
4553
4705
  // Plugin registry. Plugins push to this array to register themselves.
4554
4706
  var plugins = [];
4555
4707
 
4556
- var version = "5.1.3";
4708
+ var version = "5.1.4";
4557
4709
 
4558
4710
  // The main plot function.
4559
4711
  function plot(placeholder, data, options) {
@@ -9957,13 +10109,15 @@
9957
10109
  $(el).trigger(event);
9958
10110
  });
9959
10111
 
9960
- // Register $.plot and $.color on the jQuery object.
9961
- $.plot = /** @type {typeof $.plot} */ (function(placeholder, data, options) {
10112
+ function jqueryPlot(placeholder, data, options) {
9962
10113
  var el = typeof placeholder === 'string'
9963
10114
  ? document.querySelector(placeholder)
9964
10115
  : (placeholder instanceof $ ? placeholder[0] : placeholder);
9965
10116
  return plot(el, data, options);
9966
- });
10117
+ }
10118
+
10119
+ // Register $.plot and $.color on the jQuery object.
10120
+ $.plot = /** @type {typeof $.plot} */ (/** @type {unknown} */ (jqueryPlot));
9967
10121
 
9968
10122
  $.plot.plugins = plugins;
9969
10123
  $.plot.version = version;
@@ -9985,7 +10139,9 @@
9985
10139
  var origExtract = color.extract;
9986
10140
  $.color = Object.create(color);
9987
10141
  $.color.extract = function(elem, cssProp) {
9988
- if (elem instanceof $ && elem.length) elem = elem[0];
10142
+ if (elem instanceof $) {
10143
+ elem = elem[0];
10144
+ }
9989
10145
  return origExtract(elem, cssProp);
9990
10146
  };
9991
10147