From 32363165eada8fdfa450bdbb41b91195c8d3d713 Mon Sep 17 00:00:00 2001 From: phil Date: Thu, 14 Mar 2024 17:02:30 +0530 Subject: [PATCH] Update/fix plot params --- src/app/info/info-data.service.ts | 72 +++++++++++++----------- src/app/info/info-plot/plot.component.ts | 19 ++++--- src/app/openapi/models/PlotParams.ts | 6 +- 3 files changed, 51 insertions(+), 46 deletions(-) diff --git a/src/app/info/info-data.service.ts b/src/app/info/info-data.service.ts index b597e29..8e3efe5 100644 --- a/src/app/info/info-data.service.ts +++ b/src/app/info/info-data.service.ts @@ -12,7 +12,7 @@ import { Tag, TagAction } from './info-tags/tags.service' import { ConfigService } from '../config.service' import { DataService } from '../_services/data.service' -import { ApiService, ModelInfo, FeatureInfo } from '../openapi' +import { ApiService, ModelInfo, FeatureInfo, PlotParams } from '../openapi' // const getModelInfoQuery = gql` // query modelInfo ($store: String!) { @@ -346,37 +346,35 @@ export class LegendItem { // } // } -export class PlotBaseLine { - constructor( - public name: string, - public value: number, - public color: string, - ) {} -} +// export class PlotBaseLine { +// constructor( +// public name: string, +// public value: number, +// public color: string, +// ) {} +// } -export class PlotBgShape { - constructor( - public name: string, - public valueTop: number, - public valueBottom: number, - public color: string, - ) {} -} +// export class PlotBgShape { +// constructor( +// public name: string, +// public valueTop: number, +// public valueBottom: number, +// public color: string, +// ) {} +// } -export class PlotParams { - constructor( - public baseLines: PlotBaseLine[] = [], - public bgShapes: PlotBgShape[] = [], - public barBase?: number - ) {} -} +// export class PlotParams { +// constructor( +// public baseLines: PlotBaseLine[] = [], +// public bgShapes: PlotBgShape[] = [], +// public barBase?: number +// ) {} +// } -export class PlotDataParams { - constructor( - public data: Object, - public comment: string, - public params: PlotParams, - ) {} +export type PlotDataParams = { + data: Object[], + comment: string, + params: PlotParams } export class InfoItem { @@ -547,15 +545,21 @@ export class InfoDataService { this.dataService.getValues(store, +id, value, resampling), this.getPlotParams(store, id, value), ]).pipe(map( - res => new PlotDataParams( - res[0].body, - res[0].headers['comment'], - res[1], - ) + res => { return { + data: JSON.parse(res[0][0]), + // comment: res[0].headers['comment'], + comment: res[0][1], + params: res[1], + }} )) } getPlotParams(store: string, id: string, value: string): Observable { + return this.api.getPlotParamsApiPlotParamsStoreGet({ + 'store': store, + 'id': id, + 'value': value + }) console.warn('Migrate Graphql') return observableOf() // return this.apollo.query({ diff --git a/src/app/info/info-plot/plot.component.ts b/src/app/info/info-plot/plot.component.ts index f4dfc65..a33c463 100644 --- a/src/app/info/info-plot/plot.component.ts +++ b/src/app/info/info-plot/plot.component.ts @@ -1,5 +1,6 @@ import { Component, OnInit, ViewChild, Input, AfterViewInit, ChangeDetectionStrategy, ChangeDetectorRef } from '@angular/core' +import { MatSlideToggle } from '@angular/material/slide-toggle' import { Observable, of } from 'rxjs' import { map, catchError } from 'rxjs/operators' @@ -10,8 +11,8 @@ import { MatSnackBar } from '@angular/material/snack-bar' import { PlotlyComponent, PlotlyService } from 'angular-plotly.js' import { DataService } from '../../_services/data.service' -import { FullInfo, InfoDataService, PlotDataParams, PlotParams } from '../info-data.service' -import { MatSlideToggle } from '@angular/material/slide-toggle' +import { FullInfo, InfoDataService, PlotDataParams } from '../info-data.service' +import { PlotParams } from '../../openapi' @Component({ selector: 'gisaf-info-plot', @@ -175,7 +176,7 @@ export class InfoPlotComponent implements OnInit, AfterViewInit { ) } - createPlot(data: any, plotParams?: PlotParams) { + createPlot(data: Object[], plotParams?: PlotParams) { // Kept compatibility with previous API const values = data.map(d => d[this.value]) this.plotData = [] @@ -197,7 +198,7 @@ export class InfoPlotComponent implements OnInit, AfterViewInit { } }, } - if (plotParams.barBase) { + if (plotParams?.barBase) { plotData['base'] = plotParams.barBase // Adjust the height of the bars plotData['y'] = plotData['y'].map(v => v - plotParams.barBase) @@ -206,7 +207,7 @@ export class InfoPlotComponent implements OnInit, AfterViewInit { // Add plot "decorations" found in plotParams //const xRange = [data[0].time, data[data.length-1].time] - plotParams.baseLines.forEach( + plotParams?.baseLines.forEach( bl => { this.plotData.push({ x: this.xRange, @@ -221,7 +222,7 @@ export class InfoPlotComponent implements OnInit, AfterViewInit { }) } ) - this.plotLayout['shapes'] = plotParams.bgShapes.map( + this.plotLayout['shapes'] = plotParams?.bgShapes.map( shape => { return { type: 'rect', @@ -241,7 +242,7 @@ export class InfoPlotComponent implements OnInit, AfterViewInit { } ) // Fake plot, just to add legend entries - plotParams.bgShapes.forEach( + plotParams?.bgShapes.forEach( bl => { this.plotData.push({ x: [0], @@ -263,12 +264,12 @@ export class InfoPlotComponent implements OnInit, AfterViewInit { // Give some space around min and max values this.minY = Math.min.apply(Math, values) this.minEY = Math.min( - Math.min.apply(Math, plotParams.baseLines.map(bl => bl.value)), + Math.min.apply(Math, plotParams?.baseLines.map(bl => bl.value)), this.minY ) this.maxY = Math.max.apply(Math, values) this.maxEY = Math.max( - Math.max.apply(Math, plotParams.baseLines.map(bl => bl.value)), + Math.max.apply(Math, plotParams?.baseLines.map(bl => bl.value)), this.maxY ) this.borderY = (this.maxY - this.minY) * this.marginRatio diff --git a/src/app/openapi/models/PlotParams.ts b/src/app/openapi/models/PlotParams.ts index 66bfe07..a149d0e 100644 --- a/src/app/openapi/models/PlotParams.ts +++ b/src/app/openapi/models/PlotParams.ts @@ -5,8 +5,8 @@ import type { PlotBaseLine } from './PlotBaseLine'; import type { PlotBgShape } from './PlotBgShape'; export type PlotParams = { - baseLines: Array; - bgShape: Array; - barBase: number; + baseLines?: Array; + bgShapes?: Array; + barBase?: (number | null); };