2020-08-05 03:19:54 +00:00
|
|
|
import Component from '@ember/component';
|
2020-08-05 18:55:17 +00:00
|
|
|
import { copy } from 'ember-copy';
|
|
|
|
import { computed, get } from '@ember/object';
|
2020-08-05 03:19:54 +00:00
|
|
|
import { tagName } from '@ember-decorators/component';
|
|
|
|
import classic from 'ember-classic-decorator';
|
|
|
|
|
|
|
|
@classic
|
|
|
|
@tagName('')
|
|
|
|
export default class ScaleEventsChart extends Component {
|
|
|
|
events = [];
|
|
|
|
|
|
|
|
activeEvent = null;
|
|
|
|
|
2021-02-17 21:01:44 +00:00
|
|
|
@computed('annotations', 'events.[]')
|
2020-08-05 03:19:54 +00:00
|
|
|
get data() {
|
2020-08-05 05:00:10 +00:00
|
|
|
const data = this.events.filterBy('hasCount').sortBy('time');
|
2020-08-05 04:28:11 +00:00
|
|
|
|
|
|
|
// Extend the domain of the chart to the current time
|
|
|
|
data.push({
|
|
|
|
time: new Date(),
|
|
|
|
count: data.lastObject.count,
|
|
|
|
});
|
|
|
|
|
|
|
|
// Make sure the domain of the chart includes the first annotation
|
|
|
|
const firstAnnotation = this.annotations.sortBy('time')[0];
|
|
|
|
if (firstAnnotation && firstAnnotation.time < data[0].time) {
|
|
|
|
data.unshift({
|
|
|
|
time: firstAnnotation.time,
|
|
|
|
count: data[0].count,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-08-05 05:00:10 +00:00
|
|
|
return data;
|
2020-08-05 03:19:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@computed('events.[]')
|
|
|
|
get annotations() {
|
|
|
|
return this.events.rejectBy('hasCount').map(ev => ({
|
|
|
|
type: ev.error ? 'error' : 'info',
|
|
|
|
time: ev.time,
|
2020-08-05 18:55:17 +00:00
|
|
|
event: copy(ev),
|
2020-08-05 03:19:54 +00:00
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
toggleEvent(ev) {
|
2020-08-05 18:55:17 +00:00
|
|
|
if (this.activeEvent && get(this.activeEvent, 'event.uid') === get(ev, 'event.uid')) {
|
2020-08-05 03:19:54 +00:00
|
|
|
this.closeEventDetails();
|
|
|
|
} else {
|
|
|
|
this.set('activeEvent', ev);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
closeEventDetails() {
|
|
|
|
this.set('activeEvent', null);
|
|
|
|
}
|
|
|
|
}
|