import {Component, OnInit, ViewChild} from '@angular/core'; import {StateService} from '../state.service'; import * as d3 from 'd3'; import {TableInfoData} from '../api.service'; @Component({ selector: 'app-progress-view', templateUrl: './progress-view.component.html', styleUrls: ['./progress-view.component.css'] }) export class ProgressViewComponent implements OnInit { @ViewChild('chart') chart; public plot; public data; public layout; public hist; public amountOfCandidates; public hover = 0; private _sliderValue = 0; constructor(private state: StateService) { } ngOnInit(): void { this.state.onNewLshData.subscribe(() => { this.showgraph(); this.showHistogram(); }); } showHistogram() { const table = this.state.lshData.average_table; this.hist = { data: [{ x: Object.keys(table), y: Object.values(table).map((values: number[]) => values.length), // / (this.service.rawValues.length - this.service.windowSize)), type: 'bar', opacity: 0.5, marker: { color: Object.keys(table).map((key) => { return this.getColor(Number(key) / Number(Object.keys(table)[Object.keys(table).length - 1])); }), line: { color: 'black', width: 0, } } }], layout: { hovermode: 'closest', autosize: true, margin: { l: 10, r: 10, t: 10, b: 10, pad: 4 }, xaxis: { showticklabels: false }, yaxis: { showticklabels: false }, height: 200, width: 400, } }; } onHover(data) { console.log(data); this.setSliderValue({value: data.points[0].x}); } hoverPlot(averages) { const subplots = []; this.data = averages.map((prototype) => { const channelData = []; prototype.max.forEach((channel, index) => { channelData.push({ x: [...Array(channel.length).keys()], y: channel, xaxis: 'x', yaxis: `y${index + 2}`, type: 'scatter', fill: null, mode: 'lines', line: { color: 'rgb(55, 128, 191)', width: 3 } }); }); prototype.min.forEach((channel, index) => { channelData.push({ x: [...Array(channel.length).keys()], y: channel, xaxis: 'x', yaxis: `y${index + 2}`, type: 'scatter', fill: 'tonexty', mode: 'lines', line: { color: 'rgb(55, 128, 191)', width: 3 } }); }); prototype.average.forEach((channel, index) => { channelData.push({ x: [...Array(channel.length).keys()], y: channel, xaxis: 'x', yaxis: `y${index + 2}`, type: 'line', line: { color: 'red', width: 3 } }); }); return channelData; }); for (let index = 0; index < this.state.queryWindow.length; index++) { subplots.push([`xy${index + 2}`]); } this.layout = { grid: { rows: this.state.queryWindow.length, columns: 1, subplots: subplots, }, 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: 350, width: 400, }; this.state.queryWindow.forEach((channel: number[], index: number) => { this.layout[`yaxis${index + 2}`] = { zeroline: false, showticklabels: false, }; }); } public setSliderValue(v) { this._sliderValue = v.value; d3.selectAll('circle').transition().style('stroke', undefined); d3.select('#node-' + v.value).transition().style('stroke', 'black').style('stroke-width', 20); const data = this.hist; data.data[0].marker.line.width = Object.keys(this.state.lshData.average_table).map((key) => { return Number(key) === v.value ? 4 : 0; }); this.hist = data; } public get sliderValue(): number { return this._sliderValue; } public get maxLength(): number { return Object.keys(this.table).length - 1; } public get table() { return this.state.lshData.average_table; } async showgraph() { const tableInfo: TableInfoData = await this.state.getTableInfo(Object.values(this.state.lshData.average_table)); this.hoverPlot(tableInfo.prototypes); const distances = tableInfo.distances; } getColor(value) { const hue=((1-value)*120).toString(10); return ["hsl(",hue,",100%,50%)"].join(""); } }