labels.component.ts 1.53 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(); });
18
19
  }

Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
20
  async createSubplots() {
21
22
    this.goodLabels = [];
    this.badLabels = [];
23
    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
24
    Object.keys(this.state.labels).forEach((key, i) => {
25
26
27
28
29
      const index = Number(key);
      const plot =
        {
          index,
          data: [{
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
30
31
            x: [...Array(this.state.windowSize).keys()],
            y: labelWindows[i],
32
33
34
35
36
37
38
39
40
41
            type: 'line'
          }],
          layout: {
            title: `Index: ${index.toString()}`,
            hovermode: 'closest',
            autosize: true,
            margin: {
              l: 30,
              r: 30,
              t: 30,
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
42
              b: 5,
43
44
              pad: 4
            },
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
45
            height: 150,
46
47
48
49
            width: 150,
            titlefont: {
              size: 9
            },
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
50
51
52
            xaxis: {
              showticklabels: false,
            }
53
54
          }
        };
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
55
      if (this.state.labels[key]) {
56
57
58
59
        this.goodLabels.push(plot);
      } else {
        this.badLabels.push(plot);
      }
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
60
    });
61
62
63
  }

}