Trazabilidad, Datos y definiciones and the risk lists as the old app: declared panels, old labels and order; page tests against the capture
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import type { Figure } from '../plot';
|
||||
import type { Reading } from './measures';
|
||||
import type { Catalog, Category } from './pages';
|
||||
import { type Figure, PALETTE } from '../plot';
|
||||
import { name, type Reading } from './measures';
|
||||
import type { Catalog, Category, HistoryPanel } from './pages';
|
||||
|
||||
const OLIVE = '#A8C243';
|
||||
const ROSE = '#C24269';
|
||||
@@ -415,3 +415,64 @@ export function ageShare(r: Reading, axis: string): Figure {
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/** A Trazabilidad panel's figure (pages.HISTORY), as the old tab drew it: stacked bars by
|
||||
* category, or a line with its band (95 % interval, or first to third quartile) drawn as one
|
||||
* closed shape. */
|
||||
export function historyFigure(
|
||||
panel: HistoryPanel,
|
||||
series: { label: string; r: Reading | undefined }[],
|
||||
line: string,
|
||||
xTitle: string,
|
||||
): Figure {
|
||||
const x = series.map((s) => s.label);
|
||||
const layout = (y: string) => ({
|
||||
xaxis: { title: { text: xTitle }, type: 'category' as const },
|
||||
yaxis: { title: { text: y } },
|
||||
});
|
||||
if (panel.kind === 'stack') {
|
||||
const found = [...new Set(series.flatMap((s) => Object.keys(s.r?.strata['category'] ?? {})))];
|
||||
const declared = panel.series ?? [];
|
||||
const named = [
|
||||
...declared,
|
||||
...found
|
||||
.filter((c) => !declared.some((d) => d.code === c))
|
||||
.map((c, i) => ({ code: c, label: name(c), color: PALETTE[i % PALETTE.length] })),
|
||||
];
|
||||
return {
|
||||
data: named.map((c) => ({
|
||||
type: 'bar',
|
||||
name: c.label,
|
||||
x,
|
||||
y: series.map((s) => s.r?.strata['category']?.[c.code]?.['initial-population'] ?? 0),
|
||||
marker: { color: c.color },
|
||||
})),
|
||||
layout: { ...layout(panel.axis ?? 'Pacientes'), barmode: 'stack' },
|
||||
};
|
||||
}
|
||||
const k = panel.kind === 'percent' ? 100 : 1;
|
||||
const at = (v?: number) => (v === undefined ? null : v * k);
|
||||
return {
|
||||
data: [
|
||||
{
|
||||
x: [...x, ...[...x].reverse()],
|
||||
y: [...series.map((s) => at(s.r?.high)), ...[...series].reverse().map((s) => at(s.r?.low))],
|
||||
mode: 'lines',
|
||||
fill: 'toself',
|
||||
fillcolor: line + '33',
|
||||
line: { width: 0 },
|
||||
name: panel.kind === 'percent' ? 'Intervalo de confianza' : 'Primer a tercer cuartil',
|
||||
hoverinfo: 'skip',
|
||||
},
|
||||
{
|
||||
x,
|
||||
y: series.map((s) => at(s.r?.score)),
|
||||
mode: 'lines+markers',
|
||||
name: panel.kind === 'percent' ? 'Porcentaje' : 'Mediana',
|
||||
line: { color: line },
|
||||
marker: { color: line },
|
||||
},
|
||||
],
|
||||
layout: layout(panel.kind === 'percent' ? 'Porcentaje' : 'Días'),
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user