Every chart uses the shared short number format: axes, hover and bar/value text
Counts print as integers and other values with at most one decimal, in tick labels (valueAxis, percentAxis), hover templates and bar and pie text.
This commit is contained in:
@@ -4,6 +4,8 @@ import type { Catalog, Category, HistoryPanel } from './pages';
|
||||
|
||||
const OLIVE = '#A8C243';
|
||||
const ROSE = '#C24269';
|
||||
export const SHORT = '.1~f';
|
||||
export const percentAxis = { ticksuffix: ' %', tickformat: '.0f', hoverformat: SHORT };
|
||||
|
||||
const count = (n: number) => n.toLocaleString('es-MX');
|
||||
const percent = (n: number) => (Math.round(n * 10) / 10).toLocaleString('es-MX');
|
||||
@@ -32,12 +34,17 @@ export function routeFigure(steps: { label: string; r: Reading | undefined }[]):
|
||||
array: shown.map((s) => (s.r!.high ?? s.r!.score!) - s.r!.score!),
|
||||
arrayminus: shown.map((s) => s.r!.score! - (s.r!.low ?? s.r!.score!)),
|
||||
},
|
||||
hovertemplate: '%{y}<br>mediana %{x} días<extra></extra>',
|
||||
hovertemplate: `%{y}<br>mediana %{x:${SHORT}} días<extra></extra>`,
|
||||
} as Partial<Plotly.Data>,
|
||||
],
|
||||
layout: {
|
||||
showlegend: false,
|
||||
xaxis: { title: { text: 'Días' }, rangemode: 'tozero', zeroline: false },
|
||||
xaxis: {
|
||||
title: { text: 'Días' },
|
||||
rangemode: 'tozero',
|
||||
zeroline: false,
|
||||
...valueAxis(shown.flatMap((s) => [s.r!.score, s.r!.high])),
|
||||
},
|
||||
yaxis: { autorange: 'reversed', type: 'category', automargin: true },
|
||||
},
|
||||
};
|
||||
@@ -96,7 +103,7 @@ export function nestedDonut(r: Reading, catalog: Catalog, center: string): Figur
|
||||
),
|
||||
line: { color: '#FFFFFF', width: 2 },
|
||||
},
|
||||
hovertemplate: '%{label}<br>%{value} (%{percent})<extra></extra>',
|
||||
hovertemplate: '%{label}<br>%{value:d} (%{percent:.1~%})<extra></extra>',
|
||||
},
|
||||
{
|
||||
...common,
|
||||
@@ -111,7 +118,7 @@ export function nestedDonut(r: Reading, catalog: Catalog, center: string): Figur
|
||||
colors: catalog.categories.map((c) => rgba(c.color, faded.has(c.code) ? 0.3 : 1)),
|
||||
line: { color: '#FFFFFF', width: 2 },
|
||||
},
|
||||
hovertemplate: '%{label}<br>%{value} (%{percent})<extra></extra>',
|
||||
hovertemplate: '%{label}<br>%{value:d} (%{percent:.1~%})<extra></extra>',
|
||||
},
|
||||
] as Partial<Plotly.Data>[],
|
||||
layout: { margin: { t: 10, l: 10, r: 10, b: 10 } },
|
||||
@@ -140,13 +147,13 @@ export function scenarioBars(
|
||||
x: scenarios.map((s, i) => (totals[i] ? (100 * n(s, c.code)) / totals[i] : 0)),
|
||||
customdata: scenarios.map((s) => n(s, c.code)),
|
||||
marker: { color: c.color },
|
||||
hovertemplate: `${c.label}<br>%{y}: %{customdata} (%{x:.1f} %)<extra></extra>`,
|
||||
hovertemplate: `${c.label}<br>%{y}: %{customdata} (%{x:.1~f} %)<extra></extra>`,
|
||||
})) as Partial<Plotly.Data>[],
|
||||
layout: {
|
||||
barmode: 'stack',
|
||||
xaxis: {
|
||||
title: { text: '% de pacientes del escenario con resultado' },
|
||||
ticksuffix: ' %',
|
||||
...percentAxis,
|
||||
range: [0, 100.5],
|
||||
dtick: 20,
|
||||
},
|
||||
@@ -206,7 +213,7 @@ export function rateDots(
|
||||
array: rows.map((x) => (x.rate === null ? 0 : x.high! - x.rate)),
|
||||
arrayminus: rows.map((x) => (x.rate === null ? 0 : x.rate - x.low!)),
|
||||
},
|
||||
hovertemplate: '%{y}: %{x:.1f} %<extra></extra>',
|
||||
hovertemplate: '%{y}: %{x:.1~f} %<extra></extra>',
|
||||
} as Partial<Plotly.Data>,
|
||||
],
|
||||
layout: {
|
||||
@@ -218,7 +225,7 @@ export function rateDots(
|
||||
categoryarray: [...y].reverse(),
|
||||
automargin: true,
|
||||
},
|
||||
xaxis: { range: [0, 100], ticksuffix: ' %', zeroline: false, title: { text: spec.axis } },
|
||||
xaxis: { range: [0, 100], ...percentAxis, zeroline: false, title: { text: spec.axis } },
|
||||
annotations: rows.map((x) => ({
|
||||
x: 1,
|
||||
xref: 'paper',
|
||||
@@ -274,7 +281,10 @@ export function boxFigure(r: Reading, period: string): Figure {
|
||||
hovertemplate: `Q1 ${decimal(q1)} · mediana ${decimal(r.score!)} · Q3 ${decimal(q3)} días<extra></extra>`,
|
||||
} as Partial<Plotly.Data>,
|
||||
],
|
||||
layout: { showlegend: false, yaxis: { title: { text: 'días' }, rangemode: 'tozero' } },
|
||||
layout: {
|
||||
showlegend: false,
|
||||
yaxis: { title: { text: 'días' }, rangemode: 'tozero', ...valueAxis([q1, r.score!, q3]) },
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -294,9 +304,9 @@ export function shareDonut(r: Reading, catalog: Catalog, center: string): Figure
|
||||
colors: catalog.categories.map((c) => c.color),
|
||||
line: { color: '#FFFFFF', width: 2 },
|
||||
},
|
||||
texttemplate: values.map((v) => (v ? '%{label}<br>%{percent}' : '')),
|
||||
texttemplate: values.map((v) => (v ? '%{label}<br>%{percent:.1~%}' : '')),
|
||||
textposition: 'outside',
|
||||
hovertemplate: '%{label}<br>%{value} (%{percent})<extra></extra>',
|
||||
hovertemplate: '%{label}<br>%{value:d} (%{percent:.1~%})<extra></extra>',
|
||||
} as Partial<Plotly.Data>,
|
||||
],
|
||||
layout: {
|
||||
@@ -327,9 +337,9 @@ export function countBars(r: Reading, catalog: Catalog, axis: string, period: st
|
||||
y,
|
||||
x: catalog.categories.map((c) => counted(r, c.code)),
|
||||
marker: { color: catalog.categories.map((c) => c.color) },
|
||||
texttemplate: '%{x}',
|
||||
texttemplate: '%{x:d}',
|
||||
textposition: 'outside',
|
||||
hovertemplate: '%{y}: %{x}<extra></extra>',
|
||||
hovertemplate: '%{y}: %{x:d}<extra></extra>',
|
||||
} as Partial<Plotly.Data>,
|
||||
],
|
||||
layout: {
|
||||
@@ -377,13 +387,21 @@ export function ageStack(r: Reading, names: [string, string]): Figure {
|
||||
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} pacientes<extra></extra>',
|
||||
hovertemplate: '%{x}<br>%{fullData.name}: %{y:d} pacientes<extra></extra>',
|
||||
})) as Partial<Plotly.Data>[];
|
||||
}),
|
||||
layout: {
|
||||
barmode: 'stack',
|
||||
xaxis: { title: { text: 'Grupo de edad' }, type: 'category' },
|
||||
yaxis: { title: { text: 'Pacientes' }, rangemode: 'tozero' },
|
||||
yaxis: {
|
||||
title: { text: 'Pacientes' },
|
||||
rangemode: 'tozero',
|
||||
...valueAxis(
|
||||
bands.flatMap((band) =>
|
||||
TEA_SEXES.map(({ code }) => cells[`${band}|${code}`]?.['denominator'] ?? 0),
|
||||
),
|
||||
),
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -402,14 +420,14 @@ export function ageShare(r: Reading, axis: string): Figure {
|
||||
return row?.['denominator'] ? (100 * (row['numerator'] ?? 0)) / row['denominator'] : null;
|
||||
}),
|
||||
marker: { color },
|
||||
texttemplate: '%{y:.1f} %',
|
||||
texttemplate: '%{y:.1~f} %',
|
||||
textposition: 'outside',
|
||||
hovertemplate: '%{x}: %{y:.1f} %<extra>%{fullData.name}</extra>',
|
||||
hovertemplate: '%{x}: %{y:.1~f} %<extra>%{fullData.name}</extra>',
|
||||
})),
|
||||
layout: {
|
||||
barmode: 'group',
|
||||
xaxis: { title: { text: 'Grupo de edad' }, type: 'category' },
|
||||
yaxis: { title: { text: axis }, range: [0, 100], ticksuffix: ' %' },
|
||||
yaxis: { title: { text: axis }, range: [0, 100], ...percentAxis },
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -420,7 +438,8 @@ export function valueAxis(values: Iterable<number | null | undefined>) {
|
||||
const narrow = found.length > 0 && Math.max(...found) - Math.min(...found) <= 5;
|
||||
return {
|
||||
type: 'linear' as const,
|
||||
tickformat: counts ? 'd' : '.1~f',
|
||||
tickformat: counts ? 'd' : SHORT,
|
||||
hoverformat: counts ? 'd' : SHORT,
|
||||
...(counts && narrow ? { dtick: 1 } : {}),
|
||||
};
|
||||
}
|
||||
@@ -499,7 +518,7 @@ export function sexCountBars(r: Reading, catalog: Catalog, axis: string, period:
|
||||
name: name(code),
|
||||
marker: { color },
|
||||
x: catalog.categories.map((c) => cells[`${code}|${c.code}`]?.['initial-population'] ?? 0),
|
||||
hovertemplate: '%{y}: %{x}<extra>%{fullData.name}</extra>',
|
||||
hovertemplate: '%{y}: %{x:d}<extra>%{fullData.name}</extra>',
|
||||
})) as Partial<Plotly.Data>[],
|
||||
layout: { ...base.layout, barmode: 'group', showlegend: true },
|
||||
};
|
||||
@@ -592,13 +611,19 @@ export function teaSexBars(r: Reading, selectedSex?: string): Figure {
|
||||
return [percent(total ? (100 * y[j]) / total : 0), total];
|
||||
}),
|
||||
hovertemplate:
|
||||
'%{x} · %{fullData.name}<br>%{y} niños, %{customdata[0]} % de %{customdata[1]}<extra></extra>',
|
||||
'%{x} · %{fullData.name}<br>%{y:d} niños, %{customdata[0]} % de %{customdata[1]}<extra></extra>',
|
||||
};
|
||||
}),
|
||||
layout: {
|
||||
barmode: 'group',
|
||||
xaxis: { title: { text: 'Sexo' }, type: 'category' },
|
||||
yaxis: { title: { text: 'Niños' }, rangemode: 'tozero' },
|
||||
yaxis: {
|
||||
title: { text: 'Niños' },
|
||||
rangemode: 'tozero',
|
||||
...valueAxis(
|
||||
TEA_SEXES.map(({ code }) => r.strata['sex']?.[code]?.['initial-population'] ?? 0),
|
||||
),
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -626,7 +651,7 @@ export function teaAlterations(r: Reading): Figure {
|
||||
xaxis: { type: 'category', title: { text: 'Alteración del EEG' } },
|
||||
yaxis: {
|
||||
range: [0, 100],
|
||||
ticksuffix: ' %',
|
||||
...percentAxis,
|
||||
title: { text: '% de niños con EEG de buena calidad' },
|
||||
},
|
||||
},
|
||||
|
||||
@@ -32,6 +32,7 @@ import {
|
||||
} from '../fhir';
|
||||
import { scenarioFigure } from '../gobernanza/figures';
|
||||
import { ageGroup, CAMA_AGE_GROUPS, camaRows } from '../indicadores/follow-up';
|
||||
import { SHORT } from '../indicadores/figures';
|
||||
import { LABELS, name, PRIORITY } from '../indicadores/measures';
|
||||
import { Figure, PALETTE, Plot } from '../plot';
|
||||
import { Loading } from '../loading';
|
||||
@@ -273,7 +274,8 @@ export class Paciente {
|
||||
yaxis: {
|
||||
title: { text: 'Probabilidad (%)' },
|
||||
range: [0, Math.max(5, this.top() * 110)],
|
||||
tickformat: '.1f',
|
||||
tickformat: SHORT,
|
||||
hoverformat: SHORT,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
@@ -249,7 +249,7 @@ export function ageNorm(rows: Centile[], metric: Metric, age: number): Figure {
|
||||
},
|
||||
],
|
||||
layout: {
|
||||
xaxis: { title: { text: 'Edad (meses)' } },
|
||||
xaxis: { title: { text: 'Edad (meses)' }, ...valueAxis([age]) },
|
||||
yaxis: {
|
||||
title: { text: metric.unit ?? 'Valor' },
|
||||
...valueAxis([metric.value, ...rows.flatMap(({ p5, median, p95 }) => [p5, median, p95])]),
|
||||
@@ -390,7 +390,7 @@ export function probabilityCurve(
|
||||
return {
|
||||
data,
|
||||
layout: {
|
||||
xaxis: { title: { text: 'Puntuación z' } },
|
||||
xaxis: { title: { text: 'Puntuación z' }, ...valueAxis([pair.z, 0]) },
|
||||
yaxis: { title: { text: 'Probabilidad (%)' }, ...valueAxis([0, 100]), range: [0, 100] },
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user