1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/web/ synced 2025-03-16 00:00:03 +01:00
VILLASweb/app/components/d3-alarm.js

71 lines
1.5 KiB
JavaScript
Raw Normal View History

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: [],
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 litAlarm = false;
var cx = this.size / 2;
var radius = this.size / 2 * 0.97;
for (var zone in this.alarmZones) {
2015-10-23 07:20:10 -04:00
var from = this.alarmZones[zone].from;
var to = this.alarmZones[zone].to;
if (this.value >= from && this.value <= to) {
2015-10-22 16:18:42 -04:00
litAlarm = true;
}
}
if (litAlarm) {
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-23 07:20:10 -04:00
// reschedule
2015-10-22 16:18:42 -04:00
}.observes('value')
});