github.com/hernad/nomad@v1.6.112/ui/app/components/scale-events-chart.js (about)

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