| import { Injectable } from '@angular/core'; |
| import { Node } from '../../navigator/node'; |
| import { Subject } from 'rxjs'; |
| import { MeasuredValues, ChartData, ChartXyDataSet, ChartPoint } from '../model/chartviewer.model'; |
| import { getDataArray } from './chart-viewer-data.service'; |
| import { zip } from 'rxjs/operators'; |
| |
| @Injectable({ |
| providedIn: 'root' |
| }) |
| export class ChartViewerService { |
| |
| private nodeMetaSubject = new Subject<Node>(); |
| |
| constructor() {} |
| |
| public sendNodeMeta(nodeMeta: Node) { |
| this.nodeMetaSubject.next(nodeMeta); |
| } |
| |
| public onNodeMetaChange() { |
| return this.nodeMetaSubject.asObservable(); |
| } |
| |
| public toXyDataSet(xData: number[], yData: MeasuredValues) { |
| const yValues = getDataArray(yData).values as number[]; |
| const points = this.getDataPoints(xData, yValues); |
| const dataset = new ChartXyDataSet(yData.name, points); |
| return dataset; |
| } |
| |
| private getDataPoints(xData: number[], yData: number[], startIndex = 0) { |
| if (xData != undefined && xData.length <= yData.length) { |
| return xData.map((x, i) => new ChartPoint(x, yData[i])); |
| } else if (xData != undefined && xData.length > yData.length) { |
| return yData.map((y, i) => new ChartPoint(xData[i], y)); |
| } |
| } |
| } |