42 | * k.o.call(this);
43 | *
44 | */
45 | k.o = function () {
46 | var s = this;
47 |
48 | this.o = null; // array of options
49 | this.$ = null; // jQuery wrapped element
50 | this.i = null; // mixed HTMLInputElement or array of HTMLInputElement
51 | this.g = null; // 2D graphics context for 'pre-rendering'
52 | this.v = null; // value ; mixed array or integer
53 | this.cv = null; // change value ; not commited value
54 | this.x = 0; // canvas x position
55 | this.y = 0; // canvas y position
56 | this.$c = null; // jQuery canvas element
57 | this.c = null; // rendered canvas context
58 | this.t = 0; // touches index
59 | this.isInit = false;
60 | this.fgColor = null; // main color
61 | this.pColor = null; // previous color
62 | this.dH = null; // draw hook
63 | this.cH = null; // change hook
64 | this.eH = null; // cancel hook
65 | this.rH = null; // release hook
66 |
67 | this.run = function () {
68 | var cf = function (e, conf) {
69 | var k;
70 | for (k in conf) {
71 | s.o[k] = conf[k];
72 | }
73 | s.init();
74 | s._configure()
75 | ._draw();
76 | };
77 |
78 | if(this.$.data('kontroled')) return;
79 | this.$.data('kontroled', true);
80 |
81 | this.extend();
82 | this.o = $.extend(
83 | {
84 | // Config
85 | min : this.$.data('min') || 0,
86 | max : this.$.data('max') || 100,
87 | stopper : true,
88 | readOnly : this.$.data('readonly'),
89 |
90 | // UI
91 | cursor : (this.$.data('cursor') === true && 30)
92 | || this.$.data('cursor')
93 | || 0,
94 | thickness : this.$.data('thickness') || 0.35,
95 | width : this.$.data('width') || 200,
96 | height : this.$.data('height') || 200,
97 | displayInput : this.$.data('displayinput') == null || this.$.data('displayinput'),
98 | displayPrevious : this.$.data('displayprevious'),
99 | fgColor : this.$.data('fgcolor') || '#87CEEB',
100 | inline : false,
101 |
102 | // Hooks
103 | draw : null, // function () {}
104 | change : null, // function (value) {}
105 | cancel : null, // function () {}
106 | release : null // function (value) {}
107 | }, this.o
108 | );
109 |
110 | // routing value
111 | if(this.$.is('fieldset')) {
112 |
113 | // fieldset = array of integer
114 | this.v = {};
115 | this.i = this.$.find('input')
116 | this.i.each(function(k) {
117 | var $this = $(this);
118 | s.i[k] = $this;
119 | s.v[k] = $this.val();
120 |
121 | $this.bind(
122 | 'change'
123 | , function () {
124 | var val = {};
125 | val[k] = $this.val();
126 | s.val(val);
127 | }
128 | );
129 | });
130 | this.$.find('legend').remove();
131 |
132 | } else {
133 | // input = integer
134 | this.i = this.$;
135 | this.v = this.$.val();
136 | (this.v == '') && (this.v = this.o.min);
137 |
138 | this.$.bind(
139 | 'change'
140 | , function () {
141 | s.val(s.$.val());
142 | }
143 | );
144 | }
145 |
146 | (!this.o.displayInput) && this.$.hide();
147 |
148 | this.$c = $('');
151 | this.c = this.$c[0].getContext("2d");
152 |
153 | this.$
154 | .wrap($(''))
157 | .before(this.$c);
158 |
159 | if (this.v instanceof Object) {
160 | this.cv = {};
161 | this.copy(this.v, this.cv);
162 | } else {
163 | this.cv = this.v;
164 | }
165 |
166 | this.$
167 | .bind("configure", cf)
168 | .parent()
169 | .bind("configure", cf);
170 |
171 | this._listen()
172 | ._configure()
173 | ._xy()
174 | .init();
175 |
176 | this.isInit = true;
177 |
178 | this._draw();
179 |
180 | return this;
181 | };
182 |
183 | this._draw = function () {
184 |
185 | // canvas pre-rendering
186 | var d = true,
187 | c = document.createElement('canvas');
188 |
189 | c.width = s.o.width;
190 | c.height = s.o.height;
191 | s.g = c.getContext('2d');
192 |
193 | s.clear();
194 |
195 | s.dH
196 | && (d = s.dH());
197 |
198 | (d !== false) && s.draw();
199 |
200 | s.c.drawImage(c, 0, 0);
201 | c = null;
202 | };
203 |
204 | this._touch = function (e) {
205 |
206 | var touchMove = function (e) {
207 |
208 | var v = s.xy2val(
209 | e.originalEvent.touches[s.t].pageX,
210 | e.originalEvent.touches[s.t].pageY
211 | );
212 |
213 | if (v == s.cv) return;
214 |
215 | if (
216 | s.cH
217 | && (s.cH(v) === false)
218 | ) return;
219 |
220 |
221 | s.change(v);
222 | s._draw();
223 | };
224 |
225 | // get touches index
226 | this.t = k.c.t(e);
227 |
228 | // First touch
229 | touchMove(e);
230 |
231 | // Touch events listeners
232 | k.c.d
233 | .bind("touchmove.k", touchMove)
234 | .bind(
235 | "touchend.k"
236 | , function () {
237 | k.c.d.unbind('touchmove.k touchend.k');
238 |
239 | if (
240 | s.rH
241 | && (s.rH(s.cv) === false)
242 | ) return;
243 |
244 | s.val(s.cv);
245 | }
246 | );
247 |
248 | return this;
249 | };
250 |
251 | this._mouse = function (e) {
252 |
253 | var mouseMove = function (e) {
254 | var v = s.xy2val(e.pageX, e.pageY);
255 | if (v == s.cv) return;
256 |
257 | if (
258 | s.cH
259 | && (s.cH(v) === false)
260 | ) return;
261 |
262 | s.change(v);
263 | s._draw();
264 | };
265 |
266 | // First click
267 | mouseMove(e);
268 |
269 | // Mouse events listeners
270 | k.c.d
271 | .bind("mousemove.k", mouseMove)
272 | .bind(
273 | // Escape key cancel current change
274 | "keyup.k"
275 | , function (e) {
276 | if (e.keyCode === 27) {
277 | k.c.d.unbind("mouseup.k mousemove.k keyup.k");
278 |
279 | if (
280 | s.eH
281 | && (s.eH() === false)
282 | ) return;
283 |
284 | s.cancel();
285 | }
286 | }
287 | )
288 | .bind(
289 | "mouseup.k"
290 | , function (e) {
291 | k.c.d.unbind('mousemove.k mouseup.k keyup.k');
292 |
293 | if (
294 | s.rH
295 | && (s.rH(s.cv) === false)
296 | ) return;
297 |
298 | s.val(s.cv);
299 | }
300 | );
301 |
302 | return this;
303 | };
304 |
305 | this._xy = function () {
306 | var o = this.$c.offset();
307 | this.x = o.left;
308 | this.y = o.top;
309 | return this;
310 | };
311 |
312 | this._listen = function () {
313 |
314 | if (!this.o.readOnly) {
315 | this.$c
316 | .bind(
317 | "mousedown"
318 | , function (e) {
319 | e.preventDefault();
320 | s._xy()._mouse(e);
321 | }
322 | )
323 | .bind(
324 | "touchstart"
325 | , function (e) {
326 | e.preventDefault();
327 | s._xy()._touch(e);
328 | }
329 | );
330 | this.listen();
331 | } else {
332 | this.$.attr('readonly', 'readonly');
333 | }
334 |
335 | return this;
336 | };
337 |
338 | this._configure = function () {
339 |
340 | // Hooks
341 | if (this.o.draw) this.dH = this.o.draw;
342 | if (this.o.change) this.cH = this.o.change;
343 | if (this.o.cancel) this.eH = this.o.cancel;
344 | if (this.o.release) this.rH = this.o.release;
345 |
346 | if (this.o.displayPrevious) {
347 | this.pColor = this.h2rgba(this.o.fgColor, "0.4");
348 | this.fgColor = this.h2rgba(this.o.fgColor, "0.6");
349 | } else {
350 | this.fgColor = this.o.fgColor;
351 | }
352 |
353 | return this;
354 | };
355 |
356 | this._clear = function () {
357 | this.$c[0].width = this.$c[0].width;
358 | };
359 |
360 | // Abstract methods
361 | this.listen = function () {}; // on start, one time
362 | this.extend = function () {}; // each time configure triggered
363 | this.init = function () {}; // each time configure triggered
364 | this.change = function (v) {}; // on change
365 | this.val = function (v) {}; // on release
366 | this.xy2val = function (x, y) {}; //
367 | this.draw = function () {}; // on change / on release
368 | this.clear = function () { this._clear(); };
369 |
370 | // Utils
371 | this.h2rgba = function (h, a) {
372 | var rgb;
373 | h = h.substring(1,7)
374 | rgb = [parseInt(h.substring(0,2),16)
375 | ,parseInt(h.substring(2,4),16)
376 | ,parseInt(h.substring(4,6),16)];
377 | return "rgba(" + rgb[0] + "," + rgb[1] + "," + rgb[2] + "," + a + ")";
378 | };
379 |
380 | this.copy = function (f, t) {
381 | for (var i in f) { t[i] = f[i]; }
382 | };
383 | };
384 |
385 |
386 | /**
387 | * k.Dial
388 | */
389 | k.Dial = function () {
390 | k.o.call(this);
391 |
392 | this.startAngle = null;
393 | this.xy = null;
394 | this.radius = null;
395 | this.lineWidth = null;
396 | this.cursorExt = null;
397 | this.w2 = null;
398 | this.PI2 = 2*Math.PI;
399 |
400 | this.extend = function () {
401 | this.o = $.extend(
402 | {
403 | bgColor : this.$.data('bgcolor') || '#EEEEEE',
404 | angleOffset : this.$.data('angleoffset') || 0,
405 | angleArc : this.$.data('anglearc') || 360,
406 | inline : true
407 | }, this.o
408 | );
409 | };
410 |
411 | this.val = function (v) {
412 | if (null != v) {
413 | this.cv = this.o.stopper ? max(min(v, this.o.max), this.o.min) : v;
414 | this.v = this.cv;
415 | this.$.val(this.v);
416 | this._draw();
417 | } else {
418 | return this.v;
419 | }
420 | };
421 |
422 | this.xy2val = function (x, y) {
423 | var a, ret;
424 |
425 | a = Math.atan2(
426 | x - (this.x + this.w2)
427 | , - (y - this.y - this.w2)
428 | ) - this.angleOffset;
429 |
430 | if(this.angleArc != this.PI2 && (a < 0) && (a > -0.5)) {
431 | // if isset angleArc option, set to min if .5 under min
432 | a = 0;
433 | } else if (a < 0) {
434 | a += this.PI2;
435 | }
436 |
437 | ret = ~~ (0.5 + (a * (this.o.max - this.o.min) / this.angleArc))
438 | + this.o.min;
439 |
440 | this.o.stopper
441 | && (ret = max(min(ret, this.o.max), this.o.min));
442 |
443 | return ret;
444 | };
445 |
446 | this.listen = function () {
447 | // bind MouseWheel
448 | var s = this,
449 | mw = function (e) {
450 | e.preventDefault();
451 |
452 | var ori = e.originalEvent
453 | ,deltaX = ori.detail || ori.wheelDeltaX
454 | ,deltaY = ori.detail || ori.wheelDeltaY
455 | ,v = parseInt(s.$.val()) + (deltaX>0 || deltaY>0 ? 1 : deltaX<0 || deltaY<0 ? -1 : 0);
456 |
457 | if (
458 | s.cH
459 | && (s.cH(v) === false)
460 | ) return;
461 |
462 | s.val(v);
463 | }
464 | , kval, to, m = 1, kv = {37:-1, 38:1, 39:1, 40:-1};
465 |
466 | this.$
467 | .bind(
468 | "keydown"
469 | ,function (e) {
470 | var kc = e.keyCode;
471 | kval = parseInt(String.fromCharCode(kc));
472 |
473 | if (isNaN(kval)) {
474 |
475 | (kc !== 13) // enter
476 | && (kc !== 8) // bs
477 | && (kc !== 9) // tab
478 | && (kc !== 189) // -
479 | && e.preventDefault();
480 |
481 | // arrows
482 | if ($.inArray(kc,[37,38,39,40]) > -1) {
483 | e.preventDefault();
484 |
485 | var v = parseInt(s.$.val()) + kv[kc] * m;
486 |
487 | s.o.stopper
488 | && (v = max(min(v, s.o.max), s.o.min));
489 |
490 | s.change(v);
491 | s._draw();
492 |
493 | // long time keydown speed-up
494 | to = window.setTimeout(
495 | function () { m*=2; }
496 | ,30
497 | );
498 | }
499 | }
500 | }
501 | )
502 | .bind(
503 | "keyup"
504 | ,function (e) {
505 | if (isNaN(kval)) {
506 | if (to) {
507 | window.clearTimeout(to);
508 | to = null;
509 | m = 1;
510 | s.val(s.$.val());
511 | }
512 | } else {
513 | // kval postcond
514 | (s.$.val() > s.o.max && s.$.val(s.o.max))
515 | || (s.$.val() < s.o.min && s.$.val(s.o.min));
516 | }
517 |
518 | }
519 | );
520 |
521 | this.$c.bind("mousewheel DOMMouseScroll", mw);
522 | this.$.bind("mousewheel DOMMouseScroll", mw)
523 | };
524 |
525 | this.init = function () {
526 |
527 | if (
528 | this.v < this.o.min
529 | || this.v > this.o.max
530 | ) this.v = this.o.min;
531 |
532 | this.$.val(this.v);
533 | this.w2 = this.o.width / 2;
534 | this.cursorExt = this.o.cursor / 100;
535 | this.xy = this.w2;
536 | this.lineWidth = this.xy * this.o.thickness;
537 | this.radius = this.xy - this.lineWidth / 2;
538 |
539 | this.o.angleOffset
540 | && (this.o.angleOffset = isNaN(this.o.angleOffset) ? 0 : this.o.angleOffset);
541 |
542 | this.o.angleArc
543 | && (this.o.angleArc = isNaN(this.o.angleArc) ? this.PI2 : this.o.angleArc);
544 |
545 | // deg to rad
546 | this.angleOffset = this.o.angleOffset * Math.PI / 180;
547 | this.angleArc = this.o.angleArc * Math.PI / 180;
548 |
549 | // compute start and end angles
550 | this.startAngle = 1.5 * Math.PI + this.angleOffset;
551 | this.endAngle = 1.5 * Math.PI + this.angleOffset + this.angleArc;
552 |
553 | var s = max(
554 | String(Math.abs(this.o.max)).length
555 | , String(Math.abs(this.o.min)).length
556 | , 2
557 | ) + 2;
558 |
559 | this.o.displayInput
560 | && this.i.css({
561 | 'width' : ((this.o.width / 2 + 4) >> 0) + 'px'
562 | ,'height' : ((this.o.width / 3) >> 0) + 'px'
563 | ,'position' : 'absolute'
564 | ,'vertical-align' : 'middle'
565 | ,'margin-top' : ((this.o.width / 3) >> 0) + 'px'
566 | ,'margin-left' : '-' + ((this.o.width * 3 / 4 + 2) >> 0) + 'px'
567 | ,'border' : 0
568 | ,'background' : 'none'
569 | ,'font' : 'bold ' + ((this.o.width / s) >> 0) + 'px Arial'
570 | ,'text-align' : 'center'
571 | ,'color' : this.o.fgColor
572 | ,'padding' : '0px'
573 | ,'-webkit-appearance': 'none'
574 | })
575 | || this.i.css({
576 | 'width' : '0px'
577 | ,'visibility' : 'hidden'
578 | });
579 | };
580 |
581 | this.change = function (v) {
582 | this.cv = v;
583 | this.$.val(v);
584 | };
585 |
586 | this.angle = function (v) {
587 | return (v - this.o.min) * this.angleArc / (this.o.max - this.o.min);
588 | };
589 |
590 | this.draw = function () {
591 |
592 | var c = this.g, // context
593 | a = this.angle(this.cv) // Angle
594 | , sat = this.startAngle // Start angle
595 | , eat = sat + a // End angle
596 | , sa, ea // Previous angles
597 | , r = 1;
598 |
599 | c.lineWidth = this.lineWidth;
600 |
601 | this.o.cursor
602 | && (sat = eat - this.cursorExt)
603 | && (eat = eat + this.cursorExt);
604 |
605 | c.beginPath();
606 | c.strokeStyle = this.o.bgColor;
607 | c.arc(this.xy, this.xy, this.radius, this.endAngle, this.startAngle, true);
608 | c.stroke();
609 |
610 | if (this.o.displayPrevious) {
611 | ea = this.startAngle + this.angle(this.v);
612 | sa = this.startAngle;
613 | this.o.cursor
614 | && (sa = ea - this.cursorExt)
615 | && (ea = ea + this.cursorExt);
616 |
617 | c.beginPath();
618 | c.strokeStyle = this.pColor;
619 | c.arc(this.xy, this.xy, this.radius, sa, ea, false);
620 | c.stroke();
621 | r = (this.cv == this.v);
622 | }
623 |
624 | c.beginPath();
625 | c.strokeStyle = r ? this.o.fgColor : this.fgColor ;
626 | c.arc(this.xy, this.xy, this.radius, sat, eat, false);
627 | c.stroke();
628 | };
629 |
630 | this.cancel = function () {
631 | this.val(this.v);
632 | };
633 | };
634 |
635 | $.fn.dial = $.fn.knob = function (o) {
636 | return this.each(
637 | function () {
638 | var d = new k.Dial();
639 | d.o = o;
640 | d.$ = $(this);
641 | d.run();
642 | }
643 | ).parent();
644 | };
645 |
646 | });
--------------------------------------------------------------------------------
/assets/javascripts/rickshaw-1.4.3.min.js:
--------------------------------------------------------------------------------
1 | var Rickshaw={namespace:function(namespace,obj){var parts=namespace.split(".");var parent=Rickshaw;for(var i=1,length=parts.length;iPaste the following at the top of <%= params[:dashboard] %>.erb
27 | 28 |You may have mistyped the address or the page may have moved.
24 |6 | 7 |
8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /widgets/number/number.scss: -------------------------------------------------------------------------------- 1 | // ---------------------------------------------------------------------------- 2 | // Sass declarations 3 | // ---------------------------------------------------------------------------- 4 | $background-color: #47bbb3; 5 | $value-color: #fff; 6 | 7 | $title-color: rgba(255, 255, 255, 0.7); 8 | $moreinfo-color: rgba(255, 255, 255, 0.7); 9 | 10 | // ---------------------------------------------------------------------------- 11 | // Widget-number styles 12 | // ---------------------------------------------------------------------------- 13 | .widget-number { 14 | 15 | background-color: $background-color; 16 | 17 | .title { 18 | color: $title-color; 19 | } 20 | 21 | .value { 22 | color: $value-color; 23 | } 24 | 25 | .change-rate { 26 | font-weight: 500; 27 | font-size: 30px; 28 | color: $value-color; 29 | } 30 | 31 | .more-info { 32 | color: $moreinfo-color; 33 | } 34 | 35 | .updated-at { 36 | color: rgba(0, 0, 0, 0.3); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /widgets/simplemon/simplemon.coffee: -------------------------------------------------------------------------------- 1 | class Dashing.Simplemon extends Dashing.Widget 2 | @accessor 'current', Dashing.AnimatedValue 3 | 4 | ready: -> 5 | setInterval(@checkUpdate, 500) 6 | 7 | onData: (data) -> 8 | if data.color 9 | # clear existing "color-*" classes 10 | $(@get('node')).attr 'class', (i,c) -> 11 | c.replace /\bcolor-\S+/g, '' 12 | # add new class 13 | $(@get('node')).addClass "color-#{data.color}" 14 | 15 | checkUpdate: => 16 | if updatedAt = @get('updatedAt') 17 | timestamp = new Date(updatedAt * 1000) 18 | now = new Date() 19 | diff = now.getTime() - timestamp.getTime() 20 | if diff > 30000 21 | @onData({color:'grey'}) 22 | -------------------------------------------------------------------------------- /widgets/simplemon/simplemon.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /widgets/simplemon/simplemon.scss: -------------------------------------------------------------------------------- 1 | // ---------------------------------------------------------------------------- 2 | // Sass declarations 3 | // ---------------------------------------------------------------------------- 4 | $background-color: #47bbb3; 5 | $value-color: #fff; 6 | 7 | $background-color-green: #105010; 8 | $background-color-green-1: #105010; 9 | $background-color-green-2: #105010; 10 | $value-color-green: #fff; 11 | 12 | $background-color-red: #ff0000; 13 | $background-color-red-1: #ff0000; 14 | $background-color-red-2: #bb0000; 15 | $value-color-red: #fff; 16 | 17 | $background-color-yellow: #ff6c00; 18 | $background-color-yellow-1: #ff6c00; 19 | $background-color-yellow-2: #ff3d00; 20 | $value-color-yellow: #fff; 21 | 22 | $background-color-grey: #999999; 23 | $value-color-grey: #fff; 24 | 25 | $title-color: rgba(255, 255, 255, 0.7); 26 | $title-color-uns: rgba(0, 0, 0, 0.7); 27 | $moreinfo-color: rgba(255, 255, 255, 0.7); 28 | 29 | @-webkit-keyframes status-yellow-background { 30 | 0% { background-color: $background-color-yellow-1; } 31 | 50% { background-color: $background-color-yellow-2; } 32 | 100% { background-color: $background-color-yellow-1; } 33 | } 34 | @-webkit-keyframes status-red-background { 35 | 0% { background-color: $background-color-red-1; } 36 | 50% { background-color: $background-color-red-2; } 37 | 100% { background-color: $background-color-red-1; } 38 | } 39 | @-webkit-keyframes status-green-background { 40 | 0% { background-color: $background-color-green-1; } 41 | 50% { background-color: $background-color-green-2; } 42 | 100% { background-color: $background-color-green-1; } 43 | } 44 | @mixin animation($animation-name, $duration, $function, $animation-iteration-count:""){ 45 | -webkit-animation: $animation-name $duration $function #{$animation-iteration-count}; 46 | -moz-animation: $animation-name $duration $function #{$animation-iteration-count}; 47 | -ms-animation: $animation-name $duration $function #{$animation-iteration-count}; 48 | } 49 | 50 | 51 | // ---------------------------------------------------------------------------- 52 | // Widget-number styles 53 | // ---------------------------------------------------------------------------- 54 | .widget-simplemon { 55 | 56 | background-color: $background-color; 57 | 58 | .title { 59 | color: $title-color; 60 | } 61 | 62 | .value { 63 | color: $value-color; 64 | } 65 | 66 | .updated-at { 67 | color: rgba(0, 0, 0, 0.5); 68 | } 69 | 70 | } 71 | .widget-simplemon.color-green { 72 | background-color: $background-color-green; 73 | .value { color: $value-color-green; } 74 | } 75 | .widget-simplemon.color-green-blink { 76 | background-color: $background-color-green; 77 | @include animation(status-green-background, 2s, ease, infinite); 78 | .value { color: $value-color-green; } 79 | } 80 | .widget-simplemon.color-red { 81 | background-color: $background-color-red; 82 | .value { color: $value-color-red; } 83 | } 84 | .widget-simplemon.color-red-blink { 85 | background-color: $background-color-red; 86 | @include animation(status-red-background, 2s, ease, infinite); 87 | .value { color: $value-color-red; } 88 | } 89 | .widget-simplemon.color-yellow { 90 | background-color: $background-color-yellow; 91 | .value { color: $value-color-yellow; } 92 | } 93 | .widget-simplemon.color-yellow-blink { 94 | @include animation(status-yellow-background, 2s, ease, infinite); 95 | background-color: $background-color-yellow; 96 | .value { color: $value-color-yellow; } 97 | } 98 | .widget-simplemon.color-grey { 99 | background-color: $background-color-grey; 100 | .value { color: $value-color-grey; } 101 | } 102 | -------------------------------------------------------------------------------- /widgets/table/table.coffee: -------------------------------------------------------------------------------- 1 | class Dashing.Table extends Dashing.Widget 2 | -------------------------------------------------------------------------------- /widgets/table/table.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |7 | |
---|
13 | 14 | 15 | | 16 |
![]()
4 | 5 |