components/content/content.component.ts
Main content for application with tabs:
encapsulation | ViewEncapsulation.None |
selector | app-content |
imports |
NshmpDataTablePanelComponent
MatTabGroup
MatTab
MatTabContent
PlotsComponent
LowerCasePipe
NshmpScrollToTopComponent
|
templateUrl | ./content.component.html |
styleUrl | ./content.component.scss |
Properties |
Methods |
hazardFilename |
hazardFilename()
|
Defined in components/content/content.component.ts:78
|
Filename for hazard export CSV
Returns :
string
|
magnitudeFilename |
magnitudeFilename()
|
Defined in components/content/content.component.ts:84
|
Returns :
string
|
sourcesFilename |
sourcesFilename()
|
Defined in components/content/content.component.ts:90
|
Returns :
string
|
spectraFilename |
spectraFilename()
|
Defined in components/content/content.component.ts:97
|
Filename for spectra export CSV
Returns :
string
|
Private tableParams |
tableParams()
|
Defined in components/content/content.component.ts:103
|
Returns :
PlotTableDataParams
|
hasData |
Default value : computed(() => this.service.serviceResponse() !== null)
|
Defined in components/content/content.component.ts:38
|
Whether there is data |
hazardTableData |
Default value : computed(() => {
const plot = this.service.hazardPlotState();
const data = [...plot.plotData.data];
// Remove return period from data
data.shift();
return plotUtils.plotDataToTableData(
{
...plot,
plotData: {
...plot.plotData,
data,
},
},
this.tableParams(),
);
})
|
Defined in components/content/content.component.ts:41
|
Hazard table data |
magnitudesTableData |
Default value : computed(() => {
const plot = this.service.magnitudesPlotState();
return plotUtils.plotDataToTableData(plot, this.tableParams());
})
|
Defined in components/content/content.component.ts:60
|
Hazard table data |
service |
Default value : inject(AppService)
|
Defined in components/content/content.component.ts:35
|
sourcesTableData |
Default value : computed(() => {
const plot = this.service.sourcesPlotState();
return plotUtils.plotDataToTableData(plot, this.tableParams());
})
|
Defined in components/content/content.component.ts:67
|
Hazard table data |
spectraTableData |
Default value : computed(() =>
hazardUtils.responseSpectraToTableData(this.service.responseSpectra()),
)
|
Defined in components/content/content.component.ts:73
|
Spectra table data |
import {LowerCasePipe} from '@angular/common';
import {Component, computed, inject, ViewEncapsulation} from '@angular/core';
import {MatTab, MatTabContent, MatTabGroup} from '@angular/material/tabs';
import {hazardUtils} from '@ghsc/nshmp-lib-ng/hazard';
import {NshmpDataTablePanelComponent, NshmpScrollToTopComponent} from '@ghsc/nshmp-lib-ng/nshmp';
import {PlotTableDataParams, plotUtils} from '@ghsc/nshmp-lib-ng/plot';
import {Imt, imtToString} from '@ghsc/nshmp-utils-ts/libs/nshmp-lib/gmm';
import {PlotData} from 'plotly.js';
import {AppService} from '../../services/app.service';
import {PlotsComponent} from '../plots/plots.component';
/**
* Main content for application with tabs:
* - Plots tab: show dynamic hazard plots
* - Hazard data tab: table of hazard data
* - Spectra data tab: table of spectra data
*/
@Component({
encapsulation: ViewEncapsulation.None,
imports: [
NshmpDataTablePanelComponent,
MatTabGroup,
MatTab,
MatTabContent,
PlotsComponent,
LowerCasePipe,
NshmpScrollToTopComponent,
],
selector: 'app-content',
styleUrl: './content.component.scss',
templateUrl: './content.component.html',
})
export class ContentComponent {
service = inject(AppService);
/** Whether there is data */
hasData = computed(() => this.service.serviceResponse() !== null);
/** Hazard table data */
hazardTableData = computed(() => {
const plot = this.service.hazardPlotState();
const data = [...plot.plotData.data];
// Remove return period from data
data.shift();
return plotUtils.plotDataToTableData(
{
...plot,
plotData: {
...plot.plotData,
data,
},
},
this.tableParams(),
);
});
/** Hazard table data */
magnitudesTableData = computed(() => {
const plot = this.service.magnitudesPlotState();
return plotUtils.plotDataToTableData(plot, this.tableParams());
});
/** Hazard table data */
sourcesTableData = computed(() => {
const plot = this.service.sourcesPlotState();
return plotUtils.plotDataToTableData(plot, this.tableParams());
});
/** Spectra table data */
spectraTableData = computed(() =>
hazardUtils.responseSpectraToTableData(this.service.responseSpectra()),
);
/** Filename for hazard export CSV */
hazardFilename(): string {
const {model, sourceType, vs30} = this.service.formGroup.getRawValue();
return `hazard-curves-${model}-${sourceType}-${vs30}.csv`;
}
magnitudeFilename(): string {
const {imt, model, vs30} = this.service.formGroup.getRawValue();
return `magnitude-curves-${model}-${imt}-${vs30}.csv`;
}
sourcesFilename(): string {
const {imt, model, vs30} = this.service.formGroup.getRawValue();
return `sources-curves-${model}-${imt}-${vs30}.csv`;
}
/** Filename for spectra export CSV */
spectraFilename(): string {
const {model, sourceType, vs30} = this.service.formGroup.getRawValue();
return `response-spectra-${model}-${sourceType}-${vs30}.csv`;
}
private tableParams(): PlotTableDataParams {
return {
addLabel: true,
labelTransform: label => (label in Imt ? imtToString(label as Imt) : label),
xLabelTransform: (label: string, data: Partial<PlotData>) =>
data?.name === Imt.PGV.toString() ? label.replace('(g)', '(cm/s)') : label,
xValueFormat: (x: number) => x.toFixed(4),
yValueFormat: (y: number) => y.toExponential(4),
};
}
}
<mat-tab-group class="height-full group">
<!-- Plots tab -->
<mat-tab labelClass="plots-tab" label="Plots">
<nshmp-scroll-to-top>
<app-plots />
</nshmp-scroll-to-top>
</mat-tab>
<!-- Hazard data tab -->
<mat-tab labelClass="hazard-tab" label="Hazard Curve Data" [disabled]="hasData() === false">
<ng-template matTabContent>
<div class="grid-container-widescreen">
<nshmp-data-table-panel
[table]="hazardTableData()"
[filename]="hazardFilename() | lowercase"
buttonText="Export Hazard as CSV"
title="Hazard Data"
class="grid-container-widescreen"
/>
</div>
</ng-template>
</mat-tab>
<!-- Magnititudes data tab -->
<mat-tab labelClass="magnitudes-tab" label="Magnitude Data" [disabled]="hasData() === false">
<ng-template matTabContent>
<div class="grid-container-widescreen">
<nshmp-data-table-panel
[table]="magnitudesTableData()"
[filename]="magnitudeFilename() | lowercase"
buttonText="Export Magnitude Data as CSV"
title="Magnitude Data"
/>
</div>
</ng-template>
</mat-tab>
<!-- Sources data tab -->
<mat-tab labelClass="sources-tab" label="Sources Data" [disabled]="hasData() === false">
<ng-template matTabContent>
<div class="grid-container-widescreen">
<nshmp-data-table-panel
[table]="sourcesTableData()"
[filename]="sourcesFilename() | lowercase"
buttonText="Export Sources Data as CSV"
title="Sources Data"
/>
</div>
</ng-template>
</mat-tab>
<!-- Spectra data tab -->
<mat-tab labelClass="spectra-tab" label="Response Spectrum Data" [disabled]="hasData() === false">
<ng-template matTabContent>
<div class="grid-container-widescreen">
<nshmp-data-table-panel
[table]="spectraTableData()"
[filename]="spectraFilename() | lowercase"
buttonText="Export Response Spectra as CSV"
title="Response Spectra Data"
/>
</div>
</ng-template>
</mat-tab>
</mat-tab-group>