F4: TEA indicators display after review

- Prevalencia registrada (M31): the sex selector, its signal and the bar outline highlight are gone; the headline always shows the total rate and the bars keep one bar per sex
- Indicadores de oportunidad: the box charts show Q3, Mediana and Q1 in the hover, formatted with the shared one-decimal hover format, instead of annotations
- Porcentaje de confirmacion diagnostica (M24): the stacked bars, axis title, ticks, bar text and hover are in percent of the patients of each sex and age group
- Porcentaje de pacientes con / sin EEG (M21, M22): bar text shows the percentage only
- Headroom: the shared percent axis now ends at 110 with ticks every 20, and the shared plot builder never clips bar labels (cliponaxis false for every bar trace), so a 100 % bar keeps its label; the per-trace cliponaxis on the bar builders was removed
- Indicadores clinicos: route, grid and figure-row charts all use one height (430 px, was 300/320/360)

Choices: percent axis headroom lives in percentAxis, with rate dots keeping their own 0-100 range; the clinical height is a single component constant.
This commit is contained in:
2026-12-03 17:02:21 -06:00
parent dca39203d2
commit 3154ba92df
5 changed files with 78 additions and 98 deletions
+29 -60
View File
@@ -11,6 +11,8 @@ export const percentAxis = {
ticksuffix: ' %',
tickformat: '.0f',
hoverformat: SHORT,
range: [0, 110],
dtick: 20,
};
const count = (n: number) => n.toLocaleString('es-MX');
@@ -231,7 +233,7 @@ export function rateDots(
categoryarray: [...y].reverse(),
automargin: true,
},
xaxis: { range: [0, 100], ...percentAxis, zeroline: false, title: { text: spec.axis } },
xaxis: { ...percentAxis, range: [0, 100], zeroline: false, title: { text: spec.axis } },
annotations: rows.map((x) => ({
x: 1,
xref: 'paper',
@@ -272,17 +274,6 @@ export function fill(template: string, r: Reading): string {
export function boxFigure(r: Reading, period: string): Figure {
const q1 = r.low ?? r.score!;
const q3 = r.high ?? r.score!;
const label = (text: string, y: number, yanchor: 'top' | 'middle' | 'bottom') => ({
x: period,
y,
text: `${text} ${decimal(y)}`,
xref: 'x' as const,
yref: 'y' as const,
xanchor: 'left' as const,
yanchor,
xshift: 56,
showarrow: false,
});
return {
data: [
{
@@ -296,16 +287,11 @@ export function boxFigure(r: Reading, period: string): Figure {
upperfence: [q3],
marker: { color: '#4269C2' },
fillcolor: 'rgba(66,105,194,0.55)',
hoverinfo: 'skip',
hovertemplate: `Q3: %{q3:${SHORT}}<br>Mediana: %{median:${SHORT}}<br>Q1: %{q1:${SHORT}}<extra></extra>`,
} as Partial<Plotly.Data>,
],
layout: {
showlegend: false,
annotations: [
label('Q3', q3, 'bottom'),
label('Mediana', r.score!, 'middle'),
label('Q1', q1, 'top'),
],
yaxis: { title: { text: 'días' }, rangemode: 'tozero', ...valueAxis([q1, r.score!, q3]) },
},
};
@@ -399,32 +385,28 @@ export function ageStack(r: Reading, names: [string, string]): Figure {
return {
data: TEA_SEXES.flatMap(({ code, color }) => {
const rows = bands.map((band) => cells[`${band}|${code}`]);
const confirmed = rows.map((row) => row?.['numerator'] ?? 0);
const totals = rows.map((row) => row?.['denominator'] ?? 0);
return [confirmed, totals.map((n, i) => n - confirmed[i])].map((y, i) => ({
type: 'bar',
name: `${name(code)} · ${names[i]}`,
offsetgroup: code,
x,
y,
marker: { color: i ? rgba(color, 0.25) : color },
text: y.map((n, j) => (n ? `${n} (${percent((100 * n) / totals[j])} %)` : '')),
textposition: 'inside',
hovertemplate: '%{x}<br>%{fullData.name}: %{y:d} pacientes<extra></extra>',
})) as Partial<Plotly.Data>[];
const confirmed = rows.map((row, j) =>
totals[j] ? (100 * (row?.['numerator'] ?? 0)) / totals[j] : 0,
);
return [confirmed, totals.map((total, j) => (total ? 100 - confirmed[j] : 0))].map(
(y, i) => ({
type: 'bar',
name: `${name(code)} · ${names[i]}`,
offsetgroup: code,
x,
y,
marker: { color: i ? rgba(color, 0.25) : color },
text: y.map((share) => (share ? `${percent(share)} %` : '')),
textposition: 'inside',
hovertemplate: `%{x}<br>%{fullData.name}: %{y:${SHORT}} %<extra></extra>`,
}),
) as Partial<Plotly.Data>[];
}),
layout: {
barmode: 'stack',
xaxis: { title: { text: 'Grupo de edad' }, type: 'category' },
yaxis: {
title: { text: 'Pacientes' },
rangemode: 'tozero',
...valueAxis(
bands.flatMap((band) =>
TEA_SEXES.map(({ code }) => cells[`${band}|${code}`]?.['denominator'] ?? 0),
),
),
},
yaxis: { title: { text: '% de pacientes' }, ...percentAxis },
},
};
}
@@ -445,11 +427,7 @@ export function ageShare(r: Reading, axis: string): Figure {
x,
y: shares,
marker: { color },
text: shares.map((share, i) =>
share === null
? ''
: `${percent(share)} % (${rows[i]['numerator'] ?? 0}/${rows[i]['denominator']})`,
),
text: shares.map((share) => (share === null ? '' : `${percent(share)} %`)),
textposition: 'outside',
hovertemplate: '%{x}: %{text}<extra>%{fullData.name}</extra>',
};
@@ -457,7 +435,7 @@ export function ageShare(r: Reading, axis: string): Figure {
layout: {
barmode: 'group',
xaxis: { title: { text: 'Grupo de edad' }, type: 'category' },
yaxis: { title: { text: axis }, range: [0, 100], ...percentAxis },
yaxis: { title: { text: axis }, ...percentAxis },
},
};
}
@@ -674,17 +652,16 @@ function prevalenceCounts(r: Reading, sex?: string): { confirmed: number; total:
};
}
export function prevalenceHeadline(r: Reading, sex?: string) {
const found = sex ? r.rates?.['sex']?.[sex] : r.score;
if (found === undefined) return undefined;
const { confirmed, total } = prevalenceCounts(r, sex);
export function prevalenceHeadline(r: Reading) {
if (r.score === undefined) return undefined;
const { confirmed, total } = prevalenceCounts(r);
return {
value: perTenThousand(found),
value: perTenThousand(r.score),
detail: `${RATE_UNIT} · ${count(confirmed)} confirmados de ${count(total)} niños`,
};
}
export function teaSexBars(r: Reading, selectedSex?: string): Figure {
export function teaSexBars(r: Reading): Figure {
const x = TEA_SEXES.map(({ code }) => name(code));
const y = TEA_SEXES.map(({ code }) => r.rates?.['sex']?.[code] ?? 0);
return {
@@ -694,16 +671,9 @@ export function teaSexBars(r: Reading, selectedSex?: string): Figure {
name: 'Prevalencia registrada',
x,
y,
marker: {
color: TEA_SEXES.map(({ color }) => color),
line: {
color: '#000000',
width: TEA_SEXES.map(({ code }) => (code === selectedSex ? 2 : 0)),
},
},
marker: { color: TEA_SEXES.map(({ color }) => color) },
text: y.map((value) => perTenThousand(value)),
textposition: 'outside',
cliponaxis: false,
customdata: TEA_SEXES.map(({ code }) => {
const { confirmed, total } = prevalenceCounts(r, code);
return [confirmed, total];
@@ -736,7 +706,6 @@ export function teaAlterations(r: Reading): Figure {
marker: { color: rows.map((_, i) => PALETTE[(i + 1) % PALETTE.length]) },
text: rates.map((rate) => `${percent(rate)} %`),
textposition: 'outside',
cliponaxis: false,
customdata,
hovertemplate:
'%{x}<br>%{text} (%{customdata[0]} de %{customdata[1]} niños)<extra></extra>',