@kevinburke/flot 5.1.0 → 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 +118 -0
- package/dist/flot.js +132 -38
- package/dist/flot.min.js +1 -1
- package/dist/flot.min.js.map +1 -1
- package/dist/flot.mjs +132 -38
- package/dist/jquery.flot.js +154 -38
- package/dist/jquery.flot.min.js +1 -1
- package/dist/jquery.flot.min.js.map +1 -1
- package/dist/plugins/jquery.flot.crosshair.js +1 -1
- package/dist/plugins/jquery.flot.image.js +1 -1
- package/dist/plugins/jquery.flot.pie.js +11 -3
- package/dist/plugins/jquery.flot.pie.min.js +1 -1
- package/dist/plugins/jquery.flot.pie.min.js.map +1 -1
- package/dist/plugins/jquery.flot.resize.js +1 -1
- package/dist/plugins/jquery.flot.threshold.js +1 -1
- package/package.json +14 -6
- package/source/helpers.js +16 -4
- package/source/jquery-adapter.js +19 -0
- package/source/jquery.canvaswrapper.js +17 -7
- package/source/jquery.flot.browser.js +1 -1
- package/source/jquery.flot.composeImages.js +1 -1
- package/source/jquery.flot.hover.js +4 -4
- package/source/jquery.flot.js +23 -5
- package/source/jquery.flot.legend.js +37 -4
- package/source/jquery.flot.navigate.js +19 -1
- package/source/jquery.flot.pie.js +10 -2
- package/source/jquery.flot.selection.js +3 -2
- package/source/jquery.flot.time.js +3 -3
- package/source/jquery.flot.touch.js +6 -1
- package/source/jquery.flot.touchNavigate.js +5 -3
- package/types/test.ts +7 -7
- package/source/jquery.js +0 -9473
|
@@ -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.
|
|
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];
|
|
@@ -119,6 +119,17 @@ import { plugins } from './jquery.flot.js';
|
|
|
119
119
|
shape.strokeWidth = entry.options.points.lineWidth;
|
|
120
120
|
iconHtml += getEntryIconHtml(shape);
|
|
121
121
|
}
|
|
122
|
+
// fallback for plugin-drawn series (pie, errorbars, etc.)
|
|
123
|
+
// that don't turn on any of lines/bars/points — without
|
|
124
|
+
// this the legend entry has a label but no icon. Upstream
|
|
125
|
+
// flot/flot#1641, minus the switch to `else if` so series
|
|
126
|
+
// that deliberately overlay (e.g. lines + points) keep
|
|
127
|
+
// rendering both icons.
|
|
128
|
+
if (iconHtml === '') {
|
|
129
|
+
shape.name = 'box';
|
|
130
|
+
shape.fillColor = entry.color;
|
|
131
|
+
iconHtml += getEntryIconHtml(shape);
|
|
132
|
+
}
|
|
122
133
|
|
|
123
134
|
labelHtml = '<text x="' + shape.xPos + '" y="' + shape.yPos + '" text-anchor="start"><tspan dx="2em" dy="1.2em">' + shape.label + '</tspan></text>'
|
|
124
135
|
html[j++] = '<g>' + iconHtml + labelHtml + '</g>';
|
|
@@ -158,9 +169,17 @@ import { plugins } from './jquery.flot.js';
|
|
|
158
169
|
legendEl.style.pointerEvents = 'none';
|
|
159
170
|
placeholder.appendChild(legendEl);
|
|
160
171
|
} else {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
172
|
+
// Accept either a DOM Element or a jQuery-wrapped container.
|
|
173
|
+
// Upstream flot/flot#1750 switched to `$(container).get(0)` to
|
|
174
|
+
// always land on the underlying element; since this fork is
|
|
175
|
+
// jQuery-optional, do the unwrap inline.
|
|
176
|
+
var container = options.legend.container;
|
|
177
|
+
if (container && typeof container.get === 'function' && container[0]) {
|
|
178
|
+
container = container[0];
|
|
179
|
+
}
|
|
180
|
+
container.innerHTML = html.join('');
|
|
181
|
+
container.style.width = width + 'px';
|
|
182
|
+
container.style.height = height + 'em';
|
|
164
183
|
}
|
|
165
184
|
}
|
|
166
185
|
|
|
@@ -254,6 +273,14 @@ import { plugins } from './jquery.flot.js';
|
|
|
254
273
|
'width="1.5em" height="1.5em"' +
|
|
255
274
|
'/>';
|
|
256
275
|
break;
|
|
276
|
+
case 'box':
|
|
277
|
+
html = '<use xlink:href="#box" class="legendIcon" ' +
|
|
278
|
+
'x="' + x + '" ' +
|
|
279
|
+
'y="' + y + '" ' +
|
|
280
|
+
'fill="' + fill + '" ' +
|
|
281
|
+
'width="1.5em" height="1.5em"' +
|
|
282
|
+
'/>';
|
|
283
|
+
break;
|
|
257
284
|
default:
|
|
258
285
|
// default is circle
|
|
259
286
|
html = '<use xlink:href="#circle" class="legendIcon" ' +
|
|
@@ -276,6 +303,12 @@ import { plugins } from './jquery.flot.js';
|
|
|
276
303
|
'<polyline points="0,15 5,5 10,10 15,0"/>' +
|
|
277
304
|
'</symbol>' +
|
|
278
305
|
|
|
306
|
+
// Fallback icon for plugin-drawn series that don't turn on
|
|
307
|
+
// any of lines / bars / points. Upstream flot/flot#1641.
|
|
308
|
+
'<symbol id="box" stroke-width="1" viewBox="-5 -5 25 25">' +
|
|
309
|
+
'<rect x="0" y="0" width="15" height="15"/>' +
|
|
310
|
+
'</symbol>' +
|
|
311
|
+
|
|
279
312
|
'<symbol id="area" stroke-width="1" viewBox="-5 -5 25 25">' +
|
|
280
313
|
'<polyline points="0,15 5,5 10,10 15,0, 15,15, 0,15"/>' +
|
|
281
314
|
'</symbol>' +
|
|
@@ -555,6 +555,17 @@ import { bind, unbind, trigger, css } from './helpers.js';
|
|
|
555
555
|
var minD = axis.p2c(opts.panRange[0]) - axis.p2c(axis.min);
|
|
556
556
|
// calc max delta (revealing right edge of plot)
|
|
557
557
|
var maxD = axis.p2c(opts.panRange[1]) - axis.p2c(axis.max);
|
|
558
|
+
// For the y-axis, screen coordinates are inverted
|
|
559
|
+
// (p2c(smaller v) > p2c(larger v)), so minD/maxD end up
|
|
560
|
+
// with the opposite signs from the x-axis case. Swap
|
|
561
|
+
// them so the clamp comparisons below keep their
|
|
562
|
+
// x-axis semantics. Upstream flot/flot#1789, ports the
|
|
563
|
+
// minimal form of PR #1793.
|
|
564
|
+
if (axis.direction === 'y') {
|
|
565
|
+
var swap = minD;
|
|
566
|
+
minD = maxD;
|
|
567
|
+
maxD = swap;
|
|
568
|
+
}
|
|
558
569
|
// limit delta to min or max if enabled
|
|
559
570
|
if (opts.panRange[0] !== undefined && d >= maxD) d = maxD;
|
|
560
571
|
if (opts.panRange[1] !== undefined && d <= minD) d = minD;
|
|
@@ -719,6 +730,13 @@ import { bind, unbind, trigger, css } from './helpers.js';
|
|
|
719
730
|
var minD = p + axis.p2c(opts.panRange[0]) - axis.p2c(axisMin);
|
|
720
731
|
// calc max delta (revealing right edge of plot)
|
|
721
732
|
var maxD = p + axis.p2c(opts.panRange[1]) - axis.p2c(axisMax);
|
|
733
|
+
// Same y-axis swap as plot.pan — see comment there.
|
|
734
|
+
// Upstream flot/flot#1789 / PR #1793.
|
|
735
|
+
if (axis.direction === 'y') {
|
|
736
|
+
var swap = minD;
|
|
737
|
+
minD = maxD;
|
|
738
|
+
maxD = swap;
|
|
739
|
+
}
|
|
722
740
|
// limit delta to min or max if enabled
|
|
723
741
|
if (opts.panRange[0] !== undefined && d >= maxD) d = maxD;
|
|
724
742
|
if (opts.panRange[1] !== undefined && d <= minD) d = minD;
|
|
@@ -772,7 +790,7 @@ import { bind, unbind, trigger, css } from './helpers.js';
|
|
|
772
790
|
ctx.lineJoin = "round";
|
|
773
791
|
var startx = Math.round(panHint.start.x),
|
|
774
792
|
starty = Math.round(panHint.start.y),
|
|
775
|
-
endx, endy;
|
|
793
|
+
endx = 0, endy = 0;
|
|
776
794
|
|
|
777
795
|
if (panAxes) {
|
|
778
796
|
if (panAxes[0].direction === 'x') {
|
|
@@ -539,6 +539,11 @@ import { extend, bind, unbind, trigger, width, height } from './helpers.js';
|
|
|
539
539
|
// Placed here because it needs to be accessed from multiple locations
|
|
540
540
|
|
|
541
541
|
function drawDonutHole(layer) {
|
|
542
|
+
// The closure-scoped `options` is set by the processDatapoints
|
|
543
|
+
// hook on first draw, but drawDonutHole can be reached from
|
|
544
|
+
// paths that fire before that hook, leaving `options` null.
|
|
545
|
+
// Read it eagerly. Upstream flot/flot#1559.
|
|
546
|
+
var options = plot.getOptions();
|
|
542
547
|
if (options.series.pie.innerRadius > 0) {
|
|
543
548
|
// subtract the center
|
|
544
549
|
layer.save();
|
|
@@ -651,9 +656,12 @@ import { extend, bind, unbind, trigger, width, height } from './helpers.js';
|
|
|
651
656
|
// trigger click or hover event (they send the same parameters so we share their code)
|
|
652
657
|
|
|
653
658
|
function triggerClickHoverEvent(eventname, e) {
|
|
659
|
+
// See drawDonutHole above: read `options` fresh in case the
|
|
660
|
+
// event fires before processDatapoints has run.
|
|
661
|
+
var options = plot.getOptions();
|
|
654
662
|
var offset = plot.offset();
|
|
655
|
-
var canvasX = parseInt(e.pageX - offset.left);
|
|
656
|
-
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));
|
|
657
665
|
var item = findNearbySlice(canvasX, canvasY);
|
|
658
666
|
|
|
659
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 =
|
|
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
|
-
|
|
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/test.ts
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
// sensible types. Run `npx tsc --noEmit types/test.ts` to check.
|
|
3
3
|
|
|
4
4
|
import {
|
|
5
|
+
color,
|
|
5
6
|
type DataSeries,
|
|
6
7
|
type Plot,
|
|
7
8
|
type PlotOptions,
|
|
8
|
-
color,
|
|
9
9
|
plot,
|
|
10
10
|
saturated,
|
|
11
11
|
version,
|
|
@@ -44,11 +44,11 @@ const p: Plot = plot(el, data, options);
|
|
|
44
44
|
// Plot methods
|
|
45
45
|
p.getData();
|
|
46
46
|
p.setData(data);
|
|
47
|
-
const
|
|
48
|
-
const
|
|
49
|
-
const
|
|
50
|
-
const
|
|
51
|
-
const
|
|
47
|
+
const _offset = p.getPlotOffset();
|
|
48
|
+
const _width: number = p.width();
|
|
49
|
+
const _height: number = p.height();
|
|
50
|
+
const _axes = p.getAxes();
|
|
51
|
+
const _xAxes = p.getXAxes();
|
|
52
52
|
|
|
53
53
|
// Plugin methods (optional)
|
|
54
54
|
p.highlight?.(0, 0);
|
|
@@ -66,7 +66,7 @@ saturated.floorInBase(17, 5);
|
|
|
66
66
|
saturated.multiplyAdd(1e300, 10, 5);
|
|
67
67
|
|
|
68
68
|
// Version string
|
|
69
|
-
const
|
|
69
|
+
const _v: string = version;
|
|
70
70
|
|
|
71
71
|
// String placeholder also works
|
|
72
72
|
plot("#placeholder", data);
|