@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,584 @@
1
+ /* Pretty handling of time axes.
2
+
3
+ Copyright (c) 2007-2014 IOLA and Ole Laursen.
4
+ Licensed under the MIT license.
5
+
6
+ Set axis.mode to "time" to enable. See the section "Time series data" in
7
+ API.txt for details.
8
+ */
9
+
10
+ import { plugins } from './jquery.flot.js';
11
+ import { saturated } from './jquery.flot.saturated.js';
12
+
13
+ 'use strict';
14
+
15
+ var options = {
16
+ xaxis: {
17
+ timezone: null, // "browser" for local to the client or timezone for timezone-js
18
+ timeformat: null, // format string to use
19
+ twelveHourClock: false, // 12 or 24 time in time mode
20
+ monthNames: null, // list of names of months
21
+ timeBase: 'seconds' // are the values in given in mircoseconds, milliseconds or seconds
22
+ },
23
+ yaxis: {
24
+ timeBase: 'seconds'
25
+ }
26
+ };
27
+
28
+ var floorInBase = saturated.floorInBase;
29
+
30
+ // Method to provide microsecond support to Date like classes.
31
+ var CreateMicroSecondDate = function(DateType, microEpoch) {
32
+ var newDate = new DateType(microEpoch);
33
+
34
+ var oldSetTime = newDate.setTime.bind(newDate);
35
+ newDate.update = function(microEpoch) {
36
+ // Round epoch to 3 decimal accuracy
37
+ microEpoch = Math.round(microEpoch * 1000) / 1000;
38
+
39
+ oldSetTime(microEpoch);
40
+
41
+ // Microseconds are stored as integers
42
+ this.microseconds = 1000 * (microEpoch - Math.floor(microEpoch));
43
+ };
44
+
45
+ var oldGetTime = newDate.getTime.bind(newDate);
46
+ newDate.getTime = function () {
47
+ var microEpoch = oldGetTime() + this.microseconds / 1000;
48
+ return microEpoch;
49
+ };
50
+
51
+ newDate.setTime = function (microEpoch) {
52
+ this.update(microEpoch);
53
+ };
54
+
55
+ newDate.getMicroseconds = function() {
56
+ return this.microseconds;
57
+ };
58
+
59
+ newDate.setMicroseconds = function(microseconds) {
60
+ var epochWithoutMicroseconds = oldGetTime();
61
+ var newEpoch = epochWithoutMicroseconds + microseconds / 1000;
62
+ this.update(newEpoch);
63
+ };
64
+
65
+ newDate.setUTCMicroseconds = function(microseconds) { this.setMicroseconds(microseconds); }
66
+
67
+ newDate.getUTCMicroseconds = function() { return this.getMicroseconds(); }
68
+
69
+ newDate.microseconds = null;
70
+ newDate.microEpoch = null;
71
+ newDate.update(microEpoch);
72
+ return newDate;
73
+ }
74
+
75
+ // Returns a string with the date d formatted according to fmt.
76
+ // A subset of the Open Group's strftime format is supported.
77
+
78
+ export function formatDate(d, fmt, monthNames, dayNames) {
79
+ if (typeof d.strftime === "function") {
80
+ return d.strftime(fmt);
81
+ }
82
+
83
+ var leftPad = function(n, pad) {
84
+ n = "" + n;
85
+ pad = "" + (pad == null ? "0" : pad);
86
+ return n.length === 1 ? pad + n : n;
87
+ };
88
+
89
+ var formatSubSeconds = function(milliseconds, microseconds, numberDecimalPlaces) {
90
+ var totalMicroseconds = milliseconds * 1000 + microseconds;
91
+ var formattedString;
92
+ if (numberDecimalPlaces < 6 && numberDecimalPlaces > 0) {
93
+ var magnitude = parseFloat('1e' + (numberDecimalPlaces - 6));
94
+ totalMicroseconds = Math.round(Math.round(totalMicroseconds * magnitude) / magnitude);
95
+ formattedString = ('00000' + totalMicroseconds).slice(-6, -(6 - numberDecimalPlaces));
96
+ } else {
97
+ totalMicroseconds = Math.round(totalMicroseconds)
98
+ formattedString = ('00000' + totalMicroseconds).slice(-6);
99
+ }
100
+ return formattedString;
101
+ };
102
+
103
+ var r = [];
104
+ var escape = false;
105
+ var hours = d.getHours();
106
+ var isAM = hours < 12;
107
+
108
+ if (!monthNames) {
109
+ monthNames = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
110
+ }
111
+
112
+ if (!dayNames) {
113
+ dayNames = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
114
+ }
115
+
116
+ var hours12;
117
+ if (hours > 12) {
118
+ hours12 = hours - 12;
119
+ } else if (hours === 0) {
120
+ hours12 = 12;
121
+ } else {
122
+ hours12 = hours;
123
+ }
124
+
125
+ var decimals = -1;
126
+ for (var i = 0; i < fmt.length; ++i) {
127
+ var c = fmt.charAt(i);
128
+
129
+ if (!isNaN(Number(c)) && Number(c) > 0) {
130
+ decimals = Number(c);
131
+ } else if (escape) {
132
+ switch (c) {
133
+ case 'a': c = "" + dayNames[d.getDay()]; break;
134
+ case 'b': c = "" + monthNames[d.getMonth()]; break;
135
+ case 'd': c = leftPad(d.getDate()); break;
136
+ case 'e': c = leftPad(d.getDate(), " "); break;
137
+ case 'h': // For back-compat with 0.7; remove in 1.0
138
+ case 'H': c = leftPad(hours); break;
139
+ case 'I': c = leftPad(hours12); break;
140
+ case 'l': c = leftPad(hours12, " "); break;
141
+ case 'm': c = leftPad(d.getMonth() + 1); break;
142
+ case 'M': c = leftPad(d.getMinutes()); break;
143
+ // quarters not in Open Group's strftime specification
144
+ case 'q':
145
+ c = "" + (Math.floor(d.getMonth() / 3) + 1); break;
146
+ case 'S': c = leftPad(d.getSeconds()); break;
147
+ case 's': c = "" + formatSubSeconds(d.getMilliseconds(), d.getMicroseconds(), decimals); break;
148
+ case 'y': c = leftPad(d.getFullYear() % 100); break;
149
+ case 'Y': c = "" + d.getFullYear(); break;
150
+ case 'p': c = (isAM) ? ("" + "am") : ("" + "pm"); break;
151
+ case 'P': c = (isAM) ? ("" + "AM") : ("" + "PM"); break;
152
+ case 'w': c = "" + d.getDay(); break;
153
+ }
154
+ r.push(c);
155
+ escape = false;
156
+ } else {
157
+ if (c === "%") {
158
+ escape = true;
159
+ } else {
160
+ r.push(c);
161
+ }
162
+ }
163
+ }
164
+
165
+ return r.join("");
166
+ }
167
+
168
+ // To have a consistent view of time-based data independent of which time
169
+ // zone the client happens to be in we need a date-like object independent
170
+ // of time zones. This is done through a wrapper that only calls the UTC
171
+ // versions of the accessor methods.
172
+
173
+ export function makeUtcWrapper(d) {
174
+ function addProxyMethod(sourceObj, sourceMethod, targetObj, targetMethod) {
175
+ sourceObj[sourceMethod] = function() {
176
+ return targetObj[targetMethod].apply(targetObj, arguments);
177
+ };
178
+ }
179
+
180
+ var utc = {
181
+ date: d
182
+ };
183
+
184
+ // support strftime, if found
185
+ if (d.strftime !== undefined) {
186
+ addProxyMethod(utc, "strftime", d, "strftime");
187
+ }
188
+
189
+ addProxyMethod(utc, "getTime", d, "getTime");
190
+ addProxyMethod(utc, "setTime", d, "setTime");
191
+
192
+ var props = ["Date", "Day", "FullYear", "Hours", "Minutes", "Month", "Seconds", "Milliseconds", "Microseconds"];
193
+
194
+ for (var p = 0; p < props.length; p++) {
195
+ addProxyMethod(utc, "get" + props[p], d, "getUTC" + props[p]);
196
+ addProxyMethod(utc, "set" + props[p], d, "setUTC" + props[p]);
197
+ }
198
+
199
+ return utc;
200
+ }
201
+
202
+ // select time zone strategy. This returns a date-like object tied to the
203
+ // desired timezone
204
+ export function dateGenerator(ts, opts) {
205
+ var maxDateValue = 8640000000000000;
206
+
207
+ if (opts && opts.timeBase === 'seconds') {
208
+ ts *= 1000;
209
+ } else if (opts.timeBase === 'microseconds') {
210
+ ts /= 1000;
211
+ }
212
+
213
+ if (ts > maxDateValue) {
214
+ ts = maxDateValue;
215
+ } else if (ts < -maxDateValue) {
216
+ ts = -maxDateValue;
217
+ }
218
+
219
+ if (opts.timezone === "browser") {
220
+ return CreateMicroSecondDate(Date, ts);
221
+ } else if (!opts.timezone || opts.timezone === "utc") {
222
+ return makeUtcWrapper(CreateMicroSecondDate(Date, ts));
223
+ } else if (typeof timezoneJS !== "undefined" && typeof timezoneJS.Date !== "undefined") {
224
+ var d = CreateMicroSecondDate(timezoneJS.Date, ts);
225
+ // timezone-js is fickle, so be sure to set the time zone before
226
+ // setting the time.
227
+ d.setTimezone(opts.timezone);
228
+ d.setTime(ts);
229
+ return d;
230
+ } else {
231
+ return makeUtcWrapper(CreateMicroSecondDate(Date, ts));
232
+ }
233
+ }
234
+
235
+ // map of app. size of time units in seconds
236
+ var timeUnitSizeSeconds = {
237
+ "microsecond": 0.000001,
238
+ "millisecond": 0.001,
239
+ "second": 1,
240
+ "minute": 60,
241
+ "hour": 60 * 60,
242
+ "day": 24 * 60 * 60,
243
+ "month": 30 * 24 * 60 * 60,
244
+ "quarter": 3 * 30 * 24 * 60 * 60,
245
+ "year": 365.2425 * 24 * 60 * 60
246
+ };
247
+
248
+ // map of app. size of time units in milliseconds
249
+ var timeUnitSizeMilliseconds = {
250
+ "microsecond": 0.001,
251
+ "millisecond": 1,
252
+ "second": 1000,
253
+ "minute": 60 * 1000,
254
+ "hour": 60 * 60 * 1000,
255
+ "day": 24 * 60 * 60 * 1000,
256
+ "month": 30 * 24 * 60 * 60 * 1000,
257
+ "quarter": 3 * 30 * 24 * 60 * 60 * 1000,
258
+ "year": 365.2425 * 24 * 60 * 60 * 1000
259
+ };
260
+
261
+ // map of app. size of time units in microseconds
262
+ var timeUnitSizeMicroseconds = {
263
+ "microsecond": 1,
264
+ "millisecond": 1000,
265
+ "second": 1000000,
266
+ "minute": 60 * 1000000,
267
+ "hour": 60 * 60 * 1000000,
268
+ "day": 24 * 60 * 60 * 1000000,
269
+ "month": 30 * 24 * 60 * 60 * 1000000,
270
+ "quarter": 3 * 30 * 24 * 60 * 60 * 1000000,
271
+ "year": 365.2425 * 24 * 60 * 60 * 1000000
272
+ };
273
+
274
+ // the allowed tick sizes, after 1 year we use
275
+ // an integer algorithm
276
+
277
+ var baseSpec = [
278
+ [1, "microsecond"], [2, "microsecond"], [5, "microsecond"], [10, "microsecond"],
279
+ [25, "microsecond"], [50, "microsecond"], [100, "microsecond"], [250, "microsecond"], [500, "microsecond"],
280
+ [1, "millisecond"], [2, "millisecond"], [5, "millisecond"], [10, "millisecond"],
281
+ [25, "millisecond"], [50, "millisecond"], [100, "millisecond"], [250, "millisecond"], [500, "millisecond"],
282
+ [1, "second"], [2, "second"], [5, "second"], [10, "second"],
283
+ [30, "second"],
284
+ [1, "minute"], [2, "minute"], [5, "minute"], [10, "minute"],
285
+ [30, "minute"],
286
+ [1, "hour"], [2, "hour"], [4, "hour"],
287
+ [8, "hour"], [12, "hour"],
288
+ [1, "day"], [2, "day"], [3, "day"],
289
+ [0.25, "month"], [0.5, "month"], [1, "month"],
290
+ [2, "month"]
291
+ ];
292
+
293
+ // we don't know which variant(s) we'll need yet, but generating both is
294
+ // cheap
295
+
296
+ var specMonths = baseSpec.concat([[3, "month"], [6, "month"],
297
+ [1, "year"]]);
298
+ var specQuarters = baseSpec.concat([[1, "quarter"], [2, "quarter"],
299
+ [1, "year"]]);
300
+
301
+ export function dateTickGenerator(axis) {
302
+ var opts = axis.options,
303
+ ticks = [],
304
+ d = dateGenerator(axis.min, opts),
305
+ minSize = 0;
306
+
307
+ // make quarter use a possibility if quarters are
308
+ // mentioned in either of these options
309
+ var spec = (opts.tickSize && opts.tickSize[1] ===
310
+ "quarter") ||
311
+ (opts.minTickSize && opts.minTickSize[1] ===
312
+ "quarter") ? specQuarters : specMonths;
313
+
314
+ var timeUnitSize;
315
+ if (opts.timeBase === 'seconds') {
316
+ timeUnitSize = timeUnitSizeSeconds;
317
+ } else if (opts.timeBase === 'microseconds') {
318
+ timeUnitSize = timeUnitSizeMicroseconds;
319
+ } else {
320
+ timeUnitSize = timeUnitSizeMilliseconds;
321
+ }
322
+
323
+ if (opts.minTickSize !== null && opts.minTickSize !== undefined) {
324
+ if (typeof opts.tickSize === "number") {
325
+ minSize = opts.tickSize;
326
+ } else {
327
+ minSize = opts.minTickSize[0] * timeUnitSize[opts.minTickSize[1]];
328
+ }
329
+ }
330
+
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) {
335
+ break;
336
+ }
337
+ }
338
+
339
+ var size = spec[i][0];
340
+ var unit = spec[i][1];
341
+ // special-case the possibility of several years
342
+ if (unit === "year") {
343
+ // if given a minTickSize in years, just use it,
344
+ // ensuring that it's an integer
345
+
346
+ if (opts.minTickSize !== null && opts.minTickSize !== undefined && opts.minTickSize[1] === "year") {
347
+ size = Math.floor(opts.minTickSize[0]);
348
+ } else {
349
+ var magn = parseFloat('1e' + Math.floor(Math.log(axis.delta / timeUnitSize.year) / Math.LN10));
350
+ var norm = (axis.delta / timeUnitSize.year) / magn;
351
+
352
+ if (norm < 1.5) {
353
+ size = 1;
354
+ } else if (norm < 3) {
355
+ size = 2;
356
+ } else if (norm < 7.5) {
357
+ size = 5;
358
+ } else {
359
+ size = 10;
360
+ }
361
+
362
+ size *= magn;
363
+ }
364
+
365
+ // minimum size for years is 1
366
+
367
+ if (size < 1) {
368
+ size = 1;
369
+ }
370
+ }
371
+
372
+ axis.tickSize = opts.tickSize || [size, unit];
373
+ var tickSize = axis.tickSize[0];
374
+ unit = axis.tickSize[1];
375
+
376
+ var step = tickSize * timeUnitSize[unit];
377
+
378
+ if (unit === "microsecond") {
379
+ d.setMicroseconds(floorInBase(d.getMicroseconds(), tickSize));
380
+ } else if (unit === "millisecond") {
381
+ d.setMilliseconds(floorInBase(d.getMilliseconds(), tickSize));
382
+ } else if (unit === "second") {
383
+ d.setSeconds(floorInBase(d.getSeconds(), tickSize));
384
+ } else if (unit === "minute") {
385
+ d.setMinutes(floorInBase(d.getMinutes(), tickSize));
386
+ } else if (unit === "hour") {
387
+ d.setHours(floorInBase(d.getHours(), tickSize));
388
+ } else if (unit === "month") {
389
+ d.setMonth(floorInBase(d.getMonth(), tickSize));
390
+ } else if (unit === "quarter") {
391
+ d.setMonth(3 * floorInBase(d.getMonth() / 3,
392
+ tickSize));
393
+ } else if (unit === "year") {
394
+ d.setFullYear(floorInBase(d.getFullYear(), tickSize));
395
+ }
396
+
397
+ // reset smaller components
398
+
399
+ if (step >= timeUnitSize.millisecond) {
400
+ d.setMicroseconds(0);
401
+ }
402
+ if (step >= timeUnitSize.second) {
403
+ d.setMilliseconds(0);
404
+ }
405
+ if (step >= timeUnitSize.minute) {
406
+ d.setSeconds(0);
407
+ }
408
+ if (step >= timeUnitSize.hour) {
409
+ d.setMinutes(0);
410
+ }
411
+ if (step >= timeUnitSize.day) {
412
+ d.setHours(0);
413
+ }
414
+ if (step >= timeUnitSize.day * 4) {
415
+ d.setDate(1);
416
+ }
417
+ if (step >= timeUnitSize.month * 2) {
418
+ d.setMonth(floorInBase(d.getMonth(), 3));
419
+ }
420
+ if (step >= timeUnitSize.quarter * 2) {
421
+ d.setMonth(floorInBase(d.getMonth(), 6));
422
+ }
423
+ if (step >= timeUnitSize.year) {
424
+ d.setMonth(0);
425
+ }
426
+
427
+ var carry = 0;
428
+ var v = Number.NaN;
429
+ var v1000;
430
+ var prev;
431
+ do {
432
+ prev = v;
433
+ v1000 = d.getTime();
434
+ if (opts && opts.timeBase === 'seconds') {
435
+ v = v1000 / 1000;
436
+ } else if (opts && opts.timeBase === 'microseconds') {
437
+ v = v1000 * 1000;
438
+ } else {
439
+ v = v1000;
440
+ }
441
+
442
+ ticks.push(v);
443
+
444
+ if (unit === "month" || unit === "quarter") {
445
+ if (tickSize < 1) {
446
+ // a bit complicated - we'll divide the
447
+ // month/quarter up but we need to take
448
+ // care of fractions so we don't end up in
449
+ // the middle of a day
450
+ d.setDate(1);
451
+ var start = d.getTime();
452
+ d.setMonth(d.getMonth() +
453
+ (unit === "quarter" ? 3 : 1));
454
+ var end = d.getTime();
455
+ d.setTime((v + carry * timeUnitSize.hour + (end - start) * tickSize));
456
+ carry = d.getHours();
457
+ d.setHours(0);
458
+ } else {
459
+ d.setMonth(d.getMonth() +
460
+ tickSize * (unit === "quarter" ? 3 : 1));
461
+ }
462
+ } else if (unit === "year") {
463
+ d.setFullYear(d.getFullYear() + tickSize);
464
+ } else {
465
+ if (opts.timeBase === 'seconds') {
466
+ d.setTime((v + step) * 1000);
467
+ } else if (opts.timeBase === 'microseconds') {
468
+ d.setTime((v + step) / 1000);
469
+ } else {
470
+ d.setTime(v + step);
471
+ }
472
+ }
473
+ } while (v < axis.max && v !== prev);
474
+
475
+ return ticks;
476
+ };
477
+
478
+ function init(plot) {
479
+ plot.hooks.processOptions.push(function (plot) {
480
+ var axes = plot.getAxes();
481
+ Object.keys(axes).forEach(function(axisName) {
482
+ var axis = axes[axisName];
483
+ var opts = axis.options;
484
+ if (opts.mode === "time") {
485
+ axis.tickGenerator = dateTickGenerator;
486
+
487
+ // if a tick formatter is already provided do not overwrite it
488
+ if ('tickFormatter' in opts && typeof opts.tickFormatter === 'function') return;
489
+
490
+ axis.tickFormatter = function (v, axis) {
491
+ var d = dateGenerator(v, axis.options);
492
+
493
+ // first check global format
494
+ if (opts.timeformat != null) {
495
+ return formatDate(d, opts.timeformat, opts.monthNames, opts.dayNames);
496
+ }
497
+
498
+ // possibly use quarters if quarters are mentioned in
499
+ // any of these places
500
+ var useQuarters = (axis.options.tickSize &&
501
+ axis.options.tickSize[1] === "quarter") ||
502
+ (axis.options.minTickSize &&
503
+ axis.options.minTickSize[1] === "quarter");
504
+
505
+ var timeUnitSize;
506
+ if (opts.timeBase === 'seconds') {
507
+ timeUnitSize = timeUnitSizeSeconds;
508
+ } else if (opts.timeBase === 'microseconds') {
509
+ timeUnitSize = timeUnitSizeMicroseconds;
510
+ } else {
511
+ timeUnitSize = timeUnitSizeMilliseconds;
512
+ }
513
+
514
+ var t = axis.tickSize[0] * timeUnitSize[axis.tickSize[1]];
515
+ var span = axis.max - axis.min;
516
+ var suffix = (opts.twelveHourClock) ? " %p" : "";
517
+ var hourCode = (opts.twelveHourClock) ? "%I" : "%H";
518
+ var factor;
519
+ var fmt;
520
+
521
+ if (opts.timeBase === 'seconds') {
522
+ factor = 1;
523
+ } else if (opts.timeBase === 'microseconds') {
524
+ factor = 1000000
525
+ } else {
526
+ factor = 1000;
527
+ }
528
+
529
+ if (t < timeUnitSize.second) {
530
+ var decimals = -Math.floor(Math.log10(t / factor))
531
+
532
+ // the two-and-halves require an additional decimal
533
+ if (String(t).indexOf('25') > -1) {
534
+ decimals++;
535
+ }
536
+
537
+ fmt = "%S.%" + decimals + "s";
538
+ } else
539
+ if (t < timeUnitSize.minute) {
540
+ fmt = hourCode + ":%M:%S" + suffix;
541
+ } else if (t < timeUnitSize.day) {
542
+ if (span < 2 * timeUnitSize.day) {
543
+ fmt = hourCode + ":%M" + suffix;
544
+ } else {
545
+ fmt = "%b %d " + hourCode + ":%M" + suffix;
546
+ }
547
+ } else if (t < timeUnitSize.month) {
548
+ fmt = "%b %d";
549
+ } else if ((useQuarters && t < timeUnitSize.quarter) ||
550
+ (!useQuarters && t < timeUnitSize.year)) {
551
+ if (span < timeUnitSize.year) {
552
+ fmt = "%b";
553
+ } else {
554
+ fmt = "%b %Y";
555
+ }
556
+ } else if (useQuarters && t < timeUnitSize.year) {
557
+ if (span < timeUnitSize.year) {
558
+ fmt = "Q%q";
559
+ } else {
560
+ fmt = "Q%q %Y";
561
+ }
562
+ } else {
563
+ fmt = "%Y";
564
+ }
565
+
566
+ var rt = formatDate(d, fmt, opts.monthNames, opts.dayNames);
567
+
568
+ return rt;
569
+ };
570
+ }
571
+ });
572
+ });
573
+ }
574
+
575
+ plugins.push({
576
+ init: init,
577
+ options: options,
578
+ name: 'time',
579
+ version: '1.0'
580
+ });
581
+
582
+ // Time-axis support used to be in Flot core, which exposed the
583
+ // formatDate function on the plot object. The entry point
584
+ // (index.js) wires these onto $.plot for backwards compatibility.