@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
package/docs/API.md ADDED
@@ -0,0 +1,1767 @@
1
+ # Flot Reference #
2
+
3
+ **Table of Contents**
4
+
5
+ [Introduction](#introduction)
6
+ | [Data Format](#data-format)
7
+ | [Plot Options](#plot-options)
8
+ | [Customizing the legend](#customizing-the-legend)
9
+ | [Customizing the axes](#customizing-the-axes)
10
+ | [Multiple axes](#multiple-axes)
11
+ | [Time series data](#time-series-data)
12
+ | [Customizing the data series](#customizing-the-data-series)
13
+ | [Customizing the grid](#customizing-the-grid)
14
+ | [Specifying gradients](#specifying-gradients)
15
+ | [Plot Methods](#plot-methods)
16
+ | [Hooks](#hooks)
17
+ | [Plugins](#plugins)
18
+ | [Version number](#version-number)
19
+
20
+ ---
21
+
22
+ ## Introduction ##
23
+
24
+ Consider a call to the plot function:
25
+
26
+ ```js
27
+ var plot = $.plot(placeholder, data, options);
28
+ ```
29
+
30
+ The placeholder is a jQuery object or DOM element or jQuery expression
31
+ that the plot will be put into. This placeholder needs to have its
32
+ width and height set as explained in the [README](README.md) (go read that now if
33
+ you haven't, it's short). The plot will modify some properties of the
34
+ placeholder so it's recommended you simply pass in a div that you
35
+ don't use for anything else. Make sure you check any fancy styling
36
+ you apply to the div, e.g. background images have been reported to be a
37
+ problem on IE 7.
38
+
39
+ The plot function can also be used as a jQuery chainable property. This form
40
+ naturally can't return the plot object directly, but you can still access it
41
+ via the 'plot' data key, like this:
42
+
43
+ ```js
44
+ var plot = $("#placeholder").plot(data, options).data("plot");
45
+ ```
46
+
47
+ The format of the data is documented below, as is the available
48
+ options. The plot object returned from the call has some methods you
49
+ can call. These are documented separately below.
50
+
51
+ Note that in general Flot gives no guarantees if you change any of the
52
+ objects you pass in to the plot function or get out of it since
53
+ they're not necessarily deep-copied.
54
+
55
+
56
+ ## Data Format ##
57
+
58
+ The data is an array of data series:
59
+
60
+ ```js
61
+ [ series1, series2, ... ]
62
+ ```
63
+
64
+ A series can either be raw data or an object with properties. The raw
65
+ data format is an array of points:
66
+
67
+ ```js
68
+ [ [x1, y1], [x2, y2], ... ]
69
+ ```
70
+
71
+ E.g.
72
+
73
+ ```js
74
+ [ [1, 3], [2, 14.01], [3.5, 3.14] ]
75
+ ```
76
+
77
+ Note that to simplify the internal logic in Flot both the x and y
78
+ values must be numbers (even if specifying time series, see below for
79
+ how to do this). This is a common problem because you might retrieve
80
+ data from the database and serialize them directly to JSON without
81
+ noticing the wrong type. If you're getting mysterious errors, double
82
+ check that you're inputting numbers and not strings.
83
+
84
+ If a null is specified as a point or if one of the coordinates is null
85
+ or couldn't be converted to a number, the point is ignored when
86
+ drawing. As a special case, a null value for lines is interpreted as a
87
+ line segment end, i.e. the points before and after the null value are
88
+ not connected.
89
+
90
+ Lines and points take two coordinates. For filled lines and bars, you
91
+ can specify a third coordinate which is the bottom of the filled
92
+ area/bar (defaults to 0). If you don't specify a third coordinate you can
93
+ specify it as a constant for the entire series using "fillTowards" (see the lines
94
+ options).
95
+
96
+ The format of a single series object is as follows:
97
+
98
+ ```js
99
+ {
100
+ color: color or number
101
+ data: rawdata
102
+ label: string
103
+ lines: specific lines options
104
+ bars: specific bars options
105
+ points: specific points options
106
+ xaxis: number
107
+ yaxis: number
108
+ clickable: boolean
109
+ hoverable: boolean
110
+ shadowSize: number
111
+ highlightColor: color or number
112
+ }
113
+ ```
114
+
115
+ You don't have to specify any of them except the data, the rest are
116
+ options that will get default values. Typically you'd only specify
117
+ label and data, like this:
118
+
119
+ ```js
120
+ {
121
+ label: "y = 3",
122
+ data: [[0, 3], [10, 3]]
123
+ }
124
+ ```
125
+
126
+ The label is used for the legend, if you don't specify one, the series
127
+ will not show up in the legend.
128
+
129
+ If you don't specify color, the series will get a color from the
130
+ auto-generated colors. The color is either a CSS color specification
131
+ (like "rgb(255, 100, 123)") or an integer that specifies which of
132
+ auto-generated colors to select, e.g. 0 will get color no. 0, etc.
133
+
134
+ The latter is mostly useful if you let the user add and remove series,
135
+ in which case you can hard-code the color index to prevent the colors
136
+ from jumping around between the series.
137
+
138
+ The "xaxis" and "yaxis" options specify which axis to use. The axes
139
+ are numbered from 1 (default), so { yaxis: 2} means that the series
140
+ should be plotted against the second y axis.
141
+
142
+ "clickable" and "hoverable" can be set to false to disable
143
+ interactivity for specific series if interactivity is turned on in
144
+ the plot, see below.
145
+
146
+ The rest of the options are all documented below as they are the same
147
+ as the default options passed in via the options parameter in the plot
148
+ command. When you specify them for a specific data series, they will
149
+ override the default options for the plot for that data series.
150
+
151
+ Here's a complete example of a simple data specification:
152
+
153
+ ```js
154
+ [ { label: "Foo", data: [ [10, 1], [17, -14], [30, 5] ] },
155
+ { label: "Bar", data: [ [11, 13], [19, 11], [30, -7] ] }
156
+ ]
157
+ ```
158
+
159
+
160
+ ## Plot Options ##
161
+
162
+ All options are completely optional. They are documented individually
163
+ below, to change them you just specify them in an object, e.g.
164
+
165
+ ```js
166
+ var options = {
167
+ series: {
168
+ lines: { show: true },
169
+ points: { show: true }
170
+ }
171
+ };
172
+
173
+ $.plot(placeholder, data, options);
174
+ ```
175
+
176
+
177
+ ## Customizing the legend ##
178
+
179
+ ```js
180
+ legend: {
181
+ show: boolean
182
+ labelFormatter: null or (fn: string, series object -> string)
183
+ labelBoxBorderColor: color
184
+ noColumns: number
185
+ position: "ne" or "nw" or "se" or "sw"
186
+ margin: number of pixels or [x margin, y margin]
187
+ backgroundColor: null or color
188
+ backgroundOpacity: number between 0 and 1
189
+ container: null or jQuery object/DOM element/jQuery expression
190
+ sorted: null/false, true, "ascending", "descending", "reverse", or a comparator
191
+ }
192
+ ```
193
+
194
+ The legend is generated as a table with the data series labels and
195
+ small label boxes with the color of the series. If you want to format
196
+ the labels in some way, e.g. make them to links, you can pass in a
197
+ function for "labelFormatter". Here's an example that makes them
198
+ clickable:
199
+
200
+ ```js
201
+ labelFormatter: function(label, series) {
202
+ // series is the series object for the label
203
+ return '<a href="#' + label + '">' + label + '</a>';
204
+ }
205
+ ```
206
+
207
+ To prevent a series from showing up in the legend, simply have the function
208
+ return null.
209
+
210
+ "noColumns" is the number of columns to divide the legend table into.
211
+ "position" specifies the overall placement of the legend within the
212
+ plot (top-right, top-left, etc.) and margin the distance to the plot
213
+ edge (this can be either a number or an array of two numbers like [x,
214
+ y]). "backgroundColor" and "backgroundOpacity" specifies the
215
+ background. The default is a partly transparent auto-detected
216
+ background.
217
+
218
+ If you want the legend to appear somewhere else in the DOM, you can
219
+ specify "container" as a jQuery object/expression to put the legend
220
+ table into. The "position" and "margin" etc. options will then be
221
+ ignored. Note that Flot will overwrite the contents of the container.
222
+
223
+ Legend entries appear in the same order as their series by default. If "sorted"
224
+ is "reverse" then they appear in the opposite order from their series. To sort
225
+ them alphabetically, you can specify true, "ascending" or "descending", where
226
+ true and "ascending" are equivalent.
227
+
228
+ You can also provide your own comparator function that accepts two
229
+ objects with "label" and "color" properties, and returns zero if they
230
+ are equal, a positive value if the first is greater than the second,
231
+ and a negative value if the first is less than the second.
232
+
233
+ ```js
234
+ sorted: function(a, b) {
235
+ // sort alphabetically in ascending order
236
+ return a.label == b.label ? 0 : (
237
+ a.label > b.label ? 1 : -1
238
+ )
239
+ }
240
+ ```
241
+
242
+
243
+ ## Customizing the axes ##
244
+
245
+ ```js
246
+ xaxis, yaxis: {
247
+ show: null or true/false
248
+ position: "bottom" or "top" or "left" or "right"
249
+ mode: null or "time" ("time" requires jquery.flot.time.js plugin)
250
+ inverted: null or true/false
251
+ timezone: null, "browser" or timezone (only makes sense for mode: "time")
252
+
253
+ color: null or color spec
254
+ tickColor: null or color spec
255
+ font: null or font spec object
256
+
257
+ min: null or number
258
+ max: null or number
259
+ autoScaleMargin: null or number
260
+ windowSize: null or number
261
+ autoScale: "none" or "loose" or "exact" or "sliding-window"
262
+ growOnly: null or boolean
263
+
264
+ transform: null or fn: number -> number
265
+ inverseTransform: null or fn: number -> number
266
+
267
+ ticks: null or number or ticks array or (fn: axis -> ticks array)
268
+ tickSize: number or array
269
+ minTickSize: number or array
270
+ tickFormatter: (fn: number, object, number -> string) or string
271
+ tickDecimals: null or number
272
+
273
+ showTickLabels: "major", "none", "endpoints", or "all"
274
+ labelWidth: null or number
275
+ labelHeight: null or number
276
+ reserveSpace: null or true
277
+
278
+ gridLines: null or true
279
+
280
+ showTicks: null or true
281
+ showMinorTicks: null or true
282
+ tickLength: null or number
283
+
284
+ alignTicksWithAxis: null or number
285
+
286
+ offset: null or object({ below: number, above: number })
287
+ boxPosition: { centerX: number, centerY: number }
288
+ }
289
+ ```
290
+
291
+ All axes have the same kind of options. The following describes how to
292
+ configure one axis, see below for what to do if you've got more than
293
+ one x axis or y axis.
294
+
295
+ If you don't set the "show" option (i.e. it is null), visibility is
296
+ auto-detected, i.e. the axis will show up if there's data associated
297
+ with it. You can override this by setting the "show" option to true or
298
+ false.
299
+
300
+ The "position" option specifies where the axis is placed, bottom or
301
+ top for x axes, left or right for y axes. The "mode" option determines
302
+ how the data is interpreted, the default of null means as decimal
303
+ numbers. Use "time" for time series data; see the time series data
304
+ section. The time plugin (jquery.flot.time.js) is required for time
305
+ series support.
306
+
307
+ The "inverted" options specifies whether the transform and inverseTransform should
308
+ include a negating transform which will reverse the axis.
309
+
310
+ The "color" option determines the color of the line and ticks for the axis, and
311
+ defaults to the grid color with transparency. For more fine-grained control you
312
+ can also set the color of the ticks separately with "tickColor".
313
+
314
+ You can customize the font and color used to draw the axis tick labels with CSS
315
+ or directly via the "font" option. When "font" is null - the default - each
316
+ tick label is given the 'flot-tick-label' class. For compatibility with Flot
317
+ 0.7 and earlier the labels are also given the 'tickLabel' class, but this is
318
+ deprecated and scheduled to be removed with the release of version 1.0.0.
319
+
320
+ To enable more granular control over styles, labels are divided between a set
321
+ of text containers, with each holding the labels for one axis. These containers
322
+ are given the classes 'flot-[x|y]-axis', and 'flot-[x|y]#-axis', where '#' is
323
+ the number of the axis when there are multiple axes. For example, the x-axis
324
+ labels for a simple plot with only a single x-axis might look like this:
325
+
326
+ ```html
327
+ <div class='flot-x-axis flot-x1-axis'>
328
+ <div class='flot-tick-label'>January 2013</div>
329
+ ...
330
+ </div>
331
+ ```
332
+
333
+ For direct control over label styles you can also provide "font" as an object
334
+ with this format:
335
+
336
+ ```js
337
+ {
338
+ size: 11,
339
+ lineHeight: 13,
340
+ style: "italic",
341
+ weight: "bold",
342
+ family: "sans-serif",
343
+ variant: "small-caps",
344
+ color: "#545454"
345
+ }
346
+ ```
347
+
348
+ The size and lineHeight must be expressed in pixels; CSS units such as 'em'
349
+ or 'smaller' are not allowed.
350
+
351
+ The options "min"/"max" are the precise minimum/maximum value on the
352
+ scale. If you don't specify either of them, a value will automatically
353
+ be chosen based on the minimum/maximum data values. Note that Flot
354
+ always examines all the data values you feed to it, even if a
355
+ restriction on another axis may make some of them invisible (this
356
+ makes interactive use more stable).
357
+
358
+ The "autoScaleMargin" is a bit esoteric: it's the fraction of margin
359
+ that the scaling algorithm will add to avoid that the outermost points
360
+ ends up on the grid border. Note that this margin is only applied when
361
+ autoScale option is set to "loose". If a margin is specified,
362
+ the plot will furthermore extend the axis end-point to the nearest
363
+ whole tick. The default value is "null" for the x axes and 0.02 for y
364
+ axes which seems appropriate for most cases.
365
+
366
+ The "windowSize" is the range of the plot that will be visible on "sliding-window" autoScale.
367
+ If autoScale is not "sliding-window" this option will be ignored. Default value is 100.
368
+
369
+ The "autoScale" option is used to automatically set the end-points of the axis. There
370
+ are three options available: "none" will set the end-points to the "min"/"max" values,
371
+ "exact" will set the end-points to minimum/maximum values in the visible area of the plot, and
372
+ "loose" will add a margin to the "exact" mode based on the "autoScaleMargin" value. The "sliding-window"
373
+ autoScale will always keep a "windowSize" range between axis.min and axis.max. The autoscaling behaviour is also affected by the growOnly flag, described below.
374
+ The default autoScale value is "none" for the x axes, and "loose" for y axes.
375
+
376
+ The "growOnly" option is useful when you want to have a smoother auto-scaling
377
+ behavior. If true the scale range will grow to adapt to the data range but won't
378
+ shrink back. This will be ignored if autoScale value is "none" or "sliding-window". The default value is false.
379
+
380
+ "transform" and "inverseTransform" are callbacks you can put in to
381
+ change the way the data is drawn. You can design a function to
382
+ compress or expand certain parts of the axis non-linearly, e.g.
383
+ suppress weekends or compress far away points with a logarithm or some
384
+ other means. When Flot draws the plot, each value is first put through
385
+ the transform function. Here's an example, the x axis can be turned
386
+ into a natural logarithm axis with the following code:
387
+
388
+ ```js
389
+ xaxis: {
390
+ transform: function (v) { return Math.log(v); },
391
+ inverseTransform: function (v) { return Math.exp(v); }
392
+ }
393
+ ```
394
+
395
+ Similarly, for reversing the y axis so the values appear in inverse
396
+ order:
397
+
398
+ ```js
399
+ yaxis: {
400
+ transform: function (v) { return -v; },
401
+ inverseTransform: function (v) { return -v; }
402
+ }
403
+ ```
404
+
405
+ Note that for finding extrema, Flot assumes that the transform
406
+ function does not reorder values (it should be monotone).
407
+
408
+ The inverseTransform is simply the inverse of the transform function
409
+ (so v == inverseTransform(transform(v)) for all relevant v). It is
410
+ required for converting from canvas coordinates to data coordinates,
411
+ e.g. for a mouse interaction where a certain pixel is clicked. If you
412
+ don't use any interactive features of Flot, you may not need it.
413
+
414
+
415
+ The rest of the options deal with the ticks.
416
+
417
+ If you don't specify any ticks, a tick generator algorithm will make
418
+ some for you. The algorithm has two passes. It first estimates how
419
+ many ticks would be reasonable and uses this number to compute a nice
420
+ round tick interval size. Then it generates the ticks.
421
+
422
+ You can specify how many ticks the algorithm aims for by setting
423
+ "ticks" to a number. The algorithm always tries to generate reasonably
424
+ round tick values so even if you ask for three ticks, you might get
425
+ five if that fits better with the rounding. If you don't want any
426
+ ticks at all, set "ticks" to 0 or an empty array.
427
+
428
+ Another option is to skip the rounding part and directly set the tick
429
+ interval size with "tickSize". If you set it to 2, you'll get ticks at
430
+ 2, 4, 6, etc. Alternatively, you can specify that you just don't want
431
+ ticks at a size less than a specific tick size with "minTickSize".
432
+ Note that for time series, the format is an array like [2, "month"],
433
+ see the next section.
434
+
435
+ If you want to completely override the tick algorithm, you can specify
436
+ an array for "ticks", either like this:
437
+
438
+ ```js
439
+ ticks: [0, 1.2, 2.4]
440
+ ```
441
+
442
+ Or like this where the labels are also customized:
443
+
444
+ ```js
445
+ ticks: [[0, "zero"], [1.2, "one mark"], [2.4, "two marks"]]
446
+ ```
447
+
448
+ You can mix the two if you like.
449
+
450
+ For extra flexibility you can specify a function as the "ticks"
451
+ parameter. The function will be called with an object with the axis
452
+ min and max and should return a ticks array. Here's a simplistic tick
453
+ generator that spits out intervals of pi, suitable for use on the x
454
+ axis for trigonometric functions:
455
+
456
+ ```js
457
+ function piTickGenerator(axis) {
458
+ var res = [], i = Math.floor(axis.min / Math.PI);
459
+ do {
460
+ var v = i * Math.PI;
461
+ res.push([v, i + "\u03c0"]);
462
+ ++i;
463
+ } while (v < axis.max);
464
+ return res;
465
+ }
466
+ ```
467
+
468
+ You can control how the ticks look like with "tickDecimals", the
469
+ number of decimals to display (default is auto-detected).
470
+
471
+ Alternatively, for ultimate control over how ticks are formatted you can
472
+ provide a function to "tickFormatter". The function is passed three
473
+ parameters, the tick value, an axis object with information and the precision,
474
+ and should return a string. The default formatter looks like this:
475
+
476
+ ```js
477
+ function formatter(val, axis, precision) {
478
+ return val.toFixed(precision);
479
+ }
480
+ ```
481
+
482
+ The axis object has "min" and "max" with the range of the axis,
483
+ "tickDecimals" with the number of decimals to round the value to and
484
+ "tickSize" with the size of the interval between ticks as calculated
485
+ by the automatic axis scaling algorithm (or specified by you). Here's
486
+ an example of a custom formatter:
487
+
488
+ ```js
489
+ function suffixFormatter(val, axis) {
490
+ if (val > 1000000)
491
+ return (val / 1000000).toFixed(axis.tickDecimals) + " MB";
492
+ else if (val > 1000)
493
+ return (val / 1000).toFixed(axis.tickDecimals) + " kB";
494
+ else
495
+ return val.toFixed(axis.tickDecimals) + " B";
496
+ }
497
+ ```
498
+
499
+ "showTickLabels" can be used to specify which ticks labels are visible:
500
+ "none", "endpoints", "major" or "all". The default is "major".
501
+
502
+ "labelWidth" and "labelHeight" specifies a fixed size of the tick
503
+ labels in pixels. They're useful in case you need to align several
504
+ plots. "reserveSpace" means that even if an axis isn't shown, Flot
505
+ should reserve space for it - it is useful in combination with
506
+ labelWidth and labelHeight for aligning multi-axis charts.
507
+
508
+ "gridLines", if true will draw lines on the grid corresponding to the major ticks
509
+ on the axis. If unspecified will default to true for the innermost axes and false
510
+ for the others.
511
+
512
+ "showTicks" specifies whether to draw tick lines at all. Default true.
513
+
514
+ "showMinorTicks" specifies whether to draw minor tick lines at all. Minor tick
515
+ lines are lines subdividing the interval between major tick lines in 5 intervals.
516
+ Default true.
517
+
518
+ "tickLength" is the length of the tick lines in pixels. A value of null means
519
+ use the default, while a number means tick lines of that length - set it to 0 to
520
+ hide the lines completely.
521
+
522
+ If you set "alignTicksWithAxis" to the number of another axis, e.g.
523
+ alignTicksWithAxis: 1, Flot will ensure that the autogenerated ticks
524
+ of this axis are aligned with the ticks of the other axis. This may
525
+ improve the looks, e.g. if you have one y axis to the left and one to
526
+ the right, because the grid lines will then match the ticks in both
527
+ ends. The trade-off is that the forced ticks won't necessarily be at
528
+ natural places.
529
+
530
+ "offset" can be used to move the plot area, or to reserve plot space.
531
+
532
+ "boxPosition" is used to reserve extra space needed in the corresponding axis
533
+ box as well as to specify where the axis should be placed inside the box.
534
+
535
+ ## Multiple axes ##
536
+
537
+ If you need more than one x axis or y axis, you need to specify for
538
+ each data series which axis they are to use, as described under the
539
+ format of the data series, e.g. { data: [...], yaxis: 2 } specifies
540
+ that a series should be plotted against the second y axis.
541
+
542
+ To actually configure that axis, you can't use the xaxis/yaxis options
543
+ directly - instead there are two arrays in the options:
544
+
545
+ ```js
546
+ xaxes: []
547
+ yaxes: []
548
+ ```
549
+
550
+ Here's an example of configuring a single x axis and two y axes (we
551
+ can leave options of the first y axis empty as the defaults are fine):
552
+
553
+ ```js
554
+ {
555
+ xaxes: [ { position: "top" } ],
556
+ yaxes: [ { }, { position: "right", min: 20 } ]
557
+ }
558
+ ```
559
+
560
+ The arrays get their default values from the xaxis/yaxis settings, so
561
+ say you want to have all y axes start at zero, you can simply specify
562
+ yaxis: { min: 0 } instead of adding a min parameter to all the axes.
563
+
564
+ Generally, the various interfaces in Flot dealing with data points
565
+ either accept an xaxis/yaxis parameter to specify which axis number to
566
+ use (starting from 1), or lets you specify the coordinate directly as
567
+ x2/x3/... or x2axis/x3axis/... instead of "x" or "xaxis".
568
+
569
+
570
+ ## Time series data ##
571
+
572
+ Please note that it is now required to include the time plugin,
573
+ jquery.flot.time.js, for time series support.
574
+
575
+ Time series are a bit more difficult than scalar data because
576
+ calendars don't follow a simple base 10 system. For many cases, Flot
577
+ abstracts most of this away, but it can still be a bit difficult to
578
+ get the data into Flot. So we'll first discuss the data format.
579
+
580
+ The time series support in Flot is based on Javascript timestamps,
581
+ i.e. everywhere a time value is expected or handed over, a Javascript
582
+ timestamp number is used. This is a number, not a Date object. A
583
+ Javascript timestamp is the number of milliseconds since January 1,
584
+ 1970 00:00:00 UTC. This is almost the same as Unix timestamps, except it's
585
+ in milliseconds, so remember to multiply by 1000!
586
+
587
+ You can see a timestamp like this
588
+
589
+ ```js
590
+ alert((new Date()).getTime())
591
+ ```
592
+
593
+ There are different schools of thought when it comes to display of
594
+ timestamps. Many will want the timestamps to be displayed according to
595
+ a certain time zone, usually the time zone in which the data has been
596
+ produced. Some want the localized experience, where the timestamps are
597
+ displayed according to the local time of the visitor. Flot supports
598
+ both. Optionally you can include a third-party library to get
599
+ additional timezone support.
600
+
601
+ Default behavior is that Flot always displays timestamps according to
602
+ UTC. The reason being that the core Javascript Date object does not
603
+ support other fixed time zones. Often your data is at another time
604
+ zone, so it may take a little bit of tweaking to work around this
605
+ limitation.
606
+
607
+ The easiest way to think about it is to pretend that the data
608
+ production time zone is UTC, even if it isn't. So if you have a
609
+ datapoint at 2002-02-20 08:00, you can generate a timestamp for eight
610
+ o'clock UTC even if it really happened eight o'clock UTC+0200.
611
+
612
+ In PHP you can get an appropriate timestamp with:
613
+
614
+ ```php
615
+ strtotime("2002-02-20 UTC") * 1000
616
+ ```
617
+
618
+ In Python you can get it with something like:
619
+
620
+ ```python
621
+ calendar.timegm(datetime_object.timetuple()) * 1000
622
+ ```
623
+ In Ruby you can get it using the `#to_i` method on the
624
+ [`Time`](http://apidock.com/ruby/Time/to_i) object. If you're using the
625
+ `active_support` gem (default for Ruby on Rails applications) `#to_i` is also
626
+ available on the `DateTime` and `ActiveSupport::TimeWithZone` objects. You
627
+ simply need to multiply the result by 1000:
628
+
629
+ ```ruby
630
+ Time.now.to_i * 1000 # => 1383582043000
631
+ # ActiveSupport examples:
632
+ DateTime.now.to_i * 1000 # => 1383582043000
633
+ ActiveSupport::TimeZone.new('Asia/Shanghai').now.to_i * 1000
634
+ # => 1383582043000
635
+ ```
636
+
637
+ In .NET you can get it with something like:
638
+
639
+ ```aspx
640
+ public static int GetJavascriptTimestamp(System.DateTime input)
641
+ {
642
+ System.TimeSpan span = new System.TimeSpan(System.DateTime.Parse("1/1/1970").Ticks);
643
+ System.DateTime time = input.Subtract(span);
644
+ return (long)(time.Ticks / 10000);
645
+ }
646
+ ```
647
+
648
+ Javascript also has some support for parsing date strings, so it is
649
+ possible to generate the timestamps manually client-side.
650
+
651
+ If you've already got the real UTC timestamp, it's too late to use the
652
+ pretend trick described above. But you can fix up the timestamps by
653
+ adding the time zone offset, e.g. for UTC+0200 you would add 2 hours
654
+ to the UTC timestamp you got. Then it'll look right on the plot. Most
655
+ programming environments have some means of getting the timezone
656
+ offset for a specific date (note that you need to get the offset for
657
+ each individual timestamp to account for daylight savings).
658
+
659
+ The alternative with core Javascript is to interpret the timestamps
660
+ according to the time zone that the visitor is in, which means that
661
+ the ticks will shift with the time zone and daylight savings of each
662
+ visitor. This behavior is enabled by setting the axis option
663
+ "timezone" to the value "browser".
664
+
665
+ If you need more time zone functionality than this, there is still
666
+ another option. If you include the "timezone-js" library
667
+ <https://github.com/mde/timezone-js> in the page and set axis.timezone
668
+ to a value recognized by said library, Flot will use timezone-js to
669
+ interpret the timestamps according to that time zone.
670
+
671
+ Once you've gotten the timestamps into the data and specified "time"
672
+ as the axis mode, Flot will automatically generate relevant ticks and
673
+ format them. As always, you can tweak the ticks via the "ticks" option
674
+ - just remember that the values should be timestamps (numbers), not
675
+ Date objects.
676
+
677
+ Tick generation and formatting can also be controlled separately
678
+ through the following axis options:
679
+
680
+ ```js
681
+ minTickSize: array
682
+ timeformat: null or format string
683
+ monthNames: null or array of size 12 of strings
684
+ dayNames: null or array of size 7 of strings
685
+ twelveHourClock: boolean
686
+ ```
687
+
688
+ Here "timeformat" is a format string to use. You might use it like
689
+ this:
690
+
691
+ ```js
692
+ xaxis: {
693
+ mode: "time",
694
+ timeformat: "%Y/%m/%d"
695
+ }
696
+ ```
697
+
698
+ This will result in tick labels like "2000/12/24". A subset of the
699
+ standard strftime specifiers are supported (plus the nonstandard %q):
700
+
701
+ ```js
702
+ %a: weekday name (customizable)
703
+ %b: month name (customizable)
704
+ %d: day of month, zero-padded (01-31)
705
+ %e: day of month, space-padded ( 1-31)
706
+ %H: hours, 24-hour time, zero-padded (00-23)
707
+ %I: hours, 12-hour time, zero-padded (01-12)
708
+ %m: month, zero-padded (01-12)
709
+ %M: minutes, zero-padded (00-59)
710
+ %q: quarter (1-4)
711
+ %S: seconds, zero-padded (00-59)
712
+ %y: year (two digits)
713
+ %Y: year (four digits)
714
+ %p: am/pm
715
+ %P: AM/PM (uppercase version of %p)
716
+ %w: weekday as number (0-6, 0 being Sunday)
717
+ ```
718
+
719
+ Flot 0.8 switched from %h to the standard %H hours specifier. The %h specifier
720
+ is still available, for backwards-compatibility, but is deprecated and
721
+ scheduled to be removed permanently with the release of version 1.0.
722
+
723
+ You can customize the month names with the "monthNames" option. For
724
+ instance, for Danish you might specify:
725
+
726
+ ```js
727
+ monthNames: ["jan", "feb", "mar", "apr", "maj", "jun", "jul", "aug", "sep", "okt", "nov", "dec"]
728
+ ```
729
+
730
+ Similarly you can customize the weekday names with the "dayNames"
731
+ option. An example in French:
732
+
733
+ ```js
734
+ dayNames: ["dim", "lun", "mar", "mer", "jeu", "ven", "sam"]
735
+ ```
736
+
737
+ If you set "twelveHourClock" to true, the autogenerated timestamps
738
+ will use 12 hour AM/PM timestamps instead of 24 hour. This only
739
+ applies if you have not set "timeformat". Use the "%I" and "%p" or
740
+ "%P" options if you want to build your own format string with 12-hour
741
+ times.
742
+
743
+ If the Date object has a strftime property (and it is a function), it
744
+ will be used instead of the built-in formatter. Thus you can include
745
+ a strftime library such as http://hacks.bluesmoon.info/strftime/ for
746
+ more powerful date/time formatting.
747
+
748
+ If everything else fails, you can control the formatting by specifying
749
+ a custom tick formatter function as usual. Here's a simple example
750
+ which will format December 24 as 24/12:
751
+
752
+ ```js
753
+ tickFormatter: function (val, axis) {
754
+ var d = new Date(val);
755
+ return d.getUTCDate() + "/" + (d.getUTCMonth() + 1);
756
+ }
757
+ ```
758
+
759
+ Note that for the time mode "tickSize" and "minTickSize" are a bit
760
+ special in that they are arrays on the form "[value, unit]" where unit
761
+ is one of "second", "minute", "hour", "day", "month" and "year". So
762
+ you can specify
763
+
764
+ ```js
765
+ minTickSize: [1, "month"]
766
+ ```
767
+
768
+ to get a tick interval size of at least 1 month and correspondingly,
769
+ if axis.tickSize is [2, "day"] in the tick formatter, the ticks have
770
+ been produced with two days in-between.
771
+
772
+
773
+ ## Customizing the data series ##
774
+
775
+ ```js
776
+ series: {
777
+ lines, points, bars: {
778
+ show: boolean
779
+ lineWidth: number
780
+ fill: boolean or number
781
+ fillColor: null or color/gradient
782
+ }
783
+
784
+ lines, bars: {
785
+ zero: boolean
786
+ }
787
+
788
+ points: {
789
+ radius: number
790
+ symbol: "circle" or function
791
+ }
792
+
793
+ bars: {
794
+ barWidth: number or array
795
+ align: "left", "right" or "center"
796
+ horizontal: boolean
797
+ }
798
+
799
+ lines: {
800
+ steps: boolean
801
+ }
802
+
803
+ shadowSize: number
804
+ highlightColor: color or number
805
+ }
806
+
807
+ colors: [ color1, color2, ... ]
808
+ ```
809
+
810
+ The options inside "series: {}" are copied to each of the series. So
811
+ you can specify that all series should have bars by putting it in the
812
+ global options, or override it for individual series by specifying
813
+ bars in a particular the series object in the array of data.
814
+
815
+ The most important options are "lines", "points" and "bars" that
816
+ specify whether and how lines, points and bars should be shown for
817
+ each data series. In case you don't specify anything at all, Flot will
818
+ default to showing lines (you can turn this off with
819
+ lines: { show: false }). You can specify the various types
820
+ independently of each other, and Flot will happily draw each of them
821
+ in turn (this is probably only useful for lines and points), e.g.
822
+
823
+ ```js
824
+ var options = {
825
+ series: {
826
+ lines: { show: true, fill: true, fillColor: "rgba(255, 255, 255, 0.8)" },
827
+ points: { show: true, fill: false }
828
+ }
829
+ };
830
+ ```
831
+
832
+ "lineWidth" is the thickness of the line or outline in pixels. You can
833
+ set it to 0 to prevent a line or outline from being drawn; this will
834
+ also hide the shadow.
835
+
836
+ "fill" is whether the shape should be filled. For lines, this produces
837
+ area graphs. You can use "fillColor" to specify the color of the fill.
838
+ If "fillColor" evaluates to false (default for everything except
839
+ points which are filled with white), the fill color is auto-set to the
840
+ color of the data series. You can adjust the opacity of the fill by
841
+ setting fill to a number between 0 (fully transparent) and 1 (fully
842
+ opaque).
843
+
844
+ For bars, fillColor can be a gradient, see the gradient documentation
845
+ below. "barWidth" is the width of the bars relative to the minimum distance
846
+ between points. If the absolute flag is provided, the width
847
+ of the bar will be in units of the x axis (or the y axis if "horizontal"
848
+ is true),contrary to most other measures that are specified in pixels.
849
+ For instance, for time series the unit is milliseconds so 24 * 60 * 60 * 1000
850
+ produces bars with the width of a day. "align" specifies whether a bar
851
+ should be left-aligned (default), right-aligned or centered on top of
852
+ the value it represents. When "horizontal" is on, the bars are drawn
853
+ horizontally, i.e. from the y axis instead of the x axis; note that the
854
+ bar end points are still defined in the same way so you'll probably want
855
+ to swap the coordinates if you've been plotting vertical bars first.
856
+
857
+ Area and bar charts normally start from zero, regardless of the data's range.
858
+ This is because they convey information through size, and starting from a
859
+ different value would distort their meaning. In cases where the fill is purely
860
+ for decorative purposes, however, "zero" allows you to override this behavior.
861
+ It defaults to true for filled lines and bars; setting it to false tells the
862
+ series to use the same automatic scaling as an un-filled line. If you want the
863
+ area filled toward a different value (+Infinity and -Infinity are good examples)
864
+ you can use the "fillTowards" option.
865
+
866
+ For lines, "steps" specifies whether two adjacent data points are
867
+ connected with a straight (possibly diagonal) line or with first a
868
+ horizontal and then a vertical line. Note that this transforms the
869
+ data by adding extra points.
870
+
871
+ For points, you can specify the radius and the symbol. The only
872
+ built-in symbol type is circles, for other types you can use a plugin
873
+ or define them yourself by specifying a callback:
874
+
875
+ ```js
876
+ function cross(ctx, x, y, radius, shadow) {
877
+ var size = radius * Math.sqrt(Math.PI) / 2;
878
+ ctx.moveTo(x - size, y - size);
879
+ ctx.lineTo(x + size, y + size);
880
+ ctx.moveTo(x - size, y + size);
881
+ ctx.lineTo(x + size, y - size);
882
+ }
883
+ ```
884
+
885
+ The parameters are the drawing context, x and y coordinates of the
886
+ center of the point, a radius which corresponds to what the circle
887
+ would have used and whether the call is to draw a shadow (due to
888
+ limited canvas support, shadows are currently faked through extra
889
+ draws). It's good practice to ensure that the area covered by the
890
+ symbol is the same as for the circle with the given radius, this
891
+ ensures that all symbols have approximately the same visual weight.
892
+
893
+ "shadowSize" is the default size of shadows in pixels. Set it to 0 to
894
+ remove shadows.
895
+
896
+ "highlightColor" is the default color of the translucent overlay used
897
+ to highlight the series when the mouse hovers over it.
898
+
899
+ The "colors" array specifies a default color theme to get colors for
900
+ the data series from. You can specify as many colors as you like, like
901
+ this:
902
+
903
+ ```js
904
+ colors: ["#d18b2c", "#dba255", "#919733"]
905
+ ```
906
+
907
+ If there are more data series than colors, Flot will try to generate
908
+ extra colors by lightening and darkening colors in the theme.
909
+
910
+
911
+ ## Customizing the grid ##
912
+
913
+ ```js
914
+ grid: {
915
+ show: boolean
916
+ aboveData: boolean
917
+ color: color
918
+ backgroundColor: color/gradient or null
919
+ margin: number or margin object
920
+ labelMargin: number
921
+ axisMargin: number
922
+ markings: array of markings or (fn: axes -> array of markings)
923
+ borderWidth: number or object with "top", "right", "bottom" and "left" properties with different widths
924
+ borderColor: color or null or object with "top", "right", "bottom" and "left" properties with different colors
925
+ minBorderMargin: number or null
926
+ clickable: boolean
927
+ hoverable: boolean
928
+ autoHighlight: boolean
929
+ mouseActiveRadius: number
930
+ }
931
+
932
+ interaction: {
933
+ redrawOverlayInterval: number or -1
934
+ }
935
+ ```
936
+
937
+ The grid is the thing with the axes and a number of ticks. Many of the
938
+ things in the grid are configured under the individual axes, but not
939
+ all. "color" is the color of the grid itself whereas "backgroundColor"
940
+ specifies the background color inside the grid area, here null means
941
+ that the background is transparent. You can also set a gradient, see
942
+ the gradient documentation below.
943
+
944
+ You can turn off the whole grid including tick labels by setting
945
+ "show" to false. "aboveData" determines whether the grid is drawn
946
+ above the data or below (below is default).
947
+
948
+ "margin" is the space in pixels between the canvas edge and the grid,
949
+ which can be either a number or an object with individual margins for
950
+ each side, in the form:
951
+
952
+ ```js
953
+ margin: {
954
+ top: top margin in pixels
955
+ left: left margin in pixels
956
+ bottom: bottom margin in pixels
957
+ right: right margin in pixels
958
+ }
959
+ ```
960
+
961
+ "labelMargin" is the space in pixels between tick labels and axis
962
+ line, and "axisMargin" is the space in pixels between axes when there
963
+ are two next to each other.
964
+
965
+ "borderWidth" is the width of the border around the plot. Set it to 0
966
+ to disable the border. Set it to an object with "top", "right",
967
+ "bottom" and "left" properties to use different widths. You can
968
+ also set "borderColor" if you want the border to have a different color
969
+ than the grid lines. Set it to an object with "top", "right", "bottom"
970
+ and "left" properties to use different colors. "minBorderMargin" controls
971
+ the default minimum margin around the border - it's used to make sure
972
+ that points aren't accidentally clipped by the canvas edge so by default
973
+ the value is computed from the point radius.
974
+
975
+ "markings" is used to draw simple lines and rectangular areas in the
976
+ background of the plot. You can either specify an array of ranges on
977
+ the form { xaxis: { from, to }, yaxis: { from, to } } (with multiple
978
+ axes, you can specify coordinates for other axes instead, e.g. as
979
+ x2axis/x3axis/...) or with a function that returns such an array given
980
+ the axes for the plot in an object as the first parameter.
981
+
982
+ You can set the color of markings by specifying "color" in the ranges
983
+ object. Here's an example array:
984
+
985
+ ```js
986
+ markings: [ { xaxis: { from: 0, to: 2 }, yaxis: { from: 10, to: 10 }, color: "#bb0000" }, ... ]
987
+ ```
988
+
989
+ If you leave out one of the values, that value is assumed to go to the
990
+ border of the plot. So for example if you only specify { xaxis: {
991
+ from: 0, to: 2 } } it means an area that extends from the top to the
992
+ bottom of the plot in the x range 0-2.
993
+
994
+ A line is drawn if from and to are the same, e.g.
995
+
996
+ ```js
997
+ markings: [ { yaxis: { from: 1, to: 1 } }, ... ]
998
+ ```
999
+
1000
+ would draw a line parallel to the x axis at y = 1. You can control the
1001
+ line width with "lineWidth" in the range object.
1002
+
1003
+ An example function that makes vertical stripes might look like this:
1004
+
1005
+ ```js
1006
+ markings: function (axes) {
1007
+ var markings = [];
1008
+ for (var x = Math.floor(axes.xaxis.min); x < axes.xaxis.max; x += 2)
1009
+ markings.push({ xaxis: { from: x, to: x + 1 } });
1010
+ return markings;
1011
+ }
1012
+ ```
1013
+
1014
+ If you set "clickable" to true, the plot will listen for click events
1015
+ on the plot area and fire a "plotclick" event on the placeholder with
1016
+ a position and a nearby data item object as parameters. The coordinates
1017
+ are available both in the unit of the axes (not in pixels) and in
1018
+ global screen coordinates.
1019
+
1020
+ Likewise, if you set "hoverable" to true, the plot will listen for
1021
+ mouse move events on the plot area and fire a "plothover" event with
1022
+ the same parameters as the "plotclick" event. If "autoHighlight" is
1023
+ true (the default), nearby data items are highlighted automatically.
1024
+ If needed, you can disable highlighting and control it yourself with
1025
+ the highlight/unhighlight plot methods described elsewhere.
1026
+
1027
+ In case hoverable is set to true, plothovercleanup event will be triggered
1028
+ on or pinc interaction or if setData() function is called.
1029
+
1030
+ You can use "plotclick" and "plothover" events like this:
1031
+
1032
+ ```js
1033
+ $.plot($("#placeholder"), [ d ], { grid: { clickable: true } });
1034
+
1035
+ $("#placeholder").bind("plotclick", function (event, pos, items) {
1036
+ alert("You clicked at " + pos.x + ", " + pos.y);
1037
+ // axis coordinates for other axes, if present, are in pos.x2, pos.x3, ...
1038
+ // if you need global screen coordinates, they are pos.pageX, pos.pageY
1039
+
1040
+ if (item) {
1041
+ highlight(item.series, item.datapoint);
1042
+ alert("You clicked a point!");
1043
+ }
1044
+ });
1045
+ ```
1046
+
1047
+ The item object in this example is either null or a nearby object on the form:
1048
+
1049
+ ```js
1050
+ item: {
1051
+ datapoint: the point, e.g. [0, 2]
1052
+ dataIndex: the index of the point in the data array
1053
+ series: the series object
1054
+ seriesIndex: the index of the series
1055
+ distance: the distance from the cursor
1056
+ pageX, pageY: the global screen coordinates of the point
1057
+ }
1058
+ ```
1059
+
1060
+ For instance, if you have specified the data like this
1061
+
1062
+ ```js
1063
+ $.plot($("#placeholder"), [ { label: "Foo", data: [[0, 10], [7, 3]] } ], ...);
1064
+ ```
1065
+
1066
+ and the mouse is near the point (7, 3), "datapoint" is [7, 3],
1067
+ "dataIndex" will be 1, "series" is a normalized series object with
1068
+ among other things the "Foo" label in series.label and the color in
1069
+ series.color, and "seriesIndex" is 0. Note that plugins and options
1070
+ that transform the data can shift the indexes from what you specified
1071
+ in the original data array.
1072
+
1073
+ If you use the above events to update some other information and want
1074
+ to clear out that info in case the mouse goes away, you'll probably
1075
+ also need to listen to "mouseout" events on the placeholder div.
1076
+
1077
+ "mouseActiveRadius" specifies how far the mouse can be from an item
1078
+ and still activate it. If there are two or more points within this
1079
+ radius, Flot chooses the closest item. For bars, the top-most bar
1080
+ (from the latest specified data series) is chosen.
1081
+
1082
+ If you want to disable interactivity for a specific data series, you
1083
+ can set "hoverable" and "clickable" to false in the options for that
1084
+ series, like this:
1085
+
1086
+ ```js
1087
+ { data: [...], label: "Foo", clickable: false }
1088
+ ```
1089
+
1090
+ "redrawOverlayInterval" specifies the maximum time to delay a redraw
1091
+ of interactive things (this works as a rate limiting device). The
1092
+ default is capped to 60 frames per second. You can set it to -1 to
1093
+ disable the rate limiting.
1094
+
1095
+
1096
+ ## Specifying gradients ##
1097
+
1098
+ A gradient is specified like this:
1099
+
1100
+ ```js
1101
+ { colors: [ color1, color2, ... ] }
1102
+ ```
1103
+
1104
+ For instance, you might specify a background on the grid going from
1105
+ black to gray like this:
1106
+
1107
+ ```js
1108
+ grid: {
1109
+ backgroundColor: { colors: ["#000", "#999"] }
1110
+ }
1111
+ ```
1112
+
1113
+ For the series you can specify the gradient as an object that
1114
+ specifies the scaling of the brightness and the opacity of the series
1115
+ color, e.g.
1116
+
1117
+ ```js
1118
+ { colors: [{ opacity: 0.8 }, { brightness: 0.6, opacity: 0.8 } ] }
1119
+ ```
1120
+
1121
+ where the first color simply has its alpha scaled, whereas the second
1122
+ is also darkened. For instance, for bars the following makes the bars
1123
+ gradually disappear, without outline:
1124
+
1125
+ ```js
1126
+ bars: {
1127
+ show: true,
1128
+ lineWidth: 0,
1129
+ fill: true,
1130
+ fillColor: { colors: [ { opacity: 0.8 }, { opacity: 0.1 } ] }
1131
+ }
1132
+ ```
1133
+
1134
+ Flot currently only supports vertical gradients drawn from top to
1135
+ bottom because that's what works with IE.
1136
+
1137
+
1138
+ ## Plot Methods ##
1139
+
1140
+ The Plot object returned from the plot function has some methods you
1141
+ can call:
1142
+
1143
+ - highlight(series, datapoint)
1144
+
1145
+ Highlight a specific datapoint in the data series. You can either
1146
+ specify the actual objects, e.g. if you got them from a
1147
+ "plotclick" event, or you can specify the indices, e.g.
1148
+ highlight(1, 3) to highlight the fourth point in the second series
1149
+ (remember, zero-based indexing).
1150
+
1151
+ - unhighlight(series, datapoint) or unhighlight()
1152
+
1153
+ Remove the highlighting of the point, same parameters as
1154
+ highlight.
1155
+
1156
+ If you call unhighlight with no parameters, e.g. as
1157
+ plot.unhighlight(), all current highlights are removed.
1158
+
1159
+ - setData(data)
1160
+
1161
+ You can use this to reset the data used. Note that axis scaling,
1162
+ ticks, legend etc. will not be recomputed (use setupGrid() to do
1163
+ that). You'll probably want to call draw() afterwards.
1164
+
1165
+ You can use this function to speed up redrawing a small plot if
1166
+ you know that the axes won't change. Put in the new data with
1167
+ setData(newdata), call draw(), and you're good to go. Note that
1168
+ for large datasets, almost all the time is consumed in draw()
1169
+ plotting the data so in this case don't bother.
1170
+
1171
+ - setupGrid(autoScale)
1172
+
1173
+ Recalculate and set axis scaling, ticks, legend etc.
1174
+
1175
+ Note that because of the drawing model of the canvas, this
1176
+ function will immediately redraw (actually reinsert in the DOM)
1177
+ the labels and the legend, but not the actual tick lines because
1178
+ they're drawn on the canvas. You need to call draw() to get the
1179
+ canvas redrawn.
1180
+
1181
+ If autoScale is truthy then the axis will be autoscaled to the data
1182
+ according to the axis.autoScale options
1183
+
1184
+ - draw()
1185
+
1186
+ Redraws the plot canvas.
1187
+
1188
+ - triggerRedrawOverlay()
1189
+
1190
+ Schedules an update of an overlay canvas used for drawing
1191
+ interactive things like a selection and point highlights. This
1192
+ is mostly useful for writing plugins. The redraw doesn't happen
1193
+ immediately, instead a timer is set to catch multiple successive
1194
+ redraws (e.g. from a mousemove). You can get to the overlay by
1195
+ setting up a drawOverlay hook.
1196
+ This function will also trigger the dispatching of the
1197
+ 'onDrawingDone' custom event on the eventholder, and 'drawingdone'
1198
+ event on the placeholder, which can be used to notify listeners
1199
+ about the finishing of a drawing operation (drawOverlay hooks).
1200
+ Use addEventListener('onDrawingDone', callback) and
1201
+ removeEventListener('onDrawingDone', callback) to register and
1202
+ unregister handlers for 'onDrawingDone' event, or use
1203
+ $('#placeholder').bind('drawingdone', callback) and
1204
+ $('#placeholder').unbind('drawingdone', callback) to
1205
+ register and unregister handlers for 'drawingdone' event.
1206
+
1207
+ - width()/height()
1208
+
1209
+ Gets the width and height of the plotting area inside the grid.
1210
+ This is smaller than the canvas or placeholder dimensions as some
1211
+ extra space is needed (e.g. for labels).
1212
+
1213
+ - offset()
1214
+
1215
+ Returns the offset of the plotting area inside the grid relative
1216
+ to the document, useful for instance for calculating mouse
1217
+ positions (event.pageX/Y minus this offset is the pixel position
1218
+ inside the plot).
1219
+
1220
+ - pointOffset({ x: xpos, y: ypos })
1221
+
1222
+ Returns the calculated offset of the data point at (x, y) in data
1223
+ space within the placeholder div. If you are working with multiple
1224
+ axes, you can specify the x and y axis references, e.g.
1225
+
1226
+ ```js
1227
+ o = pointOffset({ x: xpos, y: ypos, xaxis: 2, yaxis: 3 })
1228
+ // o.left and o.top now contains the offset within the div
1229
+ ```
1230
+
1231
+ - resize()
1232
+
1233
+ Tells Flot to resize the drawing canvas to the size of the
1234
+ placeholder. You need to run setupGrid() and draw() afterwards as
1235
+ canvas resizing is a destructive operation. This is used
1236
+ internally by the resize plugin.
1237
+
1238
+ - shutdown()
1239
+
1240
+ Cleans up any event handlers Flot has currently registered. This
1241
+ is used internally.
1242
+
1243
+ - findNearbyItem(mouseX, mouseY, seriesFilter, radius, computeDistance)
1244
+
1245
+ Returns the closest item to the position determined by mouseX and
1246
+ mouseY. The series on which the search is realized can be specified
1247
+ using seriesFilter function.
1248
+ The search area will be a circle if the function is called without the
1249
+ last parameter, otherwise the distance will be computed based on given
1250
+ function.
1251
+
1252
+ - findNearbyInterpolationPoint(posX, posY, seriesFilter)
1253
+
1254
+ Returns the interpolation on Y axis between the nearest points determined by
1255
+ posX and posY. The series on which the search is realized can be specified
1256
+ using seriesFilter function.
1257
+
1258
+ - computeValuePrecision(min, max, direction, ticks, tickDecimals)
1259
+
1260
+ Used for determining the the precision for a certain axis.
1261
+ If the tickDecimals is specified, the maximum precision
1262
+ would be at most tickDecimals. Otherwise, it would be computed
1263
+ based on the axis minimum and maximum and the number of ticks.
1264
+
1265
+ - computeTickSize (min, max, noTicks, tickDecimals)
1266
+
1267
+ Returns the size used for axis ticks. This is used internally.
1268
+
1269
+
1270
+ There are also some members that let you peek inside the internal
1271
+ workings of Flot which is useful in some cases. Note that if you change
1272
+ something in the objects returned, you're changing the objects used by
1273
+ Flot to keep track of its state, so be careful.
1274
+
1275
+ - getData()
1276
+
1277
+ Returns an array of the data series currently used in normalized
1278
+ form with missing settings filled in according to the global
1279
+ options. So for instance to find out what color Flot has assigned
1280
+ to the data series, you could do this:
1281
+
1282
+ ```js
1283
+ var series = plot.getData();
1284
+ for (var i = 0; i < series.length; ++i)
1285
+ alert(series[i].color);
1286
+ ```
1287
+
1288
+ A notable other interesting field besides color is datapoints
1289
+ which has a field "points" with the normalized data points in a
1290
+ flat array (the field "pointsize" is the increment in the flat
1291
+ array to get to the next point so for a dataset consisting only of
1292
+ (x,y) pairs it would be 2).
1293
+
1294
+ - getAxes()
1295
+
1296
+ Gets an object with the axes. The axes are returned as the
1297
+ attributes of the object, so for instance getAxes().xaxis is the
1298
+ x axis.
1299
+
1300
+ Various things are stuffed inside an axis object, e.g. you could
1301
+ use getAxes().xaxis.ticks to find out what the ticks are for the
1302
+ xaxis. Two other useful attributes are p2c and c2p, functions for
1303
+ transforming from data point space to the canvas plot space and
1304
+ back. Both returns values that are offset with the plot offset.
1305
+ Check the Flot source code for the complete set of attributes (or
1306
+ output an axis with console.log() and inspect it).
1307
+
1308
+ With multiple axes, the extra axes are returned as x2axis, x3axis,
1309
+ etc., e.g. getAxes().y2axis is the second y axis. You can check
1310
+ y2axis.used to see whether the axis is associated with any data
1311
+ points and y2axis.show to see if it is currently shown.
1312
+
1313
+ - getPlaceholder()
1314
+
1315
+ Returns placeholder that the plot was put into. This can be useful
1316
+ for plugins for adding DOM elements or firing events.
1317
+
1318
+ - getCanvas()
1319
+
1320
+ Returns the canvas used for drawing in case you need to hack on it
1321
+ yourself. You'll probably need to get the plot offset too.
1322
+
1323
+ - getSurface()
1324
+
1325
+ Returns a wrapper over a canvas element that offers additional support
1326
+ for measuring and writing text. See the CanvasWrapper plugin.
1327
+
1328
+ - getEventHolder()
1329
+
1330
+ Returns the event holder element.
1331
+
1332
+ - getPlotOffset()
1333
+
1334
+ Gets the offset that the grid has within the canvas as an object
1335
+ with distances from the canvas edges as "left", "right", "top",
1336
+ "bottom". I.e., if you draw a circle on the canvas with the center
1337
+ placed at (left, top), its center will be at the top-most, left
1338
+ corner of the grid.
1339
+
1340
+ - getOptions()
1341
+
1342
+ Gets the options for the plot, normalized, with default values
1343
+ filled in. You get a reference to actual values used by Flot, so
1344
+ if you modify the values in here, Flot will use the new values.
1345
+ If you change something, you probably have to call draw() or
1346
+ setupGrid() or triggerRedrawOverlay() to see the change.
1347
+
1348
+ - computeRangeForDataSeries(series, force)
1349
+
1350
+ Computes the minimum and the maximum values of the specified series.
1351
+ If the autoScale of the x axis is set to 'none' then the corresponding
1352
+ minimum and maximum will be Infinity and -Infinity respectively.
1353
+ The computation will be skiped for the y axis as well when autoScale
1354
+ of this axis is set to 'none'. Pass true to the force argument
1355
+ to force the computation regardless the autoScale value of the axis.
1356
+
1357
+ - adjustSeriesDataRange(series, range)
1358
+
1359
+ Adjusts the minimum and the maximum values based on the options of
1360
+ the series. For example if bars are being drawn then this function
1361
+ will decrease the minimum and increase the maximum to make sure the
1362
+ first and the last bar will have enough space.
1363
+
1364
+
1365
+ ## Utils ##
1366
+ There are some features, which may not fall explicitly into plugins category.
1367
+
1368
+ - composeImages(sources, destinationCanvas)
1369
+
1370
+ ComposeImages allows you pass to it several canvases and SVGs as part of the
1371
+ plots themselves, and overlaps them to create a downloadable image.
1372
+ *composeImages* is a function, which takes as input an array of canvases
1373
+ and SVGs, and outputs a canvas which contains the overlapped inputs, in the same
1374
+ order they exist in the array. The output canvas can be externally converted to
1375
+ a downloadable image. Some browser even support downloading canvases.
1376
+
1377
+ How to use *composeImages* function:
1378
+ ```js
1379
+ function composeImagesOnClick() {
1380
+ var sources = [myCanvas, mySvg, myOtherCanvas, myOtherSvg],
1381
+ destinationCanvas = document.getElementById('destinationCanvas'),
1382
+ destinationImage = document.getElementById('destinationImage');
1383
+ $.plot.composeImages(sources, destinationCanvas)
1384
+ .then(function() {
1385
+ destinationImage.width = destinationCanvas.width;
1386
+ destinationImage.height = destinationCanvas.height;
1387
+ destinationImage.src = destinationCanvas.toDataURL('image/png');
1388
+ });
1389
+ }
1390
+ ```
1391
+
1392
+ - getPageXY(e)
1393
+
1394
+ This function calculates the pageX and pageY which are not valid
1395
+ while running the tests with Edge and creating events using the
1396
+ recommended WheelEvent or MouseEvent constructors.
1397
+
1398
+ ```js
1399
+ var page = $.plot.browser.getPageXY(e);
1400
+ console.log(page.X === e.pageX); // true unless the event was constructed in Edge
1401
+ console.log(page.Y === e.pageY); // true unless the event was constructed in Edge
1402
+ ```
1403
+
1404
+ - getPixelRatio(context)
1405
+
1406
+ Determine the screen's ratio of physical to device-independent
1407
+ pixels. This is the ratio between the canvas width that the browser
1408
+ advertises and the number of pixels actually present in that space.
1409
+
1410
+ The iPhone 4, for example, has a device-independent width of 320px,
1411
+ but its screen is actually 640px wide. It therefore has a pixel
1412
+ ratio of 2, while most normal devices have a ratio of 1.
1413
+
1414
+ ```js
1415
+ var pixelRatio = $.plot.browser.getPixelRatio(canvas.getContext('2d'));
1416
+ ```
1417
+
1418
+ - isSafari()
1419
+ - isMobileSafari()
1420
+
1421
+ ```js
1422
+ console.log($.plot.browser.isSafari()); // true when running on Safari
1423
+ console.log($.plot.browser.isMobileSafari()); // true when running on Mobile Safari
1424
+ ```
1425
+
1426
+ ## Hooks ##
1427
+
1428
+ In addition to the public methods, the Plot object also has some hooks
1429
+ that can be used to modify the plotting process. You can install a
1430
+ callback function at various points in the process, the function then
1431
+ gets access to the internal data structures in Flot.
1432
+
1433
+ Here's an overview of the phases Flot goes through:
1434
+
1435
+ 1. Plugin initialization, parsing options
1436
+
1437
+ 2. Constructing the canvases used for drawing
1438
+
1439
+ 3. Set data: parsing data specification, calculating colors,
1440
+ copying raw data points into internal format,
1441
+ normalizing them, finding max/min for axis auto-scaling
1442
+
1443
+ 4. Grid setup: calculating axis spacing, ticks, inserting tick
1444
+ labels, the legend
1445
+
1446
+ 5. Draw: drawing the grid, drawing each of the series in turn
1447
+
1448
+ 6. Setting up event handling for interactive features
1449
+
1450
+ 7. Responding to events, if any
1451
+
1452
+ 8. Shutdown: this mostly happens in case a plot is overwritten
1453
+
1454
+ Each hook is simply a function which is put in the appropriate array.
1455
+ You can add them through the "hooks" option, and they are also available
1456
+ after the plot is constructed as the "hooks" attribute on the returned
1457
+ plot object, e.g.
1458
+
1459
+ ```js
1460
+ // define a simple draw hook
1461
+ function hellohook(plot, canvascontext) { alert("hello!"); };
1462
+
1463
+ // pass it in, in an array since we might want to specify several
1464
+ var plot = $.plot(placeholder, data, { hooks: { draw: [hellohook] } });
1465
+
1466
+ // we can now find it again in plot.hooks.draw[0] unless a plugin
1467
+ // has added other hooks
1468
+ ```
1469
+
1470
+ The available hooks are described below. All hook callbacks get the
1471
+ plot object as first parameter. You can find some examples of defined
1472
+ hooks in the plugins bundled with Flot.
1473
+
1474
+ - processOptions [phase 1]
1475
+
1476
+ ```function(plot, options)```
1477
+
1478
+ Called after Flot has parsed and merged options. Useful in the
1479
+ instance where customizations beyond simple merging of default
1480
+ values is needed. A plugin might use it to detect that it has been
1481
+ enabled and then turn on or off other options.
1482
+
1483
+
1484
+ - processRawData [phase 3]
1485
+
1486
+ ```function(plot, series, data, datapoints)```
1487
+
1488
+ Called before Flot copies and normalizes the raw data for the given
1489
+ series. If the function fills in datapoints.points with normalized
1490
+ points and sets datapoints.pointsize to the size of the points,
1491
+ Flot will skip the copying/normalization step for this series.
1492
+
1493
+ In any case, you might be interested in setting datapoints.format,
1494
+ an array of objects for specifying how a point is normalized and
1495
+ how it interferes with axis scaling. It accepts the following options:
1496
+
1497
+ ```js
1498
+ {
1499
+ x, y: boolean,
1500
+ number: boolean,
1501
+ required: boolean,
1502
+ defaultValue: value,
1503
+ autoScale: boolean
1504
+ }
1505
+ ```
1506
+
1507
+ "x" and "y" specify whether the value is plotted against the x or y axis,
1508
+ and is currently used only to calculate axis min-max ranges. The default
1509
+ format array, for example, looks like this:
1510
+
1511
+ ```js
1512
+ [
1513
+ { x: true, number: true, required: true },
1514
+ { y: true, number: true, required: true }
1515
+ ]
1516
+ ```
1517
+
1518
+ This indicates that a point, i.e. [0, 25], consists of two values, with the
1519
+ first being plotted on the x axis and the second on the y axis.
1520
+
1521
+ If "number" is true, then the value must be numeric, and is set to null if
1522
+ it cannot be converted to a number.
1523
+
1524
+ "defaultValue" provides a fallback in case the original value is null. This
1525
+ is for instance handy for bars, where one can omit the third coordinate
1526
+ (the bottom of the bar), which then defaults to zero.
1527
+
1528
+ If "required" is true, then the value must exist (be non-null) for the
1529
+ point as a whole to be valid. If no value is provided, then the entire
1530
+ point is cleared out with nulls, turning it into a gap in the series.
1531
+
1532
+ "autoScale" determines whether the value is considered when calculating an
1533
+ automatic min-max range for the axes that the value is plotted against.
1534
+
1535
+ - processDatapoints [phase 3]
1536
+
1537
+ ```function(plot, series, datapoints)```
1538
+
1539
+ Called after normalization of the given series but before finding
1540
+ min/max of the data points. This hook is useful for implementing data
1541
+ transformations. "datapoints" contains the normalized data points in
1542
+ a flat array as datapoints.points with the size of a single point
1543
+ given in datapoints.pointsize. Here's a simple transform that
1544
+ multiplies all y coordinates by 2:
1545
+
1546
+ ```js
1547
+ function multiply(plot, series, datapoints) {
1548
+ var points = datapoints.points, ps = datapoints.pointsize;
1549
+ for (var i = 0; i < points.length; i += ps)
1550
+ points[i + 1] *= 2;
1551
+ }
1552
+ ```
1553
+
1554
+ Note that you must leave datapoints in a good condition as Flot
1555
+ doesn't check it or do any normalization on it afterwards.
1556
+
1557
+ - processOffset [phase 4]
1558
+
1559
+ ```function(plot, offset)```
1560
+
1561
+ Called after Flot has initialized the plot's offset, but before it
1562
+ draws any axes or plot elements. This hook is useful for customizing
1563
+ the margins between the grid and the edge of the canvas. "offset" is
1564
+ an object with attributes "top", "bottom", "left" and "right",
1565
+ corresponding to the margins on the four sides of the plot.
1566
+
1567
+ - adjustSeriesDataRange [phase 4]
1568
+
1569
+ ```function(series, range)```
1570
+
1571
+ Called after the minimum and the maximum of a series were computed and
1572
+ adjusted. This is an extra opportunity to do further adjustments.
1573
+
1574
+ - setRange [phase 4]
1575
+
1576
+ ```function(plot, axis)```
1577
+
1578
+ Called before computing the range for axis. This can be used for adjusting
1579
+ the axis minimum or maximum.
1580
+
1581
+
1582
+ - drawBackground [phase 5]
1583
+
1584
+ ```function(plot, canvascontext)```
1585
+
1586
+ Called before all other drawing operations. Used to draw backgrounds
1587
+ or other custom elements before the plot or axes have been drawn.
1588
+
1589
+ - drawSeries [phase 5]
1590
+
1591
+ ```function(plot, canvascontext, serie, i, getColorOrGradient)```
1592
+
1593
+ Hook for custom drawing of a single series. Called just before the
1594
+ standard drawing routine has been called in the loop that draws
1595
+ each series.
1596
+
1597
+ - draw [phase 5]
1598
+
1599
+ ```function(plot, canvascontext)```
1600
+
1601
+ Hook for drawing on the canvas. Called after the grid is drawn
1602
+ (unless it's disabled or grid.aboveData is set) and the series have
1603
+ been plotted (in case any points, lines or bars have been turned
1604
+ on). For examples of how to draw things, look at the source code.
1605
+
1606
+ - bindEvents [phase 6]
1607
+
1608
+ ```function(plot, eventHolder)```
1609
+
1610
+ Called after Flot has setup its event handlers. Should set any
1611
+ necessary event handlers on eventHolder, a jQuery object with the
1612
+ canvas, e.g.
1613
+
1614
+ ```js
1615
+ function (plot, eventHolder) {
1616
+ eventHolder.mousedown(function (e) {
1617
+ alert("You pressed the mouse at " + e.pageX + " " + e.pageY);
1618
+ });
1619
+ }
1620
+ ```
1621
+
1622
+ Interesting events include click, mousemove, mouseup/down. You can
1623
+ use all jQuery events. Usually, the event handlers will update the
1624
+ state by drawing something (add a drawOverlay hook and call
1625
+ triggerRedrawOverlay) or firing an externally visible event for
1626
+ user code. See the crosshair plugin for an example.
1627
+
1628
+ Currently, eventHolder actually contains both the static canvas
1629
+ used for the plot itself and the overlay canvas used for
1630
+ interactive features because some versions of IE get the stacking
1631
+ order wrong. The hook only gets one event, though (either for the
1632
+ overlay or for the static canvas).
1633
+
1634
+ Note that custom plot events generated by Flot are not generated on
1635
+ eventHolder, but on the div placeholder supplied as the first
1636
+ argument to the plot call. You can get that with
1637
+ plot.getPlaceholder() - that's probably also the one you should use
1638
+ if you need to fire a custom event.
1639
+
1640
+ - drawOverlay [phase 7]
1641
+
1642
+ ```function (plot, canvascontext)```
1643
+
1644
+ The drawOverlay hook is used for interactive things that need a
1645
+ canvas to draw on. The model currently used by Flot works the way
1646
+ that an extra overlay canvas is positioned on top of the static
1647
+ canvas. This overlay is cleared and then completely redrawn
1648
+ whenever something interesting happens. This hook is called when
1649
+ the overlay canvas is to be redrawn.
1650
+
1651
+ "canvascontext" is the 2D context of the overlay canvas. You can
1652
+ use this to draw things. You'll most likely need some of the
1653
+ metrics computed by Flot, e.g. plot.width()/plot.height(). See the
1654
+ crosshair plugin for an example.
1655
+
1656
+ After this hook executes, the dispatching of the 'onDrawingDone'
1657
+ custom event on the eventholder will be triggered, as well as the
1658
+ 'drawingdone' event will be fired on the placeholder, which can
1659
+ be used to notify listeners about the finishing of a drawing
1660
+ operation. Use addEventListener('onDrawingDone', callback) and
1661
+ removeEventListener('onDrawingDone', callback) to register and
1662
+ unregister handlers for 'onDrawingDone' event, or use
1663
+ $('#placeholder').bind('drawingdone', callback) and
1664
+ $('#placeholder').unbind('drawingdone', callback) to
1665
+ register and unregister handlers for 'drawingdone' event.
1666
+
1667
+ - resize [phase 7]
1668
+
1669
+ ```function (plot, width, height)```
1670
+
1671
+ The resize hook is used to be notified after the plot was resized.
1672
+
1673
+ - findNearbyItems [phase 7]
1674
+ ```function (canvasX, canvasY, series, radius, computeDistance, items)```
1675
+
1676
+ The findNearbyItems hook is used to extend the default behavior of
1677
+ the flot-provided 'findNearbyItems' function. The hover plugin, as an
1678
+ example, will report items discovered through this hook through the
1679
+ hover and click events it raises.
1680
+
1681
+ canvasX and canvasY are the canvas-space coordinates used to search from
1682
+ for the nearby items.
1683
+
1684
+ series is the current data series for which the findNearbyItems hook should return nearby data. The hook will be called for each data series separately, as long as it is not filtered out by the seriesFilter function used by the caller.
1685
+
1686
+ seriesIndex is the index of the data series. This is largely being provided
1687
+ as it is needed in the returned item (if found).
1688
+
1689
+ radius is the base distance from an item that you should use
1690
+ as an area to search in if you aren't searching in strict bounds
1691
+
1692
+ computeDistance is a function to utilize to compute the distance
1693
+ from the cursor. It may not be provided, so you will still need
1694
+ to provide your own distance calculation
1695
+
1696
+ items is an array you should push your found items into. It is
1697
+ unsorted and may hold items from any other plugin or flot's
1698
+ base calculation. Note that the items returned by flot's base
1699
+ findNearbyItems method will be sorted by distance.
1700
+
1701
+ The item to be returned should have the following:
1702
+
1703
+ datapoint - The specific bit of information hovered over
1704
+
1705
+ dataIndex - The index of the passed in datapoint in a series
1706
+
1707
+ series - The information about the series that was hovered over
1708
+
1709
+ seriesIndex - The index of the series hovered over
1710
+
1711
+ distance - Distance, in pixels, between the item and cursor.
1712
+ If distance is returned as undefined, the item will
1713
+ be treated as "infinite" distance, and will not be
1714
+ chosen instead of an item with a distance returned
1715
+
1716
+ Distance is added here to the items previously returned from
1717
+ 'findNearbyItem' so that we can decide which item should be
1718
+ returned as 'item' to 'plothover' and 'plotclick' events
1719
+
1720
+ - shutdown [phase 8]
1721
+
1722
+ ```function (plot, eventHolder)```
1723
+
1724
+ Run when plot.shutdown() is called, which usually only happens in
1725
+ case a plot is overwritten by a new plot. If you're writing a
1726
+ plugin that adds extra DOM elements or event handlers, you should
1727
+ add a callback to clean up after you. Take a look at the section in
1728
+ the [PLUGINS](PLUGINS.md) document for more info.
1729
+
1730
+
1731
+ ## Plugins ##
1732
+
1733
+ Plugins extend the functionality of Flot. To use a plugin, simply
1734
+ include its Javascript file after Flot in the HTML page.
1735
+
1736
+ If you're worried about download size/latency, you can concatenate all
1737
+ the plugins you use, and Flot itself for that matter, into one big file
1738
+ (make sure you get the order right), then optionally run it through a
1739
+ Javascript minifier such as YUI Compressor.
1740
+
1741
+ Here's a brief explanation of how the plugin plumbings work:
1742
+
1743
+ Each plugin registers itself in the global array $.plot.plugins. When
1744
+ you make a new plot object with $.plot, Flot goes through this array
1745
+ calling the "init" function of each plugin and merging default options
1746
+ from the "option" attribute of the plugin. The init function gets a
1747
+ reference to the plot object created and uses this to register hooks
1748
+ and add new public methods if needed.
1749
+
1750
+ See the [PLUGINS](PLUGINS.md) document for details on how to write a plugin. As the
1751
+ above description hints, it's actually pretty easy.
1752
+
1753
+ Some of the flot plugins add new functionalities (like touch support), while other are parts spliced out of the main jquery.flot.js and grouped based on commune functionalities.
1754
+ Read the documentation of some of the most used plugins of flot:
1755
+ * [jquery.flot.absRelTime.js](absRelTime.md)
1756
+ * [jquery.flot.browser.js](browser.md)
1757
+ * [jquery.canvaswrapper.js](canvaswrapper.md)
1758
+ * [jquery.flot.composeImages.js](composeImages.md)
1759
+ * [jquery.flot.drawSeries.js](drawSeries.md)
1760
+ * [jquery.flot.hover.js](hover.md)
1761
+ * [jquery.flot.logaxis.js](logaxis.md)
1762
+ * [jquery.flot.navigate.js](navigate.md)
1763
+
1764
+
1765
+ ## Version number ##
1766
+
1767
+ The version number of Flot is available in ```$.plot.version```.