2021-02-23 01:47:18 +00:00
|
|
|
import Component from '@glimmer/component';
|
|
|
|
import { tracked } from '@glimmer/tracking';
|
|
|
|
import { get } from '@ember/object';
|
2020-08-05 18:55:17 +00:00
|
|
|
import { copy } from 'ember-copy';
|
2020-08-05 03:19:54 +00:00
|
|
|
|
|
|
|
export default class ScaleEventsChart extends Component {
|
2021-02-23 01:47:18 +00:00
|
|
|
/** Args
|
|
|
|
events = []
|
|
|
|
*/
|
2020-08-05 03:19:54 +00:00
|
|
|
|
2021-02-23 01:47:18 +00:00
|
|
|
@tracked activeEvent = null;
|
2020-08-05 03:19:54 +00:00
|
|
|
|
|
|
|
get data() {
|
2021-02-23 01:47:18 +00:00
|
|
|
const data = this.args.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
|
|
|
}
|
|
|
|
|
|
|
|
get annotations() {
|
2021-12-28 14:45:20 +00:00
|
|
|
return this.args.events.rejectBy('hasCount').map((ev) => ({
|
2020-08-05 03:19:54 +00:00
|
|
|
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) {
|
2021-12-28 16:08:12 +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 {
|
2021-02-23 01:47:18 +00:00
|
|
|
this.activeEvent = ev;
|
2020-08-05 03:19:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
closeEventDetails() {
|
2021-02-23 01:47:18 +00:00
|
|
|
this.activeEvent = null;
|
2020-08-05 03:19:54 +00:00
|
|
|
}
|
|
|
|
}
|