components/data/data.component.ts
Table of MFD data from service response.
| changeDetection | ChangeDetectionStrategy.OnPush |
| host | { |
| selector | app-data |
| imports |
NshmpDataTablePanelComponent
LowerCasePipe
AsyncPipe
|
| templateUrl | ./data.component.html |
| styleUrl | ./data.component.scss |
Properties |
|
Methods |
|
| Private toTableData | ||||||||||||
toTableData(serviceResponse: SourceLogicTreesResponse, form: ControlForm)
|
||||||||||||
|
Defined in components/data/data.component.ts:59
|
||||||||||||
|
Convert service response to table data.
Parameters :
Returns :
TableData[]
|
| mfdFilename$ |
Default value : this.service.formGroup.valueChanges.pipe(
map(values => {
if (values.source === null || this.service.usage() === null) {
return 'mfd.csv';
}
const sourceTree = this.service
.findTreeInfo(this.service.usage().response.trees, values.source, values.sourceTree)
?.name?.replace(/ /g, '_');
return `mfd-${values.source.tectonicSettings}-${values.source.sourceType}-${
sourceTree ?? values.sourceTree
}.csv`;
}),
)
|
|
Defined in components/data/data.component.ts:37
|
| mfdTableData |
Default value : computed(() => {
const serviceResponse = this.service.serviceResponse();
if (serviceResponse) {
return this.toTableData(serviceResponse, this.service.formGroup.getRawValue());
} else {
return [];
}
})
|
|
Defined in components/data/data.component.ts:27
|
|
MFD table data |
| Private service |
Default value : inject(AppService)
|
|
Defined in components/data/data.component.ts:24
|
import {AsyncPipe, LowerCasePipe} from '@angular/common';
import {ChangeDetectionStrategy, Component, computed, inject} from '@angular/core';
import {hazardUtils} from '@ghsc/nshmp-lib-ng/hazard';
import {NshmpDataTablePanelComponent, TableData} from '@ghsc/nshmp-lib-ng/nshmp';
import {SourceLogicTreesResponse} from '@ghsc/nshmp-utils-ts/libs/nshmp-haz/www/source-logic-trees-service';
import {Sequences} from '@ghsc/nshmp-utils-ts/libs/nshmp-lib/data';
import {map} from 'rxjs';
import {ControlForm} from '../../models/control-form.model';
import {AppService} from '../../services/app.service';
/**
* Table of MFD data from service response.
*/
@Component({
changeDetection: ChangeDetectionStrategy.OnPush,
host: {id: 'source-mfd-data'},
imports: [NshmpDataTablePanelComponent, LowerCasePipe, AsyncPipe],
selector: 'app-data',
styleUrl: './data.component.scss',
templateUrl: './data.component.html',
})
export class DataComponent {
private service = inject(AppService);
/** MFD table data */
mfdTableData = computed(() => {
const serviceResponse = this.service.serviceResponse();
if (serviceResponse) {
return this.toTableData(serviceResponse, this.service.formGroup.getRawValue());
} else {
return [];
}
});
mfdFilename$ = this.service.formGroup.valueChanges.pipe(
map(values => {
if (values.source === null || this.service.usage() === null) {
return 'mfd.csv';
}
const sourceTree = this.service
.findTreeInfo(this.service.usage().response.trees, values.source, values.sourceTree)
?.name?.replace(/ /g, '_');
return `mfd-${values.source.tectonicSettings}-${values.source.sourceType}-${
sourceTree ?? values.sourceTree
}.csv`;
}),
);
/**
* Convert service response to table data.
*
* @param branches The source branches
* @param form Control panel form field values
*/
private toTableData(serviceResponse: SourceLogicTreesResponse, form: ControlForm): TableData[] {
const branches = serviceResponse.response.branches;
const tree = serviceResponse.response;
if (branches === null || branches === undefined) {
return [];
}
const totalMfd = form.cumulative ? Sequences.toCumulative(tree.totalMfd) : tree.totalMfd;
const tableData: TableData[] = [
{
label: 'Total MFD',
td: totalMfd.xs,
th: 'Magnitude',
},
{
td: totalMfd.ys.map(y => y.toExponential(4)),
th: 'Rate',
},
];
branches.forEach(branch => {
this.service.filterMfds(branch.mfds, form.mfdType).forEach(mfdInfo => {
const label = `${branch.path} - ${mfdInfo.id}`;
let xySequence = hazardUtils.cleanXySequence(mfdInfo.mfd.data);
if (form.cumulative) {
xySequence = Sequences.toCumulative(xySequence);
}
tableData.push({
label,
td: xySequence.xs,
th: 'Magnitude',
});
tableData.push({
td: xySequence.ys.map(y => y.toExponential(4)),
th: 'Rate',
});
tableData.push({
td: [branch.weight],
th: 'Branch Weight',
});
tableData.push({
td: [mfdInfo.weight],
th: 'MFD Weight',
});
Object.entries(mfdInfo.mfd.props).forEach(([key, value]: [string, string]) => {
tableData.push({
td: [value],
th: key,
});
});
});
});
return tableData;
}
}
<nshmp-data-table-panel
[table]="mfdTableData()"
[filename]="mfdFilename$ | async | lowercase"
buttonText="Export MFD as CSV"
title="MFD Data"
/>