@kevinburke/flot 5.1.0 → 5.1.1

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/dist/flot.mjs CHANGED
@@ -1,4 +1,4 @@
1
- /*! @kevinburke/flot v5.1.0 | MIT License | https://github.com/kevinburke/flot */
1
+ /*! @kevinburke/flot v5.1.1 | MIT License | https://github.com/kevinburke/flot */
2
2
  var browser = {
3
3
  getPageXY: function (e) {
4
4
  var doc = document.documentElement,
@@ -716,10 +716,16 @@ var Canvas = function(cls, container) {
716
716
  var styleCache = layerCache[styleKey];
717
717
  for (var key in styleCache) {
718
718
  if (Object.prototype.hasOwnProperty.call(styleCache, key)) {
719
+ // styleCache entries can exist without a
720
+ // positions array (e.g. when a Flot plugin
721
+ // populates the cache outside the normal
722
+ // addText path). Upstream flot/flot#1444.
719
723
  var positions = styleCache[key].positions;
720
- positions.forEach(function(position) {
721
- position.active = false;
722
- });
724
+ if (positions != null) {
725
+ positions.forEach(function(position) {
726
+ position.active = false;
727
+ });
728
+ }
723
729
  }
724
730
  }
725
731
  }
@@ -3358,8 +3364,11 @@ Licensed under the MIT license.
3358
3364
  };
3359
3365
 
3360
3366
  // we might need an extra decimal since forced
3361
- // ticks don't necessarily fit naturally
3362
- if (!axis.mode && opts.tickDecimals == null) {
3367
+ // ticks don't necessarily fit naturally.
3368
+ // Guard against axis.delta <= 0 (min == max): Math.log(0)
3369
+ // is -Infinity, so extraDec would be +Infinity and
3370
+ // toFixed(Infinity) throws. Upstream #1869 / PR #1870.
3371
+ if (!axis.mode && opts.tickDecimals == null && axis.delta > 0) {
3363
3372
  var extraDec = Math.max(0, -Math.floor(Math.log(axis.delta) / Math.LN10) + 1),
3364
3373
  ts = axis.tickGenerator(axis, plot);
3365
3374
 
@@ -4266,7 +4275,13 @@ Licensed under the MIT license.
4266
4275
  maxy = maxDistance / series.yaxis.scale,
4267
4276
  points = series.datapoints.points,
4268
4277
  ps = series.datapoints.pointsize,
4269
- smallestDistance = Number.POSITIVE_INFINITY;
4278
+ // Seed with maxDistance (or its square, matching the
4279
+ // default squared-distance metric) so points outside
4280
+ // the hover radius are never selected. Without this,
4281
+ // the maxx/maxy coordinate-space pre-filter is the
4282
+ // only radius check, and it's disabled for axes with
4283
+ // inverseTransform — see upstream flot/flot#1871.
4284
+ smallestDistance = computeDistance ? maxDistance : maxDistance * maxDistance;
4270
4285
 
4271
4286
  // with inverse transforms, we can't use the maxx/maxy
4272
4287
  // optimization, sadly
@@ -4466,7 +4481,16 @@ Licensed under the MIT license.
4466
4481
  } else {
4467
4482
  // assume this is a gradient spec; IE currently only
4468
4483
  // supports a simple vertical gradient properly, so that's
4469
- // what we support too
4484
+ // what we support too.
4485
+ // createLinearGradient throws if any coordinate is NaN or
4486
+ // ±Infinity (e.g. when the plot container has zero size
4487
+ // or the user supplies bogus bounds) — fall back to the
4488
+ // default solid color instead. Global isFinite coerces
4489
+ // null → 0 (finite), matching the drawSeriesPoints path
4490
+ // that passes (null, null). Upstream flot/flot#1867.
4491
+ if (!isFinite(top) || !isFinite(bottom)) {
4492
+ return defaultColor;
4493
+ }
4470
4494
  var gradient = ctx.createLinearGradient(0, top, 0, bottom);
4471
4495
 
4472
4496
  for (var i = 0, l = spec.colors.length; i < l; ++i) {
@@ -4494,7 +4518,7 @@ Licensed under the MIT license.
4494
4518
  // Plugin registry. Plugins push to this array to register themselves.
4495
4519
  var plugins = [];
4496
4520
 
4497
- var version = "5.1.0";
4521
+ var version = "5.1.1";
4498
4522
 
4499
4523
  // The main plot function.
4500
4524
  function plot(placeholder, data, options) {
@@ -5755,6 +5779,17 @@ Licensed under the MIT license.
5755
5779
  var minD = axis.p2c(opts.panRange[0]) - axis.p2c(axis.min);
5756
5780
  // calc max delta (revealing right edge of plot)
5757
5781
  var maxD = axis.p2c(opts.panRange[1]) - axis.p2c(axis.max);
5782
+ // For the y-axis, screen coordinates are inverted
5783
+ // (p2c(smaller v) > p2c(larger v)), so minD/maxD end up
5784
+ // with the opposite signs from the x-axis case. Swap
5785
+ // them so the clamp comparisons below keep their
5786
+ // x-axis semantics. Upstream flot/flot#1789, ports the
5787
+ // minimal form of PR #1793.
5788
+ if (axis.direction === 'y') {
5789
+ var swap = minD;
5790
+ minD = maxD;
5791
+ maxD = swap;
5792
+ }
5758
5793
  // limit delta to min or max if enabled
5759
5794
  if (opts.panRange[0] !== undefined && d >= maxD) d = maxD;
5760
5795
  if (opts.panRange[1] !== undefined && d <= minD) d = minD;
@@ -5919,6 +5954,13 @@ Licensed under the MIT license.
5919
5954
  var minD = p + axis.p2c(opts.panRange[0]) - axis.p2c(axisMin);
5920
5955
  // calc max delta (revealing right edge of plot)
5921
5956
  var maxD = p + axis.p2c(opts.panRange[1]) - axis.p2c(axisMax);
5957
+ // Same y-axis swap as plot.pan — see comment there.
5958
+ // Upstream flot/flot#1789 / PR #1793.
5959
+ if (axis.direction === 'y') {
5960
+ var swap = minD;
5961
+ minD = maxD;
5962
+ maxD = swap;
5963
+ }
5922
5964
  // limit delta to min or max if enabled
5923
5965
  if (opts.panRange[0] !== undefined && d >= maxD) d = maxD;
5924
5966
  if (opts.panRange[1] !== undefined && d <= minD) d = minD;
@@ -9482,6 +9524,17 @@ temporary images load their data.
9482
9524
  shape.strokeWidth = entry.options.points.lineWidth;
9483
9525
  iconHtml += getEntryIconHtml(shape);
9484
9526
  }
9527
+ // fallback for plugin-drawn series (pie, errorbars, etc.)
9528
+ // that don't turn on any of lines/bars/points — without
9529
+ // this the legend entry has a label but no icon. Upstream
9530
+ // flot/flot#1641, minus the switch to `else if` so series
9531
+ // that deliberately overlay (e.g. lines + points) keep
9532
+ // rendering both icons.
9533
+ if (iconHtml === '') {
9534
+ shape.name = 'box';
9535
+ shape.fillColor = entry.color;
9536
+ iconHtml += getEntryIconHtml(shape);
9537
+ }
9485
9538
 
9486
9539
  labelHtml = '<text x="' + shape.xPos + '" y="' + shape.yPos + '" text-anchor="start"><tspan dx="2em" dy="1.2em">' + shape.label + '</tspan></text>';
9487
9540
  html[j++] = '<g>' + iconHtml + labelHtml + '</g>';
@@ -9521,9 +9574,17 @@ temporary images load their data.
9521
9574
  legendEl.style.pointerEvents = 'none';
9522
9575
  placeholder.appendChild(legendEl);
9523
9576
  } else {
9524
- options.legend.container.innerHTML = html.join('');
9525
- options.legend.container.style.width = width + 'px';
9526
- options.legend.container.style.height = height + 'em';
9577
+ // Accept either a DOM Element or a jQuery-wrapped container.
9578
+ // Upstream flot/flot#1750 switched to `$(container).get(0)` to
9579
+ // always land on the underlying element; since this fork is
9580
+ // jQuery-optional, do the unwrap inline.
9581
+ var container = options.legend.container;
9582
+ if (container && typeof container.get === 'function' && container[0]) {
9583
+ container = container[0];
9584
+ }
9585
+ container.innerHTML = html.join('');
9586
+ container.style.width = width + 'px';
9587
+ container.style.height = height + 'em';
9527
9588
  }
9528
9589
  }
9529
9590
 
@@ -9617,6 +9678,14 @@ temporary images load their data.
9617
9678
  'width="1.5em" height="1.5em"' +
9618
9679
  '/>';
9619
9680
  break;
9681
+ case 'box':
9682
+ html = '<use xlink:href="#box" class="legendIcon" ' +
9683
+ 'x="' + x + '" ' +
9684
+ 'y="' + y + '" ' +
9685
+ 'fill="' + fill + '" ' +
9686
+ 'width="1.5em" height="1.5em"' +
9687
+ '/>';
9688
+ break;
9620
9689
  default:
9621
9690
  // default is circle
9622
9691
  html = '<use xlink:href="#circle" class="legendIcon" ' +
@@ -9639,6 +9708,12 @@ temporary images load their data.
9639
9708
  '<polyline points="0,15 5,5 10,10 15,0"/>' +
9640
9709
  '</symbol>' +
9641
9710
 
9711
+ // Fallback icon for plugin-drawn series that don't turn on
9712
+ // any of lines / bars / points. Upstream flot/flot#1641.
9713
+ '<symbol id="box" stroke-width="1" viewBox="-5 -5 25 25">' +
9714
+ '<rect x="0" y="0" width="15" height="15"/>' +
9715
+ '</symbol>' +
9716
+
9642
9717
  '<symbol id="area" stroke-width="1" viewBox="-5 -5 25 25">' +
9643
9718
  '<polyline points="0,15 5,5 10,10 15,0, 15,15, 0,15"/>' +
9644
9719
  '</symbol>' +
@@ -1,4 +1,4 @@
1
- /*! @kevinburke/flot v5.1.0 | MIT License | https://github.com/kevinburke/flot */
1
+ /*! @kevinburke/flot v5.1.1 | MIT License | https://github.com/kevinburke/flot */
2
2
  (function ($) {
3
3
  'use strict';
4
4
 
@@ -719,10 +719,16 @@
719
719
  var styleCache = layerCache[styleKey];
720
720
  for (var key in styleCache) {
721
721
  if (Object.prototype.hasOwnProperty.call(styleCache, key)) {
722
+ // styleCache entries can exist without a
723
+ // positions array (e.g. when a Flot plugin
724
+ // populates the cache outside the normal
725
+ // addText path). Upstream flot/flot#1444.
722
726
  var positions = styleCache[key].positions;
723
- positions.forEach(function(position) {
724
- position.active = false;
725
- });
727
+ if (positions != null) {
728
+ positions.forEach(function(position) {
729
+ position.active = false;
730
+ });
731
+ }
726
732
  }
727
733
  }
728
734
  }
@@ -3361,8 +3367,11 @@
3361
3367
  };
3362
3368
 
3363
3369
  // we might need an extra decimal since forced
3364
- // ticks don't necessarily fit naturally
3365
- if (!axis.mode && opts.tickDecimals == null) {
3370
+ // ticks don't necessarily fit naturally.
3371
+ // Guard against axis.delta <= 0 (min == max): Math.log(0)
3372
+ // is -Infinity, so extraDec would be +Infinity and
3373
+ // toFixed(Infinity) throws. Upstream #1869 / PR #1870.
3374
+ if (!axis.mode && opts.tickDecimals == null && axis.delta > 0) {
3366
3375
  var extraDec = Math.max(0, -Math.floor(Math.log(axis.delta) / Math.LN10) + 1),
3367
3376
  ts = axis.tickGenerator(axis, plot);
3368
3377
 
@@ -4269,7 +4278,13 @@
4269
4278
  maxy = maxDistance / series.yaxis.scale,
4270
4279
  points = series.datapoints.points,
4271
4280
  ps = series.datapoints.pointsize,
4272
- smallestDistance = Number.POSITIVE_INFINITY;
4281
+ // Seed with maxDistance (or its square, matching the
4282
+ // default squared-distance metric) so points outside
4283
+ // the hover radius are never selected. Without this,
4284
+ // the maxx/maxy coordinate-space pre-filter is the
4285
+ // only radius check, and it's disabled for axes with
4286
+ // inverseTransform — see upstream flot/flot#1871.
4287
+ smallestDistance = computeDistance ? maxDistance : maxDistance * maxDistance;
4273
4288
 
4274
4289
  // with inverse transforms, we can't use the maxx/maxy
4275
4290
  // optimization, sadly
@@ -4469,7 +4484,16 @@
4469
4484
  } else {
4470
4485
  // assume this is a gradient spec; IE currently only
4471
4486
  // supports a simple vertical gradient properly, so that's
4472
- // what we support too
4487
+ // what we support too.
4488
+ // createLinearGradient throws if any coordinate is NaN or
4489
+ // ±Infinity (e.g. when the plot container has zero size
4490
+ // or the user supplies bogus bounds) — fall back to the
4491
+ // default solid color instead. Global isFinite coerces
4492
+ // null → 0 (finite), matching the drawSeriesPoints path
4493
+ // that passes (null, null). Upstream flot/flot#1867.
4494
+ if (!isFinite(top) || !isFinite(bottom)) {
4495
+ return defaultColor;
4496
+ }
4473
4497
  var gradient = ctx.createLinearGradient(0, top, 0, bottom);
4474
4498
 
4475
4499
  for (var i = 0, l = spec.colors.length; i < l; ++i) {
@@ -4497,7 +4521,7 @@
4497
4521
  // Plugin registry. Plugins push to this array to register themselves.
4498
4522
  var plugins = [];
4499
4523
 
4500
- var version = "5.1.0";
4524
+ var version = "5.1.1";
4501
4525
 
4502
4526
  // The main plot function.
4503
4527
  function plot(placeholder, data, options) {
@@ -5758,6 +5782,17 @@
5758
5782
  var minD = axis.p2c(opts.panRange[0]) - axis.p2c(axis.min);
5759
5783
  // calc max delta (revealing right edge of plot)
5760
5784
  var maxD = axis.p2c(opts.panRange[1]) - axis.p2c(axis.max);
5785
+ // For the y-axis, screen coordinates are inverted
5786
+ // (p2c(smaller v) > p2c(larger v)), so minD/maxD end up
5787
+ // with the opposite signs from the x-axis case. Swap
5788
+ // them so the clamp comparisons below keep their
5789
+ // x-axis semantics. Upstream flot/flot#1789, ports the
5790
+ // minimal form of PR #1793.
5791
+ if (axis.direction === 'y') {
5792
+ var swap = minD;
5793
+ minD = maxD;
5794
+ maxD = swap;
5795
+ }
5761
5796
  // limit delta to min or max if enabled
5762
5797
  if (opts.panRange[0] !== undefined && d >= maxD) d = maxD;
5763
5798
  if (opts.panRange[1] !== undefined && d <= minD) d = minD;
@@ -5922,6 +5957,13 @@
5922
5957
  var minD = p + axis.p2c(opts.panRange[0]) - axis.p2c(axisMin);
5923
5958
  // calc max delta (revealing right edge of plot)
5924
5959
  var maxD = p + axis.p2c(opts.panRange[1]) - axis.p2c(axisMax);
5960
+ // Same y-axis swap as plot.pan — see comment there.
5961
+ // Upstream flot/flot#1789 / PR #1793.
5962
+ if (axis.direction === 'y') {
5963
+ var swap = minD;
5964
+ minD = maxD;
5965
+ maxD = swap;
5966
+ }
5925
5967
  // limit delta to min or max if enabled
5926
5968
  if (opts.panRange[0] !== undefined && d >= maxD) d = maxD;
5927
5969
  if (opts.panRange[1] !== undefined && d <= minD) d = minD;
@@ -9485,6 +9527,17 @@
9485
9527
  shape.strokeWidth = entry.options.points.lineWidth;
9486
9528
  iconHtml += getEntryIconHtml(shape);
9487
9529
  }
9530
+ // fallback for plugin-drawn series (pie, errorbars, etc.)
9531
+ // that don't turn on any of lines/bars/points — without
9532
+ // this the legend entry has a label but no icon. Upstream
9533
+ // flot/flot#1641, minus the switch to `else if` so series
9534
+ // that deliberately overlay (e.g. lines + points) keep
9535
+ // rendering both icons.
9536
+ if (iconHtml === '') {
9537
+ shape.name = 'box';
9538
+ shape.fillColor = entry.color;
9539
+ iconHtml += getEntryIconHtml(shape);
9540
+ }
9488
9541
 
9489
9542
  labelHtml = '<text x="' + shape.xPos + '" y="' + shape.yPos + '" text-anchor="start"><tspan dx="2em" dy="1.2em">' + shape.label + '</tspan></text>';
9490
9543
  html[j++] = '<g>' + iconHtml + labelHtml + '</g>';
@@ -9524,9 +9577,17 @@
9524
9577
  legendEl.style.pointerEvents = 'none';
9525
9578
  placeholder.appendChild(legendEl);
9526
9579
  } else {
9527
- options.legend.container.innerHTML = html.join('');
9528
- options.legend.container.style.width = width + 'px';
9529
- options.legend.container.style.height = height + 'em';
9580
+ // Accept either a DOM Element or a jQuery-wrapped container.
9581
+ // Upstream flot/flot#1750 switched to `$(container).get(0)` to
9582
+ // always land on the underlying element; since this fork is
9583
+ // jQuery-optional, do the unwrap inline.
9584
+ var container = options.legend.container;
9585
+ if (container && typeof container.get === 'function' && container[0]) {
9586
+ container = container[0];
9587
+ }
9588
+ container.innerHTML = html.join('');
9589
+ container.style.width = width + 'px';
9590
+ container.style.height = height + 'em';
9530
9591
  }
9531
9592
  }
9532
9593
 
@@ -9620,6 +9681,14 @@
9620
9681
  'width="1.5em" height="1.5em"' +
9621
9682
  '/>';
9622
9683
  break;
9684
+ case 'box':
9685
+ html = '<use xlink:href="#box" class="legendIcon" ' +
9686
+ 'x="' + x + '" ' +
9687
+ 'y="' + y + '" ' +
9688
+ 'fill="' + fill + '" ' +
9689
+ 'width="1.5em" height="1.5em"' +
9690
+ '/>';
9691
+ break;
9623
9692
  default:
9624
9693
  // default is circle
9625
9694
  html = '<use xlink:href="#circle" class="legendIcon" ' +
@@ -9642,6 +9711,12 @@
9642
9711
  '<polyline points="0,15 5,5 10,10 15,0"/>' +
9643
9712
  '</symbol>' +
9644
9713
 
9714
+ // Fallback icon for plugin-drawn series that don't turn on
9715
+ // any of lines / bars / points. Upstream flot/flot#1641.
9716
+ '<symbol id="box" stroke-width="1" viewBox="-5 -5 25 25">' +
9717
+ '<rect x="0" y="0" width="15" height="15"/>' +
9718
+ '</symbol>' +
9719
+
9645
9720
  '<symbol id="area" stroke-width="1" viewBox="-5 -5 25 25">' +
9646
9721
  '<polyline points="0,15 5,5 10,10 15,0, 15,15, 0,15"/>' +
9647
9722
  '</symbol>' +