components/content/content.component.ts
Main content for application with tabs:
selector | app-content |
imports |
NshmpLibNgDataTablePanelComponent
MatTabGroup
MatTab
MatTabContent
PlotsComponent
LowerCasePipe
|
templateUrl | ./content.component.html |
styleUrl | ./content.component.scss |
Properties |
Methods |
constructor(service: AppService)
|
||||||
Defined in components/content/content.component.ts:68
|
||||||
Parameters :
|
hazardFilename |
hazardFilename()
|
Defined in components/content/content.component.ts:73
|
Filename for hazard export CSV
Returns :
string
|
spectraFilename |
spectraFilename()
|
Defined in components/content/content.component.ts:80
|
Filename for spectra export CSV
Returns :
string
|
hasData |
Default value : computed(() => this.service.serviceResponse() !== null)
|
Defined in components/content/content.component.ts:34
|
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,
},
},
{
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),
},
);
})
|
Defined in components/content/content.component.ts:37
|
Hazard table data |
Public service |
Type : AppService
|
Defined in components/content/content.component.ts:70
|
spectraTableData |
Default value : computed(() =>
hazardUtils.responseSpectraToTableData(this.service.responseSpectra()),
)
|
Defined in components/content/content.component.ts:66
|
Spectra table data |
import {LowerCasePipe} from '@angular/common';
import {Component, computed} from '@angular/core';
import {MatTab, MatTabContent, MatTabGroup} from '@angular/material/tabs';
import {hazardUtils} from '@ghsc/nshmp-lib-ng/hazard';
import {NshmpLibNgDataTablePanelComponent} from '@ghsc/nshmp-lib-ng/nshmp';
import {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({
imports: [
NshmpLibNgDataTablePanelComponent,
MatTabGroup,
MatTab,
MatTabContent,
PlotsComponent,
LowerCasePipe,
],
selector: 'app-content',
styleUrl: './content.component.scss',
templateUrl: './content.component.html',
})
export class ContentComponent {
/** 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,
},
},
{
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),
},
);
});
/** Spectra table data */
spectraTableData = computed(() =>
hazardUtils.responseSpectraToTableData(this.service.responseSpectra()),
);
constructor(public service: AppService) {}
/** Filename for hazard export CSV */
hazardFilename(): string {
const {sourceType, vs30} = this.service.formGroup.getRawValue();
return `hazard-curves-${sourceType}-${vs30}.csv`;
}
/** Filename for spectra export CSV */
spectraFilename(): string {
const {sourceType, vs30} = this.service.formGroup.getRawValue();
return `response-spectra-${sourceType}-${vs30}.csv`;
}
}
<mat-tab-group class="height-full">
<!-- Plots tab -->
<mat-tab labelClass="plots-tab" label="Plots">
<ng-template matTabContent>
<app-plots />
</ng-template>
</mat-tab>
<!-- Hazard data tab -->
<mat-tab
labelClass="hazard-tab"
label="Hazard Curve Data"
[disabled]="hasData() === false"
>
<ng-template matTabContent>
<nshmp-lib-ng-data-table-panel
[table]="hazardTableData()"
[filename]="hazardFilename() | lowercase"
buttonText="Export Hazard as CSV"
title="Hazard Data"
/>
</ng-template>
</mat-tab>
<!-- Spectra data tab -->
<mat-tab
labelClass="spectra-tab"
label="Response Spectrum Data"
[disabled]="hasData() === false"
>
<ng-template matTabContent>
<nshmp-lib-ng-data-table-panel
[table]="spectraTableData()"
[filename]="spectraFilename() | lowercase"
buttonText="Export Response Spectra as CSV"
title="Response Spectra Data"
/>
</ng-template>
</mat-tab>
</mat-tab-group>