import {ChangeDetectorRef, Component, OnInit} from '@angular/core'; import { CacheService } from '../cache.service'; import {throwError} from 'rxjs'; @Component({ selector: 'app-overview-window', templateUrl: './overview-window.component.html', styleUrls: ['./overview-window.component.css'] }) export class OverviewWindowComponent implements OnInit { public defaultColors: string[]; public defaultSizes: number[]; public defaultOpacity: number[]; public showPlot = false; public data; public layout; constructor(private service: CacheService) { } async ngOnInit(): Promise { this.service.onNewWindows.subscribe(() => { this.initializePlot(); }); this.service.onNewTables.subscribe(() => { if (this.service.query) { this.updatePlot(); } }); } async initializePlot() { this.service.query = undefined; const size = this.service.rawValues.length; this.defaultColors = Array(size).fill('#a3a7e4'); this.defaultSizes = Array(size).fill(5); this.defaultOpacity = Array(size).fill(1); this.data = [{ x: this.service.rawIndices, y: this.service.rawValues, type: 'scattergl', mode: 'markers', marker: { size: this.defaultSizes.slice(), color: this.defaultColors.slice()} }]; this.layout = { hovermode: 'closest', autosize: true, margin: { l: 40, r: 0, b: 40, t: 0, pad: 4 }, height: 200, xaxis: { showticklabels: false, // rangeslider: {} }, }; this.showPlot = true; console.log("showing plot"); } async clicked(clickData) { for (const point of clickData.points) { this.service.query = point.pointNumber; const temp = {}; temp[point.pointNumber] = true; this.service.labels = temp; } await this.updatePlot(); } async updatePlot() { const colors: string[] = []; const sizes: number[] = []; const opacity: number[] = []; // Similarity const windowSimilarity = await this.service.getSimilarWindows(this.service.windows[this.service.query]); for (const frequency in windowSimilarity){ for (const index of windowSimilarity[frequency]) { colors[index] = this.getColor(Number(frequency) / this.service.nrOfTables); sizes[index] = 5; opacity[index] = Math.max(Number(frequency) / this.service.nrOfTables, 0.5); } } // Labeled for (const index in this.service.labels) { colors[Number(index)] = this.service.labels[index] ? '#4caf50' : '#f44336'; sizes[Number(index)] = 10; opacity[Number(index)] = 1; } // Query colors[this.service.query] = '#cf00ff'; sizes[this.service.query] = 10; opacity[this.service.query] = 1; this.data[0].marker.color = colors; this.data[0].marker.size = sizes; this.data[0].marker.opacity = opacity; } public getColor(value: number) { // value from 0 to 1 const hueValue = Math.min((1 - value) , 1); const hue = ((1 - hueValue) * 120).toString(10); const sat = value * 100; return `hsl(${hue}, ${sat}%, 50%)`; } }