labels.component.ts 2.46 KB
Newer Older
1
import { Component, OnInit } from '@angular/core';
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
2
import {StateService} from '../state.service';
3
4
5
6
7
8
9
10
11
12

@Component({
  selector: 'app-labels',
  templateUrl: './labels.component.html',
  styleUrls: ['./labels.component.css']
})
export class LabelsComponent implements OnInit {

  public goodLabels = [];
  public badLabels = [];
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
13
14

  constructor(private state: StateService) { }
15
16

  ngOnInit(): void {
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
17
    this.state.onNewLabels.subscribe(() => { this.createSubplots(); });
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
18
    this.state.onNewSelection.subscribe(() => { this.createSubplots(); });
19
20
  }

Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
21
  async createSubplots() {
22
23
    this.goodLabels = [];
    this.badLabels = [];
24
    const labelWindows: number[][][] = await this.state.getWindow(Object.keys(this.state.labels).map(Number));
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
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
    for (const idx in Object.keys(this.state.labels).map(Number)) {
      const window = labelWindows[idx];
      const data = [];
      this.state.selection.forEach((channelIndex, index) => {
        const channel = window[channelIndex];
        data.push({
          x: [...Array(channel.length).keys()],
          y: channel,
          type: 'line',
          xaxis: 'x',
          yaxis: `y${index + 2}`,
        });
      });
      const subplots = [];
      this.state.selection.forEach((channelIndex, index) => {
        subplots.push([`xy${index + 2}`]);
      });
      const plot = {
        index: Object.keys(this.state.labels).map(Number)[idx],
        data: data,
        layout: {
          grid: {
            rows: this.state.selection.length,
            columns: 1,
            subplots: subplots,
          },
          showlegend: false,
          hovermode: 'closest',
          autosize: true,
          margin: {
            l: 30,
            r: 30,
            t: 30,
            b: 0,
            pad: 4
          },
          height: 100 * this.state.selection.length,
          width: 300,
          titlefont: {
            size: 9
          },
          xaxis: {
            showgrid: false,
            zeroline: false,
            showticklabels: false,
          },
          yaxis: {
            zeroline: false,
            showticklabels: false,
74
          }
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
75
76
77
78
79
80
        }
      };
      this.state.selection.forEach((channelIndex, index) => {
        plot.layout[`yaxis${index + 2}`] = {
          zeroline: false,
          showticklabels: false,
81
        };
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
82
83
      });
      if (this.state.labels[Object.keys(this.state.labels).map(Number)[idx]]) {
84
85
86
87
        this.goodLabels.push(plot);
      } else {
        this.badLabels.push(plot);
      }
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
88
    }
89
90
  }
}