File

components/plots/plots.component.ts

Description

Main application plots showing magnitude frequency distribution: magnitude vs. rate.

By default all MFD types are show, select menu with ability to change to specific MFD type.

Implements

OnInit OnDestroy

Metadata

Index

Properties
Methods

Constructor

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

Methods

ngOnDestroy
ngOnDestroy()
Returns : void
ngOnInit
ngOnInit()
Returns : void

Properties

formGroup
Default value : this.service.formGroup

Form field state

mfdPlotData
Default value : this.service.mfdPlotData

MFD plot data state

Private mfdSubscription
Default value : new Subscription()
MfdType
Default value : MfdType
mfdTypes
Default value : computed(() => { const serviceResponse = this.service.serviceResponse(); if (serviceResponse === null) { return []; } const mfdTypes = serviceResponse.response.branches .map(branch => { return branch.mfds.map(mfdInfo => mfdInfo.mfd.props.type); }) .reduce((prev, curr) => [...prev, ...curr]); return Array.from(new Set(mfdTypes)).sort((a, b) => a.localeCompare(b)); })

MFD types plotted for select menu

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

Repo metadata

import {Component, computed, OnDestroy, OnInit} from '@angular/core';
import {ReactiveFormsModule} from '@angular/forms';
import {MatOption} from '@angular/material/core';
import {MatDivider} from '@angular/material/divider';
import {
  MatAccordion,
  MatExpansionPanel,
  MatExpansionPanelHeader,
  MatExpansionPanelTitle,
} from '@angular/material/expansion';
import {MatFormField, MatLabel} from '@angular/material/form-field';
import {MatSelect} from '@angular/material/select';
import {NshmpLibNgAppMetadataComponent} from '@ghsc/nshmp-lib-ng/nshmp';
import {
  NshmpLibNgPlotComponent,
  NshmpLibNgPlotsContainerComponent,
} from '@ghsc/nshmp-lib-ng/plot';
import {Subscription} from 'rxjs';

import {MfdType} from '../../models/control-form.model';
import {AppService} from '../../services/app.service';
import {ParameterSummaryComponent} from '../parameter-summary/parameter-summary.component';

/**
 * Main application plots showing magnitude frequency distribution: magnitude vs. rate.
 *
 * By default all MFD types are show, select menu with ability to change to specific MFD type.
 */
@Component({
  imports: [
    NshmpLibNgPlotsContainerComponent,
    NshmpLibNgPlotComponent,
    NshmpLibNgAppMetadataComponent,
    MatAccordion,
    MatExpansionPanel,
    MatExpansionPanelHeader,
    MatExpansionPanelTitle,
    MatDivider,
    MatFormField,
    MatLabel,
    MatSelect,
    MatOption,
    ParameterSummaryComponent,
    ReactiveFormsModule,
  ],
  selector: 'app-plots',
  styleUrl: './plots.component.scss',
  templateUrl: './plots.component.html',
})
export class PlotsComponent implements OnInit, OnDestroy {
  MfdType = MfdType;

  /** Form field state */
  formGroup = this.service.formGroup;

  /** MFD plot data state */
  mfdPlotData = this.service.mfdPlotData;

  /** MFD types plotted for select menu */
  mfdTypes = computed(() => {
    const serviceResponse = this.service.serviceResponse();

    if (serviceResponse === null) {
      return [];
    }

    const mfdTypes = serviceResponse.response.branches
      .map(branch => {
        return branch.mfds.map(mfdInfo => mfdInfo.mfd.props.type);
      })
      .reduce((prev, curr) => [...prev, ...curr]);

    return Array.from(new Set(mfdTypes)).sort((a, b) => a.localeCompare(b));
  });

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

  private mfdSubscription = new Subscription();

  constructor(private service: AppService) {}

  ngOnInit(): void {
    this.mfdSubscription =
      this.formGroup.controls.mfdType.valueChanges.subscribe(() => {
        if (
          this.formGroup.controls.mfdType.enabled &&
          this.service.serviceResponse() !== null
        ) {
          this.service.createPlots();
        }
      });
  }
  ngOnDestroy(): void {
    this.mfdSubscription.unsubscribe();
  }
}
<nshmp-lib-ng-plots-container>
  <mat-accordion multi>
    <!-- MFD plot -->
    <mat-expansion-panel expanded>
      <mat-expansion-panel-header>
        <mat-panel-title>Magnitude Frequency Distribution</mat-panel-title>
      </mat-expansion-panel-header>

      <mat-divider />

      <!-- Select MFD type -->
      <div>
        <mat-form-field class="grid-col-12 padding-top-4 mfd-type-select">
          <mat-label>MFD Type</mat-label>

          <mat-select [formControl]="formGroup.controls?.mfdType">
            <mat-option [value]="MfdType.ALL">
              {{ MfdType.ALL }}
            </mat-option>

            <mat-option [value]="MfdType.TOTAL">
              {{ MfdType.TOTAL }}
            </mat-option>

            @for (mfdType of mfdTypes(); track mfdType) {
              <mat-option [value]="mfdType">
                {{ mfdType }}
              </mat-option>
            }
          </mat-select>
        </mat-form-field>
      </div>

      @if (mfdPlotData()) {
        <nshmp-lib-ng-plot class="mfd-plot" [plot]="mfdPlotData()" />
      }
    </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 ""