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

@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
10
11
12
export class OverviewWindowComponent {
  public config;
  public series;
13
  public showPlot = false;
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
14
  public id = "overview";
15
16
17
18

  public data;
  public layout;

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

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

  async initializePlot() {
34
    this.service.query = undefined;
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
35
36
37
38
39
40
41
42
43
44
    // 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
45
46
47
48
49
        height: " 30px",
        'auto-fit': true
      },
      "plotarea": {
        "margin-top": "10px"
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
50
51
52
53
54
      },
      'scale-x': {
        zooming: true,
        zoomTo: [0, this.service.windowSize],
        'auto-fit': true
55
      },
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
56
      'scale-y': {
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
57
        // zooming: true,
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
58
        'auto-fit': true
59
      },
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
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
87
88
      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,
        }]
89
    };
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
90
91
92
93
94
95
96
97
98
99
100
101
102
    // zingchart.render({
    //   id: 'overview',
    //   data: this.config,
    //   height: 200,
    //   width: '100%'
    // });
    // zingchart.bind('overview', 'click', (e) => {
    //   const xyInformation = zingchart.exec('overview', 'getxyinfo', {
    //     x: e.x,
    //     y: e.y
    //   });
    //   this.clicked({nodeindex: xyInformation[2].nodeidx});
    // });
103
    console.log("showing plot");
104
105
106
  }

  async clicked(clickData) {
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
107
108
109
110
111
112
113
114
    if (!this.service.querySelectionMode) {
      return;
    }
    this.service.querySelectionMode = false;
    const xyInformation = zingchart.exec("zingchart-ng-1", 'getxyinfo', {
      x: clickData.x,
      y: clickData.y
    });
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
115
    console.log('clicked node');
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
116
117
    console.log(xyInformation);
    const index = Math.floor(xyInformation[2].nodeidx / this.service.stepSize);
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
118
119
120
121
    this.service.query = index;
    const temp = {};
    temp[index] = true;
    this.service.labels = temp;
122
123
124
125
    await this.updatePlot();
  }

  async updatePlot() {
126
127
128
    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
129
130
    let goodLabels = [];
    let badLabels = [];
131
    for (const index in this.service.labels) {
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
132
133
134
135
136
      if (this.service.labels[index]) {
        goodLabels.push(this.data[index]);
      } else {
        badLabels.push(this.data[index]);
      }
137
    }
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
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
    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,
      }
    ];
168
169
  }

170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
  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;
192
  }
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
193
194
195
196
197
198
199
200
201

  zoom(p) {
    if (p.ev.wheelDelta > 0) {
      zingchart.exec("zingchart-ng-1", 'zoomin');
    } else if (p.ev.wheelDelta < 0) {
      zingchart.exec("zingchart-ng-1", 'zoomout');
    }
    console.log(p);
  }
202
}