CaCu: show screening rounds and restore category palettes
This commit is contained in:
@@ -133,8 +133,8 @@ export const LABELS: Record<string, string> = {
|
||||
good: 'Bueno',
|
||||
bad: 'Malo',
|
||||
not_analyzed: 'Sin analizar',
|
||||
initial: 'Inicial',
|
||||
subsequent: 'Subsecuente',
|
||||
initial: 'Detección inicial',
|
||||
subsequent: 'Detección subsecuente',
|
||||
positive: 'Positivo',
|
||||
negative: 'Negativo',
|
||||
hpv_16: 'VPH 16',
|
||||
@@ -202,15 +202,23 @@ export function detail(measure: Measure, r: Reading | undefined): string {
|
||||
const pct = (v?: number) => (v === undefined ? '—' : `${(v * 100).toFixed(1)} %`);
|
||||
|
||||
/** A donut of one stratifier's counts (initial population), or of numerator vs the rest. */
|
||||
export function donut(measure: Measure, r: Reading, stratifier = 'category'): Figure {
|
||||
let labels: string[], values: number[];
|
||||
export function donut(
|
||||
measure: Measure,
|
||||
r: Reading,
|
||||
stratifier = 'category',
|
||||
/** a colour by category code (a proportion: `numerator` and `rest`); a part without one takes the palette's */
|
||||
colors?: Record<string, string>,
|
||||
): Figure {
|
||||
let labels: string[], values: number[], codes: string[];
|
||||
if (scoring(measure) === 'proportion') {
|
||||
const { numerator = 0, denominator = 0 } = r.populations;
|
||||
labels = ['Numerador', 'Resto'];
|
||||
codes = ['numerator', 'rest'];
|
||||
values = [numerator, denominator - numerator];
|
||||
} else {
|
||||
const cells = Object.entries(r.strata[stratifier] ?? {});
|
||||
labels = cells.map(([v]) => name(v));
|
||||
codes = cells.map(([v]) => v);
|
||||
values = cells.map(([, c]) => c['initial-population'] ?? 0);
|
||||
}
|
||||
return {
|
||||
@@ -222,7 +230,7 @@ export function donut(measure: Measure, r: Reading, stratifier = 'category'): Fi
|
||||
values,
|
||||
sort: false,
|
||||
textinfo: 'value+percent',
|
||||
marker: { colors: PALETTE },
|
||||
marker: { colors: codes.map((c, i) => colors?.[c] ?? PALETTE[i % PALETTE.length]) },
|
||||
},
|
||||
],
|
||||
layout: { showlegend: true, margin: { t: 32, r: 8, b: 32, l: 8 } },
|
||||
|
||||
Reference in New Issue
Block a user