From 47c0d342b9e70ee0ac01c6c9b0773308e4a64aa8 Mon Sep 17 00:00:00 2001 From: Brandon Clayton <bclayton@usgs.gov> Date: Fri, 22 Nov 2024 08:42:11 -0700 Subject: [PATCH] switch axis --- .../services/app.service.ts | 70 ++++++++++++------- 1 file changed, 44 insertions(+), 26 deletions(-) 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 cc022de36..cd895db09 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 @@ -1,6 +1,6 @@ import {HttpParams} from '@angular/common/http'; import {computed, Injectable, Signal, signal} from '@angular/core'; -import {FormBuilder} from '@angular/forms'; +import {FormBuilder, Validators} from '@angular/forms'; import {ActivatedRoute, Router} from '@angular/router'; import { FormGroupControls, @@ -57,7 +57,7 @@ export class AppService /** Form group */ formGroup = this.formBuilder.group({ ...this.defaultFormValues(), - locations: this.formBuilder.array([this.locationForm()]), + locations: this.formBuilder.array<FormGroupControls<Location>>([]), }); /** State */ @@ -177,38 +177,38 @@ export class AppService * Returns the default plots. */ defaultPlots(): Plots { - const xLabel = 'Depth (meters)'; + const yLabel = 'Depth (meters)'; return { density: this.defaultPlot({ id: 'density', title: 'Density Profile', - xLabel, - yLabel: 'Density Profile (kg/m3)', + xLabel: 'Density Profile (kg/m3)', + yLabel, }), porosity: this.defaultPlot({ id: 'porosity', title: 'Porosity Profile', - xLabel, - yLabel: 'Porosity Profile', + xLabel: 'Porosity Profile', + yLabel, }), temperature: this.defaultPlot({ id: 'temperature', title: 'Temperature Profile', - xLabel, - yLabel: 'Temperature Profile (°C)', + xLabel: 'Temperature Profile (°C)', + yLabel, }), vp: this.defaultPlot({ id: 'p-wave', title: 'P-wave Profile', - xLabel, - yLabel: 'P-wave Profile (m/s)', + xLabel: 'P-wave Profile (m/s)', + yLabel, }), vs: this.defaultPlot({ id: 's-wave', title: 'S-wave Profile', - xLabel, - yLabel: 'S-wave Profile (m/s)', + xLabel: 'S-wave Profile (m/s)', + yLabel, }), }; } @@ -240,6 +240,7 @@ export class AppService usageResponse, }); + this.addLocationForm(); this.initialFormSet(); }); } @@ -327,15 +328,19 @@ export class AppService const plotOptions: PlotOptions = { layout: { xaxis: { - range: [values.depthMin, values.depthMax], + nticks: 15, + range: [0, 100], type: 'linear', }, yaxis: { - range: [0, 100], + autorange: 'reversed', + nticks: 15, + range: [values.depthMin, values.depthMax], type: 'linear', }, }, }; + const plotData = plotUtils.defaultPlot({ ...options, mobileOptions: plotOptions, @@ -397,6 +402,19 @@ export class AppService longitude: [NaN, [this.validateRequired(), this.validateNan()]], }); + if (this.usage()) { + const locations = this.usage().response.parameters.location; + + form.controls.latitude.addValidators([ + Validators.min(locations.latitude.min), + Validators.max(locations.latitude.max), + ]); + form.controls.longitude.addValidators([ + Validators.min(locations.longitude.min), + Validators.max(locations.longitude.max), + ]); + } + form.valueChanges.subscribe(() => { this.formGroup.controls.locations.updateValueAndValidity(); this.formGroup.controls.locations.markAsDirty(); @@ -436,7 +454,7 @@ export class AppService const vpPlotData: Partial<PlotData>[] = []; const densityPlotData: Partial<PlotData>[] = []; - const xs = serviceResponse.request.depths.depth_vector; + const ys = serviceResponse.request.depths.depth_vector; serviceResponse.response.results.forEach(result => { const name = `${result.location.latitude}, ${result.location.longitude}`; @@ -444,36 +462,36 @@ export class AppService temperaturePlotData.push({ mode: 'lines+markers', name, - x: xs, - y: result.profile.temperature, + x: result.profile.temperature, + y: ys, }); porosityPlotData.push({ mode: 'lines+markers', name, - x: xs, - y: result.profile.porosity, + x: result.profile.porosity, + y: ys, }); vpPlotData.push({ mode: 'lines+markers', name, - x: xs, - y: result.profile.vp, + x: result.profile.vp, + y: ys, }); vsPlotData.push({ mode: 'lines+markers', name, - x: xs, - y: result.profile.vs, + x: result.profile.vs, + y: ys, }); densityPlotData.push({ mode: 'lines+markers', name, - x: xs, - y: result.profile.density, + x: result.profile.density, + y: ys, }); }); -- GitLab