progress-view.component.ts 2.35 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
13
14

  constructor(private cache: CacheService) { }

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

Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
18
19
20
  averagePlot(averages) {
    const data = averages.map((average, i) => {
      return {
21
22
23
        x: [...Array(average.length).keys()],
        y: average,
        type: 'line',
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
        visible: i === 0
      };
    });
    const visibility = Array(averages.length).fill(false);
    const steps = [];
    for (let i = averages.length - 1; i >= 0; i--) {
      const v = visibility.slice();
      v[i] = true;
      steps.push({
        label: (100 * (averages.length - i) / averages.length).toString() + '%',
        method: 'restyle',
        args: ['visible', v]
      });
    }
    visibility[averages.length - 1] = true;
    return {
      data,
41
      layout: {
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
42
        showlegend: false,
43
44
45
        hovermode: 'closest',
        autosize: true,
        margin: {
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
46
47
48
          l: 50,
          r: 30,
          t: 30,
49
50
51
52
53
54
55
56
          pad: 4
        },
        xaxis: {
          showticklabels: false
        },
        yaxis: {
          showticklabels: false
        },
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
        height: 300,
        width: 200,
        sliders: [{
          active: averages.length - 1,
          pad: {t: 30},
          currentvalue: {
            xanchor: 'right',
            prefix: 'Similarity: ',
            font: {
              color: '#888',
              size: 10
            }
          },
          steps
        }]
      },
73
74
75
76
77
    };
  }

  async initializeInfo(): Promise<void> {
    const allWindows = [];
78
79
80
81
82
83
84
    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()]);
      }
85
    }
86
    const averages = await this.cache.getAverageProgressWindows(allWindows);
87
    this.plot = this.averagePlot(averages);
88
89
90
91
92
  }

  public get similarity() {
    return this.cache.windowSimilarity;
  }
93
94
95
96

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