CaCu: show screening rounds and restore category palettes
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { type Figure, PALETTE } from '../plot';
|
||||
import { reconciles } from './bars';
|
||||
import { name, type Reading } from './measures';
|
||||
import type { Catalog, Category, HistoryPanel } from './pages';
|
||||
|
||||
@@ -96,14 +97,25 @@ 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`) */
|
||||
order?: string[],
|
||||
): Figure {
|
||||
const cells = r.strata[`${stratum}-category`] ?? {};
|
||||
const scenarios = [...new Set(Object.keys(cells).map((k) => k.split('|')[0]))].sort((a, b) =>
|
||||
label(a).localeCompare(label(b), 'es'),
|
||||
);
|
||||
const found = [...new Set(Object.keys(cells).map((k) => k.split('|')[0]))];
|
||||
const listed = Object.values(cells).map((c) => c['initial-population']);
|
||||
const scenarios = order
|
||||
? [
|
||||
...order.filter(
|
||||
(s) => found.includes(s) || reconciles(listed, r.populations['initial-population'] ?? 0),
|
||||
),
|
||||
...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 y = scenarios.map(label);
|
||||
const y = order
|
||||
? scenarios.map((s, i) => `${label(s)}<br>n = ${totals[i]}`)
|
||||
: scenarios.map(label);
|
||||
return {
|
||||
data: catalog.categories.map((c) => ({
|
||||
type: 'bar',
|
||||
@@ -118,7 +130,11 @@ export function scenarioBars(
|
||||
layout: {
|
||||
barmode: 'stack',
|
||||
xaxis: {
|
||||
title: { text: '% de pacientes del escenario con resultado' },
|
||||
title: {
|
||||
text: order
|
||||
? '% de pacientes con resultado'
|
||||
: '% de pacientes del escenario con resultado',
|
||||
},
|
||||
ticksuffix: ' %',
|
||||
range: [0, 100.5],
|
||||
dtick: 20,
|
||||
|
||||
Reference in New Issue
Block a user