overview-window.component.ts 3.94 KB
Newer Older
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
1
import { Component} from '@angular/core';
2
3
4
5
6
7
8
import { CacheService } from '../cache.service';

@Component({
  selector: 'app-overview-window',
  templateUrl: './overview-window.component.html',
  styleUrls: ['./overview-window.component.css']
})
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
9
10
11
export class OverviewWindowComponent {
  public config;
  public series;
12
13
14
15
16
  public showPlot = false;

  public data;
  public layout;

Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
17
18
  constructor(private service: CacheService) {
  }
19
20

  async ngOnInit(): Promise<void> {
21
22
    this.service.onNewData.subscribe(() => this.initializePlot());
    this.service.onNewWindows.subscribe(() => {  });
23
    this.service.onNewTables.subscribe(() => {
24
      if (this.service.query) {
25
26
27
        this.updatePlot();
      }
    });
28
    this.service.onNewSlider.subscribe((v) => this.updateCandidates(v));
29
30
31
  }

  async initializePlot() {
32
    this.service.query = undefined;
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
33
34
35
36
37
38
39
40
41
42
    // this.data = this.service.rawIndices.map((e, i) => {
    //   return [e, values[i]];
    // });
    this.data = [];
    for (let i = 0; i < this.service.rawValues.length; i++) {
      this.data.push([i, this.service.rawValues[i]]);
    }
    this.config = {
      type: "mixed",
      preview: {
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
43
44
45
46
47
        height: " 30px",
        'auto-fit': true
      },
      "plotarea": {
        "margin-top": "10px"
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
48
49
50
51
52
      },
      'scale-x': {
        zooming: true,
        zoomTo: [0, this.service.windowSize],
        'auto-fit': true
53
      },
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
54
      'scale-y': {
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
55
        // zooming: true,
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
56
        'auto-fit': true
57
      },
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
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
      series: [
        {
          type: 'line',
          values: this.data,
          text: 'Raw Values',
          zIndex: 5,
          marker: {
            alpha: 0.0,
            zIndex: 10
          }
        },
        {
          type: 'scatter',
          values: [],
          text: 'Good labels',
          marker: {
            backgroundColor: '#4caf50'
          },
          zIndex: 20,
        },
        {
          type: 'scatter',
          values: [],
          text: 'Bad labels',
          marker: {
            backgroundColor: '#f44336'
          },
          zIndex: 20,
        }]
87
    };
88
    console.log("showing plot");
89
90
91
  }

  async clicked(clickData) {
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
92
93
94
95
96
97
    console.log('clicked node');
    const index = Math.floor(clickData.nodeindex / this.service.stepSize);
    this.service.query = index;
    const temp = {};
    temp[index] = true;
    this.service.labels = temp;
98
99
100
101
    await this.updatePlot();
  }

  async updatePlot() {
102
103
104
    if (this.service.query) {
      const windowSimilarity = await this.service.getSimilarWindows(this.service.query);
    }
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
105
106
    let goodLabels = [];
    let badLabels = [];
107
    for (const index in this.service.labels) {
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
108
109
110
111
112
      if (this.service.labels[index]) {
        goodLabels.push(this.data[index]);
      } else {
        badLabels.push(this.data[index]);
      }
113
    }
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
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
    this.series = [
      {
        type: 'line',
        values: this.data,
        text: 'Raw Values',
        zIndex: 5,
        marker: {
          alpha: 0.0,
          zIndex: 10
        }
      },
      {
        type: 'scatter',
        values: goodLabels,
        text: 'Good labels',
        marker: {
          backgroundColor: '#4caf50'
        },
        zIndex: 20,
      },
      {
        type: 'scatter',
        values: badLabels,
        text: 'Bad labels',
        marker: {
          backgroundColor: '#f44336'
        },
        zIndex: 20,
      }
    ];
144
145
  }

146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
  async updateCandidates(sliderIndex) {
    console.log("Updating chart");
    console.log(this.service.windowSimilarity);
    console.log(sliderIndex);
    const candidates = this.service.windowSimilarity[sliderIndex.toString()];
    console.log(candidates);
    const labels = [];
    for (const index of candidates) {
      labels.push(this.data[index]);
    }
    console.log(labels);
    const newSeries = this.series.slice(0, 3);
    newSeries.push({
      type: 'scatter',
      values: labels,
      text: 'Similar windows',
      marker: {
        backgroundColor: '#b1a343'
      },
      zIndex: 20,
    });
    this.series = newSeries;
168
169
  }
}