progress-view.component.ts 3.27 KB
Newer Older
1
2
3
4
5
6
7
8
9
import { Component, OnInit } from '@angular/core';
import {CacheService} from '../cache.service';

@Component({
  selector: 'app-progress-view',
  templateUrl: './progress-view.component.html',
  styleUrls: ['./progress-view.component.css']
})
export class ProgressViewComponent implements OnInit {
10
  public plot;
11
12
  public data;
  public layout;
13
14
15
16

  constructor(private cache: CacheService) { }

  ngOnInit(): void {
17
    this.cache.onNewSimilarity.subscribe(() => { this.initializeInfo(); });
18
19
  }

Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
20
  averagePlot(averages) {
21
    let highest = 100;
22
23
    let data = averages.map((average, i) => {
      if (average.average.length !== 0 && i < highest) {
24
25
        highest = i;
      }
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
      return [
        {
          x: [...Array(average.average.length).keys()],
          y: average.average,
          type: 'line',
          visible: i === highest,
        },
        {
          x: [...Array(average.average.length).keys()],
          y: average.max,
          type: 'scatter',
          visible: i === highest,
          fill: null,
          mode: 'lines',
          line: {
            color: 'rgb(55, 128, 191)',
            width: 3
          }
          },
        {
          x: [...Array(average.average.length).keys()],
          y: average.min,
          type: 'scatter',
          visible: i === highest,
          fill: 'tonexty',
          mode: 'lines',
          line: {
            color: 'rgb(55, 128, 191)',
            width: 3
          }
          },
      ];
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
58
    });
59
60
    data = [].concat(...data);
    const visibility = Array(averages.length * 3).fill(false);
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
61
62
63
    const steps = [];
    for (let i = averages.length - 1; i >= 0; i--) {
      const v = visibility.slice();
64
65
66
      v[i * 3 + 2] = true;
      v[i * 3 + 1] = true;
      v[i * 3] = true;
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
67
68
69
70
71
72
      steps.push({
        label: (100 * (averages.length - i) / averages.length).toString() + '%',
        method: 'restyle',
        args: ['visible', v]
      });
    }
73
74
    // console.log(averages.length - 1 - highest);
    // visibility[averages.length - 1 - highest] = true;
75
76
77
78
79
80
81
82
83
84
    this.data = data;
    this.layout = {
      showlegend: false,
      hovermode: 'closest',
      autosize: true,
      margin: {
        l: 50,
        r: 30,
        t: 30,
        pad: 4
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
85
      },
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
      xaxis: {
        showticklabels: false
      },
      yaxis: {
        showticklabels: false
      },
      height: 300,
      width: 200,
      sliders: [{
        active: averages.length - 1 - highest,
        pad: {t: 30},
        currentvalue: {
          xanchor: 'right',
          prefix: 'Similarity: ',
          font: {
            color: '#888',
            size: 10
          }
        },
        steps
      }]
107
108
109
110
    };
  }

  async initializeInfo(): Promise<void> {
111
    console.log('Updating progress view');
112
    const allWindows = [];
113
114
115
116
117
118
119
    const keys = Object.keys(this.similarity);
    for (let i = this.cache.nrOfTables; i >= 1; i--) {
      if (keys.indexOf(i.toString()) === -1) {
        allWindows.push([]);
      } else {
        allWindows.push(this.similarity[i.toString()]);
      }
120
    }
121
    const averages = await this.cache.getAverageProgressWindows(allWindows);
122
    this.plot = this.averagePlot(averages);
123
124
125
126
127
  }

  public get similarity() {
    return this.cache.windowSimilarity;
  }
128
129
130
131

  public setSliderValue(v) {
    this.cache.sliderValue = v.slider.active;
  }
132
}