File

components/plots/plots.component.ts

Description

Ground motion response spectra mean and sigma plots.

Metadata

Index

Properties
Methods

Constructor

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

Methods

Private filterData
filterData(plot: PlotlyPlot)

Don't plot PGV values.

Parameters :
Name Type Optional Description
plot PlotlyPlot No

The plot

Returns : PlotlyPlot
Private splicePgv
splicePgv(data: T[], iPgv: number)
Type parameters :
  • T
Parameters :
Name Type Optional
data T[] No
iPgv number No
Returns : void

Properties

repositories
Default value : computed(() => this.service.usage()?.metadata?.repositories)

Repo metadata

sigmaPlotData
Default value : computed(() => this.filterData(this.service.sigmaPlotState().plotData), )

Sigma plot data

spectraPlotData
Default value : computed(() => ({ ...this.filterData(this.service.spectraPlotState().plotData), }))

Response spectra plot data

import {Component, computed} from '@angular/core';
import {MatDivider} from '@angular/material/divider';
import {
  MatAccordion,
  MatExpansionPanel,
  MatExpansionPanelHeader,
  MatExpansionPanelTitle,
} from '@angular/material/expansion';
import {gmmUtils} from '@ghsc/nshmp-lib-ng/gmm';
import {NshmpLibNgAppMetadataComponent} from '@ghsc/nshmp-lib-ng/nshmp';
import {
  NshmpLibNgPlotComponent,
  NshmpLibNgPlotsContainerComponent,
} from '@ghsc/nshmp-lib-ng/plot';
import {PlotlyPlot} from '@ghsc/nshmp-utils-ts/libs/plotly';
import {PlotData} from 'plotly.js';

import {AppService} from '../../services/app.service';
import {ParameterSummaryComponent} from '../parameter-summary/parameter-summary.component';

/**
 * Ground motion response spectra mean and sigma plots.
 */
@Component({
  imports: [
    NshmpLibNgPlotsContainerComponent,
    NshmpLibNgPlotComponent,
    NshmpLibNgAppMetadataComponent,
    MatAccordion,
    MatExpansionPanel,
    MatExpansionPanelHeader,
    MatExpansionPanelTitle,
    MatDivider,
    ParameterSummaryComponent,
  ],
  selector: 'app-plots',
  styleUrl: './plots.component.scss',
  templateUrl: './plots.component.html',
})
export class PlotsComponent {
  /** Sigma plot data */
  sigmaPlotData = computed(() =>
    this.filterData(this.service.sigmaPlotState().plotData),
  );

  /** Response spectra plot data */
  spectraPlotData = computed(() => ({
    ...this.filterData(this.service.spectraPlotState().plotData),
  }));

  /** Repo metadata */
  repositories = computed(() => this.service.usage()?.metadata?.repositories);

  constructor(private service: AppService) {}

  /**
   * Don't plot PGV values.
   *
   * @param plot The plot
   */
  private filterData(plot: PlotlyPlot): PlotlyPlot {
    const data = plot.data.map(data => {
      const iPgv = data.x.findIndex(x => x === gmmUtils.XS_PGV);
      const plotData: Partial<PlotData> = {
        ...data,
        x: [...data.x] as number[],
        y: [...data.y] as number[],
      };

      if (iPgv !== -1) {
        this.splicePgv(plotData.x as number[], iPgv);
        this.splicePgv(plotData.y as number[], iPgv);
        this.splicePgv(plotData.hovertemplate as string[], iPgv);
        this.splicePgv(plotData.marker.symbol as string[], iPgv);
      }

      return plotData;
    });

    return {
      ...plot,
      data,
    };
  }

  private splicePgv<T>(data: T[], iPgv: number): void {
    if (Array.isArray(data)) {
      data.splice(iPgv, 1);
    }
  }
}
<nshmp-lib-ng-plots-container>
  <mat-accordion multi>
    <!-- Spectra plot -->
    <mat-expansion-panel expanded>
      <mat-expansion-panel-header>
        <mat-panel-title>Response Spectra</mat-panel-title>
      </mat-expansion-panel-header>

      <mat-divider />

      @if (spectraPlotData()) {
        <nshmp-lib-ng-plot class="spectra-plot" [plot]="spectraPlotData()" />
      }
    </mat-expansion-panel>

    <!-- Sigma plot -->
    <mat-expansion-panel expanded>
      <mat-expansion-panel-header>
        <mat-panel-title>Standard Deviations</mat-panel-title>
      </mat-expansion-panel-header>

      <mat-divider />

      @if (sigmaPlotData()) {
        <nshmp-lib-ng-plot class="sigma-plot" [plot]="sigmaPlotData()" />
      }
    </mat-expansion-panel>

    <!-- Parameter summary -->
    <mat-expansion-panel expanded>
      <mat-expansion-panel-header>
        <mat-panel-title>Parameter Summary</mat-panel-title>
      </mat-expansion-panel-header>

      <mat-divider />
      <app-parameter-summary />
    </mat-expansion-panel>

    <!-- App metadata -->
    <mat-expansion-panel expanded>
      <mat-expansion-panel-header>
        <mat-panel-title>Application Metadata</mat-panel-title>
      </mat-expansion-panel-header>

      <mat-divider />
      <nshmp-lib-ng-app-metadata [repositories]="repositories()" />
    </mat-expansion-panel>
  </mat-accordion>
</nshmp-lib-ng-plots-container>
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""