2015-10-09 09:22:35 +02:00
|
|
|
import Ember from 'ember';
|
|
|
|
|
|
|
|
export default Ember.Component.extend({
|
2015-10-09 11:35:31 +02:00
|
|
|
tagName: 'div',
|
2015-10-09 09:22:35 +02:00
|
|
|
classNames: ['line-chart'],
|
2015-10-12 12:25:14 +02:00
|
|
|
xaxisLength: 60,
|
2015-10-13 14:12:34 +02:00
|
|
|
updateTime: 100,
|
2015-10-09 09:22:35 +02:00
|
|
|
|
2015-10-09 11:35:31 +02:00
|
|
|
init: function() {
|
|
|
|
this._super();
|
|
|
|
this.addObserver('data', this.dataDidChange);
|
|
|
|
},
|
|
|
|
|
2015-10-09 09:22:35 +02:00
|
|
|
didInsertElement: function() {
|
2015-10-09 11:35:31 +02:00
|
|
|
this._drawPlot();
|
2015-10-09 12:29:32 +02:00
|
|
|
|
|
|
|
Ember.run.later(this, function() {
|
|
|
|
this._drawPlot();
|
2015-10-13 14:12:34 +02:00
|
|
|
}, this.updateTime);
|
2015-10-09 11:35:31 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
dataDidChange: function() {
|
|
|
|
this._drawPlot();
|
|
|
|
},
|
2015-10-09 09:22:35 +02:00
|
|
|
|
2015-10-09 11:35:31 +02:00
|
|
|
_drawPlot: function() {
|
2015-10-13 14:12:34 +02:00
|
|
|
var element = this.get('element');
|
|
|
|
if (element && element.id) {
|
|
|
|
if (this.data && this.data.length > 0) {
|
2015-10-12 17:36:34 +02:00
|
|
|
var firstTimestamp = this.data[0][0];
|
|
|
|
var lastTimestamp = this.data[this.data.length - 1][0];
|
|
|
|
|
|
|
|
var diff = lastTimestamp - firstTimestamp;
|
2015-10-13 16:02:28 +02:00
|
|
|
var diffValue = this.xaxisLength * 1000;
|
2015-10-12 17:36:34 +02:00
|
|
|
|
|
|
|
if (diff > diffValue) {
|
|
|
|
firstTimestamp = lastTimestamp - diffValue;
|
|
|
|
} else {
|
|
|
|
lastTimestamp = +firstTimestamp + +diffValue;
|
|
|
|
}
|
|
|
|
|
2015-10-12 12:25:14 +02:00
|
|
|
$.plot('#' + element.id, [this.data], {
|
|
|
|
xaxis: {
|
|
|
|
mode: 'time',
|
2015-10-12 17:36:34 +02:00
|
|
|
timeformat: '%M:%S',
|
|
|
|
min: firstTimestamp,
|
|
|
|
max: lastTimestamp
|
2015-10-12 12:25:14 +02:00
|
|
|
}
|
|
|
|
});
|
2015-10-13 14:12:34 +02:00
|
|
|
} else {
|
|
|
|
// display empty chart
|
|
|
|
$.plot('#' + element.id, [[]], {
|
|
|
|
xaxis: {
|
|
|
|
show: false
|
|
|
|
},
|
|
|
|
yaxis: {
|
|
|
|
show: false
|
|
|
|
}
|
|
|
|
});
|
2015-10-09 13:13:44 +02:00
|
|
|
}
|
|
|
|
}
|
2015-10-13 14:12:34 +02:00
|
|
|
|
|
|
|
// try again
|
|
|
|
Ember.run.later(this, function() {
|
|
|
|
this._drawPlot();
|
|
|
|
}, this.updateTime);
|
2015-10-09 09:22:35 +02:00
|
|
|
}
|
|
|
|
});
|