CaCu's page by readings, screening stages, ages and exports
This commit is contained in:
@@ -0,0 +1,144 @@
|
||||
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',
|
||||
imports: [Loading, MatButtonToggleModule, Plot],
|
||||
template: `
|
||||
<h3 class="title">{{ title() }}</h3>
|
||||
@if (headline()) {
|
||||
<p class="headline">{{ headline() }}</p>
|
||||
}
|
||||
@if (note()) {
|
||||
<p class="state">{{ note() }}</p>
|
||||
}
|
||||
@if (modes().length > 1) {
|
||||
<mat-button-toggle-group
|
||||
[attr.aria-label]="title()"
|
||||
[value]="mode().label"
|
||||
(change)="chosen.set($event.value)"
|
||||
>
|
||||
@for (m of modes(); track m.label) {
|
||||
<mat-button-toggle [value]="m.label">{{ m.label }}</mat-button-toggle>
|
||||
}
|
||||
</mat-button-toggle-group>
|
||||
}
|
||||
@if (mode().caption) {
|
||||
<p class="state">{{ mode().caption }}</p>
|
||||
}
|
||||
@if (loading()) {
|
||||
<app-loading what="la figura" [figure]="true" />
|
||||
} @else if (figure(); as f) {
|
||||
<app-plot [figure]="f" [height]="300" />
|
||||
} @else if (table(); as t) {
|
||||
<table [attr.aria-label]="mode().label">
|
||||
<thead>
|
||||
<tr>
|
||||
<th></th>
|
||||
@for (h of t.head; track h) {
|
||||
<th>{{ h }}</th>
|
||||
}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@for (row of t.rows; track row.label) {
|
||||
<tr>
|
||||
<th scope="row">
|
||||
{{ row.label }}
|
||||
<span class="track" aria-hidden="true">
|
||||
<span
|
||||
class="bar"
|
||||
[style.width.%]="row.width"
|
||||
[style.background]="row.color"
|
||||
></span>
|
||||
@for (m of row.marks; track $index) {
|
||||
<span class="mark" [style.left.%]="m"></span>
|
||||
}
|
||||
</span>
|
||||
</th>
|
||||
@for (c of row.cells; track $index) {
|
||||
<td>{{ c }}</td>
|
||||
}
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
} @else {
|
||||
<p class="state">Sin datos en el periodo.</p>
|
||||
}
|
||||
`,
|
||||
styles: `
|
||||
:host {
|
||||
display: block;
|
||||
min-width: 0;
|
||||
}
|
||||
.title {
|
||||
margin: 0 0 8px;
|
||||
}
|
||||
.headline {
|
||||
font-weight: 500;
|
||||
}
|
||||
mat-button-toggle-group {
|
||||
flex-wrap: wrap;
|
||||
margin: 4px 0;
|
||||
}
|
||||
table {
|
||||
border-collapse: collapse;
|
||||
width: 100%;
|
||||
}
|
||||
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%;
|
||||
}
|
||||
.mark {
|
||||
background: #333;
|
||||
height: 12px;
|
||||
position: absolute;
|
||||
top: -2px;
|
||||
width: 2px;
|
||||
}
|
||||
`,
|
||||
})
|
||||
export class Readings {
|
||||
readonly title = input.required<string>();
|
||||
readonly headline = input('');
|
||||
readonly note = input('');
|
||||
readonly modes = input.required<Mode[]>();
|
||||
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,
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user