2015-10-22 16:18:42 -04:00
|
|
|
import Ember from 'ember';
|
|
|
|
|
|
|
|
export default Ember.Component.extend({
|
|
|
|
tagName: 'span',
|
|
|
|
classNames: ['alarm'],
|
|
|
|
|
|
|
|
size: 40,
|
|
|
|
value: 0,
|
|
|
|
alarmZones: [],
|
2015-10-26 11:21:25 -04:00
|
|
|
|
|
|
|
_blinking: false,
|
|
|
|
_blinkState: false,
|
2015-10-22 16:18:42 -04:00
|
|
|
|
|
|
|
didInsertElement: function() {
|
|
|
|
this._drawAlarm();
|
|
|
|
},
|
|
|
|
|
|
|
|
_drawAlarm: function() {
|
|
|
|
// calculate dimensions
|
|
|
|
var cx = this.size / 2;
|
|
|
|
var radius = this.size / 2 * 0.97;
|
|
|
|
|
|
|
|
// create body element
|
2015-10-22 18:17:46 -04:00
|
|
|
var body = d3.select('#' + this.elementId).append("svg:svg").attr("width", this.size).attr("height", this.size);
|
2015-10-22 16:18:42 -04:00
|
|
|
this.set('svgBody', body);
|
|
|
|
|
|
|
|
// add background
|
|
|
|
body.append("svg:circle")
|
|
|
|
.attr("cx", cx)
|
|
|
|
.attr("cy", cx)
|
|
|
|
.attr("r", radius)
|
|
|
|
.style("fill", "#ccc")
|
|
|
|
.style("stroke", "#000")
|
|
|
|
.style("stroke-width", "0.5px");
|
|
|
|
|
2015-10-23 07:20:10 -04:00
|
|
|
this._redraw();
|
2015-10-22 16:18:42 -04:00
|
|
|
},
|
|
|
|
|
2015-10-23 07:20:10 -04:00
|
|
|
_redraw: function() {
|
2015-10-22 16:18:42 -04:00
|
|
|
var cx = this.size / 2;
|
|
|
|
var radius = this.size / 2 * 0.97;
|
2015-10-26 11:21:25 -04:00
|
|
|
var litAlarm = this._shouldLitAlarm();
|
2015-10-22 16:18:42 -04:00
|
|
|
|
2015-10-26 11:21:25 -04:00
|
|
|
if (litAlarm && this._blinking === false) {
|
|
|
|
// start blinking
|
|
|
|
this._blinkState = true;
|
|
|
|
this._blinking = true;
|
2015-10-26 12:41:50 -04:00
|
|
|
|
|
|
|
Ember.run.later(this, this._updateBlinkState, 1000);
|
2015-10-26 11:21:25 -04:00
|
|
|
} else if (litAlarm === false && this._blinking === true) {
|
|
|
|
// stop blinking
|
|
|
|
this._blinking = false;
|
2015-10-22 16:18:42 -04:00
|
|
|
}
|
|
|
|
|
2015-10-26 11:21:25 -04:00
|
|
|
if (litAlarm && (this._blinking === true && this._blinkState === true)) {
|
2015-10-22 16:18:42 -04:00
|
|
|
this.svgBody.append("svg:circle")
|
|
|
|
.attr("cx", cx)
|
|
|
|
.attr("cy", cx)
|
|
|
|
.attr("r", radius * 0.8)
|
2015-10-23 07:20:10 -04:00
|
|
|
.style("fill", "#F00")
|
2015-10-22 16:18:42 -04:00
|
|
|
.style("stroke", "#000")
|
|
|
|
.style("stroke-width", "0.5px");
|
|
|
|
} else {
|
|
|
|
this.svgBody.append("svg:circle")
|
|
|
|
.attr("cx", cx)
|
|
|
|
.attr("cy", cx)
|
|
|
|
.attr("r", radius * 0.8)
|
|
|
|
.style("fill", "#633")
|
|
|
|
.style("stroke", "#000")
|
|
|
|
.style("stroke-width", "0.5px");
|
|
|
|
}
|
2015-10-26 11:21:25 -04:00
|
|
|
}.observes('value'),
|
|
|
|
|
|
|
|
_shouldLitAlarm: function() {
|
|
|
|
for (var zone in this.alarmZones) {
|
|
|
|
// get border for zone
|
|
|
|
var from = this.alarmZones[zone].from;
|
|
|
|
var to = this.alarmZones[zone].to;
|
|
|
|
|
|
|
|
if (this.value >= from && this.value <= to) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2015-10-26 12:41:50 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
_updateBlinkState: function() {
|
|
|
|
if (this._blinking === true) {
|
|
|
|
this._blinkState = !this._blinkState;
|
|
|
|
|
|
|
|
Ember.run.later(this, this._updateBlinkState, 1000);
|
|
|
|
}
|
2015-10-26 11:21:25 -04:00
|
|
|
}
|
2015-10-22 16:18:42 -04:00
|
|
|
});
|