import { Component, OnInit } from '@angular/core'; import {StateService} from '../state.service'; @Component({ selector: 'app-labeling-window', templateUrl: './labeling-window.component.html', styleUrls: ['./labeling-window.component.css'] }) export class LabelingWindowComponent implements OnInit { public topk: number[]; public subplots = []; public labels: boolean[] = []; private k = 12; constructor(private state: StateService) { } ngOnInit(): void { this.state.onNewTable.subscribe(() => this.showSamples()); } async train() { this.state.labels = Object.assign({}, this.state.labels, this.labels); await this.state.getQueryWindow(this.state.labels); await this.state.update(); } async updateQuery() { this.state.labels = Object.assign({}, this.state.labels, this.labels); await this.state.getQueryWindow(this.state.labels); } public labelCorrect(index: number) { this.labels[index] = true; } public labelUndefined(index: number) { if (this.labels[index] !== undefined) { delete this.labels[index]; } } public labelIncorrect(index: number) { this.labels[index] = false; } async showSamples() { this.topk = this.state.lshData.candidates.slice(0, this.k); this.subplots = []; const values = await this.state.getWindow(this.topk); this.topk.forEach((index, i) => { this.subplots.push( { index, data: [{ x: [...Array(values[i].length).keys()], y: values[i], type: 'line' }], layout: { title: `Index: ${index.toString()}`, hovermode: 'closest', autosize: true, margin: { l: 30, r: 30, t: 30, b: 0, pad: 4 }, height: 150, width: 300, titlefont: { size: 9 }, xaxis: { showgrid: false, zeroline: false, showticklabels: false, }, yaxis: { zeroline: false, showticklabels: false, } } } ); }); } public get show() { return !!this.state.lshData; } }