File

components/disagg-data/disagg-data.component.ts

Metadata

Index

Properties
Methods
Inputs

Constructor

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

Inputs

componentData
Required :  true

Disaggregation component data state

showExportButton
Default value : true

Methods

epsilonKeys
epsilonKeys()
Returns : string[]
toBinData
toBinData(data: DisaggData)
Parameters :
Name Type Optional
data DisaggData No
Returns : string[]

Properties

Readonly componentData

Disaggregation component data state

metadata
Default value : computed(() => this.service.serviceResponse().response.metadata)
Public service
Type : AppService
Readonly showExportButton
Default value : true
import {Component, computed, input} from '@angular/core';
import {MatButton} from '@angular/material/button';
import {MatDivider} from '@angular/material/divider';
import {
  DisaggComponentData,
  DisaggData,
} from '@ghsc/nshmp-utils-ts/libs/nshmp-haz/www/disagg-service';

import {AppService} from '../../services/app.service';

@Component({
  imports: [MatDivider, MatButton],
  selector: 'app-disagg-data',
  styleUrl: './disagg-data.component.scss',
  templateUrl: './disagg-data.component.html',
})
export class DisaggDataComponent {
  /** Disaggregation component data state */
  readonly componentData = input.required<DisaggComponentData>();

  readonly showExportButton = input(true);

  metadata = computed(() => this.service.serviceResponse().response.metadata);

  constructor(public service: AppService) {}

  toBinData(data: DisaggData): string[] {
    const bins = this.service.serviceResponse().response.metadata.εbins;

    const binData = bins.map(
      bin => data.εdata.find(data => data.εbin === bin.id)?.value ?? 0,
    );

    const total = binData.reduce((a, b) => a + b, 0);

    return [total, ...binData].map(num => num.toExponential(2));
  }

  epsilonKeys(): string[] {
    const keys = this.componentData().summary.find(
      data => data.name.toLowerCase() === 'epsilon keys',
    );

    return ['ALL_ε', ...keys.data.map(data => `${data.name}=${data.value}`)];
  }
}
@if (componentData()) {
  @if (componentData().data.length > 0) {
    @if (showExportButton()) {
      <!-- Export button -->
      <div class="print-display-none">
        <button
          class="primary export-button"
          mat-raised-button
          [disabled]="componentData().data === null"
          (click)="service.saveComponentData()"
        >
          Export Data as CSV
        </button>
      </div>

      <mat-divider />
    }

    <div class="horizontal-scrolling disagg-data">
      <div>
        <table class="grid-col-12">
          <thead>
            <tr>
              <th nowrap>{{ metadata().rlabel }}</th>
              <th nowrap>{{ metadata().mlabel }}</th>
              @for (key of epsilonKeys(); track key) {
                <th nowrap>{{ key }}</th>
              }
            </tr>
          </thead>
          <tbody>
            @for (data of componentData().data; track data) {
              <tr>
                <td noWrap>{{ data.r }}</td>
                <td nowrap>{{ data.m }}</td>

                @for (binData of toBinData(data); track $index) {
                  <td nowrap>{{ binData }}</td>
                }
              </tr>
            }
          </tbody>
        </table>
      </div>
    </div>
  }
}
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""