Screening route chart: it follows the page's period filter, with no filter of its own
The chart takes the page's period type and shows the newest of the periods the filter applies that has published boxes (the newest with data when the filter applies every period), so it moves with the other indicators. Its own period selector is gone; the period shown is written over the chart.
This commit is contained in:
@@ -8,12 +8,7 @@
|
||||
}
|
||||
@if (model(); as m) {
|
||||
<div class="controls">
|
||||
<mat-form-field appearance="outline" subscriptSizing="dynamic">
|
||||
<mat-label>Periodo</mat-label>
|
||||
<mat-select [value]="m.period" (selectionChange)="selectPeriod($event.value)" aria-label="Periodo de la ruta del tamizaje">
|
||||
@for (period of m.periods; track period) { <mat-option [value]="period">{{ periodLabel(period) }}</mat-option> }
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
@if (m.period) { <p class="period">Periodo: {{ periodLabel(m.period) }}</p> }
|
||||
<mat-button-toggle-group [value]="view()" (change)="selectView($event.value)" aria-label="Vista de los tiempos">
|
||||
<mat-button-toggle value="cumulative">Acumulado desde la toma</mat-button-toggle>
|
||||
<mat-button-toggle value="steps">Por pasos</mat-button-toggle>
|
||||
|
||||
@@ -64,8 +64,10 @@ describe('Ruta del tamizaje: componente', () => {
|
||||
expect((f.componentInstance.figure()!.data[0] as Record<string, unknown>)['base']).toBeUndefined();
|
||||
f.componentInstance.selectView('steps'); f.detectChanges();
|
||||
expect((f.componentInstance.figure()!.data[0] as Record<string, unknown>)['base']).toBeDefined();
|
||||
f.componentInstance.selectPeriod('2025-S1'); f.detectChanges();
|
||||
// the period follows the page's filter, with no request of its own
|
||||
f.componentRef.setInput('periodos', ['2025-S1']); f.detectChanges();
|
||||
expect(f.componentInstance.model()!.period).toBe('2025-S1');
|
||||
expect(f.nativeElement.querySelector('mat-select')).toBeNull();
|
||||
f.componentRef.setInput('tema', 'oscuro'); f.detectChanges();
|
||||
expect(f.componentInstance.figure()!.layout['paper_bgcolor']).toBe('#081839');
|
||||
http.expectNone(() => true);
|
||||
|
||||
@@ -3,9 +3,7 @@ import { HttpErrorResponse } from '@angular/common/http';
|
||||
import { forkJoin, Subscription, timeout, TimeoutError } from 'rxjs';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { MatButtonToggleModule } from '@angular/material/button-toggle';
|
||||
import { MatFormFieldModule } from '@angular/material/form-field';
|
||||
import { MatProgressBarModule } from '@angular/material/progress-bar';
|
||||
import { MatSelectModule } from '@angular/material/select';
|
||||
import { PlotlyChart } from '../../shared/plotly/plotly-chart';
|
||||
import { Dominio, IndicadorDatos, Tema, TipoPeriodo } from './indicadores.models';
|
||||
import { etiquetaPeriodo } from './indicadores-historico-figures';
|
||||
@@ -16,7 +14,7 @@ import { ROUTE_IDS, RouteIncompatible, RouteView, routeCellText, routeFigure, ro
|
||||
/** Days along the screening route, from the sample to each event, as horizontal bars: cumulative or step by step. */
|
||||
@Component({
|
||||
selector: 'app-indicador-screening-route',
|
||||
imports: [MatButtonModule, MatButtonToggleModule, MatFormFieldModule, MatProgressBarModule, MatSelectModule, PlotlyChart],
|
||||
imports: [MatButtonModule, MatButtonToggleModule, MatProgressBarModule, PlotlyChart],
|
||||
templateUrl: './indicador-screening-route.html',
|
||||
styleUrl: './indicador-screening-route.scss',
|
||||
})
|
||||
@@ -24,17 +22,18 @@ export class IndicadorScreeningRoute {
|
||||
readonly dominio = input.required<Dominio>();
|
||||
readonly tema = input.required<Tema>();
|
||||
readonly tipo = input<TipoPeriodo>('semestre');
|
||||
/** The periods of the page's filter: the chart shows the newest of them with data, and has no period filter of its own. */
|
||||
readonly periodos = input<readonly string[] | undefined>(undefined);
|
||||
/** The measures load once the region is visible. */
|
||||
readonly visible = input(true);
|
||||
|
||||
readonly status = signal<'deferred' | 'loading' | 'ready' | 'empty' | 'error' | 'incompatible'>('deferred');
|
||||
readonly message = signal('');
|
||||
readonly view = signal<RouteView>('cumulative');
|
||||
readonly requestedPeriod = signal<string | undefined>(undefined);
|
||||
private readonly payloads = signal<Record<string, IndicadorDatos> | undefined>(undefined);
|
||||
readonly model = computed(() => {
|
||||
const data = this.payloads();
|
||||
return data ? routeModel(data, this.tipo(), this.requestedPeriod()) : undefined;
|
||||
return data ? routeModel(data, this.tipo(), this.periodos()) : undefined;
|
||||
});
|
||||
readonly figure = computed(() => {
|
||||
const model = this.model();
|
||||
@@ -56,7 +55,6 @@ export class IndicadorScreeningRoute {
|
||||
}
|
||||
|
||||
retry() { this.load(this.dominio(), this.tipo()); }
|
||||
selectPeriod(period: string) { this.requestedPeriod.set(period); }
|
||||
selectView(view: RouteView) { this.view.set(view); }
|
||||
|
||||
private load(dominio: Dominio, tipo: TipoPeriodo) {
|
||||
@@ -67,7 +65,7 @@ export class IndicadorScreeningRoute {
|
||||
this.subscription = forkJoin(requests).pipe(timeout({ first: 40000 })).subscribe({
|
||||
next: data => {
|
||||
try {
|
||||
const model = routeModel(data, tipo, this.requestedPeriod());
|
||||
const model = routeModel(data, tipo, this.periodos());
|
||||
this.payloads.set(data);
|
||||
this.status.set(routeHasData(model) ? 'ready' : 'empty');
|
||||
} catch (error) { this.failure(error); }
|
||||
|
||||
@@ -126,7 +126,7 @@
|
||||
<span>Incluye el periodo y los indicadores seleccionados. Elige «Guardar como PDF» en el cuadro de impresión.</span>
|
||||
</div>
|
||||
}
|
||||
@if (screeningRouteAvailable) { <app-indicador-screening-route [dominio]="dominio" [tema]="tema" /> }
|
||||
@if (screeningRouteAvailable) { <app-indicador-screening-route [dominio]="dominio" [tema]="tema" [tipo]="filters?.applied?.tipo ?? 'semestre'" [periodos]="periodosDelFiltro()" /> }
|
||||
<div class="catalog-grid">
|
||||
@for (item of clinicosItems(); track cardIdentity(item)) {
|
||||
<app-indicador-catalog-card [id]="cardElementId(item)" [dominio]="dominio" [indicador]="item" [tema]="tema" [applied]="figureApplied(item)" [independentPeriods]="independentPeriods(item)"
|
||||
|
||||
@@ -344,6 +344,12 @@ export class IndicadoresPage {
|
||||
return this.dominio === 'cama' && !this.catalogLoading() && !this.catalogError() && this.catalog().length > 0
|
||||
&& !this.catalog().some(item => item.id === ID_HISTOPATOLOGIA_CAMA);
|
||||
}
|
||||
/** The periods the page's filter applies, for the charts that follow it with no filter of their own (the screening
|
||||
* route); `undefined` when it applies every period. */
|
||||
periodosDelFiltro(): readonly string[] | undefined {
|
||||
const seleccion = this.filters?.applied.selection;
|
||||
return seleccion?.mode === 'explicit' ? seleccion.periodos : undefined;
|
||||
}
|
||||
// CaCu's screening route chart, once the catalog publishes every measure it reads.
|
||||
get screeningRouteAvailable() {
|
||||
return this.dominio === 'cacu' && ROUTE_IDS.every(id => this.catalog().some(item => item.id === id));
|
||||
|
||||
@@ -49,6 +49,17 @@ describe('Ruta del tamizaje: modelo', () => {
|
||||
expect(routeModel(data, 'semestre').period).toBe('2025-S2');
|
||||
expect(routeModel(data, 'semestre', '2026-S1').period).toBe('2026-S1');
|
||||
});
|
||||
it('con los periodos del filtro de la página se usa el más reciente de ellos con cajas publicadas', () => {
|
||||
// Fails if the chart, which has no period filter of its own, ignores the page's periods or opens on an empty one of
|
||||
// them while an earlier one it was given has data.
|
||||
const vacio = (id: string) => payload(id, [row('2025-S1', [10, 1, 2, 3]), row('2025-S2', S2[id]),
|
||||
row('2026-S1', [0, null as never, null as never, null as never], { suprimido: 1 })], ['2025-S1', '2025-S2', '2026-S1']);
|
||||
const data = Object.fromEntries(ROUTE_IDS.map(id => [id, vacio(id)]));
|
||||
expect(routeModel(data, 'semestre', ['2025-S1', '2026-S1', '2025-S2']).period).toBe('2025-S2');
|
||||
expect(routeModel(data, 'semestre', ['2025-S1']).period).toBe('2025-S1');
|
||||
expect(routeModel(data, 'semestre', ['2026-S1']).period).toBe('2026-S1');
|
||||
expect(routeModel(data, 'semestre', ['2023-S1']).period).toBe('2025-S2');
|
||||
});
|
||||
it('un paso suprimido o sin datos no se dibuja y la cadena sigue desde el último publicado', () => {
|
||||
// Pins down: nothing is drawn as zero and the next step starts at the last published end. Fails if a suppressed box
|
||||
// becomes a bar or leaves a gap in the chain.
|
||||
|
||||
@@ -47,7 +47,8 @@ const fail = (message: string): never => { throw new RouteIncompatible(message);
|
||||
const NOT_AVAILABLE: Caja = { estado: 'No disponible' };
|
||||
|
||||
/** The seven C3r /datos payloads -> one row per event for a period, newest period first when none is requested. */
|
||||
export function routeModel(data: Record<string, IndicadorDatos>, tipo: TipoPeriodo, requested?: string): RouteModel {
|
||||
export function routeModel(data: Record<string, IndicadorDatos>, tipo: TipoPeriodo,
|
||||
requested?: string | readonly string[]): RouteModel {
|
||||
const boxes: Record<string, Record<string, Caja>> = {};
|
||||
for (const id of ROUTE_IDS) {
|
||||
const d = data[id];
|
||||
@@ -66,9 +67,12 @@ export function routeModel(data: Record<string, IndicadorDatos>, tipo: TipoPerio
|
||||
}
|
||||
}
|
||||
const periods = [...new Set(ROUTE_IDS.flatMap(id => data[id].periodos))].sort().reverse();
|
||||
// Without a valid request the newest period that has a published box: a semester that has just begun is empty.
|
||||
// The newest of the requested periods (the page's filter) that has a published box, else the newest requested one;
|
||||
// without a valid request, the newest period that has a published box: a semester that has just begun is empty.
|
||||
const hasData = (p: string) => ROUTE_IDS.some(id => boxes[id][p]?.estado === 'Publicado');
|
||||
const period = requested && periods.includes(requested) ? requested : periods.find(hasData) ?? periods[0];
|
||||
const pedidos = (typeof requested === 'string' ? [requested] : [...(requested ?? [])])
|
||||
.filter(p => periods.includes(p)).sort().reverse();
|
||||
const period = pedidos.length ? pedidos.find(hasData) ?? pedidos[0] : periods.find(hasData) ?? periods[0];
|
||||
let cursor = 0;
|
||||
const rows = ROUTE_STEPS.map((step): RouteRow => {
|
||||
const fromSample = period ? boxes[step.sinceSample][period] ?? NOT_AVAILABLE : NOT_AVAILABLE;
|
||||
|
||||
Reference in New Issue
Block a user