iobroker.ebus 3.2.4 → 3.2.6

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 (47) hide show
  1. package/.eslintrc.json +34 -34
  2. package/.releaseconfig.json +3 -0
  3. package/LICENSE +20 -20
  4. package/README.md +147 -130
  5. package/admin/index_m.html +419 -419
  6. package/admin/style.css +18 -18
  7. package/admin/words.js +27 -27
  8. package/io-package.json +218 -192
  9. package/lib/support_tools.js +370 -370
  10. package/lib/tools.js +99 -99
  11. package/main.js +1232 -1232
  12. package/package.json +13 -11
  13. package/widgets/ebus/lib/js/flot/jquery.canvaswrapper.js +549 -549
  14. package/widgets/ebus/lib/js/flot/jquery.colorhelpers.js +199 -199
  15. package/widgets/ebus/lib/js/flot/jquery.flot.axislabels.js +212 -212
  16. package/widgets/ebus/lib/js/flot/jquery.flot.browser.js +98 -98
  17. package/widgets/ebus/lib/js/flot/jquery.flot.categories.js +202 -202
  18. package/widgets/ebus/lib/js/flot/jquery.flot.composeImages.js +330 -330
  19. package/widgets/ebus/lib/js/flot/jquery.flot.crosshair.js +202 -202
  20. package/widgets/ebus/lib/js/flot/jquery.flot.drawSeries.js +662 -662
  21. package/widgets/ebus/lib/js/flot/jquery.flot.errorbars.js +375 -375
  22. package/widgets/ebus/lib/js/flot/jquery.flot.fillbetween.js +254 -254
  23. package/widgets/ebus/lib/js/flot/jquery.flot.flatdata.js +47 -47
  24. package/widgets/ebus/lib/js/flot/jquery.flot.hover.js +361 -361
  25. package/widgets/ebus/lib/js/flot/jquery.flot.image.js +249 -249
  26. package/widgets/ebus/lib/js/flot/jquery.flot.js +2953 -2953
  27. package/widgets/ebus/lib/js/flot/jquery.flot.legend.js +437 -437
  28. package/widgets/ebus/lib/js/flot/jquery.flot.logaxis.js +298 -298
  29. package/widgets/ebus/lib/js/flot/jquery.flot.navigate.js +834 -834
  30. package/widgets/ebus/lib/js/flot/jquery.flot.pie.js +794 -794
  31. package/widgets/ebus/lib/js/flot/jquery.flot.resize.js +60 -60
  32. package/widgets/ebus/lib/js/flot/jquery.flot.saturated.js +43 -43
  33. package/widgets/ebus/lib/js/flot/jquery.flot.selection.js +527 -527
  34. package/widgets/ebus/lib/js/flot/jquery.flot.stack.js +220 -220
  35. package/widgets/ebus/lib/js/flot/jquery.flot.symbol.js +98 -98
  36. package/widgets/ebus/lib/js/flot/jquery.flot.threshold.js +143 -143
  37. package/widgets/ebus/lib/js/flot/jquery.flot.time.js +586 -586
  38. package/widgets/ebus/lib/js/flot/jquery.flot.touch.js +320 -320
  39. package/widgets/ebus/lib/js/flot/jquery.flot.touchNavigate.js +360 -360
  40. package/widgets/ebus/lib/js/flot/jquery.flot.uiConstants.js +10 -10
  41. package/widgets/ebus/lib/js/flot/jquery.js +9473 -9473
  42. package/widgets/ebus/lib/js/lib/globalize.culture.en-US.js +33 -33
  43. package/widgets/ebus/lib/js/lib/globalize.js +1601 -1601
  44. package/widgets/ebus/lib/js/lib/jquery.event.drag.js +145 -145
  45. package/widgets/ebus/lib/js/lib/jquery.mousewheel.js +86 -86
  46. package/widgets/ebus.html +2395 -2395
  47. package/readme.txt +0 -297
