File

components/plots/plots.component.ts

Description

Dynamic hazard compare application plots.

Metadata

Index

Properties

Constructor

constructor(service: AppService, headerService: HeaderService)
Parameters :
Name Type Optional
service AppService No
headerService HeaderService No

Properties

Private hazardComponentsPlotData
Default value : computed( () => this.service.plots().get(Plots.HAZARD_COMPONENTS).plotData, )

Hazard components plot data

Private hazardDiffPlotData
Default value : computed( () => this.service.plots().get(Plots.HAZARD_DIFFERENCES).plotData, )

Hazard % diff plot data

Private hazardPlotData
Default value : computed( () => this.service.plots().get(Plots.HAZARD).plotData, )

Hazard plot data

panelsClosed
Default value : computed( () => !this.headerService.controlPanelSelected() && !this.headerService.settingsSelected(), )

Wheather both the control and settings panels are closed

panelsOpened
Default value : computed( () => this.headerService.controlPanelSelected() && this.headerService.settingsSelected(), )

Wheather both the control and settings panels are opened

plots
Type : PlotInfo[]
Default value : [ { diffPlotData: this.hazardDiffPlotData, plotData: this.hazardPlotData, title: 'Hazard Curves', }, { diffPlotData: this.spectraDiffPlotData, plotData: this.spectraPlotData, title: 'Spectra', }, { plotData: this.hazardComponentsPlotData, title: 'Hazard Components', }, { plotData: this.spectraComponentsPlotData, title: 'Spectra Components', }, ]

The plots

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

Repo metadata

Private spectraComponentsPlotData
Default value : computed( () => this.service.plots().get(Plots.SPECTRUM_COMPONENTS).plotData, )

Spectra components plot data

Private spectraDiffPlotData
Default value : computed( () => this.service.plots().get(Plots.SPECTRUM_DIFFERENCES).plotData, )

Spectra % diff plot data

Private spectraPlotData
Default value : computed( () => this.service.plots().get(Plots.SPECTRUM).plotData, )

Spectra plot data

import {NgClass} from '@angular/common';
import {Component, computed, Signal} from '@angular/core';
import {MatDivider} from '@angular/material/divider';
import {
  MatAccordion,
  MatExpansionPanel,
  MatExpansionPanelHeader,
  MatExpansionPanelTitle,
} from '@angular/material/expansion';
import {NshmpLibNgHazardDesignCodeWarningComponent} from '@ghsc/nshmp-lib-ng/hazard';
import {NshmpLibNgAppMetadataComponent} from '@ghsc/nshmp-lib-ng/nshmp';
import {
  NshmpLibNgPlotComponent,
  NshmpLibNgPlotsContainerComponent,
} from '@ghsc/nshmp-lib-ng/plot';
import {HeaderService} from '@ghsc/nshmp-template';
import {PlotlyPlot} from '@ghsc/nshmp-utils-ts/libs/plotly';

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

/**
 * The plot info for an expansion panel
 */
interface PlotInfo {
  /** Main plot data */
  plotData: Signal<PlotlyPlot>;
  /** Expansion panel title */
  title: string;

  /** % diff plot data */
  diffPlotData?: Signal<PlotlyPlot>;
}

/**
 * Dynamic hazard compare application plots.
 */
@Component({
  imports: [
    NshmpLibNgPlotsContainerComponent,
    NshmpLibNgHazardDesignCodeWarningComponent,
    NshmpLibNgAppMetadataComponent,
    NshmpLibNgPlotComponent,
    NgClass,
    MatAccordion,
    MatExpansionPanel,
    MatExpansionPanelHeader,
    MatExpansionPanelTitle,
    MatDivider,
    ParameterSummaryComponent,
  ],
  selector: 'app-plots',
  styleUrl: './plots.component.scss',
  templateUrl: './plots.component.html',
})
export class PlotsComponent {
  /** Hazard plot data */
  private hazardPlotData = computed(
    () => this.service.plots().get(Plots.HAZARD).plotData,
  );

  /** Hazard components plot data */
  private hazardComponentsPlotData = computed(
    () => this.service.plots().get(Plots.HAZARD_COMPONENTS).plotData,
  );

  /** Hazard % diff plot data */
  private hazardDiffPlotData = computed(
    () => this.service.plots().get(Plots.HAZARD_DIFFERENCES).plotData,
  );

  /** Spectra components plot data */
  private spectraComponentsPlotData = computed(
    () => this.service.plots().get(Plots.SPECTRUM_COMPONENTS).plotData,
  );

  /** Spectra % diff plot data */
  private spectraDiffPlotData = computed(
    () => this.service.plots().get(Plots.SPECTRUM_DIFFERENCES).plotData,
  );

  /** Spectra plot data */
  private spectraPlotData = computed(
    () => this.service.plots().get(Plots.SPECTRUM).plotData,
  );

  /** Wheather both the control and settings panels are closed */
  panelsClosed = computed(
    () =>
      !this.headerService.controlPanelSelected() &&
      !this.headerService.settingsSelected(),
  );

  /** Wheather both the control and settings panels are opened */
  panelsOpened = computed(
    () =>
      this.headerService.controlPanelSelected() &&
      this.headerService.settingsSelected(),
  );

  /** The plots */
  plots: PlotInfo[] = [
    {
      diffPlotData: this.hazardDiffPlotData,
      plotData: this.hazardPlotData,
      title: 'Hazard Curves',
    },
    {
      diffPlotData: this.spectraDiffPlotData,
      plotData: this.spectraPlotData,
      title: 'Spectra',
    },
    {
      plotData: this.hazardComponentsPlotData,
      title: 'Hazard Components',
    },
    {
      plotData: this.spectraComponentsPlotData,
      title: 'Spectra Components',
    },
  ];

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

  constructor(
    private service: AppService,
    private headerService: HeaderService,
  ) {}
}
<nshmp-lib-ng-plots-container containerClass="grid-container-widescreen-xl">
  <nshmp-lib-ng-hazard-design-code-warning />

  <div class="grid-row">
    @for (plot of plots; track plot) {
      <div
        class="grid-col-12 plots-panel widescreen:grid-col-6"
        [ngClass]="{
          'panels-opened': panelsOpened(),
          'desktop-lg:grid-col-6': panelsClosed(),
        }"
      >
        <mat-accordion>
          <mat-expansion-panel expanded>
            <mat-expansion-panel-header>
              <mat-panel-title>{{ plot.title }}</mat-panel-title>
            </mat-expansion-panel-header>
            <mat-divider />

            <nshmp-lib-ng-plot [plot]="plot.plotData()" />

            @if (plot.diffPlotData) {
              <div class="padding-top-4">
                <mat-divider />
                <nshmp-lib-ng-plot [plot]="plot.diffPlotData()" />
              </div>
            }
          </mat-expansion-panel>
        </mat-accordion>
      </div>
    }

    <div class="grid-col-12 plots-panel">
      <mat-accordion multi>
        <!-- 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>
    </div>
  </div>
</nshmp-lib-ng-plots-container>
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""