import { Component, computed, input, signal } from '@angular/core'; import { MatButtonToggleModule } from '@angular/material/button-toggle'; import { Loading } from '../loading'; import { Figure, Plot } from '../plot'; import { bars, Mode } from './bars'; import { Reading } from './measures'; /** A card read one mode at a time: its title, its headline, the toggle and the bars. */ @Component({ selector: 'app-readings', host: { '[class.cama]': 'camaStyle()' }, imports: [Loading, MatButtonToggleModule, Plot], template: ` @if (!hideTitle()) {

{{ title() }}

} @if (headline()) {

{{ headline() }}

} @if (note()) {

{{ note() }}

} @if (modes().length > 1) { @for (m of modes(); track m.label) { {{ m.label }} } } @if (mode().heading) {

{{ mode().heading }}

} @if (mode().caption) {

{{ mode().caption }}

} @if (loading()) { } @else if (figure(); as f) { } @else if (table(); as t) { @for (h of t.head; track h) { } @for (row of t.rows; track row.label) { @for (c of row.cells; track $index) { } }
{{ h }}
{{ row.label }} @if (row.none) { {{ row.none }} } @else { } {{ c }}
@if (t.legend; as legend) {

@for (l of legend; track l.label) { {{ l.label }} }

} } @else {

Sin datos en el periodo.

} `, styles: ` :host { display: block; min-width: 0; } :host(.cama) { overflow-x: auto; } .title { margin: 0 0 8px; } :host(.cama) .title { font-size: 18px; font-weight: 500; } .heading { font-size: 14px; font-weight: 500; margin: 12px 0 4px; } .headline { font-weight: 500; } :host(.cama) .headline { margin: 8px 0; } :host(.cama) .state { color: var(--color-text-secondary); font-size: 13px; margin: 8px 0; } mat-button-toggle-group { flex-wrap: wrap; margin: 4px 0; } table { border-collapse: collapse; width: 100%; } :host(.cama) table { font-size: 13px; } :host(.cama) thead th { font-weight: 500; } th, td { font-weight: 400; padding: 4px 6px; text-align: right; white-space: nowrap; } th[scope='row'] { text-align: left; white-space: normal; width: 60%; } .track { background: rgba(0, 0, 0, 0.06); display: block; height: 8px; position: relative; } .bar { background: #a8c243; display: block; height: 100%; } .parts { display: flex; } .none { color: rgba(0, 0, 0, 0.6); display: block; font-size: 12px; font-weight: 400; } .legend { display: flex; flex-wrap: wrap; font-size: 12px; gap: 4px 16px; margin: 8px 0 0; } .legend i { display: inline-block; height: 10px; margin-right: 6px; width: 10px; } .mark { background: #333; height: 12px; position: absolute; top: -2px; width: 2px; } `, }) export class Readings { readonly title = input.required(); readonly headline = input(''); readonly note = input(''); /** the card around it names it already (tabs inside one card) */ readonly hideTitle = input(false); readonly camaStyle = input(false); readonly modes = input.required(); readonly loading = input(false); /** A measure's reading in the applied period, and the figure of a mode that has one. */ readonly read = input.required<(measure: string) => Reading | undefined>(); readonly draw = input.required<(mode: Mode) => Figure | undefined>(); protected readonly chosen = signal(''); protected readonly mode = computed( () => this.modes().find((m) => m.label === this.chosen()) ?? this.modes()[0], ); protected readonly table = computed(() => bars(this.mode(), this.read())); protected readonly figure = computed(() => this.mode().kind === 'figure' ? this.draw()(this.mode()) : undefined, ); }