@kevinburke/flot 5.0.0

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.
Files changed (69) hide show
  1. package/CHANGELOG.md +1814 -0
  2. package/LICENSE.txt +22 -0
  3. package/README.md +119 -0
  4. package/dist/flot.js +9830 -0
  5. package/dist/flot.min.js +2 -0
  6. package/dist/flot.min.js.map +1 -0
  7. package/dist/flot.mjs +9805 -0
  8. package/dist/jquery.flot.js +9869 -0
  9. package/dist/jquery.flot.min.js +2 -0
  10. package/dist/jquery.flot.min.js.map +1 -0
  11. package/dist/plugins/jquery.flot.crosshair.js +207 -0
  12. package/dist/plugins/jquery.flot.crosshair.min.js +2 -0
  13. package/dist/plugins/jquery.flot.crosshair.min.js.map +1 -0
  14. package/dist/plugins/jquery.flot.image.js +261 -0
  15. package/dist/plugins/jquery.flot.image.min.js +2 -0
  16. package/dist/plugins/jquery.flot.image.min.js.map +1 -0
  17. package/dist/plugins/jquery.flot.pie.js +815 -0
  18. package/dist/plugins/jquery.flot.pie.min.js +2 -0
  19. package/dist/plugins/jquery.flot.pie.min.js.map +1 -0
  20. package/dist/plugins/jquery.flot.resize.js +62 -0
  21. package/dist/plugins/jquery.flot.resize.min.js +2 -0
  22. package/dist/plugins/jquery.flot.resize.min.js.map +1 -0
  23. package/dist/plugins/jquery.flot.threshold.js +148 -0
  24. package/dist/plugins/jquery.flot.threshold.min.js +2 -0
  25. package/dist/plugins/jquery.flot.threshold.min.js.map +1 -0
  26. package/docs/API.md +1767 -0
  27. package/docs/PLUGINS.md +143 -0
  28. package/docs/absRelTime.md +42 -0
  29. package/docs/browser.md +24 -0
  30. package/docs/canvaswrapper.md +116 -0
  31. package/docs/composeImages.md +32 -0
  32. package/docs/drawSeries.md +35 -0
  33. package/docs/hover.md +21 -0
  34. package/docs/interactions.md +57 -0
  35. package/docs/logaxis.md +27 -0
  36. package/docs/navigate.md +110 -0
  37. package/package.json +53 -0
  38. package/source/helpers.js +168 -0
  39. package/source/index.js +70 -0
  40. package/source/jquery-adapter.js +83 -0
  41. package/source/jquery.canvaswrapper.js +546 -0
  42. package/source/jquery.colorhelpers.js +198 -0
  43. package/source/jquery.flot.axislabels.js +214 -0
  44. package/source/jquery.flot.browser.js +53 -0
  45. package/source/jquery.flot.categories.js +202 -0
  46. package/source/jquery.flot.composeImages.js +327 -0
  47. package/source/jquery.flot.crosshair.js +203 -0
  48. package/source/jquery.flot.drawSeries.js +699 -0
  49. package/source/jquery.flot.errorbars.js +375 -0
  50. package/source/jquery.flot.fillbetween.js +254 -0
  51. package/source/jquery.flot.flatdata.js +47 -0
  52. package/source/jquery.flot.hover.js +354 -0
  53. package/source/jquery.flot.image.js +252 -0
  54. package/source/jquery.flot.js +2814 -0
  55. package/source/jquery.flot.legend.js +444 -0
  56. package/source/jquery.flot.logaxis.js +299 -0
  57. package/source/jquery.flot.navigate.js +842 -0
  58. package/source/jquery.flot.pie.js +811 -0
  59. package/source/jquery.flot.resize.js +57 -0
  60. package/source/jquery.flot.saturated.js +40 -0
  61. package/source/jquery.flot.selection.js +552 -0
  62. package/source/jquery.flot.stack.js +220 -0
  63. package/source/jquery.flot.symbol.js +98 -0
  64. package/source/jquery.flot.threshold.js +144 -0
  65. package/source/jquery.flot.time.js +584 -0
  66. package/source/jquery.flot.touch.js +320 -0
  67. package/source/jquery.flot.touchNavigate.js +357 -0
  68. package/source/jquery.flot.uiConstants.js +9 -0
  69. package/source/jquery.js +9473 -0
