CaCu indicators: one selector for the cytology and HPV genotype views, grouped bars and genotype labels
This commit is contained in:
@@ -97,22 +97,33 @@ export function scenarioBars(
|
||||
catalog: Catalog,
|
||||
stratum: string,
|
||||
label: (code: string) => string,
|
||||
/** the groups in this order; an empty one is drawn when the counts reconcile (see `reconciles`) */
|
||||
/** the groups in this order (the ones the report lists, then any other) */
|
||||
order?: string[],
|
||||
options: {
|
||||
/** draw an empty group of `order` when the counts reconcile (see `reconciles`) */
|
||||
fill?: boolean;
|
||||
/** a bar is the share of all the group's records, not only of those the catalog draws */
|
||||
ofAll?: boolean;
|
||||
} = {},
|
||||
): Figure {
|
||||
const cells = r.strata[`${stratum}-category`] ?? {};
|
||||
const found = [...new Set(Object.keys(cells).map((k) => k.split('|')[0]))];
|
||||
const listed = Object.values(cells).map((c) => c['initial-population']);
|
||||
const empty = reconciles(listed, r.populations['initial-population'] ?? 0);
|
||||
const scenarios = order
|
||||
? [
|
||||
...order.filter(
|
||||
(s) => found.includes(s) || reconciles(listed, r.populations['initial-population'] ?? 0),
|
||||
),
|
||||
...order.filter((s) => found.includes(s) || (options.fill && empty)),
|
||||
...found.filter((s) => !order.includes(s)),
|
||||
]
|
||||
: found.sort((a, b) => label(a).localeCompare(label(b), 'es'));
|
||||
const n = (s: string, c: string) => cells[`${s}|${c}`]?.['initial-population'] ?? 0;
|
||||
const totals = scenarios.map((s) => catalog.categories.reduce((t, c) => t + n(s, c.code), 0));
|
||||
const totals = scenarios.map((s) =>
|
||||
options.ofAll
|
||||
? Object.entries(cells)
|
||||
.filter(([k]) => k.split('|')[0] === s)
|
||||
.reduce((t, [, c]) => t + (c['initial-population'] ?? 0), 0)
|
||||
: catalog.categories.reduce((t, c) => t + n(s, c.code), 0),
|
||||
);
|
||||
const y = order
|
||||
? scenarios.map((s, i) => `${label(s)}<br>n = ${totals[i]}`)
|
||||
: scenarios.map(label);
|
||||
@@ -132,7 +143,9 @@ export function scenarioBars(
|
||||
xaxis: {
|
||||
title: {
|
||||
text: order
|
||||
? '% de pacientes con resultado'
|
||||
? options.ofAll
|
||||
? '% de los reportes del grupo'
|
||||
: '% de pacientes con resultado'
|
||||
: '% de pacientes del escenario con resultado',
|
||||
},
|
||||
ticksuffix: ' %',
|
||||
|
||||
Reference in New Issue
Block a user