iobroker.ebus 3.3.7 → 3.3.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -0
- package/io-package.json +94 -14
- package/package.json +2 -1
- package/widgets/ebus/img/Prev_tplebus.png +0 -0
- package/widgets/ebus/lib/js/flot/jquery.canvaswrapper.js +549 -0
- package/widgets/ebus/lib/js/flot/jquery.colorhelpers.js +199 -0
- package/widgets/ebus/lib/js/flot/jquery.flot.axislabels.js +212 -0
- package/widgets/ebus/lib/js/flot/jquery.flot.browser.js +98 -0
- package/widgets/ebus/lib/js/flot/jquery.flot.categories.js +202 -0
- package/widgets/ebus/lib/js/flot/jquery.flot.composeImages.js +330 -0
- package/widgets/ebus/lib/js/flot/jquery.flot.crosshair.js +202 -0
- package/widgets/ebus/lib/js/flot/jquery.flot.drawSeries.js +662 -0
- package/widgets/ebus/lib/js/flot/jquery.flot.errorbars.js +375 -0
- package/widgets/ebus/lib/js/flot/jquery.flot.fillbetween.js +254 -0
- package/widgets/ebus/lib/js/flot/jquery.flot.flatdata.js +47 -0
- package/widgets/ebus/lib/js/flot/jquery.flot.hover.js +361 -0
- package/widgets/ebus/lib/js/flot/jquery.flot.image.js +249 -0
- package/widgets/ebus/lib/js/flot/jquery.flot.js +2953 -0
- package/widgets/ebus/lib/js/flot/jquery.flot.legend.js +437 -0
- package/widgets/ebus/lib/js/flot/jquery.flot.logaxis.js +298 -0
- package/widgets/ebus/lib/js/flot/jquery.flot.navigate.js +834 -0
- package/widgets/ebus/lib/js/flot/jquery.flot.pie.js +794 -0
- package/widgets/ebus/lib/js/flot/jquery.flot.resize.js +60 -0
- package/widgets/ebus/lib/js/flot/jquery.flot.saturated.js +43 -0
- package/widgets/ebus/lib/js/flot/jquery.flot.selection.js +527 -0
- package/widgets/ebus/lib/js/flot/jquery.flot.stack.js +220 -0
- package/widgets/ebus/lib/js/flot/jquery.flot.symbol.js +98 -0
- package/widgets/ebus/lib/js/flot/jquery.flot.threshold.js +143 -0
- package/widgets/ebus/lib/js/flot/jquery.flot.time.js +586 -0
- package/widgets/ebus/lib/js/flot/jquery.flot.touch.js +320 -0
- package/widgets/ebus/lib/js/flot/jquery.flot.touchNavigate.js +360 -0
- package/widgets/ebus/lib/js/flot/jquery.flot.uiConstants.js +10 -0
- package/widgets/ebus/lib/js/flot/jquery.js +9473 -0
- package/widgets/ebus/lib/js/lib/globalize.culture.en-US.js +33 -0
- package/widgets/ebus/lib/js/lib/globalize.js +1601 -0
- package/widgets/ebus/lib/js/lib/jquery.event.drag.js +145 -0
- package/widgets/ebus/lib/js/lib/jquery.mousewheel.js +86 -0
- package/widgets/ebus.html +2395 -0
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
/* global jQuery */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
## jquery.flot.hover.js
|
|
5
|
+
|
|
6
|
+
This plugin is used for mouse hover and tap on a point of plot series.
|
|
7
|
+
It supports the following options:
|
|
8
|
+
```js
|
|
9
|
+
grid: {
|
|
10
|
+
hoverable: false, //to trigger plothover event on mouse hover or tap on a point
|
|
11
|
+
clickable: false //to trigger plotclick event on mouse hover
|
|
12
|
+
}
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
It listens to native mouse move event or click, as well as artificial generated
|
|
16
|
+
tap and touchevent.
|
|
17
|
+
|
|
18
|
+
When the mouse is over a point or a tap on a point is performed, that point or
|
|
19
|
+
the correscponding bar will be highlighted and a "plothover" event will be generated.
|
|
20
|
+
|
|
21
|
+
Custom "touchevent" is triggered when any touch interaction is made. Hover plugin
|
|
22
|
+
handles this events by unhighlighting all of the previously highlighted points and generates
|
|
23
|
+
"plothovercleanup" event to notify any part that is handling plothover (for exemple to cleanup
|
|
24
|
+
the tooltip from webcharts).
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
(function($) {
|
|
28
|
+
'use strict';
|
|
29
|
+
|
|
30
|
+
var options = {
|
|
31
|
+
grid: {
|
|
32
|
+
hoverable: false,
|
|
33
|
+
clickable: false
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
var browser = $.plot.browser;
|
|
38
|
+
|
|
39
|
+
var eventType = {
|
|
40
|
+
click: 'click',
|
|
41
|
+
hover: 'hover'
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function init(plot) {
|
|
45
|
+
var lastMouseMoveEvent;
|
|
46
|
+
var highlights = [];
|
|
47
|
+
|
|
48
|
+
console.log("hover init");
|
|
49
|
+
|
|
50
|
+
function bindEvents(plot, eventHolder) {
|
|
51
|
+
var o = plot.getOptions();
|
|
52
|
+
|
|
53
|
+
if (o.grid.hoverable || o.grid.clickable) {
|
|
54
|
+
eventHolder[0].addEventListener('touchevent', triggerCleanupEvent, false);
|
|
55
|
+
eventHolder[0].addEventListener('tap', generatePlothoverEvent, false);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (o.grid.clickable) {
|
|
59
|
+
eventHolder.bind("click", onClick);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (o.grid.hoverable) {
|
|
63
|
+
eventHolder.bind("mousemove", onMouseMove);
|
|
64
|
+
|
|
65
|
+
// Use bind, rather than .mouseleave, because we officially
|
|
66
|
+
// still support jQuery 1.2.6, which doesn't define a shortcut
|
|
67
|
+
// for mouseenter or mouseleave. This was a bug/oversight that
|
|
68
|
+
// was fixed somewhere around 1.3.x. We can return to using
|
|
69
|
+
// .mouseleave when we drop support for 1.2.6.
|
|
70
|
+
|
|
71
|
+
eventHolder.bind("mouseleave", onMouseLeave);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function shutdown(plot, eventHolder) {
|
|
76
|
+
eventHolder[0].removeEventListener('tap', generatePlothoverEvent);
|
|
77
|
+
eventHolder[0].removeEventListener('touchevent', triggerCleanupEvent);
|
|
78
|
+
eventHolder.unbind("mousemove", onMouseMove);
|
|
79
|
+
eventHolder.unbind("mouseleave", onMouseLeave);
|
|
80
|
+
eventHolder.unbind("click", onClick);
|
|
81
|
+
highlights = [];
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function generatePlothoverEvent(e) {
|
|
85
|
+
var o = plot.getOptions(),
|
|
86
|
+
newEvent = new CustomEvent('mouseevent');
|
|
87
|
+
|
|
88
|
+
//transform from touch event to mouse event format
|
|
89
|
+
newEvent.pageX = e.detail.changedTouches[0].pageX;
|
|
90
|
+
newEvent.pageY = e.detail.changedTouches[0].pageY;
|
|
91
|
+
newEvent.clientX = e.detail.changedTouches[0].clientX;
|
|
92
|
+
newEvent.clientY = e.detail.changedTouches[0].clientY;
|
|
93
|
+
|
|
94
|
+
if (o.grid.hoverable) {
|
|
95
|
+
doTriggerClickHoverEvent(newEvent, eventType.hover, 30);
|
|
96
|
+
}
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function doTriggerClickHoverEvent(event, eventType, searchDistance) {
|
|
101
|
+
var series = plot.getData();
|
|
102
|
+
if (event !== undefined &&
|
|
103
|
+
series.length > 0 &&
|
|
104
|
+
series[0].xaxis.c2p !== undefined &&
|
|
105
|
+
series[0].yaxis.c2p !== undefined) {
|
|
106
|
+
var eventToTrigger = "plot" + eventType;
|
|
107
|
+
var seriesFlag = eventType + "able";
|
|
108
|
+
triggerClickHoverEvent(eventToTrigger, event,
|
|
109
|
+
function(i) {
|
|
110
|
+
return series[i][seriesFlag] !== false;
|
|
111
|
+
}, searchDistance);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function onMouseMove(e) {
|
|
116
|
+
lastMouseMoveEvent = e;
|
|
117
|
+
plot.getPlaceholder()[0].lastMouseMoveEvent = e;
|
|
118
|
+
doTriggerClickHoverEvent(e, eventType.hover);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function onMouseLeave(e) {
|
|
122
|
+
lastMouseMoveEvent = undefined;
|
|
123
|
+
plot.getPlaceholder()[0].lastMouseMoveEvent = undefined;
|
|
124
|
+
triggerClickHoverEvent("plothover", e,
|
|
125
|
+
function(i) {
|
|
126
|
+
return false;
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function onClick(e) {
|
|
131
|
+
doTriggerClickHoverEvent(e, eventType.click);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function triggerCleanupEvent() {
|
|
135
|
+
plot.unhighlight();
|
|
136
|
+
plot.getPlaceholder().trigger('plothovercleanup');
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// trigger click or hover event (they send the same parameters
|
|
140
|
+
// so we share their code)
|
|
141
|
+
function triggerClickHoverEvent(eventname, event, seriesFilter, searchDistance) {
|
|
142
|
+
var options = plot.getOptions(),
|
|
143
|
+
offset = plot.offset(),
|
|
144
|
+
page = browser.getPageXY(event),
|
|
145
|
+
canvasX = page.X - offset.left,
|
|
146
|
+
canvasY = page.Y - offset.top,
|
|
147
|
+
pos = plot.c2p({
|
|
148
|
+
left: canvasX,
|
|
149
|
+
top: canvasY
|
|
150
|
+
}),
|
|
151
|
+
distance = searchDistance !== undefined ? searchDistance : options.grid.mouseActiveRadius;
|
|
152
|
+
|
|
153
|
+
pos.pageX = page.X;
|
|
154
|
+
pos.pageY = page.Y;
|
|
155
|
+
|
|
156
|
+
var items = plot.findNearbyItems(canvasX, canvasY, seriesFilter, distance);
|
|
157
|
+
var item = items[0];
|
|
158
|
+
|
|
159
|
+
for (let i = 1; i < items.length; ++i) {
|
|
160
|
+
if (item.distance === undefined ||
|
|
161
|
+
items[i].distance < item.distance) {
|
|
162
|
+
item = items[i];
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
if (item) {
|
|
167
|
+
// fill in mouse pos for any listeners out there
|
|
168
|
+
item.pageX = parseInt(item.series.xaxis.p2c(item.datapoint[0]) + offset.left, 10);
|
|
169
|
+
item.pageY = parseInt(item.series.yaxis.p2c(item.datapoint[1]) + offset.top, 10);
|
|
170
|
+
} else {
|
|
171
|
+
item = null;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (options.grid.autoHighlight) {
|
|
175
|
+
// clear auto-highlights
|
|
176
|
+
for (let i = 0; i < highlights.length; ++i) {
|
|
177
|
+
var h = highlights[i];
|
|
178
|
+
if ((h.auto === eventname &&
|
|
179
|
+
!(item && h.series === item.series &&
|
|
180
|
+
h.point[0] === item.datapoint[0] &&
|
|
181
|
+
h.point[1] === item.datapoint[1])) || !item) {
|
|
182
|
+
unhighlight(h.series, h.point);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
if (item) {
|
|
187
|
+
highlight(item.series, item.datapoint, eventname);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
plot.getPlaceholder().trigger(eventname, [pos, item, items]);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function highlight(s, point, auto) {
|
|
195
|
+
if (typeof s === "number") {
|
|
196
|
+
s = plot.getData()[s];
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
if (typeof point === "number") {
|
|
200
|
+
var ps = s.datapoints.pointsize;
|
|
201
|
+
point = s.datapoints.points.slice(ps * point, ps * (point + 1));
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
var i = indexOfHighlight(s, point);
|
|
205
|
+
if (i === -1) {
|
|
206
|
+
highlights.push({
|
|
207
|
+
series: s,
|
|
208
|
+
point: point,
|
|
209
|
+
auto: auto
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
plot.triggerRedrawOverlay();
|
|
213
|
+
} else if (!auto) {
|
|
214
|
+
highlights[i].auto = false;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
function unhighlight(s, point) {
|
|
219
|
+
if (s == null && point == null) {
|
|
220
|
+
highlights = [];
|
|
221
|
+
plot.triggerRedrawOverlay();
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
if (typeof s === "number") {
|
|
226
|
+
s = plot.getData()[s];
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
if (typeof point === "number") {
|
|
230
|
+
var ps = s.datapoints.pointsize;
|
|
231
|
+
point = s.datapoints.points.slice(ps * point, ps * (point + 1));
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
var i = indexOfHighlight(s, point);
|
|
235
|
+
if (i !== -1) {
|
|
236
|
+
highlights.splice(i, 1);
|
|
237
|
+
|
|
238
|
+
plot.triggerRedrawOverlay();
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
function indexOfHighlight(s, p) {
|
|
243
|
+
for (var i = 0; i < highlights.length; ++i) {
|
|
244
|
+
var h = highlights[i];
|
|
245
|
+
if (h.series === s &&
|
|
246
|
+
h.point[0] === p[0] &&
|
|
247
|
+
h.point[1] === p[1]) {
|
|
248
|
+
return i;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
return -1;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
function processDatapoints() {
|
|
256
|
+
triggerCleanupEvent();
|
|
257
|
+
doTriggerClickHoverEvent(lastMouseMoveEvent, eventType.hover);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
function setupGrid() {
|
|
261
|
+
doTriggerClickHoverEvent(lastMouseMoveEvent, eventType.hover);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
function drawOverlay(plot, octx, overlay) {
|
|
265
|
+
var plotOffset = plot.getPlotOffset(),
|
|
266
|
+
i, hi;
|
|
267
|
+
|
|
268
|
+
octx.save();
|
|
269
|
+
octx.translate(plotOffset.left, plotOffset.top);
|
|
270
|
+
for (i = 0; i < highlights.length; ++i) {
|
|
271
|
+
hi = highlights[i];
|
|
272
|
+
|
|
273
|
+
if (hi.series.bars.show) drawBarHighlight(hi.series, hi.point, octx);
|
|
274
|
+
else drawPointHighlight(hi.series, hi.point, octx, plot);
|
|
275
|
+
}
|
|
276
|
+
octx.restore();
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
function drawPointHighlight(series, point, octx, plot) {
|
|
280
|
+
var x = point[0],
|
|
281
|
+
y = point[1],
|
|
282
|
+
axisx = series.xaxis,
|
|
283
|
+
axisy = series.yaxis,
|
|
284
|
+
highlightColor = (typeof series.highlightColor === "string") ? series.highlightColor : $.color.parse(series.color).scale('a', 0.5).toString();
|
|
285
|
+
|
|
286
|
+
if (x < axisx.min || x > axisx.max || y < axisy.min || y > axisy.max) {
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
var pointRadius = series.points.radius + series.points.lineWidth / 2;
|
|
291
|
+
octx.lineWidth = pointRadius;
|
|
292
|
+
octx.strokeStyle = highlightColor;
|
|
293
|
+
var radius = 1.5 * pointRadius;
|
|
294
|
+
x = axisx.p2c(x);
|
|
295
|
+
y = axisy.p2c(y);
|
|
296
|
+
|
|
297
|
+
octx.beginPath();
|
|
298
|
+
var symbol = series.points.symbol;
|
|
299
|
+
if (symbol === 'circle') {
|
|
300
|
+
octx.arc(x, y, radius, 0, 2 * Math.PI, false);
|
|
301
|
+
} else if (typeof symbol === 'string' && plot.drawSymbol && plot.drawSymbol[symbol]) {
|
|
302
|
+
plot.drawSymbol[symbol](octx, x, y, radius, false);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
octx.closePath();
|
|
306
|
+
octx.stroke();
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
function drawBarHighlight(series, point, octx) {
|
|
310
|
+
var highlightColor = (typeof series.highlightColor === "string") ? series.highlightColor : $.color.parse(series.color).scale('a', 0.5).toString(),
|
|
311
|
+
fillStyle = highlightColor,
|
|
312
|
+
barLeft;
|
|
313
|
+
|
|
314
|
+
var barWidth = series.bars.barWidth[0] || series.bars.barWidth;
|
|
315
|
+
switch (series.bars.align) {
|
|
316
|
+
case "left":
|
|
317
|
+
barLeft = 0;
|
|
318
|
+
break;
|
|
319
|
+
case "right":
|
|
320
|
+
barLeft = -barWidth;
|
|
321
|
+
break;
|
|
322
|
+
default:
|
|
323
|
+
barLeft = -barWidth / 2;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
octx.lineWidth = series.bars.lineWidth;
|
|
327
|
+
octx.strokeStyle = highlightColor;
|
|
328
|
+
|
|
329
|
+
var fillTowards = series.bars.fillTowards || 0,
|
|
330
|
+
bottom = fillTowards > series.yaxis.min ? Math.min(series.yaxis.max, fillTowards) : series.yaxis.min;
|
|
331
|
+
|
|
332
|
+
$.plot.drawSeries.drawBar(point[0], point[1], point[2] || bottom, barLeft, barLeft + barWidth,
|
|
333
|
+
function() {
|
|
334
|
+
return fillStyle;
|
|
335
|
+
}, series.xaxis, series.yaxis, octx, series.bars.horizontal, series.bars.lineWidth);
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
function initHover(plot, options) {
|
|
339
|
+
plot.highlight = highlight;
|
|
340
|
+
plot.unhighlight = unhighlight;
|
|
341
|
+
if (options.grid.hoverable || options.grid.clickable) {
|
|
342
|
+
plot.hooks.drawOverlay.push(drawOverlay);
|
|
343
|
+
plot.hooks.processDatapoints.push(processDatapoints);
|
|
344
|
+
plot.hooks.setupGrid.push(setupGrid);
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
lastMouseMoveEvent = plot.getPlaceholder()[0].lastMouseMoveEvent;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
plot.hooks.bindEvents.push(bindEvents);
|
|
351
|
+
plot.hooks.shutdown.push(shutdown);
|
|
352
|
+
plot.hooks.processOptions.push(initHover);
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
$.plot.plugins.push({
|
|
356
|
+
init: init,
|
|
357
|
+
options: options,
|
|
358
|
+
name: 'hover',
|
|
359
|
+
version: '0.1'
|
|
360
|
+
});
|
|
361
|
+
})(jQuery);
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
/* Flot plugin for plotting images.
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2007-2014 IOLA and Ole Laursen.
|
|
4
|
+
Licensed under the MIT license.
|
|
5
|
+
|
|
6
|
+
The data syntax is [ [ image, x1, y1, x2, y2 ], ... ] where (x1, y1) and
|
|
7
|
+
(x2, y2) are where you intend the two opposite corners of the image to end up
|
|
8
|
+
in the plot. Image must be a fully loaded Javascript image (you can make one
|
|
9
|
+
with new Image()). If the image is not complete, it's skipped when plotting.
|
|
10
|
+
|
|
11
|
+
There are two helpers included for retrieving images. The easiest work the way
|
|
12
|
+
that you put in URLs instead of images in the data, like this:
|
|
13
|
+
|
|
14
|
+
[ "myimage.png", 0, 0, 10, 10 ]
|
|
15
|
+
|
|
16
|
+
Then call $.plot.image.loadData( data, options, callback ) where data and
|
|
17
|
+
options are the same as you pass in to $.plot. This loads the images, replaces
|
|
18
|
+
the URLs in the data with the corresponding images and calls "callback" when
|
|
19
|
+
all images are loaded (or failed loading). In the callback, you can then call
|
|
20
|
+
$.plot with the data set. See the included example.
|
|
21
|
+
|
|
22
|
+
A more low-level helper, $.plot.image.load(urls, callback) is also included.
|
|
23
|
+
Given a list of URLs, it calls callback with an object mapping from URL to
|
|
24
|
+
Image object when all images are loaded or have failed loading.
|
|
25
|
+
|
|
26
|
+
The plugin supports these options:
|
|
27
|
+
|
|
28
|
+
series: {
|
|
29
|
+
images: {
|
|
30
|
+
show: boolean
|
|
31
|
+
anchor: "corner" or "center"
|
|
32
|
+
alpha: [ 0, 1 ]
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
They can be specified for a specific series:
|
|
37
|
+
|
|
38
|
+
$.plot( $("#placeholder"), [{
|
|
39
|
+
data: [ ... ],
|
|
40
|
+
images: { ... }
|
|
41
|
+
])
|
|
42
|
+
|
|
43
|
+
Note that because the data format is different from usual data points, you
|
|
44
|
+
can't use images with anything else in a specific data series.
|
|
45
|
+
|
|
46
|
+
Setting "anchor" to "center" causes the pixels in the image to be anchored at
|
|
47
|
+
the corner pixel centers inside of at the pixel corners, effectively letting
|
|
48
|
+
half a pixel stick out to each side in the plot.
|
|
49
|
+
|
|
50
|
+
A possible future direction could be support for tiling for large images (like
|
|
51
|
+
Google Maps).
|
|
52
|
+
|
|
53
|
+
*/
|
|
54
|
+
|
|
55
|
+
(function ($) {
|
|
56
|
+
var options = {
|
|
57
|
+
series: {
|
|
58
|
+
images: {
|
|
59
|
+
show: false,
|
|
60
|
+
alpha: 1,
|
|
61
|
+
anchor: "corner" // or "center"
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
$.plot.image = {};
|
|
67
|
+
|
|
68
|
+
$.plot.image.loadDataImages = function (series, options, callback) {
|
|
69
|
+
var urls = [], points = [];
|
|
70
|
+
|
|
71
|
+
var defaultShow = options.series.images.show;
|
|
72
|
+
|
|
73
|
+
$.each(series, function (i, s) {
|
|
74
|
+
if (!(defaultShow || s.images.show)) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (s.data) {
|
|
79
|
+
s = s.data;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
$.each(s, function (i, p) {
|
|
83
|
+
if (typeof p[0] === "string") {
|
|
84
|
+
urls.push(p[0]);
|
|
85
|
+
points.push(p);
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
$.plot.image.load(urls, function (loadedImages) {
|
|
91
|
+
$.each(points, function (i, p) {
|
|
92
|
+
var url = p[0];
|
|
93
|
+
if (loadedImages[url]) {
|
|
94
|
+
p[0] = loadedImages[url];
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
callback();
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
$.plot.image.load = function (urls, callback) {
|
|
103
|
+
var missing = urls.length, loaded = {};
|
|
104
|
+
if (missing === 0) {
|
|
105
|
+
callback({});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
$.each(urls, function (i, url) {
|
|
109
|
+
var handler = function () {
|
|
110
|
+
--missing;
|
|
111
|
+
loaded[url] = this;
|
|
112
|
+
|
|
113
|
+
if (missing === 0) {
|
|
114
|
+
callback(loaded);
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
$('<img />').load(handler).error(handler).attr('src', url);
|
|
119
|
+
});
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
function drawSeries(plot, ctx, series) {
|
|
123
|
+
var plotOffset = plot.getPlotOffset();
|
|
124
|
+
|
|
125
|
+
if (!series.images || !series.images.show) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
var points = series.datapoints.points,
|
|
130
|
+
ps = series.datapoints.pointsize;
|
|
131
|
+
|
|
132
|
+
for (var i = 0; i < points.length; i += ps) {
|
|
133
|
+
var img = points[i],
|
|
134
|
+
x1 = points[i + 1], y1 = points[i + 2],
|
|
135
|
+
x2 = points[i + 3], y2 = points[i + 4],
|
|
136
|
+
xaxis = series.xaxis, yaxis = series.yaxis,
|
|
137
|
+
tmp;
|
|
138
|
+
|
|
139
|
+
// actually we should check img.complete, but it
|
|
140
|
+
// appears to be a somewhat unreliable indicator in
|
|
141
|
+
// IE6 (false even after load event)
|
|
142
|
+
if (!img || img.width <= 0 || img.height <= 0) {
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (x1 > x2) {
|
|
147
|
+
tmp = x2;
|
|
148
|
+
x2 = x1;
|
|
149
|
+
x1 = tmp;
|
|
150
|
+
}
|
|
151
|
+
if (y1 > y2) {
|
|
152
|
+
tmp = y2;
|
|
153
|
+
y2 = y1;
|
|
154
|
+
y1 = tmp;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// if the anchor is at the center of the pixel, expand the
|
|
158
|
+
// image by 1/2 pixel in each direction
|
|
159
|
+
if (series.images.anchor === "center") {
|
|
160
|
+
tmp = 0.5 * (x2 - x1) / (img.width - 1);
|
|
161
|
+
x1 -= tmp;
|
|
162
|
+
x2 += tmp;
|
|
163
|
+
tmp = 0.5 * (y2 - y1) / (img.height - 1);
|
|
164
|
+
y1 -= tmp;
|
|
165
|
+
y2 += tmp;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// clip
|
|
169
|
+
if (x1 === x2 || y1 === y2 ||
|
|
170
|
+
x1 >= xaxis.max || x2 <= xaxis.min ||
|
|
171
|
+
y1 >= yaxis.max || y2 <= yaxis.min) {
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
var sx1 = 0, sy1 = 0, sx2 = img.width, sy2 = img.height;
|
|
176
|
+
if (x1 < xaxis.min) {
|
|
177
|
+
sx1 += (sx2 - sx1) * (xaxis.min - x1) / (x2 - x1);
|
|
178
|
+
x1 = xaxis.min;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
if (x2 > xaxis.max) {
|
|
182
|
+
sx2 += (sx2 - sx1) * (xaxis.max - x2) / (x2 - x1);
|
|
183
|
+
x2 = xaxis.max;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
if (y1 < yaxis.min) {
|
|
187
|
+
sy2 += (sy1 - sy2) * (yaxis.min - y1) / (y2 - y1);
|
|
188
|
+
y1 = yaxis.min;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
if (y2 > yaxis.max) {
|
|
192
|
+
sy1 += (sy1 - sy2) * (yaxis.max - y2) / (y2 - y1);
|
|
193
|
+
y2 = yaxis.max;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
x1 = xaxis.p2c(x1);
|
|
197
|
+
x2 = xaxis.p2c(x2);
|
|
198
|
+
y1 = yaxis.p2c(y1);
|
|
199
|
+
y2 = yaxis.p2c(y2);
|
|
200
|
+
|
|
201
|
+
// the transformation may have swapped us
|
|
202
|
+
if (x1 > x2) {
|
|
203
|
+
tmp = x2;
|
|
204
|
+
x2 = x1;
|
|
205
|
+
x1 = tmp;
|
|
206
|
+
}
|
|
207
|
+
if (y1 > y2) {
|
|
208
|
+
tmp = y2;
|
|
209
|
+
y2 = y1;
|
|
210
|
+
y1 = tmp;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
tmp = ctx.globalAlpha;
|
|
214
|
+
ctx.globalAlpha *= series.images.alpha;
|
|
215
|
+
ctx.drawImage(img,
|
|
216
|
+
sx1, sy1, sx2 - sx1, sy2 - sy1,
|
|
217
|
+
x1 + plotOffset.left, y1 + plotOffset.top,
|
|
218
|
+
x2 - x1, y2 - y1);
|
|
219
|
+
ctx.globalAlpha = tmp;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
function processRawData(plot, series, data, datapoints) {
|
|
224
|
+
if (!series.images.show) {
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// format is Image, x1, y1, x2, y2 (opposite corners)
|
|
229
|
+
datapoints.format = [
|
|
230
|
+
{ required: true },
|
|
231
|
+
{ x: true, number: true, required: true },
|
|
232
|
+
{ y: true, number: true, required: true },
|
|
233
|
+
{ x: true, number: true, required: true },
|
|
234
|
+
{ y: true, number: true, required: true }
|
|
235
|
+
];
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function init(plot) {
|
|
239
|
+
plot.hooks.processRawData.push(processRawData);
|
|
240
|
+
plot.hooks.drawSeries.push(drawSeries);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
$.plot.plugins.push({
|
|
244
|
+
init: init,
|
|
245
|
+
options: options,
|
|
246
|
+
name: 'image',
|
|
247
|
+
version: '1.1'
|
|
248
|
+
});
|
|
249
|
+
})(jQuery);
|