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:
2026-11-22 16:30:01 -06:00
parent 7f1e43bdc5
commit f058f1f476
7 changed files with 34 additions and 18 deletions
@@ -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;