From e8ffce85cce1ef8fa04e640873e5a836f7a1d96f Mon Sep 17 00:00:00 2001 From: Brandon Clayton <bclayton@usgs.gov> Date: Wed, 13 Nov 2024 11:24:19 -0700 Subject: [PATCH] add default plots --- .../models/state.model.ts | 3 + .../services/app.service.ts | 64 +++++++++++++++++++ 2 files changed, 67 insertions(+) diff --git a/projects/nshmp-apps/src/app/ncm/geophysical-profiles/models/state.model.ts b/projects/nshmp-apps/src/app/ncm/geophysical-profiles/models/state.model.ts index c6ab8ee5c..74edde16d 100644 --- a/projects/nshmp-apps/src/app/ncm/geophysical-profiles/models/state.model.ts +++ b/projects/nshmp-apps/src/app/ncm/geophysical-profiles/models/state.model.ts @@ -4,7 +4,10 @@ import { GeophysicalUsage, } from '@ghsc/nshmp-utils-ts/libs/ncm/geophysical'; +import {Plots} from './plots.model'; + export interface AppState { + plots: Plots; serviceCallInfo: ServiceCallInfo; serviceResponse: GeophysicalResponse; usageResponse: GeophysicalUsage; diff --git a/projects/nshmp-apps/src/app/ncm/geophysical-profiles/services/app.service.ts b/projects/nshmp-apps/src/app/ncm/geophysical-profiles/services/app.service.ts index ba6f7e142..3941933af 100644 --- a/projects/nshmp-apps/src/app/ncm/geophysical-profiles/services/app.service.ts +++ b/projects/nshmp-apps/src/app/ncm/geophysical-profiles/services/app.service.ts @@ -5,6 +5,11 @@ import { ServiceCallInfo, SpinnerService, } from '@ghsc/nshmp-lib-ng/nshmp'; +import { + DefaultPlotOptions, + NshmpPlot, + plotUtils, +} from '@ghsc/nshmp-lib-ng/plot'; import {GeophysicalUsage} from '@ghsc/nshmp-utils-ts/libs/ncm/geophysical'; import deepEqual from 'deep-equal'; import {environment} from 'projects/nshmp-apps/src/environments/environment'; @@ -13,6 +18,7 @@ import {SharedService} from 'projects/nshmp-apps/src/shared/services/shared.serv import {catchError} from 'rxjs'; import {ControlForm} from '../models/control-form.model'; +import {Plots} from '../models/plots.model'; import {AppState} from '../models/state.model'; /** @@ -43,6 +49,13 @@ export class AppService this.addValidators(); } + /** + * Returns the plots. + */ + get plots(): Signal<Plots> { + return computed(() => this.state().plots); + } + /** * Returns the service call info. */ @@ -87,6 +100,43 @@ export class AppService }; } + defaultPlots(): Plots { + const xLabel = 'Depth (meters)'; + + return { + density: this.defaultPlot({ + id: 'density', + title: 'Density Profile', + xLabel, + yLabel: 'Density Profile (kg/m3)', + }), + porosity: this.defaultPlot({ + id: 'porosity', + title: 'Porosity Profile', + xLabel, + yLabel: 'Porosity Profile', + }), + temperature: this.defaultPlot({ + id: 'temperature', + title: 'Temperature Profile', + xLabel, + yLabel: 'Temperature Profile (°C)', + }), + vp: this.defaultPlot({ + id: 'p-wave', + title: 'P-wave Profile', + xLabel, + yLabel: 'P-wave Profile (m/s)', + }), + vs: this.defaultPlot({ + id: 's-wave', + title: 'S-wave Profile', + xLabel, + yLabel: 'S-wave Profile (m/s)', + }), + }; + } + init(): void { const spinnerRef = this.spinnerService.show( SpinnerService.MESSAGE_METADATA @@ -115,6 +165,7 @@ export class AppService initialState(): AppState { return { + plots: this.defaultPlots(), serviceCallInfo: { serviceCalls: [], serviceName: 'Geophysical profiles', @@ -150,6 +201,19 @@ export class AppService } } + private defaultPlot(options: DefaultPlotOptions): NshmpPlot { + const plotData = plotUtils.defaultPlot(options); + + return { + label: options.title, + plotData, + settingsForm: plotUtils.plotSettingsToFormGroup({ + config: plotData.config, + layout: plotUtils.plotlyLayoutToSettings(plotData.layout), + }), + }; + } + private resetState(): void { this.updateState({ serviceCallInfo: { -- GitLab