github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/ui/app/components/scale-events-chart.js (about) 1 import Component from '@glimmer/component'; 2 import { tracked } from '@glimmer/tracking'; 3 import { get } from '@ember/object'; 4 import { copy } from 'ember-copy'; 5 6 export default class ScaleEventsChart extends Component { 7 /** Args 8 events = [] 9 */ 10 11 @tracked activeEvent = null; 12 13 get data() { 14 const data = this.args.events.filterBy('hasCount').sortBy('time'); 15 16 // Extend the domain of the chart to the current time 17 data.push({ 18 time: new Date(), 19 count: data.lastObject.count, 20 }); 21 22 // Make sure the domain of the chart includes the first annotation 23 const firstAnnotation = this.annotations.sortBy('time')[0]; 24 if (firstAnnotation && firstAnnotation.time < data[0].time) { 25 data.unshift({ 26 time: firstAnnotation.time, 27 count: data[0].count, 28 }); 29 } 30 31 return data; 32 } 33 34 get annotations() { 35 return this.args.events.rejectBy('hasCount').map((ev) => ({ 36 type: ev.error ? 'error' : 'info', 37 time: ev.time, 38 event: copy(ev), 39 })); 40 } 41 42 toggleEvent(ev) { 43 if ( 44 this.activeEvent && 45 get(this.activeEvent, 'event.uid') === get(ev, 'event.uid') 46 ) { 47 this.closeEventDetails(); 48 } else { 49 this.activeEvent = ev; 50 } 51 } 52 53 closeEventDetails() { 54 this.activeEvent = null; 55 } 56 }