@@ -1,375 +1,375 @@
1
- /* Flot plugin for plotting error bars.
2
-
3
- Copyright (c) 2007-2014 IOLA and Ole Laursen.
4
- Licensed under the MIT license.
5
-
6
- Error bars are used to show standard deviation and other statistical
7
- properties in a plot.
8
-
9
- * Created by Rui Pereira - rui (dot) pereira (at) gmail (dot) com
10
-
11
- This plugin allows you to plot error-bars over points. Set "errorbars" inside
12
- the points series to the axis name over which there will be error values in
13
- your data array (*even* if you do not intend to plot them later, by setting
14
- "show: null" on xerr/yerr).
15
-
16
- The plugin supports these options:
17
-
18
- series: {
19
- points: {
20
- errorbars: "x" or "y" or "xy",
21
- xerr: {
22
- show: null/false or true,
23
- asymmetric: null/false or true,
24
- upperCap: null or "-" or function,
25
- lowerCap: null or "-" or function,
26
- color: null or color,
27
- radius: null or number
28
- },
29
- yerr: { same options as xerr }
30
- }
31
- }
32
-
33
- Each data point array is expected to be of the type:
34
-
35
- "x" [ x, y, xerr ]
36
- "y" [ x, y, yerr ]
37
- "xy" [ x, y, xerr, yerr ]
38
-
39
- Where xerr becomes xerr_lower,xerr_upper for the asymmetric error case, and
40
- equivalently for yerr. Eg., a datapoint for the "xy" case with symmetric
41
- error-bars on X and asymmetric on Y would be:
42
-
43
- [ x, y, xerr, yerr_lower, yerr_upper ]
44
-
45
- By default no end caps are drawn. Setting upperCap and/or lowerCap to "-" will
46
- draw a small cap perpendicular to the error bar. They can also be set to a
47
- user-defined drawing function, with (ctx, x, y, radius) as parameters, as eg.
48
-
49
- function drawSemiCircle( ctx, x, y, radius ) {
50
- ctx.beginPath();
51
- ctx.arc( x, y, radius, 0, Math.PI, false );
52
- ctx.moveTo( x - radius, y );
53
- ctx.lineTo( x + radius, y );
54
- ctx.stroke();
55
- }
56
-
57
- Color and radius both default to the same ones of the points series if not
58
- set. The independent radius parameter on xerr/yerr is useful for the case when
59
- we may want to add error-bars to a line, without showing the interconnecting
60
- points (with radius: 0), and still showing end caps on the error-bars.
61
- shadowSize and lineWidth are derived as well from the points series.
62
-
63
- */
64
-
65
- (function ($) {
66
- var options = {
67
- series: {
68
- points: {
69
- errorbars: null, //should be 'x', 'y' or 'xy'
70
- xerr: {err: 'x', show: null, asymmetric: null, upperCap: null, lowerCap: null, color: null, radius: null},
71
- yerr: {err: 'y', show: null, asymmetric: null, upperCap: null, lowerCap: null, color: null, radius: null}
72
- }
73
- }
74
- };
75
-
76
- function processRawData(plot, series, data, datapoints) {
77
- if (!series.points.errorbars) {
78
- return;
79
- }
80
-
81
- // x,y values
82
- var format = [
83
- { x: true, number: true, required: true },
84
- { y: true, number: true, required: true }
85
- ];
86
-
87
- var errors = series.points.errorbars;
88
- // error bars - first X then Y
89
- if (errors === 'x' || errors === 'xy') {
90
- // lower / upper error
91
- if (series.points.xerr.asymmetric) {
92
- format.push({ x: true, number: true, required: true });
93
- format.push({ x: true, number: true, required: true });
94
- } else {
95
- format.push({ x: true, number: true, required: true });
96
- }
97
- }
98
- if (errors === 'y' || errors === 'xy') {
99
- // lower / upper error
100
- if (series.points.yerr.asymmetric) {
101
- format.push({ y: true, number: true, required: true });
102
- format.push({ y: true, number: true, required: true });
103
- } else {
104
- format.push({ y: true, number: true, required: true });
105
- }
106
- }
107
- datapoints.format = format;
108
- }
109
-
110
- function parseErrors(series, i) {
111
- var points = series.datapoints.points;
112
-
113
- // read errors from points array
114
- var exl = null,
115
- exu = null,
116
- eyl = null,
117
- eyu = null;
118
- var xerr = series.points.xerr,
119
- yerr = series.points.yerr;
120
-
121
- var eb = series.points.errorbars;
122
- // error bars - first X
123
- if (eb === 'x' || eb === 'xy') {
124
- if (xerr.asymmetric) {
125
- exl = points[i + 2];
126
- exu = points[i + 3];
127
- if (eb === 'xy') {
128
- if (yerr.asymmetric) {
129
- eyl = points[i + 4];
130
- eyu = points[i + 5];
131
- } else {
132
- eyl = points[i + 4];
133
- }
134
- }
135
- } else {
136
- exl = points[i + 2];
137
- if (eb === 'xy') {
138
- if (yerr.asymmetric) {
139
- eyl = points[i + 3];
140
- eyu = points[i + 4];
141
- } else {
142
- eyl = points[i + 3];
143
- }
144
- }
145
- }
146
- // only Y
147
- } else {
148
- if (eb === 'y') {
149
- if (yerr.asymmetric) {
150
- eyl = points[i + 2];
151
- eyu = points[i + 3];
152
- } else {
153
- eyl = points[i + 2];
154
- }
155
- }
156
- }
157
-
158
- // symmetric errors?
159
- if (exu == null) exu = exl;
160
- if (eyu == null) eyu = eyl;
161
-
162
- var errRanges = [exl, exu, eyl, eyu];
163
- // nullify if not showing
164
- if (!xerr.show) {
165
- errRanges[0] = null;
166
- errRanges[1] = null;
167
- }
168
- if (!yerr.show) {
169
- errRanges[2] = null;
170
- errRanges[3] = null;
171
- }
172
- return errRanges;
173
- }
174
-
175
- function drawSeriesErrors(plot, ctx, s) {
176
- var points = s.datapoints.points,
177
- ps = s.datapoints.pointsize,
178
- ax = [s.xaxis, s.yaxis],
179
- radius = s.points.radius,
180
- err = [s.points.xerr, s.points.yerr],
181
- tmp;
182
-
183
- //sanity check, in case some inverted axis hack is applied to flot
184
- var invertX = false;
185
- if (ax[0].p2c(ax[0].max) < ax[0].p2c(ax[0].min)) {
186
- invertX = true;
187
- tmp = err[0].lowerCap;
188
- err[0].lowerCap = err[0].upperCap;
189
- err[0].upperCap = tmp;
190
- }
191
-
192
- var invertY = false;
193
- if (ax[1].p2c(ax[1].min) < ax[1].p2c(ax[1].max)) {
194
- invertY = true;
195
- tmp = err[1].lowerCap;
196
- err[1].lowerCap = err[1].upperCap;
197
- err[1].upperCap = tmp;
198
- }
199
-
200
- for (var i = 0; i < s.datapoints.points.length; i += ps) {
201
- //parse
202
- var errRanges = parseErrors(s, i);
203
-
204
- //cycle xerr & yerr
205
- for (var e = 0; e < err.length; e++) {
206
- var minmax = [ax[e].min, ax[e].max];
207
-
208
- //draw this error?
209
- if (errRanges[e * err.length]) {
210
- //data coordinates
211
- var x = points[i],
212
- y = points[i + 1];
213
-
214
- //errorbar ranges
215
- var upper = [x, y][e] + errRanges[e * err.length + 1],
216
- lower = [x, y][e] - errRanges[e * err.length];
217
-
218
- //points outside of the canvas
219
- if (err[e].err === 'x') {
220
- if (y > ax[1].max || y < ax[1].min || upper < ax[0].min || lower > ax[0].max) {
221
- continue;
222
- }
223
- }
224
-
225
- if (err[e].err === 'y') {
226
- if (x > ax[0].max || x < ax[0].min || upper < ax[1].min || lower > ax[1].max) {
227
- continue;
228
- }
229
- }
230
-
231
- // prevent errorbars getting out of the canvas
232
- var drawUpper = true,
233
- drawLower = true;
234
-
235
- if (upper > minmax[1]) {
236
- drawUpper = false;
237
- upper = minmax[1];
238
- }
239
- if (lower < minmax[0]) {
240
- drawLower = false;
241
- lower = minmax[0];
242
- }
243
-
244
- //sanity check, in case some inverted axis hack is applied to flot
245
- if ((err[e].err === 'x' && invertX) || (err[e].err === 'y' && invertY)) {
246
- //swap coordinates
247
- tmp = lower;
248
- lower = upper;
249
- upper = tmp;
250
- tmp = drawLower;
251
- drawLower = drawUpper;
252
- drawUpper = tmp;
253
- tmp = minmax[0];
254
- minmax[0] = minmax[1];
255
- minmax[1] = tmp;
256
- }
257
-
258
- // convert to pixels
259
- x = ax[0].p2c(x);
260
- y = ax[1].p2c(y);
261
- upper = ax[e].p2c(upper);
262
- lower = ax[e].p2c(lower);
263
- minmax[0] = ax[e].p2c(minmax[0]);
264
- minmax[1] = ax[e].p2c(minmax[1]);
265
-
266
- //same style as points by default
267
- var lw = err[e].lineWidth ? err[e].lineWidth : s.points.lineWidth,
268
- sw = s.points.shadowSize != null ? s.points.shadowSize : s.shadowSize;
269
-
270
- //shadow as for points
271
- if (lw > 0 && sw > 0) {
272
- var w = sw / 2;
273
- ctx.lineWidth = w;
274
- ctx.strokeStyle = "rgba(0,0,0,0.1)";
275
- drawError(ctx, err[e], x, y, upper, lower, drawUpper, drawLower, radius, w + w / 2, minmax);
276
-
277
- ctx.strokeStyle = "rgba(0,0,0,0.2)";
278
- drawError(ctx, err[e], x, y, upper, lower, drawUpper, drawLower, radius, w / 2, minmax);
279
- }
280
-
281
- ctx.strokeStyle = err[e].color
282
- ? err[e].color
283
- : s.color;
284
- ctx.lineWidth = lw;
285
- //draw it
286
- drawError(ctx, err[e], x, y, upper, lower, drawUpper, drawLower, radius, 0, minmax);
287
- }
288
- }
289
- }
290
- }
291
-
292
- function drawError(ctx, err, x, y, upper, lower, drawUpper, drawLower, radius, offset, minmax) {
293
- //shadow offset
294
- y += offset;
295
- upper += offset;
296
- lower += offset;
297
-
298
- // error bar - avoid plotting over circles
299
- if (err.err === 'x') {
300
- if (upper > x + radius) drawPath(ctx, [[upper, y], [Math.max(x + radius, minmax[0]), y]]);
301
- else drawUpper = false;
302
-
303
- if (lower < x - radius) drawPath(ctx, [[Math.min(x - radius, minmax[1]), y], [lower, y]]);
304
- else drawLower = false;
305
- } else {
306
- if (upper < y - radius) drawPath(ctx, [[x, upper], [x, Math.min(y - radius, minmax[0])]]);
307
- else drawUpper = false;
308
-
309
- if (lower > y + radius) drawPath(ctx, [[x, Math.max(y + radius, minmax[1])], [x, lower]]);
310
- else drawLower = false;
311
- }
312
-
313
- //internal radius value in errorbar, allows to plot radius 0 points and still keep proper sized caps
314
- //this is a way to get errorbars on lines without visible connecting dots
315
- radius = err.radius != null
316
- ? err.radius
317
- : radius;
318
-
319
- // upper cap
320
- if (drawUpper) {
321
- if (err.upperCap === '-') {
322
- if (err.err === 'x') drawPath(ctx, [[upper, y - radius], [upper, y + radius]]);
323
- else drawPath(ctx, [[x - radius, upper], [x + radius, upper]]);
324
- } else if ($.isFunction(err.upperCap)) {
325
- if (err.err === 'x') err.upperCap(ctx, upper, y, radius);
326
- else err.upperCap(ctx, x, upper, radius);
327
- }
328
- }
329
- // lower cap
330
- if (drawLower) {
331
- if (err.lowerCap === '-') {
332
- if (err.err === 'x') drawPath(ctx, [[lower, y - radius], [lower, y + radius]]);
333
- else drawPath(ctx, [[x - radius, lower], [x + radius, lower]]);
334
- } else if ($.isFunction(err.lowerCap)) {
335
- if (err.err === 'x') err.lowerCap(ctx, lower, y, radius);
336
- else err.lowerCap(ctx, x, lower, radius);
337
- }
338
- }
339
- }
340
-
341
- function drawPath(ctx, pts) {
342
- ctx.beginPath();
343
- ctx.moveTo(pts[0][0], pts[0][1]);
344
- for (var p = 1; p < pts.length; p++) {
345
- ctx.lineTo(pts[p][0], pts[p][1]);
346
- }
347
-
348
- ctx.stroke();
349
- }
350
-
351
- function draw(plot, ctx) {
352
- var plotOffset = plot.getPlotOffset();
353
-
354
- ctx.save();
355
- ctx.translate(plotOffset.left, plotOffset.top);
356
- $.each(plot.getData(), function (i, s) {
357
- if (s.points.errorbars && (s.points.xerr.show || s.points.yerr.show)) {
358
- drawSeriesErrors(plot, ctx, s);
359
- }
360
- });
361
- ctx.restore();
362
- }
363
-
364
- function init(plot) {
365
- plot.hooks.processRawData.push(processRawData);
366
- plot.hooks.draw.push(draw);
367
- }
368
-
369
- $.plot.plugins.push({
370
- init: init,
371
- options: options,
372
- name: 'errorbars',
373
- version: '1.0'
374
- });
375
- })(jQuery);
1
+ /* Flot plugin for plotting error bars.
2
+
3
+ Copyright (c) 2007-2014 IOLA and Ole Laursen.
4
+ Licensed under the MIT license.
5
+
6
+ Error bars are used to show standard deviation and other statistical
7
+ properties in a plot.
8
+
9
+ * Created by Rui Pereira - rui (dot) pereira (at) gmail (dot) com
10
+
11
+ This plugin allows you to plot error-bars over points. Set "errorbars" inside
12
+ the points series to the axis name over which there will be error values in
13
+ your data array (*even* if you do not intend to plot them later, by setting
14
+ "show: null" on xerr/yerr).
15
+
16
+ The plugin supports these options:
17
+
18
+ series: {
19
+ points: {
20
+ errorbars: "x" or "y" or "xy",
21
+ xerr: {
22
+ show: null/false or true,
23
+ asymmetric: null/false or true,
24
+ upperCap: null or "-" or function,
25
+ lowerCap: null or "-" or function,
26
+ color: null or color,
27
+ radius: null or number
28
+ },
29
+ yerr: { same options as xerr }
30
+ }
31
+ }
32
+
33
+ Each data point array is expected to be of the type:
34
+
35
+ "x" [ x, y, xerr ]
36
+ "y" [ x, y, yerr ]
37
+ "xy" [ x, y, xerr, yerr ]
38
+
39
+ Where xerr becomes xerr_lower,xerr_upper for the asymmetric error case, and
40
+ equivalently for yerr. Eg., a datapoint for the "xy" case with symmetric
41
+ error-bars on X and asymmetric on Y would be:
42
+
43
+ [ x, y, xerr, yerr_lower, yerr_upper ]
44
+
45
+ By default no end caps are drawn. Setting upperCap and/or lowerCap to "-" will
46
+ draw a small cap perpendicular to the error bar. They can also be set to a
47
+ user-defined drawing function, with (ctx, x, y, radius) as parameters, as eg.
48
+
49
+ function drawSemiCircle( ctx, x, y, radius ) {
50
+ ctx.beginPath();
51
+ ctx.arc( x, y, radius, 0, Math.PI, false );
52
+ ctx.moveTo( x - radius, y );
53
+ ctx.lineTo( x + radius, y );
54
+ ctx.stroke();
55
+ }
56
+
57
+ Color and radius both default to the same ones of the points series if not
58
+ set. The independent radius parameter on xerr/yerr is useful for the case when
59
+ we may want to add error-bars to a line, without showing the interconnecting
60
+ points (with radius: 0), and still showing end caps on the error-bars.
61
+ shadowSize and lineWidth are derived as well from the points series.
62
+
63
+ */
64
+
65
+ (function ($) {
66
+ var options = {
67
+ series: {
68
+ points: {
69
+ errorbars: null, //should be 'x', 'y' or 'xy'
70
+ xerr: {err: 'x', show: null, asymmetric: null, upperCap: null, lowerCap: null, color: null, radius: null},
71
+ yerr: {err: 'y', show: null, asymmetric: null, upperCap: null, lowerCap: null, color: null, radius: null}
72
+ }
73
+ }
74
+ };
75
+
76
+ function processRawData(plot, series, data, datapoints) {
77
+ if (!series.points.errorbars) {
78
+ return;
79
+ }
80
+
81
+ // x,y values
82
+ var format = [
83
+ { x: true, number: true, required: true },
84
+ { y: true, number: true, required: true }
85
+ ];
86
+
87
+ var errors = series.points.errorbars;
88
+ // error bars - first X then Y
89
+ if (errors === 'x' || errors === 'xy') {
90
+ // lower / upper error
91
+ if (series.points.xerr.asymmetric) {
92
+ format.push({ x: true, number: true, required: true });
93
+ format.push({ x: true, number: true, required: true });
94
+ } else {
95
+ format.push({ x: true, number: true, required: true });
96
+ }
97
+ }
98
+ if (errors === 'y' || errors === 'xy') {
99
+ // lower / upper error
100
+ if (series.points.yerr.asymmetric) {
101
+ format.push({ y: true, number: true, required: true });
102
+ format.push({ y: true, number: true, required: true });
103
+ } else {
104
+ format.push({ y: true, number: true, required: true });
105
+ }
106
+ }
107
+ datapoints.format = format;
108
+ }
109
+
110
+ function parseErrors(series, i) {
111
+ var points = series.datapoints.points;
112
+
113
+ // read errors from points array
114
+ var exl = null,
115
+ exu = null,
116
+ eyl = null,
117
+ eyu = null;
118
+ var xerr = series.points.xerr,
119
+ yerr = series.points.yerr;
120
+
121
+ var eb = series.points.errorbars;
122
+ // error bars - first X
123
+ if (eb === 'x' || eb === 'xy') {
124
+ if (xerr.asymmetric) {
125
+ exl = points[i + 2];
126
+ exu = points[i + 3];
127
+ if (eb === 'xy') {
128
+ if (yerr.asymmetric) {
129
+ eyl = points[i + 4];
130
+ eyu = points[i + 5];
131
+ } else {
132
+ eyl = points[i + 4];
133
+ }
134
+ }
135
+ } else {
136
+ exl = points[i + 2];
137
+ if (eb === 'xy') {
138
+ if (yerr.asymmetric) {
139
+ eyl = points[i + 3];
140
+ eyu = points[i + 4];
141
+ } else {
142
+ eyl = points[i + 3];
143
+ }
144
+ }
145
+ }
146
+ // only Y
147
+ } else {
148
+ if (eb === 'y') {
149
+ if (yerr.asymmetric) {
150
+ eyl = points[i + 2];
151
+ eyu = points[i + 3];
152
+ } else {
153
+ eyl = points[i + 2];
154
+ }
155
+ }
156
+ }
157
+
158
+ // symmetric errors?
159
+ if (exu == null) exu = exl;
160
+ if (eyu == null) eyu = eyl;
161
+
162
+ var errRanges = [exl, exu, eyl, eyu];
163
+ // nullify if not showing
164
+ if (!xerr.show) {
165
+ errRanges[0] = null;
166
+ errRanges[1] = null;
167
+ }
168
+ if (!yerr.show) {
169
+ errRanges[2] = null;
170
+ errRanges[3] = null;
171
+ }
172
+ return errRanges;
173
+ }
174
+
175
+ function drawSeriesErrors(plot, ctx, s) {
176
+ var points = s.datapoints.points,
177
+ ps = s.datapoints.pointsize,
178
+ ax = [s.xaxis, s.yaxis],
179
+ radius = s.points.radius,
180
+ err = [s.points.xerr, s.points.yerr],
181
+ tmp;
182
+
183
+ //sanity check, in case some inverted axis hack is applied to flot
184
+ var invertX = false;
185
+ if (ax[0].p2c(ax[0].max) < ax[0].p2c(ax[0].min)) {
186
+ invertX = true;
187
+ tmp = err[0].lowerCap;
188
+ err[0].lowerCap = err[0].upperCap;
189
+ err[0].upperCap = tmp;
190
+ }
191
+
192
+ var invertY = false;
193
+ if (ax[1].p2c(ax[1].min) < ax[1].p2c(ax[1].max)) {
194
+ invertY = true;
195
+ tmp = err[1].lowerCap;
196
+ err[1].lowerCap = err[1].upperCap;
197
+ err[1].upperCap = tmp;
198
+ }
199
+
200
+ for (var i = 0; i < s.datapoints.points.length; i += ps) {
201
+ //parse
202
+ var errRanges = parseErrors(s, i);
203
+
204
+ //cycle xerr & yerr
205
+ for (var e = 0; e < err.length; e++) {
206
+ var minmax = [ax[e].min, ax[e].max];
207
+
208
+ //draw this error?
209
+ if (errRanges[e * err.length]) {
210
+ //data coordinates
211
+ var x = points[i],
212
+ y = points[i + 1];
213
+
214
+ //errorbar ranges
215
+ var upper = [x, y][e] + errRanges[e * err.length + 1],
216
+ lower = [x, y][e] - errRanges[e * err.length];
217
+
218
+ //points outside of the canvas
219
+ if (err[e].err === 'x') {
220
+ if (y > ax[1].max || y < ax[1].min || upper < ax[0].min || lower > ax[0].max) {
221
+ continue;
222
+ }
223
+ }
224
+
225
+ if (err[e].err === 'y') {
226
+ if (x > ax[0].max || x < ax[0].min || upper < ax[1].min || lower > ax[1].max) {
227
+ continue;
228
+ }
229
+ }
230
+
231
+ // prevent errorbars getting out of the canvas
232
+ var drawUpper = true,
233
+ drawLower = true;
234
+
235
+ if (upper > minmax[1]) {
236
+ drawUpper = false;
237
+ upper = minmax[1];
238
+ }
239
+ if (lower < minmax[0]) {
240
+ drawLower = false;
241
+ lower = minmax[0];
242
+ }
243
+
244
+ //sanity check, in case some inverted axis hack is applied to flot
245
+ if ((err[e].err === 'x' && invertX) || (err[e].err === 'y' && invertY)) {
246
+ //swap coordinates
247
+ tmp = lower;
248
+ lower = upper;
249
+ upper = tmp;
250
+ tmp = drawLower;
251
+ drawLower = drawUpper;
252
+ drawUpper = tmp;
253
+ tmp = minmax[0];
254
+ minmax[0] = minmax[1];
255
+ minmax[1] = tmp;
256
+ }
257
+
258
+ // convert to pixels
259
+ x = ax[0].p2c(x);
260
+ y = ax[1].p2c(y);
261
+ upper = ax[e].p2c(upper);
262
+ lower = ax[e].p2c(lower);
263
+ minmax[0] = ax[e].p2c(minmax[0]);
264
+ minmax[1] = ax[e].p2c(minmax[1]);
265
+
266
+ //same style as points by default
267
+ var lw = err[e].lineWidth ? err[e].lineWidth : s.points.lineWidth,
268
+ sw = s.points.shadowSize != null ? s.points.shadowSize : s.shadowSize;
269
+
270
+ //shadow as for points
271
+ if (lw > 0 && sw > 0) {
272
+ var w = sw / 2;
273
+ ctx.lineWidth = w;
274
+ ctx.strokeStyle = "rgba(0,0,0,0.1)";
275
+ drawError(ctx, err[e], x, y, upper, lower, drawUpper, drawLower, radius, w + w / 2, minmax);
276
+
277
+ ctx.strokeStyle = "rgba(0,0,0,0.2)";
278
+ drawError(ctx, err[e], x, y, upper, lower, drawUpper, drawLower, radius, w / 2, minmax);
279
+ }
280
+
281
+ ctx.strokeStyle = err[e].color
282
+ ? err[e].color
283
+ : s.color;
284
+ ctx.lineWidth = lw;
285
+ //draw it
286
+ drawError(ctx, err[e], x, y, upper, lower, drawUpper, drawLower, radius, 0, minmax);
287
+ }
288
+ }
289
+ }
290
+ }
291
+
292
+ function drawError(ctx, err, x, y, upper, lower, drawUpper, drawLower, radius, offset, minmax) {
293
+ //shadow offset
294
+ y += offset;
295
+ upper += offset;
296
+ lower += offset;
297
+
298
+ // error bar - avoid plotting over circles
299
+ if (err.err === 'x') {
300
+ if (upper > x + radius) drawPath(ctx, [[upper, y], [Math.max(x + radius, minmax[0]), y]]);
301
+ else drawUpper = false;
302
+
303
+ if (lower < x - radius) drawPath(ctx, [[Math.min(x - radius, minmax[1]), y], [lower, y]]);
304
+ else drawLower = false;
305
+ } else {
306
+ if (upper < y - radius) drawPath(ctx, [[x, upper], [x, Math.min(y - radius, minmax[0])]]);
307
+ else drawUpper = false;
308
+
309
+ if (lower > y + radius) drawPath(ctx, [[x, Math.max(y + radius, minmax[1])], [x, lower]]);
310
+ else drawLower = false;
311
+ }
312
+
313
+ //internal radius value in errorbar, allows to plot radius 0 points and still keep proper sized caps
314
+ //this is a way to get errorbars on lines without visible connecting dots
315
+ radius = err.radius != null
316
+ ? err.radius
317
+ : radius;
318
+
319
+ // upper cap
320
+ if (drawUpper) {
321
+ if (err.upperCap === '-') {
322
+ if (err.err === 'x') drawPath(ctx, [[upper, y - radius], [upper, y + radius]]);
323
+ else drawPath(ctx, [[x - radius, upper], [x + radius, upper]]);
324
+ } else if ($.isFunction(err.upperCap)) {
325
+ if (err.err === 'x') err.upperCap(ctx, upper, y, radius);
326
+ else err.upperCap(ctx, x, upper, radius);
327
+ }
328
+ }
329
+ // lower cap
330
+ if (drawLower) {
331
+ if (err.lowerCap === '-') {
332
+ if (err.err === 'x') drawPath(ctx, [[lower, y - radius], [lower, y + radius]]);
333
+ else drawPath(ctx, [[x - radius, lower], [x + radius, lower]]);
334
+ } else if ($.isFunction(err.lowerCap)) {
335
+ if (err.err === 'x') err.lowerCap(ctx, lower, y, radius);
336
+ else err.lowerCap(ctx, x, lower, radius);
337
+ }
338
+ }
339
+ }
340
+
341
+ function drawPath(ctx, pts) {
342
+ ctx.beginPath();
343
+ ctx.moveTo(pts[0][0], pts[0][1]);
344
+ for (var p = 1; p < pts.length; p++) {
345
+ ctx.lineTo(pts[p][0], pts[p][1]);
346
+ }
347
+
348
+ ctx.stroke();
349
+ }
350
+
351
+ function draw(plot, ctx) {
352
+ var plotOffset = plot.getPlotOffset();
353
+
354
+ ctx.save();
355
+ ctx.translate(plotOffset.left, plotOffset.top);
356
+ $.each(plot.getData(), function (i, s) {
357
+ if (s.points.errorbars && (s.points.xerr.show || s.points.yerr.show)) {
358
+ drawSeriesErrors(plot, ctx, s);
359
+ }
360
+ });
361
+ ctx.restore();
362
+ }
363
+
364
+ function init(plot) {
365
+ plot.hooks.processRawData.push(processRawData);
366
+ plot.hooks.draw.push(draw);
367
+ }
368
+
369
+ $.plot.plugins.push({
370
+ init: init,
371
+ options: options,
372
+ name: 'errorbars',
373
+ version: '1.0'
374
+ });
375
+ })(jQuery);