File

components/content/content.component.ts

Description

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

Metadata

Index

Properties
Methods

Constructor

constructor(service: AppService)
Parameters :
Name Type Optional
service AppService No

Methods

hazardFilename
hazardFilename()

Filename for hazard export CSV

Returns : string
spectraFilename
spectraFilename()

Filename for spectra export CSV

Returns : string

Properties

hasData
Default value : computed(() => this.service.serviceResponse() !== null)

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), }, ); })

Hazard table data

Public service
Type : AppService
spectraTableData
Default value : computed(() => hazardUtils.responseSpectraToTableData(this.service.responseSpectra()), )

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>
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""