overview-window.component.ts 4.49 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
21
22

  async ngOnInit(): Promise<void> {
    this.service.onNewWindows.subscribe(() => { this.initializePlot(); });
    this.service.onNewTables.subscribe(() => {
23
      if (this.service.query) {
24
25
26
27
28
29
        this.updatePlot();
      }
    });
  }

  async initializePlot() {
30
    this.service.query = undefined;
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
    // 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: {
        'auto-fit': true,
        handleTop: {
          alpha	: 0.0
        },
        handleBottom: {
          alpha	: 0.0
        }
      },
      '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
55
56
      'scale-y': {
        zooming: true,
        '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
102
103
104
105
    await this.updatePlot();
  }

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

106
    // Similarity
107
    const windowSimilarity = await this.service.getSimilarWindows(this.service.windows[this.service.query]);
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
108
109
110
111
112
113
114
115
116
117
    console.log(windowSimilarity);
    // 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 = [];
118
    for (const index in this.service.labels) {
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
119
120
121
122
123
124
      console.log(index);
      if (this.service.labels[index]) {
        goodLabels.push(this.data[index]);
      } else {
        badLabels.push(this.data[index]);
      }
125
    }
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
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
    console.log(goodLabels);
    console.log(badLabels);
    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;
169

Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
170
171
172
    // this.data[0].marker.color = colors;
    // this.data[0].marker.size = sizes;
    // this.data[0].marker.opacity = opacity;
173
174
175
176
177
178
179
180
181
182
  }

  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%)`;
  }
}