iobroker.ebus 3.0.2 → 3.0.3

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.
@@ -1,469 +0,0 @@
1
- /*
2
- Axis Labels Plugin for flot.
3
- http://github.com/markrcote/flot-axislabels
4
-
5
- Original code is Copyright (c) 2010 Xuan Luo.
6
- Original code was released under the GPLv3 license by Xuan Luo, September 2010.
7
- Original code was rereleased under the MIT license by Xuan Luo, April 2012.
8
-
9
- Permission is hereby granted, free of charge, to any person obtaining
10
- a copy of this software and associated documentation files (the
11
- "Software"), to deal in the Software without restriction, including
12
- without limitation the rights to use, copy, modify, merge, publish,
13
- distribute, sublicense, and/or sell copies of the Software, and to
14
- permit persons to whom the Software is furnished to do so, subject to
15
- the following conditions:
16
-
17
- The above copyright notice and this permission notice shall be
18
- included in all copies or substantial portions of the Software.
19
-
20
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
- */
28
-
29
- (function ($) {
30
- var options = {
31
- axisLabels: {
32
- show: true
33
- }
34
- };
35
-
36
- function canvasSupported() {
37
- return !!document.createElement('canvas').getContext;
38
- }
39
-
40
- function canvasTextSupported() {
41
- if (!canvasSupported()) {
42
- return false;
43
- }
44
- var dummy_canvas = document.createElement('canvas');
45
- var context = dummy_canvas.getContext('2d');
46
- return typeof context.fillText == 'function';
47
- }
48
-
49
- function css3TransitionSupported() {
50
- var div = document.createElement('div');
51
- return typeof div.style.MozTransition != 'undefined' // Gecko
52
- || typeof div.style.OTransition != 'undefined' // Opera
53
- || typeof div.style.webkitTransition != 'undefined' // WebKit
54
- || typeof div.style.transition != 'undefined';
55
- }
56
-
57
-
58
- function AxisLabel(axisName, position, padding, plot, opts) {
59
- this.axisName = axisName;
60
- this.position = position;
61
- this.padding = padding;
62
- this.plot = plot;
63
- this.opts = opts;
64
- this.width = 0;
65
- this.height = 0;
66
- }
67
-
68
- AxisLabel.prototype.cleanup = function() {
69
- };
70
-
71
-
72
- CanvasAxisLabel.prototype = new AxisLabel();
73
- CanvasAxisLabel.prototype.constructor = CanvasAxisLabel;
74
- function CanvasAxisLabel(axisName, position, padding, plot, opts) {
75
- AxisLabel.prototype.constructor.call(this, axisName, position, padding,
76
- plot, opts);
77
- }
78
-
79
- CanvasAxisLabel.prototype.calculateSize = function() {
80
- if (!this.opts.axisLabelFontSizePixels)
81
- this.opts.axisLabelFontSizePixels = 14;
82
- if (!this.opts.axisLabelFontFamily)
83
- this.opts.axisLabelFontFamily = 'sans-serif';
84
-
85
- var textWidth = this.opts.axisLabelFontSizePixels + this.padding;
86
- var textHeight = this.opts.axisLabelFontSizePixels + this.padding;
87
- if (this.position == 'left' || this.position == 'right') {
88
- this.width = this.opts.axisLabelFontSizePixels + this.padding;
89
- this.height = 0;
90
- } else {
91
- this.width = 0;
92
- this.height = this.opts.axisLabelFontSizePixels + this.padding;
93
- }
94
- };
95
-
96
- CanvasAxisLabel.prototype.draw = function(box) {
97
- if (!this.opts.axisLabelColour)
98
- this.opts.axisLabelColour = 'black';
99
- var ctx = this.plot.getCanvas().getContext('2d');
100
- ctx.save();
101
- ctx.font = this.opts.axisLabelFontSizePixels + 'px ' +
102
- this.opts.axisLabelFontFamily;
103
-
104
- console.log("CanvasAxisLabel.prototype.draw");
105
-
106
- ctx.fillStyle = this.opts.axisLabelColour;
107
- var width = ctx.measureText(this.opts.axisLabel).width;
108
- var height = this.opts.axisLabelFontSizePixels;
109
- var x, y, angle = 0;
110
- if (this.position == 'top') {
111
- x = box.left + box.width/2 - width/2;
112
- y = box.top + height*0.72;
113
- } else if (this.position == 'bottom') {
114
- x = box.left + box.width/2 - width/2;
115
- y = box.top + box.height - height*0.72;
116
- } else if (this.position == 'left') {
117
- x = box.left + height*0.72;
118
- y = box.height/2 + box.top + width/2;
119
- angle = -Math.PI/2;
120
- } else if (this.position == 'right') {
121
- x = box.left + box.width - height*0.72;
122
- y = box.height/2 + box.top - width/2;
123
- angle = Math.PI/2;
124
- }
125
- ctx.translate(x, y);
126
- ctx.rotate(angle);
127
- ctx.fillText(this.opts.axisLabel, 0, 0);
128
- ctx.restore();
129
- };
130
-
131
-
132
- HtmlAxisLabel.prototype = new AxisLabel();
133
- HtmlAxisLabel.prototype.constructor = HtmlAxisLabel;
134
- function HtmlAxisLabel(axisName, position, padding, plot, opts) {
135
- AxisLabel.prototype.constructor.call(this, axisName, position,
136
- padding, plot, opts);
137
- this.elem = null;
138
- }
139
-
140
- HtmlAxisLabel.prototype.calculateSize = function() {
141
- var elem = $('<div class="axisLabels" style="position:absolute;">' +
142
- this.opts.axisLabel + '</div>');
143
- this.plot.getPlaceholder().append(elem);
144
- // store height and width of label itself, for use in draw()
145
- this.labelWidth = elem.outerWidth(true);
146
- this.labelHeight = elem.outerHeight(true);
147
- elem.remove();
148
-
149
- this.width = this.height = 0;
150
- if (this.position == 'left' || this.position == 'right') {
151
- this.width = this.labelWidth + this.padding;
152
- } else {
153
- this.height = this.labelHeight + this.padding;
154
- }
155
- };
156
-
157
- HtmlAxisLabel.prototype.cleanup = function() {
158
- if (this.elem) {
159
- this.elem.remove();
160
- }
161
- };
162
-
163
- HtmlAxisLabel.prototype.draw = function(box) {
164
- this.plot.getPlaceholder().find('#' + this.axisName + 'Label').remove();
165
- this.elem = $('<div id="' + this.axisName +
166
- 'Label" " class="axisLabels" style="position:absolute;">'
167
- + this.opts.axisLabel + '</div>');
168
- this.plot.getPlaceholder().append(this.elem);
169
- if (this.position == 'top') {
170
- this.elem.css('left', box.left + box.width/2 - this.labelWidth/2 +
171
- 'px');
172
- this.elem.css('top', box.top + 'px');
173
- } else if (this.position == 'bottom') {
174
- this.elem.css('left', box.left + box.width/2 - this.labelWidth/2 +
175
- 'px');
176
- this.elem.css('top', box.top + box.height - this.labelHeight +
177
- 'px');
178
- } else if (this.position == 'left') {
179
- this.elem.css('top', box.top + box.height/2 - this.labelHeight/2 +
180
- 'px');
181
- this.elem.css('left', box.left + 'px');
182
- } else if (this.position == 'right') {
183
- this.elem.css('top', box.top + box.height/2 - this.labelHeight/2 +
184
- 'px');
185
- this.elem.css('left', box.left + box.width - this.labelWidth +
186
- 'px');
187
- }
188
- };
189
-
190
-
191
- CssTransformAxisLabel.prototype = new HtmlAxisLabel();
192
- CssTransformAxisLabel.prototype.constructor = CssTransformAxisLabel;
193
- function CssTransformAxisLabel(axisName, position, padding, plot, opts) {
194
- HtmlAxisLabel.prototype.constructor.call(this, axisName, position,
195
- padding, plot, opts);
196
- }
197
-
198
- CssTransformAxisLabel.prototype.calculateSize = function() {
199
- HtmlAxisLabel.prototype.calculateSize.call(this);
200
- this.width = this.height = 0;
201
- if (this.position == 'left' || this.position == 'right') {
202
- this.width = this.labelHeight + this.padding;
203
- } else {
204
- this.height = this.labelHeight + this.padding;
205
- }
206
- };
207
-
208
- CssTransformAxisLabel.prototype.transforms = function(degrees, x, y) {
209
- var stransforms = {
210
- '-moz-transform': '',
211
- '-webkit-transform': '',
212
- '-o-transform': '',
213
- '-ms-transform': ''
214
- };
215
- if (x != 0 || y != 0) {
216
- var stdTranslate = ' translate(' + x + 'px, ' + y + 'px)';
217
- stransforms['-moz-transform'] += stdTranslate;
218
- stransforms['-webkit-transform'] += stdTranslate;
219
- stransforms['-o-transform'] += stdTranslate;
220
- stransforms['-ms-transform'] += stdTranslate;
221
- }
222
- if (degrees != 0) {
223
- var rotation = degrees / 90;
224
- var stdRotate = ' rotate(' + degrees + 'deg)';
225
- stransforms['-moz-transform'] += stdRotate;
226
- stransforms['-webkit-transform'] += stdRotate;
227
- stransforms['-o-transform'] += stdRotate;
228
- stransforms['-ms-transform'] += stdRotate;
229
- }
230
- var s = 'top: 0; left: 0; ';
231
- for (var prop in stransforms) {
232
- if (stransforms[prop]) {
233
- s += prop + ':' + stransforms[prop] + ';';
234
- }
235
- }
236
- s += ';';
237
- return s;
238
- };
239
-
240
- CssTransformAxisLabel.prototype.calculateOffsets = function(box) {
241
- var offsets = { x: 0, y: 0, degrees: 0 };
242
- if (this.position == 'bottom') {
243
- offsets.x = box.left + box.width/2 - this.labelWidth/2;
244
- offsets.y = box.top + box.height - this.labelHeight;
245
- } else if (this.position == 'top') {
246
- offsets.x = box.left + box.width/2 - this.labelWidth/2;
247
- offsets.y = box.top;
248
- } else if (this.position == 'left') {
249
- offsets.degrees = -90;
250
- offsets.x = box.left - this.labelWidth/2 + this.labelHeight/2;
251
- offsets.y = box.height/2 + box.top;
252
- } else if (this.position == 'right') {
253
- offsets.degrees = 90;
254
- offsets.x = box.left + box.width - this.labelWidth/2
255
- - this.labelHeight/2;
256
- offsets.y = box.height/2 + box.top;
257
- }
258
- offsets.x = Math.round(offsets.x);
259
- offsets.y = Math.round(offsets.y);
260
-
261
- return offsets;
262
- };
263
-
264
- CssTransformAxisLabel.prototype.draw = function(box) {
265
- this.plot.getPlaceholder().find("." + this.axisName + "Label").remove();
266
- var offsets = this.calculateOffsets(box);
267
- this.elem = $('<div class="axisLabels ' + this.axisName +
268
- 'Label" style="position:absolute; ' +
269
- this.transforms(offsets.degrees, offsets.x, offsets.y) +
270
- '">' + this.opts.axisLabel + '</div>');
271
- this.plot.getPlaceholder().append(this.elem);
272
- };
273
-
274
-
275
- IeTransformAxisLabel.prototype = new CssTransformAxisLabel();
276
- IeTransformAxisLabel.prototype.constructor = IeTransformAxisLabel;
277
- function IeTransformAxisLabel(axisName, position, padding, plot, opts) {
278
- CssTransformAxisLabel.prototype.constructor.call(this, axisName,
279
- position, padding,
280
- plot, opts);
281
- this.requiresResize = false;
282
- }
283
-
284
- IeTransformAxisLabel.prototype.transforms = function(degrees, x, y) {
285
- // I didn't feel like learning the crazy Matrix stuff, so this uses
286
- // a combination of the rotation transform and CSS positioning.
287
- var s = '';
288
- if (degrees != 0) {
289
- var rotation = degrees/90;
290
- while (rotation < 0) {
291
- rotation += 4;
292
- }
293
- s += ' filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=' + rotation + '); ';
294
- // see below
295
- this.requiresResize = (this.position == 'right');
296
- }
297
- if (x != 0) {
298
- s += 'left: ' + x + 'px; ';
299
- }
300
- if (y != 0) {
301
- s += 'top: ' + y + 'px; ';
302
- }
303
- return s;
304
- };
305
-
306
- IeTransformAxisLabel.prototype.calculateOffsets = function(box) {
307
- var offsets = CssTransformAxisLabel.prototype.calculateOffsets.call(
308
- this, box);
309
- // adjust some values to take into account differences between
310
- // CSS and IE rotations.
311
- if (this.position == 'top') {
312
- // FIXME: not sure why, but placing this exactly at the top causes
313
- // the top axis label to flip to the bottom...
314
- offsets.y = box.top + 1;
315
- } else if (this.position == 'left') {
316
- offsets.x = box.left;
317
- offsets.y = box.height/2 + box.top - this.labelWidth/2;
318
- } else if (this.position == 'right') {
319
- offsets.x = box.left + box.width - this.labelHeight;
320
- offsets.y = box.height/2 + box.top - this.labelWidth/2;
321
- }
322
- return offsets;
323
- };
324
-
325
- IeTransformAxisLabel.prototype.draw = function(box) {
326
- CssTransformAxisLabel.prototype.draw.call(this, box);
327
- if (this.requiresResize) {
328
- this.elem = this.plot.getPlaceholder().find("." + this.axisName +
329
- "Label");
330
- // Since we used CSS positioning instead of transforms for
331
- // translating the element, and since the positioning is done
332
- // before any rotations, we have to reset the width and height
333
- // in case the browser wrapped the text (specifically for the
334
- // y2axis).
335
- this.elem.css('width', this.labelWidth);
336
- this.elem.css('height', this.labelHeight);
337
- }
338
- };
339
-
340
-
341
- function init(plot) {
342
- plot.hooks.processOptions.push(function (plot, options) {
343
-
344
- if (!options.axisLabels.show)
345
- return;
346
-
347
- // This is kind of a hack. There are no hooks in Flot between
348
- // the creation and measuring of the ticks (setTicks, measureTickLabels
349
- // in setupGrid() ) and the drawing of the ticks and plot box
350
- // (insertAxisLabels in setupGrid() ).
351
- //
352
- // Therefore, we use a trick where we run the draw routine twice:
353
- // the first time to get the tick measurements, so that we can change
354
- // them, and then have it draw it again.
355
- var secondPass = false;
356
-
357
- var axisLabels = {};
358
- var axisOffsetCounts = { left: 0, right: 0, top: 0, bottom: 0 };
359
-
360
- var defaultPadding = 2; // padding between axis and tick labels
361
- plot.hooks.draw.push(function (plot, ctx) {
362
- var hasAxisLabels = false;
363
- if (!secondPass) {
364
- // MEASURE AND SET OPTIONS
365
- $.each(plot.getAxes(), function(axisName, axis) {
366
- var opts = axis.options // Flot 0.7
367
- || plot.getOptions()[axisName]; // Flot 0.6
368
-
369
- // Handle redraws initiated outside of this plug-in.
370
- if (axisName in axisLabels) {
371
- axis.labelHeight = axis.labelHeight -
372
- axisLabels[axisName].height;
373
- axis.labelWidth = axis.labelWidth -
374
- axisLabels[axisName].width;
375
- opts.labelHeight = axis.labelHeight;
376
- opts.labelWidth = axis.labelWidth;
377
- axisLabels[axisName].cleanup();
378
- delete axisLabels[axisName];
379
- }
380
-
381
- if (!opts || !opts.axisLabel || !axis.show)
382
- return;
383
-
384
- hasAxisLabels = true;
385
- var renderer = null;
386
-
387
- if (!opts.axisLabelUseHtml &&
388
- navigator.appName == 'Microsoft Internet Explorer') {
389
- var ua = navigator.userAgent;
390
- var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
391
- if (re.exec(ua) != null) {
392
- rv = parseFloat(RegExp.$1);
393
- }
394
- if (rv >= 9 && !opts.axisLabelUseCanvas && !opts.axisLabelUseHtml) {
395
- renderer = CssTransformAxisLabel;
396
- } else if (!opts.axisLabelUseCanvas && !opts.axisLabelUseHtml) {
397
- renderer = IeTransformAxisLabel;
398
- } else if (opts.axisLabelUseCanvas) {
399
- renderer = CanvasAxisLabel;
400
- } else {
401
- renderer = HtmlAxisLabel;
402
- }
403
- } else {
404
- if (opts.axisLabelUseHtml || (!css3TransitionSupported() && !canvasTextSupported()) && !opts.axisLabelUseCanvas) {
405
- renderer = HtmlAxisLabel;
406
- } else if (opts.axisLabelUseCanvas || !css3TransitionSupported()) {
407
- renderer = CanvasAxisLabel;
408
- } else {
409
- renderer = CssTransformAxisLabel;
410
- }
411
- }
412
-
413
- var padding = opts.axisLabelPadding === undefined ?
414
- defaultPadding : opts.axisLabelPadding;
415
-
416
- axisLabels[axisName] = new renderer(axisName,
417
- axis.position, padding,
418
- plot, opts);
419
-
420
- // flot interprets axis.labelHeight and .labelWidth as
421
- // the height and width of the tick labels. We increase
422
- // these values to make room for the axis label and
423
- // padding.
424
-
425
- axisLabels[axisName].calculateSize();
426
-
427
- // AxisLabel.height and .width are the size of the
428
- // axis label and padding.
429
- // Just set opts here because axis will be sorted out on
430
- // the redraw.
431
-
432
- opts.labelHeight = axis.labelHeight +
433
- axisLabels[axisName].height;
434
- opts.labelWidth = axis.labelWidth +
435
- axisLabels[axisName].width;
436
- });
437
-
438
- // If there are axis labels, re-draw with new label widths and
439
- // heights.
440
-
441
- if (hasAxisLabels) {
442
- secondPass = true;
443
- plot.setupGrid();
444
- plot.draw();
445
- }
446
- } else {
447
- secondPass = false;
448
- // DRAW
449
- $.each(plot.getAxes(), function(axisName, axis) {
450
- var opts = axis.options // Flot 0.7
451
- || plot.getOptions()[axisName]; // Flot 0.6
452
- if (!opts || !opts.axisLabel || !axis.show)
453
- return;
454
-
455
- axisLabels[axisName].draw(axis.box);
456
- });
457
- }
458
- });
459
- });
460
- }
461
-
462
-
463
- $.plot.plugins.push({
464
- init: init,
465
- options: options,
466
- name: 'axisLabels',
467
- version: '2.0'
468
- });
469
- })(jQuery);
@@ -1,221 +0,0 @@
1
- /*
2
- Axis label plugin for flot
3
-
4
- Derived from:
5
- Axis Labels Plugin for flot.
6
- http://github.com/markrcote/flot-axislabels
7
-
8
- Original code is Copyright (c) 2010 Xuan Luo.
9
- Original code was released under the GPLv3 license by Xuan Luo, September 2010.
10
- Original code was rereleased under the MIT license by Xuan Luo, April 2012.
11
-
12
- Permission is hereby granted, free of charge, to any person obtaining
13
- a copy of this software and associated documentation files (the
14
- "Software"), to deal in the Software without restriction, including
15
- without limitation the rights to use, copy, modify, merge, publish,
16
- distribute, sublicense, and/or sell copies of the Software, and to
17
- permit persons to whom the Software is furnished to do so, subject to
18
- the following conditions:
19
-
20
- The above copyright notice and this permission notice shall be
21
- included in all copies or substantial portions of the Software.
22
-
23
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30
- */
31
-
32
- (function($) {
33
- "use strict";
34
-
35
- var options = {
36
- axisLabels: {
37
- show: true
38
- }
39
- };
40
-
41
- function AxisLabel(axisName, position, padding, placeholder, axisLabel, surface) {
42
- this.axisName = axisName;
43
- this.position = position;
44
- this.padding = padding;
45
- this.placeholder = placeholder;
46
- this.axisLabel = axisLabel;
47
- this.surface = surface;
48
- this.width = 0;
49
- this.height = 0;
50
- this.elem = null;
51
- }
52
-
53
- AxisLabel.prototype.calculateSize = function() {
54
- var axisId = this.axisName + 'Label',
55
- layerId = axisId + 'Layer',
56
- className = axisId + ' axisLabels';
57
-
58
- var info = this.surface.getTextInfo(layerId, this.axisLabel, className);
59
- this.labelWidth = info.width;
60
- this.labelHeight = info.height;
61
-
62
- if (this.position === 'left' || this.position === 'right') {
63
- this.width = this.labelHeight + this.padding;
64
- this.height = 0;
65
- } else {
66
- this.width = 0;
67
- this.height = this.labelHeight + this.padding;
68
- }
69
- };
70
-
71
- AxisLabel.prototype.transforms = function(degrees, x, y, svgLayer) {
72
- var transforms = [], translate, rotate;
73
- if (x !== 0 || y !== 0) {
74
- translate = svgLayer.createSVGTransform();
75
- translate.setTranslate(x, y);
76
- transforms.push(translate);
77
- }
78
- if (degrees !== 0) {
79
- rotate = svgLayer.createSVGTransform();
80
- var centerX = Math.round(this.labelWidth / 2),
81
- centerY = 0;
82
- rotate.setRotate(degrees, centerX, centerY);
83
- transforms.push(rotate);
84
- }
85
-
86
- return transforms;
87
- };
88
-
89
- AxisLabel.prototype.calculateOffsets = function(box) {
90
- var offsets = {
91
- x: 0,
92
- y: 0,
93
- degrees: 0
94
- };
95
- if (this.position === 'bottom') {
96
- offsets.x = box.left + box.width / 2 - this.labelWidth / 2;
97
- offsets.y = box.top + box.height - this.labelHeight;
98
- } else if (this.position === 'top') {
99
- offsets.x = box.left + box.width / 2 - this.labelWidth / 2;
100
- offsets.y = box.top;
101
- } else if (this.position === 'left') {
102
- offsets.degrees = -90;
103
- offsets.x = box.left - this.labelWidth / 2;
104
- offsets.y = box.height / 2 + box.top;
105
- } else if (this.position === 'right') {
106
- offsets.degrees = 90;
107
- offsets.x = box.left + box.width - this.labelWidth / 2;
108
- offsets.y = box.height / 2 + box.top;
109
- }
110
- offsets.x = Math.round(offsets.x);
111
- offsets.y = Math.round(offsets.y);
112
-
113
- return offsets;
114
- };
115
-
116
- AxisLabel.prototype.cleanup = function() {
117
- var axisId = this.axisName + 'Label',
118
- layerId = axisId + 'Layer',
119
- className = axisId + ' axisLabels';
120
- this.surface.removeText(layerId, 0, 0, this.axisLabel, className);
121
- };
122
-
123
- AxisLabel.prototype.draw = function(box) {
124
- var axisId = this.axisName + 'Label',
125
- layerId = axisId + 'Layer',
126
- className = axisId + ' axisLabels',
127
- offsets = this.calculateOffsets(box),
128
- style = {
129
- position: 'absolute',
130
- bottom: '',
131
- right: '',
132
- display: 'inline-block',
133
- 'white-space': 'nowrap'
134
- };
135
-
136
- var layer = this.surface.getSVGLayer(layerId);
137
- var transforms = this.transforms(offsets.degrees, offsets.x, offsets.y, layer.parentNode);
138
-
139
- //console.log('###');
140
-
141
- /*
142
- var ctx = this.surface.context;
143
- ctx.fillStyle = "red";
144
- ctx.textAlign = "center";
145
- ctx.font = "30px Arial";
146
- ctx.fillText("Hello World", 10, 50);
147
- */
148
- this.surface.addText(layerId, 0, 0, this.axisLabel, className, undefined, undefined, undefined, undefined, transforms);
149
- this.surface.render();
150
- Object.keys(style).forEach(function(key) {
151
- layer.style[key] = style[key];
152
- });
153
- };
154
-
155
- function init(plot) {
156
- plot.hooks.processOptions.push(function(plot, options) {
157
- if (!options.axisLabels.show) {
158
- return;
159
- }
160
-
161
- var axisLabels = {};
162
- var defaultPadding = 2; // padding between axis and tick labels
163
-
164
- plot.hooks.axisReserveSpace.push(function(plot, axis) {
165
- var opts = axis.options;
166
- var axisName = axis.direction + axis.n;
167
-
168
- axis.labelHeight += axis.boxPosition.centerY;
169
- axis.labelWidth += axis.boxPosition.centerX;
170
-
171
- if (!opts || !opts.axisLabel || !axis.show) {
172
- return;
173
- }
174
-
175
- var padding = opts.axisLabelPadding === undefined
176
- ? defaultPadding
177
- : opts.axisLabelPadding;
178
-
179
- var axisLabel = axisLabels[axisName];
180
- if (!axisLabel) {
181
- axisLabel = new AxisLabel(axisName,
182
- opts.position, padding,
183
- plot.getPlaceholder()[0], opts.axisLabel, plot.getSurface());
184
- axisLabels[axisName] = axisLabel;
185
- }
186
-
187
- axisLabel.calculateSize();
188
-
189
- // Incrementing the sizes of the tick labels.
190
- axis.labelHeight += axisLabel.height;
191
- axis.labelWidth += axisLabel.width;
192
- });
193
-
194
- // TODO - use the drawAxis hook
195
- plot.hooks.draw.push(function(plot, ctx) {
196
- $.each(plot.getAxes(), function(flotAxisName, axis) {
197
- var opts = axis.options;
198
- if (!opts || !opts.axisLabel || !axis.show) {
199
- return;
200
- }
201
-
202
- var axisName = axis.direction + axis.n;
203
- axisLabels[axisName].draw(axis.box);
204
- });
205
- });
206
-
207
- plot.hooks.shutdown.push(function(plot, eventHolder) {
208
- for (var axisName in axisLabels) {
209
- axisLabels[axisName].cleanup();
210
- }
211
- });
212
- });
213
- };
214
-
215
- $.plot.plugins.push({
216
- init: init,
217
- options: options,
218
- name: 'axisLabels',
219
- version: '3.0'
220
- });
221
- })(jQuery);