@@ -0,0 +1,444 @@
1
+ /* Flot plugin for drawing legends.
2
+
3
+ */
4
+
5
+ import { plugins } from './jquery.flot.js';
6
+
7
+ var defaultOptions = {
8
+ legend: {
9
+ show: false,
10
+ noColumns: 1,
11
+ labelFormatter: null, // fn: string -> string
12
+ container: null, // container (as jQuery object) to put legend in, null means default on top of graph
13
+ position: 'ne', // position of default legend container within plot
14
+ margin: 5, // distance from grid edge to default legend container within plot
15
+ sorted: null // default to no legend sorting
16
+ }
17
+ };
18
+
19
+ function insertLegend(plot, options, placeholder, legendEntries) {
20
+ // clear before redraw
21
+ if (options.legend.container != null) {
22
+ options.legend.container.innerHTML = '';
23
+ } else {
24
+ var oldLegends = placeholder.querySelectorAll('.legend');
25
+ for (var li = 0; li < oldLegends.length; li++) {
26
+ oldLegends[li].remove();
27
+ }
28
+ }
29
+
30
+ if (!options.legend.show) {
31
+ return;
32
+ }
33
+
34
+ // Save the legend entries in legend options
35
+ var entries = options.legend.legendEntries = legendEntries,
36
+ plotOffset = options.legend.plotOffset = plot.getPlotOffset(),
37
+ html = [],
38
+ entry, labelHtml, iconHtml,
39
+ j = 0,
40
+ i,
41
+ pos = "",
42
+ p = options.legend.position,
43
+ m = options.legend.margin,
44
+ shape = {
45
+ name: '',
46
+ label: '',
47
+ xPos: '',
48
+ yPos: ''
49
+ };
50
+
51
+ html[j++] = '<svg class="legendLayer" style="width:inherit;height:inherit;">';
52
+ html[j++] = '<rect class="background" width="100%" height="100%"/>';
53
+ html[j++] = svgShapeDefs;
54
+
55
+ var left = 0;
56
+ var columnWidths = [];
57
+ var style = window.getComputedStyle(document.querySelector('body'));
58
+ for (i = 0; i < entries.length; ++i) {
59
+ let columnIndex = i % options.legend.noColumns;
60
+ entry = entries[i];
61
+ shape.label = entry.label;
62
+ var info = plot.getSurface().getTextInfo('', shape.label, {
63
+ style: style.fontStyle,
64
+ variant: style.fontVariant,
65
+ weight: style.fontWeight,
66
+ size: parseInt(style.fontSize),
67
+ lineHeight: parseInt(style.lineHeight),
68
+ family: style.fontFamily
69
+ });
70
+
71
+ var labelWidth = info.width;
72
+ // 36px = 1.5em + 6px margin
73
+ var iconWidth = 48;
74
+ if (columnWidths[columnIndex]) {
75
+ if (labelWidth > columnWidths[columnIndex]) {
76
+ columnWidths[columnIndex] = labelWidth + iconWidth;
77
+ }
78
+ } else {
79
+ columnWidths[columnIndex] = labelWidth + iconWidth;
80
+ }
81
+ }
82
+
83
+ // Generate html for icons and labels from a list of entries
84
+ for (i = 0; i < entries.length; ++i) {
85
+ let columnIndex = i % options.legend.noColumns;
86
+ entry = entries[i];
87
+ iconHtml = '';
88
+ shape.label = entry.label;
89
+ shape.xPos = (left + 3) + 'px';
90
+ left += columnWidths[columnIndex];
91
+ if ((i + 1) % options.legend.noColumns === 0) {
92
+ left = 0;
93
+ }
94
+ shape.yPos = Math.floor(i / options.legend.noColumns) * 1.5 + 'em';
95
+ // area
96
+ if (entry.options.lines.show && entry.options.lines.fill) {
97
+ shape.name = 'area';
98
+ shape.fillColor = entry.color;
99
+ iconHtml += getEntryIconHtml(shape);
100
+ }
101
+ // bars
102
+ if (entry.options.bars.show) {
103
+ shape.name = 'bar';
104
+ shape.fillColor = entry.color;
105
+ iconHtml += getEntryIconHtml(shape);
106
+ }
107
+ // lines
108
+ if (entry.options.lines.show && !entry.options.lines.fill) {
109
+ shape.name = 'line';
110
+ shape.strokeColor = entry.color;
111
+ shape.strokeWidth = entry.options.lines.lineWidth;
112
+ iconHtml += getEntryIconHtml(shape);
113
+ }
114
+ // points
115
+ if (entry.options.points.show) {
116
+ shape.name = entry.options.points.symbol;
117
+ shape.strokeColor = entry.color;
118
+ shape.fillColor = entry.options.points.fillColor;
119
+ shape.strokeWidth = entry.options.points.lineWidth;
120
+ iconHtml += getEntryIconHtml(shape);
121
+ }
122
+
123
+ labelHtml = '<text x="' + shape.xPos + '" y="' + shape.yPos + '" text-anchor="start"><tspan dx="2em" dy="1.2em">' + shape.label + '</tspan></text>'
124
+ html[j++] = '<g>' + iconHtml + labelHtml + '</g>';
125
+ }
126
+
127
+ html[j++] = '</svg>';
128
+ if (m[0] == null) {
129
+ m = [m, m];
130
+ }
131
+
132
+ if (p.charAt(0) === 'n') {
133
+ pos += 'top:' + (m[1] + plotOffset.top) + 'px;';
134
+ } else if (p.charAt(0) === 's') {
135
+ pos += 'bottom:' + (m[1] + plotOffset.bottom) + 'px;';
136
+ }
137
+
138
+ if (p.charAt(1) === 'e') {
139
+ pos += 'right:' + (m[0] + plotOffset.right) + 'px;';
140
+ } else if (p.charAt(1) === 'w') {
141
+ pos += 'left:' + (m[0] + plotOffset.left) + 'px;';
142
+ }
143
+
144
+ var width = 6;
145
+ for (i = 0; i < columnWidths.length; ++i) {
146
+ width += columnWidths[i];
147
+ }
148
+
149
+ var legendEl,
150
+ height = Math.ceil(entries.length / options.legend.noColumns) * 1.6;
151
+ if (!options.legend.container) {
152
+ legendEl = document.createElement('div');
153
+ legendEl.className = 'legend';
154
+ legendEl.style.cssText = 'position:absolute;' + pos;
155
+ legendEl.innerHTML = html.join('');
156
+ legendEl.style.width = width + 'px';
157
+ legendEl.style.height = height + 'em';
158
+ legendEl.style.pointerEvents = 'none';
159
+ placeholder.appendChild(legendEl);
160
+ } else {
161
+ options.legend.container.innerHTML = html.join('');
162
+ options.legend.container.style.width = width + 'px';
163
+ options.legend.container.style.height = height + 'em';
164
+ }
165
+ }
166
+
167
+ // Generate html for a shape
168
+ function getEntryIconHtml(shape) {
169
+ var html = '',
170
+ name = shape.name,
171
+ x = shape.xPos,
172
+ y = shape.yPos,
173
+ fill = shape.fillColor,
174
+ stroke = shape.strokeColor,
175
+ width = shape.strokeWidth;
176
+ switch (name) {
177
+ case 'circle':
178
+ html = '<use xlink:href="#circle" class="legendIcon" ' +
179
+ 'x="' + x + '" ' +
180
+ 'y="' + y + '" ' +
181
+ 'fill="' + fill + '" ' +
182
+ 'stroke="' + stroke + '" ' +
183
+ 'stroke-width="' + width + '" ' +
184
+ 'width="1.5em" height="1.5em"' +
185
+ '/>';
186
+ break;
187
+ case 'diamond':
188
+ html = '<use xlink:href="#diamond" class="legendIcon" ' +
189
+ 'x="' + x + '" ' +
190
+ 'y="' + y + '" ' +
191
+ 'fill="' + fill + '" ' +
192
+ 'stroke="' + stroke + '" ' +
193
+ 'stroke-width="' + width + '" ' +
194
+ 'width="1.5em" height="1.5em"' +
195
+ '/>';
196
+ break;
197
+ case 'cross':
198
+ html = '<use xlink:href="#cross" class="legendIcon" ' +
199
+ 'x="' + x + '" ' +
200
+ 'y="' + y + '" ' +
201
+ // 'fill="' + fill + '" ' +
202
+ 'stroke="' + stroke + '" ' +
203
+ 'stroke-width="' + width + '" ' +
204
+ 'width="1.5em" height="1.5em"' +
205
+ '/>';
206
+ break;
207
+ case 'rectangle':
208
+ html = '<use xlink:href="#rectangle" class="legendIcon" ' +
209
+ 'x="' + x + '" ' +
210
+ 'y="' + y + '" ' +
211
+ 'fill="' + fill + '" ' +
212
+ 'stroke="' + stroke + '" ' +
213
+ 'stroke-width="' + width + '" ' +
214
+ 'width="1.5em" height="1.5em"' +
215
+ '/>';
216
+ break;
217
+ case 'plus':
218
+ html = '<use xlink:href="#plus" class="legendIcon" ' +
219
+ 'x="' + x + '" ' +
220
+ 'y="' + y + '" ' +
221
+ // 'fill="' + fill + '" ' +
222
+ 'stroke="' + stroke + '" ' +
223
+ 'stroke-width="' + width + '" ' +
224
+ 'width="1.5em" height="1.5em"' +
225
+ '/>';
226
+ break;
227
+ case 'bar':
228
+ html = '<use xlink:href="#bars" class="legendIcon" ' +
229
+ 'x="' + x + '" ' +
230
+ 'y="' + y + '" ' +
231
+ 'fill="' + fill + '" ' +
232
+ // 'stroke="' + stroke + '" ' +
233
+ // 'stroke-width="' + width + '" ' +
234
+ 'width="1.5em" height="1.5em"' +
235
+ '/>';
236
+ break;
237
+ case 'area':
238
+ html = '<use xlink:href="#area" class="legendIcon" ' +
239
+ 'x="' + x + '" ' +
240
+ 'y="' + y + '" ' +
241
+ 'fill="' + fill + '" ' +
242
+ // 'stroke="' + stroke + '" ' +
243
+ // 'stroke-width="' + width + '" ' +
244
+ 'width="1.5em" height="1.5em"' +
245
+ '/>';
246
+ break;
247
+ case 'line':
248
+ html = '<use xlink:href="#line" class="legendIcon" ' +
249
+ 'x="' + x + '" ' +
250
+ 'y="' + y + '" ' +
251
+ // 'fill="' + fill + '" ' +
252
+ 'stroke="' + stroke + '" ' +
253
+ 'stroke-width="' + width + '" ' +
254
+ 'width="1.5em" height="1.5em"' +
255
+ '/>';
256
+ break;
257
+ default:
258
+ // default is circle
259
+ html = '<use xlink:href="#circle" class="legendIcon" ' +
260
+ 'x="' + x + '" ' +
261
+ 'y="' + y + '" ' +
262
+ 'fill="' + fill + '" ' +
263
+ 'stroke="' + stroke + '" ' +
264
+ 'stroke-width="' + width + '" ' +
265
+ 'width="1.5em" height="1.5em"' +
266
+ '/>';
267
+ }
268
+
269
+ return html;
270
+ }
271
+
272
+ // Define svg symbols for shapes
273
+ var svgShapeDefs = '' +
274
+ '<defs>' +
275
+ '<symbol id="line" fill="none" viewBox="-5 -5 25 25">' +
276
+ '<polyline points="0,15 5,5 10,10 15,0"/>' +
277
+ '</symbol>' +
278
+
279
+ '<symbol id="area" stroke-width="1" viewBox="-5 -5 25 25">' +
280
+ '<polyline points="0,15 5,5 10,10 15,0, 15,15, 0,15"/>' +
281
+ '</symbol>' +
282
+
283
+ '<symbol id="bars" stroke-width="1" viewBox="-5 -5 25 25">' +
284
+ '<polyline points="1.5,15.5 1.5,12.5, 4.5,12.5 4.5,15.5 6.5,15.5 6.5,3.5, 9.5,3.5 9.5,15.5 11.5,15.5 11.5,7.5 14.5,7.5 14.5,15.5 1.5,15.5"/>' +
285
+ '</symbol>' +
286
+
287
+ '<symbol id="circle" viewBox="-5 -5 25 25">' +
288
+ '<circle cx="0" cy="15" r="2.5"/>' +
289
+ '<circle cx="5" cy="5" r="2.5"/>' +
290
+ '<circle cx="10" cy="10" r="2.5"/>' +
291
+ '<circle cx="15" cy="0" r="2.5"/>' +
292
+ '</symbol>' +
293
+
294
+ '<symbol id="rectangle" viewBox="-5 -5 25 25">' +
295
+ '<rect x="-2.1" y="12.9" width="4.2" height="4.2"/>' +
296
+ '<rect x="2.9" y="2.9" width="4.2" height="4.2"/>' +
297
+ '<rect x="7.9" y="7.9" width="4.2" height="4.2"/>' +
298
+ '<rect x="12.9" y="-2.1" width="4.2" height="4.2"/>' +
299
+ '</symbol>' +
300
+
301
+ '<symbol id="diamond" viewBox="-5 -5 25 25">' +
302
+ '<path d="M-3,15 L0,12 L3,15, L0,18 Z"/>' +
303
+ '<path d="M2,5 L5,2 L8,5, L5,8 Z"/>' +
304
+ '<path d="M7,10 L10,7 L13,10, L10,13 Z"/>' +
305
+ '<path d="M12,0 L15,-3 L18,0, L15,3 Z"/>' +
306
+ '</symbol>' +
307
+
308
+ '<symbol id="cross" fill="none" viewBox="-5 -5 25 25">' +
309
+ '<path d="M-2.1,12.9 L2.1,17.1, M2.1,12.9 L-2.1,17.1 Z"/>' +
310
+ '<path d="M2.9,2.9 L7.1,7.1 M7.1,2.9 L2.9,7.1 Z"/>' +
311
+ '<path d="M7.9,7.9 L12.1,12.1 M12.1,7.9 L7.9,12.1 Z"/>' +
312
+ '<path d="M12.9,-2.1 L17.1,2.1 M17.1,-2.1 L12.9,2.1 Z"/>' +
313
+ '</symbol>' +
314
+
315
+ '<symbol id="plus" fill="none" viewBox="-5 -5 25 25">' +
316
+ '<path d="M0,12 L0,18, M-3,15 L3,15 Z"/>' +
317
+ '<path d="M5,2 L5,8 M2,5 L8,5 Z"/>' +
318
+ '<path d="M10,7 L10,13 M7,10 L13,10 Z"/>' +
319
+ '<path d="M15,-3 L15,3 M12,0 L18,0 Z"/>' +
320
+ '</symbol>' +
321
+ '</defs>';
322
+
323
+ // Generate a list of legend entries in their final order
324
+ function getLegendEntries(series, labelFormatter, sorted) {
325
+ var lf = labelFormatter,
326
+ legendEntries = series.reduce(function(validEntries, s, i) {
327
+ var labelEval = (lf ? lf(s.label, s) : s.label)
328
+ if (s.hasOwnProperty("label") ? labelEval : true) {
329
+ var entry = {
330
+ label: labelEval || 'Plot ' + (i + 1),
331
+ color: s.color,
332
+ options: {
333
+ lines: s.lines,
334
+ points: s.points,
335
+ bars: s.bars
336
+ }
337
+ }
338
+ validEntries.push(entry)
339
+ }
340
+ return validEntries;
341
+ }, []);
342
+
343
+ // Sort the legend using either the default or a custom comparator
344
+ if (sorted) {
345
+ if (typeof sorted === 'function') {
346
+ legendEntries.sort(sorted);
347
+ } else if (sorted === 'reverse') {
348
+ legendEntries.reverse();
349
+ } else {
350
+ var ascending = (sorted !== 'descending');
351
+ legendEntries.sort(function(a, b) {
352
+ return a.label === b.label
353
+ ? 0
354
+ : ((a.label < b.label) !== ascending ? 1 : -1 // Logical XOR
355
+ );
356
+ });
357
+ }
358
+ }
359
+
360
+ return legendEntries;
361
+ }
362
+
363
+ // return false if opts1 same as opts2
364
+ function checkOptions(opts1, opts2) {
365
+ for (var prop in opts1) {
366
+ if (opts1.hasOwnProperty(prop)) {
367
+ if (opts1[prop] !== opts2[prop]) {
368
+ return true;
369
+ }
370
+ }
371
+ }
372
+ return false;
373
+ }
374
+
375
+ // Compare two lists of legend entries
376
+ function shouldRedraw(oldEntries, newEntries) {
377
+ if (!oldEntries || !newEntries) {
378
+ return true;
379
+ }
380
+
381
+ if (oldEntries.length !== newEntries.length) {
382
+ return true;
383
+ }
384
+ var i, newEntry, oldEntry, newOpts, oldOpts;
385
+ for (i = 0; i < newEntries.length; i++) {
386
+ newEntry = newEntries[i];
387
+ oldEntry = oldEntries[i];
388
+
389
+ if (newEntry.label !== oldEntry.label) {
390
+ return true;
391
+ }
392
+
393
+ if (newEntry.color !== oldEntry.color) {
394
+ return true;
395
+ }
396
+
397
+ // check for changes in lines options
398
+ newOpts = newEntry.options.lines;
399
+ oldOpts = oldEntry.options.lines;
400
+ if (checkOptions(newOpts, oldOpts)) {
401
+ return true;
402
+ }
403
+
404
+ // check for changes in points options
405
+ newOpts = newEntry.options.points;
406
+ oldOpts = oldEntry.options.points;
407
+ if (checkOptions(newOpts, oldOpts)) {
408
+ return true;
409
+ }
410
+
411
+ // check for changes in bars options
412
+ newOpts = newEntry.options.bars;
413
+ oldOpts = oldEntry.options.bars;
414
+ if (checkOptions(newOpts, oldOpts)) {
415
+ return true;
416
+ }
417
+ }
418
+
419
+ return false;
420
+ }
421
+
422
+ function init(plot) {
423
+ plot.hooks.setupGrid.push(function (plot) {
424
+ var options = plot.getOptions();
425
+ var series = plot.getData(),
426
+ labelFormatter = options.legend.labelFormatter,
427
+ oldEntries = options.legend.legendEntries,
428
+ oldPlotOffset = options.legend.plotOffset,
429
+ newEntries = getLegendEntries(series, labelFormatter, options.legend.sorted),
430
+ newPlotOffset = plot.getPlotOffset();
431
+
432
+ if (shouldRedraw(oldEntries, newEntries) ||
433
+ checkOptions(oldPlotOffset, newPlotOffset)) {
434
+ insertLegend(plot, options, plot.getPlaceholder(), newEntries);
435
+ }
436
+ });
437
+ }
438
+
439
+ plugins.push({
440
+ init: init,
441
+ options: defaultOptions,
442
+ name: 'legend',
443
+ version: '1.0'
444
+ });