From 76a41ea3d7e0d1c364a619e10c55fb755a9589c5 Mon Sep 17 00:00:00 2001 From: Brandon Clayton <bclayton@usgs.gov> Date: Thu, 7 Nov 2024 14:24:55 -0700 Subject: [PATCH] make default plots public --- .../services/app.service.ts | 103 +++++----- .../app/gmm/distance/services/app.service.ts | 62 +++--- .../app/gmm/magnitude/services/app.service.ts | 146 ++++++------- .../app/gmm/spectra/services/app.service.ts | 176 ++++++++-------- .../app/source/mfd/services/app.service.ts | 193 +++++++++--------- 5 files changed, 340 insertions(+), 340 deletions(-) diff --git a/projects/nshmp-apps/src/app/dev/math/exceedance-explorer/services/app.service.ts b/projects/nshmp-apps/src/app/dev/math/exceedance-explorer/services/app.service.ts index 2787b5439..00d2d501f 100644 --- a/projects/nshmp-apps/src/app/dev/math/exceedance-explorer/services/app.service.ts +++ b/projects/nshmp-apps/src/app/dev/math/exceedance-explorer/services/app.service.ts @@ -34,7 +34,6 @@ export class AppService readonly formGroup = this.formBuilder.group<ControlForm>( this.defaultFormValues() ); - readonly state = signal<AppState>(this.initialState()); constructor(private formBuilder: FormBuilder) { @@ -98,6 +97,57 @@ export class AppService }; } + defaultPlots(): Map<string, NshmpPlot> { + const plots = new Map<string, NshmpPlot>(); + + const plotOptions: PlotOptions = { + layout: { + legend: { + bordercolor: ' #a9aeb1', + borderwidth: 1, + x: 0.01, + y: 0.1, + yanchor: 'bottom', + }, + yaxis: { + range: [0, 1], + tickmode: 'auto', + type: 'linear', + }, + }, + }; + + const plotData = plotUtils.defaultPlot({ + id: 'exceedance-explorer', + mobileOptions: { + ...plotOptions, + layout: { + ...plotOptions.layout, + margin: { + b: 50, + }, + }, + }, + options: {...plotOptions}, + title: 'Exceedance', + xLabel: 'Ground Motion (g)', + yLabel: 'Annual Frequency of Exceedence', + }); + + const settingsForm: NshmpPlotSettings = { + config: plotData.config, + layout: plotUtils.plotlyLayoutToSettings(plotData.layout), + }; + + plots.set(Plots.EXCEEDANCE, { + label: 'Exceedance', + plotData, + settingsForm: plotUtils.plotSettingsToFormGroup(settingsForm), + }); + + return plots; + } + /** * Exceedance X values for plot. */ @@ -241,55 +291,4 @@ export class AppService y: yValues.map(y => Maths.round(y * values.rate, 4)), }; } - - private defaultPlots(): Map<string, NshmpPlot> { - const plots = new Map<string, NshmpPlot>(); - - const plotOptions: PlotOptions = { - layout: { - legend: { - bordercolor: ' #a9aeb1', - borderwidth: 1, - x: 0.01, - y: 0.1, - yanchor: 'bottom', - }, - yaxis: { - range: [0, 1], - tickmode: 'auto', - type: 'linear', - }, - }, - }; - - const plotData = plotUtils.defaultPlot({ - id: 'exceedance-explorer', - mobileOptions: { - ...plotOptions, - layout: { - ...plotOptions.layout, - margin: { - b: 50, - }, - }, - }, - options: {...plotOptions}, - title: 'Exceedance', - xLabel: 'Ground Motion (g)', - yLabel: 'Annual Frequency of Exceedence', - }); - - const settingsForm: NshmpPlotSettings = { - config: plotData.config, - layout: plotUtils.plotlyLayoutToSettings(plotData.layout), - }; - - plots.set(Plots.EXCEEDANCE, { - label: 'Exceedance', - plotData, - settingsForm: plotUtils.plotSettingsToFormGroup(settingsForm), - }); - - return plots; - } } diff --git a/projects/nshmp-apps/src/app/gmm/distance/services/app.service.ts b/projects/nshmp-apps/src/app/gmm/distance/services/app.service.ts index 28e81a3f0..15e16e663 100644 --- a/projects/nshmp-apps/src/app/gmm/distance/services/app.service.ts +++ b/projects/nshmp-apps/src/app/gmm/distance/services/app.service.ts @@ -206,6 +206,37 @@ export class AppService }; } + /** + * Returns the default plots. + */ + defaultPlots(): Map<string, NshmpPlot> { + const plots = new Map<string, NshmpPlot>(); + + const meansPlotData = plotUtils.defaultPlot({ + id: gmmUtils.PlotType.MEANS, + options: { + layout: { + aspectRatio: gmmUtils.MEAN_ASPECT_RATIO, + }, + }, + title: 'Ground Motion vs. Distance', + xLabel: 'Distance (km)', + yLabel: 'Median ground motion (g)', + }); + + const meansPlotSettingsForm: NshmpPlotSettings = { + config: meansPlotData.config, + layout: plotUtils.plotlyLayoutToSettings(meansPlotData.layout), + }; + plots.set(gmmUtils.PlotType.MEANS, { + label: 'Means', + plotData: meansPlotData, + settingsForm: plotUtils.plotSettingsToFormGroup(meansPlotSettingsForm), + }); + + return new Map(plots); + } + /** * Initialize the application. */ @@ -310,37 +341,6 @@ export class AppService }; } - /** - * Returns the default plots. - */ - private defaultPlots(): Map<string, NshmpPlot> { - const plots = new Map<string, NshmpPlot>(); - - const meansPlotData = plotUtils.defaultPlot({ - id: gmmUtils.PlotType.MEANS, - options: { - layout: { - aspectRatio: gmmUtils.MEAN_ASPECT_RATIO, - }, - }, - title: 'Ground Motion vs. Distance', - xLabel: 'Distance (km)', - yLabel: 'Median ground motion (g)', - }); - - const meansPlotSettingsForm: NshmpPlotSettings = { - config: meansPlotData.config, - layout: plotUtils.plotlyLayoutToSettings(meansPlotData.layout), - }; - plots.set(gmmUtils.PlotType.MEANS, { - label: 'Means', - plotData: meansPlotData, - settingsForm: plotUtils.plotSettingsToFormGroup(meansPlotSettingsForm), - }); - - return new Map(plots); - } - private handleServiceResponses( serviceResponses: GmmDistanceResponse[] ): void { diff --git a/projects/nshmp-apps/src/app/gmm/magnitude/services/app.service.ts b/projects/nshmp-apps/src/app/gmm/magnitude/services/app.service.ts index 2fd233423..3f25429b0 100644 --- a/projects/nshmp-apps/src/app/gmm/magnitude/services/app.service.ts +++ b/projects/nshmp-apps/src/app/gmm/magnitude/services/app.service.ts @@ -217,6 +217,79 @@ export class AppService }; } + /** + * Returns the default plots. + */ + defaultPlots(): Map<string, NshmpPlot> { + const plots = new Map<string, NshmpPlot>(); + + const plotOptions: PlotOptions = { + layout: { + xaxis: { + nticks: 10, + range: [Math.log10(5), Math.log10(8)], + }, + yaxis: { + range: [Math.log10(0.001), Math.log10(3)], + }, + }, + }; + + const meanPlotData = plotUtils.defaultPlot({ + id: gmmUtils.PlotType.MEANS, + mobileOptions: {...plotOptions}, + options: { + ...plotOptions, + layout: { + aspectRatio: gmmUtils.MEAN_ASPECT_RATIO, + ...plotOptions.layout, + }, + }, + title: 'Ground Motion vs. Magnitude', + xLabel: 'Magnitude', + yLabel: 'Median ground motion (g)', + }); + + const sigmaPlotData = plotUtils.defaultPlot({ + id: gmmUtils.PlotType.SIGMA, + mobileOptions: {...plotOptions}, + options: { + ...plotOptions, + layout: { + aspectRatio: gmmUtils.MEAN_ASPECT_RATIO, + ...plotOptions.layout, + }, + }, + title: 'Standard Deviation', + xLabel: 'Magnitude', + yLabel: 'Standard deviation', + }); + + /** Default mean settings */ + const meanSettingsForm: NshmpPlotSettings = { + config: meanPlotData.config, + layout: plotUtils.plotlyLayoutToSettings(meanPlotData.layout), + }; + + /** Default sigma settings */ + const sigmaSettingsForm: NshmpPlotSettings = { + config: sigmaPlotData.config, + layout: plotUtils.plotlyLayoutToSettings(sigmaPlotData.layout), + }; + plots.set(gmmUtils.PlotType.MEANS, { + label: 'Response Spectra', + plotData: meanPlotData, + settingsForm: plotUtils.plotSettingsToFormGroup(meanSettingsForm), + }); + plots.set(gmmUtils.PlotType.SIGMA, { + label: 'Standard Deviation', + plotData: sigmaPlotData, + settingsForm: plotUtils.plotSettingsToFormGroup(sigmaSettingsForm), + }); + + return new Map(plots); + } + /** * Initialize the application. */ @@ -303,79 +376,6 @@ export class AppService }); } - /** - * Returns the default plots. - */ - private defaultPlots(): Map<string, NshmpPlot> { - const plots = new Map<string, NshmpPlot>(); - - const plotOptions: PlotOptions = { - layout: { - xaxis: { - nticks: 10, - range: [Math.log10(5), Math.log10(8)], - }, - yaxis: { - range: [Math.log10(0.001), Math.log10(3)], - }, - }, - }; - - const meanPlotData = plotUtils.defaultPlot({ - id: gmmUtils.PlotType.MEANS, - mobileOptions: {...plotOptions}, - options: { - ...plotOptions, - layout: { - aspectRatio: gmmUtils.MEAN_ASPECT_RATIO, - ...plotOptions.layout, - }, - }, - title: 'Ground Motion vs. Magnitude', - xLabel: 'Magnitude', - yLabel: 'Median ground motion (g)', - }); - - const sigmaPlotData = plotUtils.defaultPlot({ - id: gmmUtils.PlotType.SIGMA, - mobileOptions: {...plotOptions}, - options: { - ...plotOptions, - layout: { - aspectRatio: gmmUtils.MEAN_ASPECT_RATIO, - ...plotOptions.layout, - }, - }, - title: 'Standard Deviation', - xLabel: 'Magnitude', - yLabel: 'Standard deviation', - }); - - /** Default mean settings */ - const meanSettingsForm: NshmpPlotSettings = { - config: meanPlotData.config, - layout: plotUtils.plotlyLayoutToSettings(meanPlotData.layout), - }; - - /** Default sigma settings */ - const sigmaSettingsForm: NshmpPlotSettings = { - config: sigmaPlotData.config, - layout: plotUtils.plotlyLayoutToSettings(sigmaPlotData.layout), - }; - plots.set(gmmUtils.PlotType.MEANS, { - label: 'Response Spectra', - plotData: meanPlotData, - settingsForm: plotUtils.plotSettingsToFormGroup(meanSettingsForm), - }); - plots.set(gmmUtils.PlotType.SIGMA, { - label: 'Standard Deviation', - plotData: sigmaPlotData, - settingsForm: plotUtils.plotSettingsToFormGroup(sigmaSettingsForm), - }); - - return new Map(plots); - } - private handleServiceResponses( serviceResponses: GmmMagnitudeResponse[] ): void { diff --git a/projects/nshmp-apps/src/app/gmm/spectra/services/app.service.ts b/projects/nshmp-apps/src/app/gmm/spectra/services/app.service.ts index df47b0b27..869346cef 100644 --- a/projects/nshmp-apps/src/app/gmm/spectra/services/app.service.ts +++ b/projects/nshmp-apps/src/app/gmm/spectra/services/app.service.ts @@ -333,6 +333,94 @@ export class AppService }; } + /** + * Returns the default plots. + */ + defaultPlots(): Map<string, SpectraPlot> { + const plots = new Map<string, NshmpPlot>(); + + const plotOptions: PlotOptions = { + layout: { + xaxis: { + range: [Math.log10(0.075), Math.log10(12)], + }, + yaxis: { + range: [Math.log10(0.001), Math.log10(3)], + }, + }, + }; + + /** Default mean plot data */ + const meanPlotData = plotUtils.defaultPlot({ + id: gmmUtils.PlotType.MEANS, + mobileOptions: {...plotOptions}, + options: { + ...plotOptions, + layout: { + ...plotOptions.layout, + aspectRatio: gmmUtils.MEAN_ASPECT_RATIO, + }, + }, + title: 'Medians', + xLabel: 'Period (s)', + yLabel: 'Median ground motion (g)', + }); + + /** Default sigma plot data */ + const sigmaPlotData = plotUtils.defaultPlot({ + id: gmmUtils.PlotType.SIGMA, + mobileOptions: { + ...plotOptions, + layout: { + ...plotOptions.layout, + yaxis: { + ...plotOptions.layout.yaxis, + range: [0, 1.5], + }, + }, + }, + options: { + ...plotOptions, + layout: { + ...plotOptions.layout, + aspectRatio: gmmUtils.SIGMA_ASPECT_RATIO, + yaxis: { + ...plotOptions.layout.yaxis, + range: [0, 1.5], + }, + }, + }, + title: 'Standard Deviations', + xLabel: 'Period (s)', + yLabel: 'Standard deviation', + }); + + /** Default mean settings */ + const meanSettingsForm: NshmpPlotSettings = { + config: meanPlotData.config, + layout: plotUtils.plotlyLayoutToSettings(meanPlotData.layout), + }; + + /** Default sigma settings */ + const sigmaSettingsForm: NshmpPlotSettings = { + config: sigmaPlotData.config, + layout: plotUtils.plotlyLayoutToSettings(sigmaPlotData.layout), + }; + plots.set(gmmUtils.PlotType.MEANS, { + label: 'Response Spectra', + plotData: meanPlotData, + settingsForm: plotUtils.plotSettingsToFormGroup(meanSettingsForm), + }); + + plots.set(gmmUtils.PlotType.SIGMA, { + label: 'Standard Deviation', + plotData: sigmaPlotData, + settingsForm: plotUtils.plotSettingsToFormGroup(sigmaSettingsForm), + }); + + return new Map(plots); + } + /** * Initialize the application. */ @@ -421,94 +509,6 @@ export class AppService }); } - /** - * Returns the default plots. - */ - private defaultPlots(): Map<string, SpectraPlot> { - const plots = new Map<string, NshmpPlot>(); - - const plotOptions: PlotOptions = { - layout: { - xaxis: { - range: [Math.log10(0.075), Math.log10(12)], - }, - yaxis: { - range: [Math.log10(0.001), Math.log10(3)], - }, - }, - }; - - /** Default mean plot data */ - const meanPlotData = plotUtils.defaultPlot({ - id: gmmUtils.PlotType.MEANS, - mobileOptions: {...plotOptions}, - options: { - ...plotOptions, - layout: { - ...plotOptions.layout, - aspectRatio: gmmUtils.MEAN_ASPECT_RATIO, - }, - }, - title: 'Medians', - xLabel: 'Period (s)', - yLabel: 'Median ground motion (g)', - }); - - /** Default sigma plot data */ - const sigmaPlotData = plotUtils.defaultPlot({ - id: gmmUtils.PlotType.SIGMA, - mobileOptions: { - ...plotOptions, - layout: { - ...plotOptions.layout, - yaxis: { - ...plotOptions.layout.yaxis, - range: [0, 1.5], - }, - }, - }, - options: { - ...plotOptions, - layout: { - ...plotOptions.layout, - aspectRatio: gmmUtils.SIGMA_ASPECT_RATIO, - yaxis: { - ...plotOptions.layout.yaxis, - range: [0, 1.5], - }, - }, - }, - title: 'Standard Deviations', - xLabel: 'Period (s)', - yLabel: 'Standard deviation', - }); - - /** Default mean settings */ - const meanSettingsForm: NshmpPlotSettings = { - config: meanPlotData.config, - layout: plotUtils.plotlyLayoutToSettings(meanPlotData.layout), - }; - - /** Default sigma settings */ - const sigmaSettingsForm: NshmpPlotSettings = { - config: sigmaPlotData.config, - layout: plotUtils.plotlyLayoutToSettings(sigmaPlotData.layout), - }; - plots.set(gmmUtils.PlotType.MEANS, { - label: 'Response Spectra', - plotData: meanPlotData, - settingsForm: plotUtils.plotSettingsToFormGroup(meanSettingsForm), - }); - - plots.set(gmmUtils.PlotType.SIGMA, { - label: 'Standard Deviation', - plotData: sigmaPlotData, - settingsForm: plotUtils.plotSettingsToFormGroup(sigmaSettingsForm), - }); - - return new Map(plots); - } - private handleServiceResponses(serviceResponses: GmmSpectraResponse[]): void { const means = serviceResponses.map(s => s.response.means); const sigmas = serviceResponses.map(s => s.response.sigmas); diff --git a/projects/nshmp-apps/src/app/source/mfd/services/app.service.ts b/projects/nshmp-apps/src/app/source/mfd/services/app.service.ts index 5dea22443..9d95d18d7 100644 --- a/projects/nshmp-apps/src/app/source/mfd/services/app.service.ts +++ b/projects/nshmp-apps/src/app/source/mfd/services/app.service.ts @@ -99,6 +99,7 @@ export class AppService readonly formGroup = this.formBuilder.group<ControlForm>( this.defaultFormValues() ); + /** Application state */ readonly state = signal<AppState>(this.initialState()); @@ -262,6 +263,102 @@ export class AppService }; } + /** + * Returns the default plots. + */ + defaultPlots(): Map<string, NshmpPlot> { + const plots = new Map<string, NshmpPlot>(); + + const logicTreeOptions: PlotOptions = { + layout: { + aspectRatio: undefined, + margin: { + b: 10, + l: 10, + r: 10, + }, + }, + }; + + const plotOptions: PlotOptions = { + layout: { + xaxis: { + nticks: 10, + range: [6.5, 7.7], + type: 'linear', + }, + yaxis: { + type: 'log', + }, + }, + }; + + /** Default logic tree plot data */ + const logicTreePlotData: PlotlyPlot = { + ...plotUtils.defaultPlot({ + id: 'mfd-logic-tree', + mobileOptions: {...logicTreeOptions}, + options: {...logicTreeOptions}, + title: 'MFD Logic Tree', + xLabel: '', + yLabel: '', + }), + data: [ + { + labels: ['Logic Tree Branches'], + parents: [''], + type: 'treemap', + }, + ], + }; + + /** Default MFD plot data */ + const mfdPlotData = plotUtils.defaultPlot({ + id: 'mfd-plot', + mobileOptions: { + ...plotOptions, + layout: { + ...plotOptions.layout, + aspectRatio: '1:1', + }, + }, + options: { + ...plotOptions, + layout: { + ...plotOptions.layout, + legend: { + font: { + size: 11, + }, + }, + }, + }, + title: 'Magnitude Frequency Distribution', + xLabel: 'Magnitude', + yLabel: 'Rate (yr<sup>-1</sup>)', + }); + + plots.set(Plots.MFD, { + label: 'MFD', + plotData: mfdPlotData, + settingsForm: plotUtils.plotSettingsToFormGroup({ + config: mfdPlotData.config, + layout: plotUtils.plotlyLayoutToSettings(mfdPlotData.layout), + }), + }); + + plots.set(Plots.LOGIC_TREE, { + label: Plots.LOGIC_TREE, + plotData: logicTreePlotData, + settingsForm: plotUtils.plotSettingsToFormGroup({ + config: logicTreePlotData.config, + layout: plotUtils.plotlyLayoutToSettings(logicTreePlotData.layout), + }), + }); + + return plots; + } + /** * Return the feault source to use from settings groups. * @@ -447,102 +544,6 @@ export class AppService return `${serviceUrl}/${sourceTree}`; } - /** - * Returns the default plots. - */ - private defaultPlots(): Map<string, NshmpPlot> { - const plots = new Map<string, NshmpPlot>(); - - const logicTreeOptions: PlotOptions = { - layout: { - aspectRatio: undefined, - margin: { - b: 10, - l: 10, - r: 10, - }, - }, - }; - - const plotOptions: PlotOptions = { - layout: { - xaxis: { - nticks: 10, - range: [6.5, 7.7], - type: 'linear', - }, - yaxis: { - type: 'log', - }, - }, - }; - - /** Default logic tree plot data */ - const logicTreePlotData: PlotlyPlot = { - ...plotUtils.defaultPlot({ - id: 'mfd-logic-tree', - mobileOptions: {...logicTreeOptions}, - options: {...logicTreeOptions}, - title: 'MFD Logic Tree', - xLabel: '', - yLabel: '', - }), - data: [ - { - labels: ['Logic Tree Branches'], - parents: [''], - type: 'treemap', - }, - ], - }; - - /** Default MFD plot data */ - const mfdPlotData = plotUtils.defaultPlot({ - id: 'mfd-plot', - mobileOptions: { - ...plotOptions, - layout: { - ...plotOptions.layout, - aspectRatio: '1:1', - }, - }, - options: { - ...plotOptions, - layout: { - ...plotOptions.layout, - legend: { - font: { - size: 11, - }, - }, - }, - }, - title: 'Magnitude Frequency Distribution', - xLabel: 'Magnitude', - yLabel: 'Rate (yr<sup>-1</sup>)', - }); - - plots.set(Plots.MFD, { - label: 'MFD', - plotData: mfdPlotData, - settingsForm: plotUtils.plotSettingsToFormGroup({ - config: mfdPlotData.config, - layout: plotUtils.plotlyLayoutToSettings(mfdPlotData.layout), - }), - }); - - plots.set(Plots.LOGIC_TREE, { - label: Plots.LOGIC_TREE, - plotData: logicTreePlotData, - settingsForm: plotUtils.plotSettingsToFormGroup({ - config: logicTreePlotData.config, - layout: plotUtils.plotlyLayoutToSettings(logicTreePlotData.layout), - }), - }); - - return plots; - } - /** * Return the matching setting group from a {@link MfdSource#tectonicSettings}. * -- GitLab