overview-window.component.ts 4.29 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
28
29
30
        this.updatePlot();
      }
    });
  }

  async initializePlot() {
31
    this.service.query = undefined;
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
32
33
34
35
36
37
38
39
40
41
    // 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: {
42
        // 'auto-fit': true
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
43
44
45
46
47
      },
      'scale-x': {
        zooming: true,
        zoomTo: [0, this.service.windowSize],
        'auto-fit': true
48
      },
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
49
50
51
      'scale-y': {
        zooming: true,
        'auto-fit': true
52
      },
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
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
      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,
        }]
82
    };
83
    console.log("showing plot");
84
85
86
  }

  async clicked(clickData) {
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
87
88
89
90
91
92
    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;
93
94
95
96
97
98
99
100
    await this.updatePlot();
  }

  async updatePlot() {
    const colors: string[] = [];
    const sizes: number[]  = [];
    const opacity: number[]  = [];

101
    // Similarity
102
    const windowSimilarity = await this.service.getSimilarWindows(this.service.query);
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
103
104
105
106
107
108
109
110
111
    // for (const frequency in windowSimilarity){
    //   for (const index of windowSimilarity[frequency]) {
    //     colors[index] = this.getColor(Number(frequency) / this.service.nrOfTables);
    //     sizes[index] = 5;
    //     opacity[index] = Math.max(Number(frequency) / this.service.nrOfTables, 0.5);
    //   }
    // }
    let goodLabels = [];
    let badLabels = [];
112
    for (const index in this.service.labels) {
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
113
114
115
116
117
      if (this.service.labels[index]) {
        goodLabels.push(this.data[index]);
      } else {
        badLabels.push(this.data[index]);
      }
118
    }
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
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
    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,
      }
    ];
    //   // Labeled
    // for (const index in this.service.labels) {
    //   colors[Number(index)] = this.service.labels[index] ? '#4caf50' : '#f44336';
    //   sizes[Number(index)] = 10;
    //   opacity[Number(index)] = 1;
    // }
    //
    // // Query
    // colors[this.service.query] = '#cf00ff';
    // sizes[this.service.query] = 10;
    // opacity[this.service.query] = 1;
160

Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
161
162
163
    // this.data[0].marker.color = colors;
    // this.data[0].marker.size = sizes;
    // this.data[0].marker.opacity = opacity;
164
165
166
167
168
169
170
171
172
173
  }

  public getColor(value: number) {
    // value from 0 to 1
    const hueValue = Math.min((1 - value) , 1);
    const hue = ((1 - hueValue) * 120).toString(10);
    const sat = value * 100;
    return `hsl(${hue}, ${sat}%, 50%)`;
  }
}