import { Component} from '@angular/core'; import { CacheService } from '../cache.service'; @Component({ selector: 'app-overview-window', templateUrl: './overview-window.component.html', styleUrls: ['./overview-window.component.css'] }) export class OverviewWindowComponent { public config; public series; public showPlot = false; public data; public layout; constructor(private service: CacheService) { } async ngOnInit(): Promise { this.service.onNewData.subscribe(() => this.initializePlot()); this.service.onNewWindows.subscribe(() => { }); this.service.onNewTables.subscribe(() => { if (this.service.query) { this.updatePlot(); } }); } async initializePlot() { this.service.query = undefined; // this.data = this.service.rawIndices.map((e, i) => { // return [e, values[i]]; // }); this.data = []; for (let i = 0; i < this.service.rawValues.length; i++) { this.data.push([i, this.service.rawValues[i]]); } this.config = { type: "mixed", preview: { // 'auto-fit': true }, 'scale-x': { zooming: true, zoomTo: [0, this.service.windowSize], 'auto-fit': true }, 'scale-y': { zooming: true, 'auto-fit': true }, series: [ { type: 'line', values: this.data, text: 'Raw Values', zIndex: 5, marker: { alpha: 0.0, zIndex: 10 } }, { type: 'scatter', values: [], text: 'Good labels', marker: { backgroundColor: '#4caf50' }, zIndex: 20, }, { type: 'scatter', values: [], text: 'Bad labels', marker: { backgroundColor: '#f44336' }, zIndex: 20, }] }; console.log("showing plot"); } async clicked(clickData) { console.log('clicked node'); const index = Math.floor(clickData.nodeindex / this.service.stepSize); this.service.query = index; const temp = {}; temp[index] = 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.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); // } // } let goodLabels = []; let badLabels = []; for (const index in this.service.labels) { if (this.service.labels[index]) { goodLabels.push(this.data[index]); } else { badLabels.push(this.data[index]); } } this.series = [ { type: 'line', values: this.data, text: 'Raw Values', zIndex: 5, marker: { alpha: 0.0, zIndex: 10 } }, { type: 'scatter', values: goodLabels, text: 'Good labels', marker: { backgroundColor: '#4caf50' }, zIndex: 20, }, { type: 'scatter', values: badLabels, text: 'Bad labels', marker: { backgroundColor: '#f44336' }, zIndex: 20, } ]; // // 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%)`; } }