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 2787b5439be466c73d3d3ced8062de4aa98e4747..00d2d501fd21ddeb89291b9dac803083bfbabdcc 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 28e81a3f017775d9d26898dcff517cafcc107dff..15e16e6637fed1ceaa1050b7c7811237a5026086 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 2fd233423bf4988d94698e4590cf4dd03d08f745..3f25429b0379083d9e4c012d50d5fdb2cb2684cb 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 df47b0b27bd8c3650a996c3552050e01b841ee5a..869346cefaacbaf885331049db93f6e537fd028a 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 5dea22443c336414a538ad514519d4daf84c1caf..9d95d18d7b185d6ac98bd8f0233f6c11aca51cd3 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}. *