gaugejs-rails 0.0.1 → 0.0.2
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.
- checksums.yaml +7 -0
- data/lib/gaugejs-rails/version.rb +1 -1
- data/vendor/assets/javascripts/gauge.coffee +235 -62
- data/vendor/assets/javascripts/gauge.js +434 -95
- data/vendor/assets/javascripts/gauge.min.js +1 -37
- metadata +35 -52
@@ -1,13 +1,9 @@
|
|
1
|
+
// Generated by CoffeeScript 1.6.3
|
1
2
|
(function() {
|
2
|
-
var AnimatedText, AnimatedTextFactory, Bar, Donut, Gauge, GaugePointer, ValueUpdater, addCommas, formatNumber, secondsToString, updateObjectValues
|
3
|
-
|
4
|
-
for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; }
|
5
|
-
|
6
|
-
ctor.prototype = parent.prototype;
|
7
|
-
child.prototype = new ctor;
|
8
|
-
child.__super__ = parent.prototype;
|
9
|
-
return child;
|
10
|
-
};
|
3
|
+
var AnimatedText, AnimatedTextFactory, Bar, BaseDonut, BaseGauge, Donut, Gauge, GaugePointer, TextRenderer, ValueUpdater, addCommas, cutHex, formatNumber, mergeObjects, secondsToString, updateObjectValues, _ref, _ref1,
|
4
|
+
__hasProp = {}.hasOwnProperty,
|
5
|
+
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
6
|
+
|
11
7
|
(function() {
|
12
8
|
var browserRequestAnimationFrame, isCancelled, lastId, vendor, vendors, _i, _len;
|
13
9
|
vendors = ['ms', 'moz', 'webkit', 'o'];
|
@@ -53,19 +49,21 @@
|
|
53
49
|
};
|
54
50
|
}
|
55
51
|
})();
|
52
|
+
|
56
53
|
String.prototype.hashCode = function() {
|
57
|
-
var char, hash, i, _ref;
|
54
|
+
var char, hash, i, _i, _ref;
|
58
55
|
hash = 0;
|
59
56
|
if (this.length === 0) {
|
60
57
|
return hash;
|
61
58
|
}
|
62
|
-
for (i = 0, _ref = this.length; 0 <= _ref ?
|
59
|
+
for (i = _i = 0, _ref = this.length; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) {
|
63
60
|
char = this.charCodeAt(i);
|
64
61
|
hash = ((hash << 5) - hash) + char;
|
65
62
|
hash = hash & hash;
|
66
63
|
}
|
67
64
|
return hash;
|
68
65
|
};
|
66
|
+
|
69
67
|
secondsToString = function(sec) {
|
70
68
|
var hr, min;
|
71
69
|
hr = Math.floor(sec / 3600);
|
@@ -82,19 +80,37 @@
|
|
82
80
|
hr = hr ? hr + ':' : '';
|
83
81
|
return hr + min + ':' + sec;
|
84
82
|
};
|
83
|
+
|
85
84
|
formatNumber = function(num) {
|
86
85
|
return addCommas(num.toFixed(0));
|
87
86
|
};
|
87
|
+
|
88
88
|
updateObjectValues = function(obj1, obj2) {
|
89
|
-
var key, val
|
90
|
-
|
89
|
+
var key, val;
|
90
|
+
for (key in obj2) {
|
91
|
+
if (!__hasProp.call(obj2, key)) continue;
|
92
|
+
val = obj2[key];
|
93
|
+
obj1[key] = val;
|
94
|
+
}
|
95
|
+
return obj1;
|
96
|
+
};
|
97
|
+
|
98
|
+
mergeObjects = function(obj1, obj2) {
|
99
|
+
var key, out, val;
|
100
|
+
out = {};
|
101
|
+
for (key in obj1) {
|
102
|
+
if (!__hasProp.call(obj1, key)) continue;
|
103
|
+
val = obj1[key];
|
104
|
+
out[key] = val;
|
105
|
+
}
|
91
106
|
for (key in obj2) {
|
92
107
|
if (!__hasProp.call(obj2, key)) continue;
|
93
108
|
val = obj2[key];
|
94
|
-
|
109
|
+
out[key] = val;
|
95
110
|
}
|
96
|
-
return
|
111
|
+
return out;
|
97
112
|
};
|
113
|
+
|
98
114
|
addCommas = function(nStr) {
|
99
115
|
var rgx, x, x1, x2;
|
100
116
|
nStr += '';
|
@@ -110,15 +126,34 @@
|
|
110
126
|
}
|
111
127
|
return x1 + x2;
|
112
128
|
};
|
129
|
+
|
130
|
+
cutHex = function(nStr) {
|
131
|
+
if (nStr.charAt(0) === "#") {
|
132
|
+
return nStr.substring(1, 7);
|
133
|
+
}
|
134
|
+
return nStr;
|
135
|
+
};
|
136
|
+
|
113
137
|
ValueUpdater = (function() {
|
114
138
|
ValueUpdater.prototype.animationSpeed = 32;
|
115
|
-
|
116
|
-
|
139
|
+
|
140
|
+
function ValueUpdater(addToAnimationQueue, clear) {
|
141
|
+
if (addToAnimationQueue == null) {
|
142
|
+
addToAnimationQueue = true;
|
143
|
+
}
|
144
|
+
this.clear = clear != null ? clear : true;
|
145
|
+
if (addToAnimationQueue) {
|
146
|
+
AnimationUpdater.add(this);
|
147
|
+
}
|
117
148
|
}
|
118
|
-
|
149
|
+
|
150
|
+
ValueUpdater.prototype.update = function(force) {
|
119
151
|
var diff;
|
120
|
-
if (
|
121
|
-
|
152
|
+
if (force == null) {
|
153
|
+
force = false;
|
154
|
+
}
|
155
|
+
if (force || this.displayedValue !== this.value) {
|
156
|
+
if (this.ctx && this.clear) {
|
122
157
|
this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
|
123
158
|
}
|
124
159
|
diff = this.value - this.displayedValue;
|
@@ -132,15 +167,109 @@
|
|
132
167
|
}
|
133
168
|
return false;
|
134
169
|
};
|
170
|
+
|
135
171
|
return ValueUpdater;
|
172
|
+
|
136
173
|
})();
|
137
|
-
|
138
|
-
|
174
|
+
|
175
|
+
BaseGauge = (function(_super) {
|
176
|
+
__extends(BaseGauge, _super);
|
177
|
+
|
178
|
+
function BaseGauge() {
|
179
|
+
_ref = BaseGauge.__super__.constructor.apply(this, arguments);
|
180
|
+
return _ref;
|
181
|
+
}
|
182
|
+
|
183
|
+
BaseGauge.prototype.displayScale = 1;
|
184
|
+
|
185
|
+
BaseGauge.prototype.setTextField = function(textField) {
|
186
|
+
return this.textField = textField instanceof TextRenderer ? textField : new TextRenderer(textField);
|
187
|
+
};
|
188
|
+
|
189
|
+
BaseGauge.prototype.setMinValue = function(minValue, updateStartValue) {
|
190
|
+
var gauge, _i, _len, _ref1, _results;
|
191
|
+
this.minValue = minValue;
|
192
|
+
if (updateStartValue == null) {
|
193
|
+
updateStartValue = true;
|
194
|
+
}
|
195
|
+
if (updateStartValue) {
|
196
|
+
this.displayedValue = this.minValue;
|
197
|
+
_ref1 = this.gp || [];
|
198
|
+
_results = [];
|
199
|
+
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
|
200
|
+
gauge = _ref1[_i];
|
201
|
+
_results.push(gauge.displayedValue = this.minValue);
|
202
|
+
}
|
203
|
+
return _results;
|
204
|
+
}
|
205
|
+
};
|
206
|
+
|
207
|
+
BaseGauge.prototype.setOptions = function(options) {
|
208
|
+
if (options == null) {
|
209
|
+
options = null;
|
210
|
+
}
|
211
|
+
this.options = mergeObjects(this.options, options);
|
212
|
+
if (this.textField) {
|
213
|
+
this.textField.el.style.fontSize = options.fontSize + 'px';
|
214
|
+
}
|
215
|
+
if (this.options.angle > .5) {
|
216
|
+
this.gauge.options.angle = .5;
|
217
|
+
}
|
218
|
+
this.configDisplayScale();
|
219
|
+
return this;
|
220
|
+
};
|
221
|
+
|
222
|
+
BaseGauge.prototype.configDisplayScale = function() {
|
223
|
+
var backingStorePixelRatio, devicePixelRatio, height, prevDisplayScale, width;
|
224
|
+
prevDisplayScale = this.displayScale;
|
225
|
+
if (this.options.highDpiSupport === false) {
|
226
|
+
delete this.displayScale;
|
227
|
+
} else {
|
228
|
+
devicePixelRatio = window.devicePixelRatio || 1;
|
229
|
+
backingStorePixelRatio = this.ctx.webkitBackingStorePixelRatio || this.ctx.mozBackingStorePixelRatio || this.ctx.msBackingStorePixelRatio || this.ctx.oBackingStorePixelRatio || this.ctx.backingStorePixelRatio || 1;
|
230
|
+
this.displayScale = devicePixelRatio / backingStorePixelRatio;
|
231
|
+
}
|
232
|
+
if (this.displayScale !== prevDisplayScale) {
|
233
|
+
width = this.canvas.G__width || this.canvas.width;
|
234
|
+
height = this.canvas.G__height || this.canvas.height;
|
235
|
+
this.canvas.width = width * this.displayScale;
|
236
|
+
this.canvas.height = height * this.displayScale;
|
237
|
+
this.canvas.style.width = "" + width + "px";
|
238
|
+
this.canvas.style.height = "" + height + "px";
|
239
|
+
this.canvas.G__width = width;
|
240
|
+
this.canvas.G__height = height;
|
241
|
+
}
|
242
|
+
return this;
|
243
|
+
};
|
244
|
+
|
245
|
+
return BaseGauge;
|
246
|
+
|
247
|
+
})(ValueUpdater);
|
248
|
+
|
249
|
+
TextRenderer = (function() {
|
250
|
+
function TextRenderer(el) {
|
251
|
+
this.el = el;
|
252
|
+
}
|
253
|
+
|
254
|
+
TextRenderer.prototype.render = function(gauge) {
|
255
|
+
return this.el.innerHTML = formatNumber(gauge.displayedValue);
|
256
|
+
};
|
257
|
+
|
258
|
+
return TextRenderer;
|
259
|
+
|
260
|
+
})();
|
261
|
+
|
262
|
+
AnimatedText = (function(_super) {
|
263
|
+
__extends(AnimatedText, _super);
|
264
|
+
|
139
265
|
AnimatedText.prototype.displayedValue = 0;
|
266
|
+
|
140
267
|
AnimatedText.prototype.value = 0;
|
268
|
+
|
141
269
|
AnimatedText.prototype.setVal = function(value) {
|
142
270
|
return this.value = 1 * value;
|
143
271
|
};
|
272
|
+
|
144
273
|
function AnimatedText(elem, text) {
|
145
274
|
this.elem = elem;
|
146
275
|
this.text = text != null ? text : false;
|
@@ -149,6 +278,7 @@
|
|
149
278
|
this.value = 0;
|
150
279
|
}
|
151
280
|
}
|
281
|
+
|
152
282
|
AnimatedText.prototype.render = function() {
|
153
283
|
var textVal;
|
154
284
|
if (this.text) {
|
@@ -158,8 +288,11 @@
|
|
158
288
|
}
|
159
289
|
return this.elem.innerHTML = textVal;
|
160
290
|
};
|
291
|
+
|
161
292
|
return AnimatedText;
|
162
|
-
|
293
|
+
|
294
|
+
})(ValueUpdater);
|
295
|
+
|
163
296
|
AnimatedTextFactory = {
|
164
297
|
create: function(objList) {
|
165
298
|
var elem, out, _i, _len;
|
@@ -171,28 +304,44 @@
|
|
171
304
|
return out;
|
172
305
|
}
|
173
306
|
};
|
174
|
-
|
175
|
-
|
176
|
-
GaugePointer
|
307
|
+
|
308
|
+
GaugePointer = (function(_super) {
|
309
|
+
__extends(GaugePointer, _super);
|
310
|
+
|
311
|
+
GaugePointer.prototype.displayedValue = 0;
|
312
|
+
|
313
|
+
GaugePointer.prototype.value = 0;
|
314
|
+
|
177
315
|
GaugePointer.prototype.options = {
|
178
316
|
strokeWidth: 0.035,
|
179
|
-
length: 0.1
|
317
|
+
length: 0.1,
|
318
|
+
color: "#000000"
|
180
319
|
};
|
181
|
-
|
182
|
-
|
183
|
-
this.
|
320
|
+
|
321
|
+
function GaugePointer(gauge) {
|
322
|
+
this.gauge = gauge;
|
323
|
+
this.ctx = this.gauge.ctx;
|
324
|
+
this.canvas = this.gauge.canvas;
|
325
|
+
GaugePointer.__super__.constructor.call(this, false, false);
|
184
326
|
this.setOptions();
|
185
327
|
}
|
328
|
+
|
186
329
|
GaugePointer.prototype.setOptions = function(options) {
|
187
330
|
if (options == null) {
|
188
331
|
options = null;
|
189
332
|
}
|
190
333
|
updateObjectValues(this.options, options);
|
191
334
|
this.length = this.canvas.height * this.options.length;
|
192
|
-
|
335
|
+
this.strokeWidth = this.canvas.height * this.options.strokeWidth;
|
336
|
+
this.maxValue = this.gauge.maxValue;
|
337
|
+
this.minValue = this.gauge.minValue;
|
338
|
+
this.animationSpeed = this.gauge.animationSpeed;
|
339
|
+
return this.options.angle = this.gauge.options.angle;
|
193
340
|
};
|
194
|
-
|
195
|
-
|
341
|
+
|
342
|
+
GaugePointer.prototype.render = function() {
|
343
|
+
var angle, centerX, centerY, endX, endY, startX, startY, x, y;
|
344
|
+
angle = this.gauge.getAngle.call(this, this.displayedValue);
|
196
345
|
centerX = this.canvas.width / 2;
|
197
346
|
centerY = this.canvas.height * 0.9;
|
198
347
|
x = Math.round(centerX + this.length * Math.cos(angle));
|
@@ -201,7 +350,7 @@
|
|
201
350
|
startY = Math.round(centerY + this.strokeWidth * Math.sin(angle - Math.PI / 2));
|
202
351
|
endX = Math.round(centerX + this.strokeWidth * Math.cos(angle + Math.PI / 2));
|
203
352
|
endY = Math.round(centerY + this.strokeWidth * Math.sin(angle + Math.PI / 2));
|
204
|
-
this.ctx.fillStyle =
|
353
|
+
this.ctx.fillStyle = this.options.color;
|
205
354
|
this.ctx.beginPath();
|
206
355
|
this.ctx.arc(centerX, centerY, this.strokeWidth, 0, Math.PI * 2, true);
|
207
356
|
this.ctx.fill();
|
@@ -211,18 +360,23 @@
|
|
211
360
|
this.ctx.lineTo(endX, endY);
|
212
361
|
return this.ctx.fill();
|
213
362
|
};
|
363
|
+
|
214
364
|
return GaugePointer;
|
215
|
-
|
365
|
+
|
366
|
+
})(ValueUpdater);
|
367
|
+
|
216
368
|
Bar = (function() {
|
217
369
|
function Bar(elem) {
|
218
370
|
this.elem = elem;
|
219
371
|
}
|
372
|
+
|
220
373
|
Bar.prototype.updateValues = function(arrValues) {
|
221
374
|
this.value = arrValues[0];
|
222
375
|
this.maxValue = arrValues[1];
|
223
376
|
this.avgValue = arrValues[2];
|
224
377
|
return this.render();
|
225
378
|
};
|
379
|
+
|
226
380
|
Bar.prototype.render = function() {
|
227
381
|
var avgPercent, valPercent;
|
228
382
|
if (this.textField) {
|
@@ -240,20 +394,36 @@
|
|
240
394
|
"width": avgPercent + "%"
|
241
395
|
});
|
242
396
|
};
|
397
|
+
|
243
398
|
return Bar;
|
399
|
+
|
244
400
|
})();
|
245
|
-
|
246
|
-
|
401
|
+
|
402
|
+
Gauge = (function(_super) {
|
403
|
+
__extends(Gauge, _super);
|
404
|
+
|
247
405
|
Gauge.prototype.elem = null;
|
248
|
-
|
406
|
+
|
407
|
+
Gauge.prototype.value = [20];
|
408
|
+
|
249
409
|
Gauge.prototype.maxValue = 80;
|
410
|
+
|
411
|
+
Gauge.prototype.minValue = 0;
|
412
|
+
|
250
413
|
Gauge.prototype.displayedAngle = 0;
|
414
|
+
|
251
415
|
Gauge.prototype.displayedValue = 0;
|
416
|
+
|
252
417
|
Gauge.prototype.lineWidth = 40;
|
418
|
+
|
253
419
|
Gauge.prototype.paddingBottom = 0.1;
|
420
|
+
|
421
|
+
Gauge.prototype.percentColors = null;
|
422
|
+
|
254
423
|
Gauge.prototype.options = {
|
255
424
|
colorStart: "#6fadcf",
|
256
|
-
colorStop:
|
425
|
+
colorStop: void 0,
|
426
|
+
gradientType: 0,
|
257
427
|
strokeColor: "#e0e0e0",
|
258
428
|
pointer: {
|
259
429
|
length: 0.8,
|
@@ -261,55 +431,163 @@
|
|
261
431
|
},
|
262
432
|
angle: 0.15,
|
263
433
|
lineWidth: 0.44,
|
264
|
-
fontSize: 40
|
434
|
+
fontSize: 40,
|
435
|
+
limitMax: false,
|
436
|
+
percentColors: [[0.0, "#a9d70b"], [0.50, "#f9c802"], [1.0, "#ff0000"]]
|
265
437
|
};
|
438
|
+
|
266
439
|
function Gauge(canvas) {
|
267
440
|
this.canvas = canvas;
|
268
441
|
Gauge.__super__.constructor.call(this);
|
442
|
+
this.percentColors = null;
|
443
|
+
if (typeof G_vmlCanvasManager !== 'undefined') {
|
444
|
+
this.canvas = window.G_vmlCanvasManager.initElement(this.canvas);
|
445
|
+
}
|
269
446
|
this.ctx = this.canvas.getContext('2d');
|
270
|
-
this.gp = new GaugePointer(this
|
447
|
+
this.gp = [new GaugePointer(this)];
|
271
448
|
this.setOptions();
|
272
449
|
this.render();
|
273
450
|
}
|
451
|
+
|
274
452
|
Gauge.prototype.setOptions = function(options) {
|
453
|
+
var gauge, _i, _len, _ref1;
|
275
454
|
if (options == null) {
|
276
455
|
options = null;
|
277
456
|
}
|
278
|
-
|
457
|
+
Gauge.__super__.setOptions.call(this, options);
|
458
|
+
this.configPercentColors();
|
279
459
|
this.lineWidth = this.canvas.height * (1 - this.paddingBottom) * this.options.lineWidth;
|
280
460
|
this.radius = this.canvas.height * (1 - this.paddingBottom) - this.lineWidth;
|
281
|
-
this.
|
282
|
-
|
283
|
-
|
461
|
+
this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
|
462
|
+
this.render();
|
463
|
+
_ref1 = this.gp;
|
464
|
+
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
|
465
|
+
gauge = _ref1[_i];
|
466
|
+
gauge.setOptions(this.options.pointer);
|
467
|
+
gauge.render();
|
284
468
|
}
|
285
469
|
return this;
|
286
470
|
};
|
471
|
+
|
472
|
+
Gauge.prototype.configPercentColors = function() {
|
473
|
+
var bval, gval, i, rval, _i, _ref1, _results;
|
474
|
+
this.percentColors = null;
|
475
|
+
if (this.options.percentColors !== void 0) {
|
476
|
+
this.percentColors = new Array();
|
477
|
+
_results = [];
|
478
|
+
for (i = _i = 0, _ref1 = this.options.percentColors.length - 1; 0 <= _ref1 ? _i <= _ref1 : _i >= _ref1; i = 0 <= _ref1 ? ++_i : --_i) {
|
479
|
+
rval = parseInt((cutHex(this.options.percentColors[i][1])).substring(0, 2), 16);
|
480
|
+
gval = parseInt((cutHex(this.options.percentColors[i][1])).substring(2, 4), 16);
|
481
|
+
bval = parseInt((cutHex(this.options.percentColors[i][1])).substring(4, 6), 16);
|
482
|
+
_results.push(this.percentColors[i] = {
|
483
|
+
pct: this.options.percentColors[i][0],
|
484
|
+
color: {
|
485
|
+
r: rval,
|
486
|
+
g: gval,
|
487
|
+
b: bval
|
488
|
+
}
|
489
|
+
});
|
490
|
+
}
|
491
|
+
return _results;
|
492
|
+
}
|
493
|
+
};
|
494
|
+
|
287
495
|
Gauge.prototype.set = function(value) {
|
288
|
-
|
289
|
-
if (
|
290
|
-
|
496
|
+
var i, max_hit, val, _i, _j, _len, _ref1;
|
497
|
+
if (!(value instanceof Array)) {
|
498
|
+
value = [value];
|
499
|
+
}
|
500
|
+
if (value.length > this.gp.length) {
|
501
|
+
for (i = _i = 0, _ref1 = value.length - this.gp.length; 0 <= _ref1 ? _i < _ref1 : _i > _ref1; i = 0 <= _ref1 ? ++_i : --_i) {
|
502
|
+
this.gp.push(new GaugePointer(this));
|
503
|
+
}
|
504
|
+
}
|
505
|
+
i = 0;
|
506
|
+
max_hit = false;
|
507
|
+
for (_j = 0, _len = value.length; _j < _len; _j++) {
|
508
|
+
val = value[_j];
|
509
|
+
if (val > this.maxValue) {
|
510
|
+
this.maxValue = this.value * 1.1;
|
511
|
+
max_hit = true;
|
512
|
+
}
|
513
|
+
this.gp[i].value = val;
|
514
|
+
this.gp[i++].setOptions({
|
515
|
+
maxValue: this.maxValue,
|
516
|
+
angle: this.options.angle
|
517
|
+
});
|
518
|
+
}
|
519
|
+
this.value = value[value.length - 1];
|
520
|
+
if (max_hit) {
|
521
|
+
if (!this.options.limitMax) {
|
522
|
+
return AnimationUpdater.run();
|
523
|
+
}
|
524
|
+
} else {
|
525
|
+
return AnimationUpdater.run();
|
291
526
|
}
|
292
|
-
return AnimationUpdater.run();
|
293
527
|
};
|
528
|
+
|
294
529
|
Gauge.prototype.getAngle = function(value) {
|
295
|
-
return (1 + this.options.angle) * Math.PI + (value / this.maxValue) * (1 - this.options.angle * 2) * Math.PI;
|
530
|
+
return (1 + this.options.angle) * Math.PI + ((value - this.minValue) / (this.maxValue - this.minValue)) * (1 - this.options.angle * 2) * Math.PI;
|
296
531
|
};
|
297
|
-
|
298
|
-
|
532
|
+
|
533
|
+
Gauge.prototype.getColorForPercentage = function(pct, grad) {
|
534
|
+
var color, endColor, i, rangePct, startColor, _i, _ref1;
|
535
|
+
if (pct === 0) {
|
536
|
+
color = this.percentColors[0].color;
|
537
|
+
} else {
|
538
|
+
color = this.percentColors[this.percentColors.length - 1].color;
|
539
|
+
for (i = _i = 0, _ref1 = this.percentColors.length - 1; 0 <= _ref1 ? _i <= _ref1 : _i >= _ref1; i = 0 <= _ref1 ? ++_i : --_i) {
|
540
|
+
if (pct <= this.percentColors[i].pct) {
|
541
|
+
if (grad === true) {
|
542
|
+
startColor = this.percentColors[i - 1];
|
543
|
+
endColor = this.percentColors[i];
|
544
|
+
rangePct = (pct - startColor.pct) / (endColor.pct - startColor.pct);
|
545
|
+
color = {
|
546
|
+
r: Math.floor(startColor.color.r * (1 - rangePct) + endColor.color.r * rangePct),
|
547
|
+
g: Math.floor(startColor.color.g * (1 - rangePct) + endColor.color.g * rangePct),
|
548
|
+
b: Math.floor(startColor.color.b * (1 - rangePct) + endColor.color.b * rangePct)
|
549
|
+
};
|
550
|
+
} else {
|
551
|
+
color = this.percentColors[i].color;
|
552
|
+
}
|
553
|
+
break;
|
554
|
+
}
|
555
|
+
}
|
556
|
+
}
|
557
|
+
return 'rgb(' + [color.r, color.g, color.b].join(',') + ')';
|
558
|
+
};
|
559
|
+
|
560
|
+
Gauge.prototype.getColorForValue = function(val, grad) {
|
561
|
+
var pct;
|
562
|
+
pct = (val - this.minValue) / (this.maxValue - this.minValue);
|
563
|
+
return this.getColorForPercentage(pct, grad);
|
299
564
|
};
|
565
|
+
|
300
566
|
Gauge.prototype.render = function() {
|
301
|
-
var displayedAngle,
|
567
|
+
var displayedAngle, fillStyle, gauge, h, w, _i, _len, _ref1, _results;
|
302
568
|
w = this.canvas.width / 2;
|
303
569
|
h = this.canvas.height * (1 - this.paddingBottom);
|
304
570
|
displayedAngle = this.getAngle(this.displayedValue);
|
305
571
|
if (this.textField) {
|
306
|
-
this.textField.
|
572
|
+
this.textField.render(this);
|
307
573
|
}
|
308
|
-
grd = this.ctx.createRadialGradient(w, h, 9, w, h, 70);
|
309
574
|
this.ctx.lineCap = "butt";
|
310
|
-
|
311
|
-
|
312
|
-
this.
|
575
|
+
if (this.options.customFillStyle !== void 0) {
|
576
|
+
fillStyle = this.options.customFillStyle(this);
|
577
|
+
} else if (this.percentColors !== null) {
|
578
|
+
fillStyle = this.getColorForValue(this.displayedValue, true);
|
579
|
+
} else if (this.options.colorStop !== void 0) {
|
580
|
+
if (this.options.gradientType === 0) {
|
581
|
+
fillStyle = this.ctx.createRadialGradient(w, h, 9, w, h, 70);
|
582
|
+
} else {
|
583
|
+
fillStyle = this.ctx.createLinearGradient(0, 0, w, 0);
|
584
|
+
}
|
585
|
+
fillStyle.addColorStop(0, this.options.colorStart);
|
586
|
+
fillStyle.addColorStop(1, this.options.colorStop);
|
587
|
+
} else {
|
588
|
+
fillStyle = this.options.colorStart;
|
589
|
+
}
|
590
|
+
this.ctx.strokeStyle = fillStyle;
|
313
591
|
this.ctx.beginPath();
|
314
592
|
this.ctx.arc(w, h, this.radius, (1 + this.options.angle) * Math.PI, displayedAngle, false);
|
315
593
|
this.ctx.lineWidth = this.lineWidth;
|
@@ -318,74 +596,88 @@
|
|
318
596
|
this.ctx.beginPath();
|
319
597
|
this.ctx.arc(w, h, this.radius, displayedAngle, (2 - this.options.angle) * Math.PI, false);
|
320
598
|
this.ctx.stroke();
|
321
|
-
|
599
|
+
_ref1 = this.gp;
|
600
|
+
_results = [];
|
601
|
+
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
|
602
|
+
gauge = _ref1[_i];
|
603
|
+
_results.push(gauge.update(true));
|
604
|
+
}
|
605
|
+
return _results;
|
322
606
|
};
|
607
|
+
|
323
608
|
return Gauge;
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
609
|
+
|
610
|
+
})(BaseGauge);
|
611
|
+
|
612
|
+
BaseDonut = (function(_super) {
|
613
|
+
__extends(BaseDonut, _super);
|
614
|
+
|
615
|
+
BaseDonut.prototype.lineWidth = 15;
|
616
|
+
|
617
|
+
BaseDonut.prototype.displayedValue = 0;
|
618
|
+
|
619
|
+
BaseDonut.prototype.value = 33;
|
620
|
+
|
621
|
+
BaseDonut.prototype.maxValue = 80;
|
622
|
+
|
623
|
+
BaseDonut.prototype.minValue = 0;
|
624
|
+
|
625
|
+
BaseDonut.prototype.options = {
|
332
626
|
lineWidth: 0.10,
|
333
627
|
colorStart: "#6f6ea0",
|
334
628
|
colorStop: "#c0c0db",
|
335
629
|
strokeColor: "#eeeeee",
|
630
|
+
shadowColor: "#d5d5d5",
|
336
631
|
angle: 0.35
|
337
632
|
};
|
338
|
-
|
633
|
+
|
634
|
+
function BaseDonut(canvas) {
|
339
635
|
this.canvas = canvas;
|
340
|
-
|
636
|
+
BaseDonut.__super__.constructor.call(this);
|
637
|
+
if (typeof G_vmlCanvasManager !== 'undefined') {
|
638
|
+
this.canvas = window.G_vmlCanvasManager.initElement(this.canvas);
|
639
|
+
}
|
341
640
|
this.ctx = this.canvas.getContext('2d');
|
342
641
|
this.setOptions();
|
343
642
|
this.render();
|
344
643
|
}
|
345
|
-
|
346
|
-
|
644
|
+
|
645
|
+
BaseDonut.prototype.getAngle = function(value) {
|
646
|
+
return (1 - this.options.angle) * Math.PI + ((value - this.minValue) / (this.maxValue - this.minValue)) * ((2 + this.options.angle) - (1 - this.options.angle)) * Math.PI;
|
347
647
|
};
|
348
|
-
|
648
|
+
|
649
|
+
BaseDonut.prototype.setOptions = function(options) {
|
349
650
|
if (options == null) {
|
350
651
|
options = null;
|
351
652
|
}
|
352
|
-
|
653
|
+
BaseDonut.__super__.setOptions.call(this, options);
|
353
654
|
this.lineWidth = this.canvas.height * this.options.lineWidth;
|
354
655
|
this.radius = this.canvas.height / 2 - this.lineWidth / 2;
|
355
|
-
if (this.textField) {
|
356
|
-
this.textField.style.fontSize = options.fontSize + 'px';
|
357
|
-
}
|
358
656
|
return this;
|
359
657
|
};
|
360
|
-
|
361
|
-
|
362
|
-
};
|
363
|
-
Donut.prototype.set = function(value) {
|
658
|
+
|
659
|
+
BaseDonut.prototype.set = function(value) {
|
364
660
|
this.value = value;
|
365
661
|
if (this.value > this.maxValue) {
|
366
662
|
this.maxValue = this.value * 1.1;
|
367
663
|
}
|
368
664
|
return AnimationUpdater.run();
|
369
665
|
};
|
370
|
-
|
371
|
-
|
666
|
+
|
667
|
+
BaseDonut.prototype.render = function() {
|
668
|
+
var displayedAngle, grdFill, h, start, stop, w;
|
372
669
|
displayedAngle = this.getAngle(this.displayedValue);
|
373
670
|
w = this.canvas.width / 2;
|
374
671
|
h = this.canvas.height / 2;
|
375
672
|
if (this.textField) {
|
376
|
-
this.textField.
|
673
|
+
this.textField.render(this);
|
377
674
|
}
|
378
675
|
grdFill = this.ctx.createRadialGradient(w, h, 39, w, h, 70);
|
379
676
|
grdFill.addColorStop(0, this.options.colorStart);
|
380
677
|
grdFill.addColorStop(1, this.options.colorStop);
|
381
678
|
start = this.radius - this.lineWidth / 2;
|
382
679
|
stop = this.radius + this.lineWidth / 2;
|
383
|
-
|
384
|
-
grd.addColorStop(0, "#d5d5d5");
|
385
|
-
grd.addColorStop(0.12, this.options.strokeColor);
|
386
|
-
grd.addColorStop(0.88, this.options.strokeColor);
|
387
|
-
grd.addColorStop(1, "#d5d5d5");
|
388
|
-
this.ctx.strokeStyle = grd;
|
680
|
+
this.ctx.strokeStyle = this.options.strokeColor;
|
389
681
|
this.ctx.beginPath();
|
390
682
|
this.ctx.arc(w, h, this.radius, (1 - this.options.angle) * Math.PI, (2 + this.options.angle) * Math.PI, false);
|
391
683
|
this.ctx.lineWidth = this.lineWidth;
|
@@ -396,8 +688,48 @@
|
|
396
688
|
this.ctx.arc(w, h, this.radius, (1 - this.options.angle) * Math.PI, displayedAngle, false);
|
397
689
|
return this.ctx.stroke();
|
398
690
|
};
|
691
|
+
|
692
|
+
return BaseDonut;
|
693
|
+
|
694
|
+
})(BaseGauge);
|
695
|
+
|
696
|
+
Donut = (function(_super) {
|
697
|
+
__extends(Donut, _super);
|
698
|
+
|
699
|
+
function Donut() {
|
700
|
+
_ref1 = Donut.__super__.constructor.apply(this, arguments);
|
701
|
+
return _ref1;
|
702
|
+
}
|
703
|
+
|
704
|
+
Donut.prototype.strokeGradient = function(w, h, start, stop) {
|
705
|
+
var grd;
|
706
|
+
grd = this.ctx.createRadialGradient(w, h, start, w, h, stop);
|
707
|
+
grd.addColorStop(0, this.options.shadowColor);
|
708
|
+
grd.addColorStop(0.12, this.options._orgStrokeColor);
|
709
|
+
grd.addColorStop(0.88, this.options._orgStrokeColor);
|
710
|
+
grd.addColorStop(1, this.options.shadowColor);
|
711
|
+
return grd;
|
712
|
+
};
|
713
|
+
|
714
|
+
Donut.prototype.setOptions = function(options) {
|
715
|
+
var h, start, stop, w;
|
716
|
+
if (options == null) {
|
717
|
+
options = null;
|
718
|
+
}
|
719
|
+
Donut.__super__.setOptions.call(this, options);
|
720
|
+
w = this.canvas.width / 2;
|
721
|
+
h = this.canvas.height / 2;
|
722
|
+
start = this.radius - this.lineWidth / 2;
|
723
|
+
stop = this.radius + this.lineWidth / 2;
|
724
|
+
this.options._orgStrokeColor = this.options.strokeColor;
|
725
|
+
this.options.strokeColor = this.strokeGradient(w, h, start, stop);
|
726
|
+
return this;
|
727
|
+
};
|
728
|
+
|
399
729
|
return Donut;
|
400
|
-
|
730
|
+
|
731
|
+
})(BaseDonut);
|
732
|
+
|
401
733
|
window.AnimationUpdater = {
|
402
734
|
elements: [],
|
403
735
|
animId: null,
|
@@ -414,11 +746,11 @@
|
|
414
746
|
return AnimationUpdater.elements.push(object);
|
415
747
|
},
|
416
748
|
run: function() {
|
417
|
-
var animationFinished, elem, _i, _len,
|
749
|
+
var animationFinished, elem, _i, _len, _ref2;
|
418
750
|
animationFinished = true;
|
419
|
-
|
420
|
-
for (_i = 0, _len =
|
421
|
-
elem =
|
751
|
+
_ref2 = AnimationUpdater.elements;
|
752
|
+
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
753
|
+
elem = _ref2[_i];
|
422
754
|
if (elem.update()) {
|
423
755
|
animationFinished = false;
|
424
756
|
}
|
@@ -430,6 +762,13 @@
|
|
430
762
|
}
|
431
763
|
}
|
432
764
|
};
|
765
|
+
|
433
766
|
window.Gauge = Gauge;
|
767
|
+
|
434
768
|
window.Donut = Donut;
|
435
|
-
|
769
|
+
|
770
|
+
window.BaseDonut = BaseDonut;
|
771
|
+
|
772
|
+
window.TextRenderer = TextRenderer;
|
773
|
+
|
774
|
+
}).call(this);
|