overview-window.component.ts 4.37 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: {
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
42
43
44
45
46
        height: " 30px",
        'auto-fit': true
      },
      "plotarea": {
        "margin-top": "10px"
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
47
48
49
50
51
      },
      'scale-x': {
        zooming: true,
        zoomTo: [0, this.service.windowSize],
        'auto-fit': true
52
      },
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
53
      'scale-y': {
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
54
        // zooming: true,
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
55
        'auto-fit': true
56
      },
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
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
82
83
84
85
      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,
        }]
86
    };
87
    console.log("showing plot");
88
89
90
  }

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

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

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

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

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