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 { public plot; public data; public layout; public amountOfCandidates; private _sliderValue; constructor(private cache: CacheService) { } ngOnInit(): void { this.cache.onNewSimilarity.subscribe(() => { this.initializeInfo(); }); } averagePlot(averages) { console.log(averages); let highest = 0; averages.map((average, i) => { if (average.average.length !== 0 && i > highest) { highest = i; } }); let data = averages.map((average, i) => { return [ { x: [...Array(average.average.length).keys()], y: average.average, type: 'line', visible: i === highest, line: { color: 'red', width: 3 } }, { 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 } }, ]; }); data = [].concat(...data); const visibility = Array(averages.length * 3).fill(false); const steps = []; for (let i = 0; i < this.cache.nrOfTables; i++) { const v = visibility.slice(); v[i * 3 + 2] = true; v[i * 3 + 1] = true; v[i * 3] = true; steps.push({ label: (100 * (i + 1) / this.cache.nrOfTables).toString() + '%', method: 'restyle', args: ['visible', v] }); } this._sliderValue = highest; this.data = data; this.layout = { showlegend: false, hovermode: 'closest', autosize: true, margin: { l: 50, r: 30, t: 30, pad: 4 }, xaxis: { showgrid: false, zeroline: false, showticklabels: false, }, yaxis: { zeroline: false, showticklabels: false, }, height: 300, width: 200, sliders: [{ active: highest, pad: {t: 30}, currentvalue: { xanchor: 'right', prefix: 'Similarity: ', font: { color: '#888', size: 10 } }, steps }] }; } async initializeInfo(): Promise { console.log('Updating progress view'); console.log(this.similarity); const allWindows = []; 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()]); } } const averages = await this.cache.getAverageProgressWindows(allWindows); this.plot = this.averagePlot(averages); let candidates = []; for (let i = this._sliderValue; i < this.cache.nrOfTables; i++) { candidates = candidates.concat(this.cache.windowSimilarity[i.toString()]); } this.amountOfCandidates = candidates.length; } public get similarity() { return this.cache.windowSimilarity; } public setSliderValue(v) { this._sliderValue = v.slider.active; let candidates = []; for (let i = this._sliderValue; i < this.cache.nrOfTables; i++) { candidates = candidates.concat(this.cache.windowSimilarity[i.toString()]); } this.amountOfCandidates = candidates.length; } public showCandidates() { this.cache.sliderValue = this._sliderValue; } }