All files / src/app/components/signals-graphs signals-graphs.component.ts

88.75% Statements 71/80
85.18% Branches 23/27
91.3% Functions 21/23
88.15% Lines 67/76

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225                                                    162x 52x     52x 52x 52x   52x 52x   52x             52x                           52x 52x   52x   52x 1x 1x   52x                       52x 52x         54x 54x 56x 56x 42x         54x 40x 71x 71x 30x 25x     5x       41x         54x   54x 10x     54x 4x 4x         40x       40x   40x   40x 40x   40x   40x   40x                   40x   40x 40x   40x       11x 5x 5x               62x     62x       62x       40x       8x 1x 1x                           14x                 2x 2x       1x 1x       3x 3x   110x      
import { AfterViewInit, Component, Input, OnChanges, OnInit, ViewChild, inject } from '@angular/core';
import { DisplayModeOption, DurationOption } from '../../models/signals';
import { FormsModule } from '@angular/forms';
import { LoaderComponent } from '../loader/loader.component';
 
import { SignalsGraphComponent } from '../signals-graph/signals-graph.component';
import { MultiSelectModule } from 'primeng/multiselect';
import { Select } from 'primeng/select';
import { FloatLabelModule } from 'primeng/floatlabel';
import { ToolbarModule } from 'primeng/toolbar';
import { ButtonModule } from 'primeng/button';
import { DatePicker } from 'primeng/datepicker';
import { SplitButtonModule } from 'primeng/splitbutton';
import { MenuItem } from 'primeng/api';
import { ActivatedRoute } from '@angular/router';
import { MultiSelectSignalsComponent } from '../multi-select-signals/multi-select-signals.component';
import { RefreshRateSelectorComponent } from '../refresh-rate-selector/refresh-rate-selector.component';
import { CommandCenterComponent } from '../command-center/command-center.component';
import { arrayContains, deepCopy } from '../../utils/utils';
 
@Component({
  selector: 'app-signals-graphs',
  imports: [LoaderComponent, FormsModule, SignalsGraphComponent, MultiSelectModule, Select, FloatLabelModule, ToolbarModule, ButtonModule, DatePicker, SplitButtonModule, MultiSelectSignalsComponent, RefreshRateSelectorComponent, CommandCenterComponent],
  templateUrl: './signals-graphs.component.html',
  styleUrl: './signals-graphs.component.scss'
})
export class SignalsGraphsComponent implements OnInit, OnChanges, AfterViewInit {
  private route = inject(ActivatedRoute);
 
  isLoading: boolean;
  @Input() inputSignalIdsToPlot: string[] = [];
  @Input() showSignals: boolean = true;
  @Input() showLegend: boolean = true;
  @Input() inputZoomTime: number;
  @Input() inputIsLive: boolean = true;
  @Input() graphId: string = "";
  @Input() inputWindowLength: DurationOption;
  @Input() displayCommandCenter: boolean = true;
 
  replayWindowLengths: DurationOption[];
  windowLengths: DurationOption[];
  windowLength: DurationOption;
  refreshTime: DurationOption;
  replayWindowLength: DurationOption;
  isResponseSlowerThanRefresh: boolean = false;
  isLive: boolean;
  displayModes: DisplayModeOption[];
  displayMode: DisplayModeOption;
  refreshModes: string[];
  refreshMode: string;
  dataDateMin: Date;
  dataDateMax: Date;
 
  replayWindowMiddle: Date;
 
  windowMinTs: number;
  windowMaxTs: number;
 
  signalsSelectionLimit: number = 10;
  querySignalId: string = "signal_id";
 
  isDownloading: boolean = false;
 
  exports: MenuItem[] = [{ "label": "CSV", command: () => { this.downloadSignalsZip("csv"); } },
  { "label": "PrestoPlot", command: () => { this.downloadSignalsZip("prestoplot"); } },
  { "label": "HDF5", command: () => { this.downloadSignalsHDF5(); } }];
 
