github.com/Ilhicas/nomad@v1.0.4-0.20210304152020-e86851182bc3/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 (this.activeEvent && get(this.activeEvent, 'event.uid') === get(ev, 'event.uid')) { 44 this.closeEventDetails(); 45 } else { 46 this.activeEvent = ev; 47 } 48 } 49 50 closeEventDetails() { 51 this.activeEvent = null; 52 } 53 }