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; constructor(private cache: CacheService) { } ngOnInit(): void { this.cache.onNewSimilarity.subscribe(() => { this.initializeInfo(); }); } averagePlot(averages) { const data = averages.map((average, i) => { return { x: [...Array(average.length).keys()], y: average, type: 'line', 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, layout: { showlegend: false, hovermode: 'closest', autosize: true, margin: { l: 50, r: 30, t: 30, pad: 4 }, xaxis: { showticklabels: false }, yaxis: { showticklabels: false }, height: 300, width: 200, sliders: [{ active: averages.length - 1, pad: {t: 30}, currentvalue: { xanchor: 'right', prefix: 'Similarity: ', font: { color: '#888', size: 10 } }, steps }] }, }; } async initializeInfo(): Promise { const keys = Object.keys(this.similarity).map(a => Number(a)).sort((a, b) => b - a); const allWindows = []; for (const key of keys) { allWindows.push(this.similarity[key]); } const averages = await this.cache.getAverageWindow(allWindows); this.plot = this.averagePlot(averages); } public get similarity() { return this.cache.windowSimilarity; } public setSliderValue(v) { this.cache.sliderValue = v.slider.active; } }