  readonly baseReplayWindowLengths: DurationOption[] = [
    { label: "10s", duration: 10 },
    { label: "1mn", duration: 60 },
    { label: "5mn", duration: 300 },
    { label: "15mn", duration: 900 },
    { label: "1hr", duration: 3600 },
    { label: "4hr", duration: 3600 * 4 },
    { label: "12hr", duration: 3600 * 12 },
    { label: "24hr", duration: 3600 * 24 }
  ];
 
 
  @ViewChild(SignalsGraphComponent) graphComponent!: SignalsGraphComponent;
  @ViewChild(MultiSelectSignalsComponent) multiSelectSignals: MultiSelectSignalsComponent;
 
 
  applyInputs() {
    // Checks if current graph is standalone graph or graph of single signal
    let isStandaloneGraph: boolean = false;
    this.route.url.subscribe(urlSegments => {
      const segment = urlSegments[0].path;
      if (segment !== "signals" && segment !== "events") {
        isStandaloneGraph = true;
      }
    });
    // If it's a standalone graph, only get signal ids to plot from query
    // If query doesn't give any signals to graph, graph is empty
    if (isStandaloneGraph) {
      this.route.queryParams.subscribe(params => {
        const signalIds = params[this.querySignalId];
        if (signalIds) {
          if (signalIds instanceof Array) {
            this.inputSignalIdsToPlot = signalIds;
          }
          else {
            this.inputSignalIdsToPlot = [signalIds];
          }
        }
        else {
          this.inputSignalIdsToPlot = [];
        }
      });
    }
 
    this.isLive = this.inputIsLive;
 
    if (this.inputZoomTime !== undefined) {
      this.replayWindowMiddle = new Date(this.inputZoomTime);
    }
 
    if (!this.isLive && this.inputWindowLength !== undefined && this.replayWindowLengths !== undefined) {
      this.insertNewWindowLength(this.replayWindowLengths, this.inputWindowLength);
      this.replayWindowLength = this.inputWindowLength;
    }
  }
 
  ngAfterViewInit(): void {
    this.applyInputs();
  }
 
  ngOnInit() {
    this.isLoading = true;
 
    this.querySignalId = `signal_id${this.graphId}`;
 
    this.displayModes = [{ label: "Live mode", isLive: true }, { label: "Replay mode", isLive: false }];
    this.displayMode = this.displayModes[0];
 
    this.replayWindowLengths = deepCopy(this.baseReplayWindowLengths);
 
    this.replayWindowLength = this.replayWindowLengths[1];
 
    this.windowLengths = [
      { label: "10s", duration: 10 },
      { label: "30s", duration: 30 },
      { label: "1mn", duration: 60 },
      { label: "3mn", duration: 180 },
      { label: "5mn", duration: 300 },
      { label: "10mn", duration: 600 },
      { label: "1hr", duration: 3600 }
    ];
 
    this.windowLength = this.windowLengths[2];
 
    this.refreshModes = ["Single-point", "Full window", "Latest points"];
    this.refreshMode = this.refreshModes[0];
 
    this.isLoading = false;
  }
 
  insertNewWindowLength(windowLengths: DurationOption[], windowLength: DurationOption) {
    const insertIndex = windowLengths.findIndex(existingDuration => existingDuration.duration > windowLength.duration);
    Eif (insertIndex !== -1) {
      windowLengths.splice(insertIndex, 0, windowLength);
    }
    else {
      windowLengths.push(windowLength);
    }
  }
 
  handleDataDateMin(date: Date) {
    this.dataDateMin = date;
  }
  handleDataDateMax(date: Date) {
    this.dataDateMax = date;
  }
 
  handleResponseSlowerThanRefresh(bool: boolean) {
    this.isResponseSlowerThanRefresh = bool;
  }
 
  handleRefreshRateChange(value: DurationOption) {
    this.refreshTime = value;
  }
 
  onReplayWindowLengthUpdate(value: DurationOption) {
    this.replayWindowLengths = this.replayWindowLengths.filter(windowLength => windowLength.label !== value.label && arrayContains(this.baseReplayWindowLengths, windowLength));
    this.insertNewWindowLength(this.replayWindowLengths, value);
    this.replayWindowLength = value;
  }
 
  onDateChange() {
    if (this.replayWindowMiddle === undefined) {
      this.replayWindowMiddle = new Date(Date.now() - 500 * this.replayWindowLength.duration);
      this.inputZoomTime = this.replayWindowMiddle.valueOf();
    }
    const timestamp = this.replayWindowMiddle.valueOf() / 1000;
    this.windowMinTs = timestamp - 0.5 * this.replayWindowLength.duration;
    this.windowMaxTs = timestamp + 0.5 * this.replayWindowLength.duration;
  }
 
  ngOnChanges() {
    this.applyInputs();
  }
 
  toggleLive() {
    this.isLive = !this.isLive;
    this.inputIsLive = !this.isLive;
  }
 
  downloadSignalsZip(format: string) {
    this.isDownloading = true;
    this.graphComponent.downloadSignalsZip(format);
  }
 
  downloadSignalsHDF5() {
    this.isDownloading = true;
    this.graphComponent.downloadSignalsHDF5();
  }
 
  handleFinishedDownloading(hasFinished: boolean) {
    Eif (hasFinished) {
      this.isDownloading = false;
    }
  }
 
}