Clarify CaCu and CaMa chart labels

This commit is contained in:
Angel Capetillo Zavala
2026-12-03 15:18:22 -06:00
parent d38c795c8a
commit 63f6e16d19
13 changed files with 122 additions and 51 deletions
+41 -10
View File
@@ -16,6 +16,10 @@ export type Mode = {
kind: 'counts';
measure: string;
catalog: Category[];
/** The records counted in the category distribution. */
unit?: string;
/** What the share in the second column is a share of. */
percentLabel?: string;
hidden?: Hidden;
/** every bar on a fixed scale of 0 to 100 %, so its length is the share shown */
percent?: boolean;
@@ -27,6 +31,7 @@ export type Mode = {
order: string[];
complete?: boolean;
colors?: Colors;
percentLabel?: string;
}
| {
kind: 'positives';
@@ -35,8 +40,15 @@ export type Mode = {
order: string[];
complete?: boolean;
colors?: Colors;
percentLabel?: string;
}
| {
kind: 'signs';
measure: string;
strata: string[];
colors?: Colors;
percentLabel?: string;
}
| { kind: 'signs'; measure: string; strata: string[]; colors?: Colors }
| {
kind: 'grouped';
measure: string;
@@ -47,6 +59,8 @@ export type Mode = {
order: string[];
/** what the records are called ("pacientes", "reportes") */
unit: string;
/** The denominator of the percentage shown with each grouped result. */
percentLabel?: string;
/** draw an empty group of `order` when the counts reconcile (see `reconciles`) */
complete?: boolean;
/** each group's denominator is all its records, not only those of the catalog's categories */
@@ -55,10 +69,18 @@ export type Mode = {
}
| { kind: 'days'; steps: { label: string; measure: string }[]; tint?: Tint }
/** A proportion as one bar of 0 to 100 %, its 95 % interval as the two marks on it */
| { kind: 'ratio'; measure: string; colors?: Colors }
| { kind: 'ratio'; measure: string; colors?: Colors; percentLabel?: string }
| { kind: 'days-by'; measure: string; stratum: string; tint?: Tint }
/** A proportion as its two parts (what counted and what did not), in units, with the shares */
| { kind: 'split'; measure: string; yes: string; no: string; colors?: [string, string] }
| {
kind: 'split';
measure: string;
yes: string;
no: string;
colors?: [string, string];
unit?: string;
percentLabel?: string;
}
/** Each row's units by result (a bar in segments), and the share of the row's units with a
* result that are `malignant`; a row with units and no result is not a row with none */
| {
@@ -213,7 +235,7 @@ export function bars(mode: Mode, of: (measure: string) => Reading | undefined):
if (r?.score === undefined || !total) return undefined;
const ends = r.low !== undefined && r.high !== undefined ? [r.low, r.high] : [];
return {
head: ['n/N', '%', 'IC 95 %'],
head: ['n/N', mode.percentLabel ?? 'Porcentaje', 'IC 95 %'],
rows: [
{
label: 'Total',
@@ -239,7 +261,7 @@ export function bars(mode: Mode, of: (measure: string) => Reading | undefined):
];
const most = mode.percent ? total : Math.max(...Object.values(cells).map(size));
return {
head: ['n', '%'],
head: [mode.unit ?? 'n', mode.percentLabel ?? 'Porcentaje'],
rows: all.map(({ code, label, color }) => {
const n = size(cells[code]);
const cols = [`${n}`, pct(n, total)];
@@ -261,6 +283,7 @@ export function bars(mode: Mode, of: (measure: string) => Reading | undefined):
cells[c]['denominator'] ?? 0,
mode.colors?.[c],
]),
mode.percentLabel,
);
if (!patients(r) || !Object.keys(cells).length) return undefined;
const sound = (c: string) =>
@@ -277,6 +300,7 @@ export function bars(mode: Mode, of: (measure: string) => Reading | undefined):
ok,
(c) => (sound(c) ? [cells[c]['numerator'], cells[c]['denominator']] : undefined),
mode.colors,
mode.percentLabel,
);
}
case 'positives': {
@@ -291,6 +315,7 @@ export function bars(mode: Mode, of: (measure: string) => Reading | undefined):
const positive = size(cells[`${c}|positive`]);
return [name(c), positive, positive + size(cells[`${c}|negative`]), mode.colors?.[c]];
}),
mode.percentLabel,
);
if (!patients(r) || !found.size) return undefined;
const ok = reconciles(
@@ -306,6 +331,7 @@ export function bars(mode: Mode, of: (measure: string) => Reading | undefined):
return [positive, positive + size(cells[`${c}|negative`])];
},
mode.colors,
mode.percentLabel,
);
}
case 'signs': {
@@ -317,6 +343,7 @@ export function bars(mode: Mode, of: (measure: string) => Reading | undefined):
const positive = size(strata[s]['positive']);
return [name(s), positive, positive + size(strata[s]['negative']), mode.colors?.[s]];
}),
mode.percentLabel,
);
}
case 'days':
@@ -349,7 +376,7 @@ export function bars(mode: Mode, of: (measure: string) => Reading | undefined):
[mode.no, denominator - numerator],
];
return {
head: ['n', '%'],
head: [mode.unit ?? 'n', mode.percentLabel ?? 'Porcentaje'],
rows: parts.map(([label, n], i) => ({
label,
color: mode.colors?.[i],
@@ -480,6 +507,7 @@ function complete(
reconciled: boolean,
counts: (code: string) => [number, number] | undefined,
colors: Colors = {},
percentLabel = 'Porcentaje',
): Bars {
const extra = listed.filter((c) => !order.includes(c));
const rows: Bar[] = [...order, ...extra].map((code) => {
@@ -507,7 +535,7 @@ function complete(
const none = empty.length === classified.length;
const unclassified = counts('no_data')?.[1] ?? 0;
return {
head: ['n/N', '%'],
head: ['n/N', percentLabel],
rows,
note: !reconciled
? 'Los conteos del informe no concilian con el total de pacientes: los grupos ausentes no se muestran como cero.'
@@ -520,10 +548,13 @@ function complete(
};
}
function ratios(rows: [string, number, number, string?][]): Bars | undefined {
function ratios(
rows: [string, number, number, string?][],
percentLabel = 'Porcentaje',
): Bars | undefined {
if (!rows.length) return undefined;
return {
head: ['n/N', '%'],
head: ['n/N', percentLabel],
rows: rows.map(([label, n, total, color]) => ({
label,
color,
@@ -543,7 +574,7 @@ function medians(
const top = Math.max(...rows.flatMap((r) => [r.score?.score ?? 0, r.score?.high ?? 0])) || 1;
const at = (v: number) => (100 * v) / top;
return {
head: ['Mediana', 'n', 'Q1–Q3'],
head: ['Mediana', 'Observaciones', 'Q1–Q3'],
markColor: tint?.mark,
rows: rows.map(({ label, n, score: s }) => {
if (s?.score === undefined) return { label, width: 0, marks: [], cells: ['—', `${n}`, '—'] };