diff --git a/src/app/features/indicadores/indicador-confirmacion-citologia.html b/src/app/features/indicadores/indicador-confirmacion-citologia.html
index 6a2bbd1..616eddb 100644
--- a/src/app/features/indicadores/indicador-confirmacion-citologia.html
+++ b/src/app/features/indicadores/indicador-confirmacion-citologia.html
@@ -33,7 +33,7 @@
@if (status() === 'empty') {
{{ vista.textos.vacio }}
}
@else {
@if (!vista.botones) {
- Haz clic en un anillo de la dona para elegir un grupo o un resultado; el centro vuelve a «{{ etiquetaBase }}».
+ Haz clic en un anillo de la dona para elegir un grupo o un resultado; el centro regresa un paso, hasta el total.
}
diff --git a/src/app/features/indicadores/indicador-confirmacion-citologia.ts b/src/app/features/indicadores/indicador-confirmacion-citologia.ts
index dfa2142..5ede646 100644
--- a/src/app/features/indicadores/indicador-confirmacion-citologia.ts
+++ b/src/app/features/indicadores/indicador-confirmacion-citologia.ts
@@ -8,7 +8,7 @@ import { Dominio, Indicador, IndicadorMetadatos, PlotlyFigure, Tema } from './in
import { describePeriods, filterCompatibility, GlobalApplied } from './indicadores-memory';
import { IndicadoresSnapshots, snapshotKey } from './indicadores-snapshots';
import { httpMessage } from './indicadores-http';
-import { clicConfirmacion, ConfirmacionIncompatible, CONFIRMACION_CACU, donaConfirmacion, estadoTasa, figuraTasas,
+import { clicConfirmacion, clicDona, ConfirmacionIncompatible, CONFIRMACION_CACU, donaConfirmacion, donaExpandible, estadoTasa, figuraTasas,
lectura, ModeloConfirmacion, modeloConfirmacion, periodosConfirmacion, SeleccionConfirmacion, seleccionBase, seleccionEtiqueta,
Celda, Tasa, tasas, vistaConfirmacion } from './indicadores-confirmacion-citologia';
@@ -45,8 +45,7 @@ export class IndicadorConfirmacionCitologia implements OnChanges, OnDestroy {
get appliedSummary() { return describePeriods(this.applied.tipo, this.applied.selection); }
get selectionLabel() { return this.model && this.selection ? seleccionEtiqueta(this.model, this.selection) : ''; }
get reading() { return this.model && this.selection ? lectura(this.model, this.selection) : ''; }
- get etiquetaBase() { return this.model ? seleccionEtiqueta(this.model, seleccionBase(this.model)) : ''; }
- get isBase() { return !!this.model && !!this.selection && !this.selection.categoria && this.selection.grupo === this.model.base; }
+ get isBase() { return !!this.model && !!this.selection && !this.selection.categoria && this.selection.grupo === (this.vista.botones ? this.model.base : undefined); }
get rates() { return this.model && this.selection ? tasas(this.model, this.selection) : []; }
// CaCu's words when the catalog doesn't name this indicator, so the messages still read.
get vista() { return vistaConfirmacion(this.dominio, this.indicador) ?? CONFIRMACION_CACU; }
@@ -118,7 +117,8 @@ export class IndicadorConfirmacionCitologia implements OnChanges, OnDestroy {
}
private activatePeriod() {
this.model = this.pages[this.periodIndex];
- this.selection = this.model ? seleccionBase(this.model) : undefined;
+ // With buttons the view opens on the base group; without, on the total, as CaCu's interactive donut.
+ this.selection = this.model ? (this.vista.botones ? seleccionBase(this.model) : {}) : undefined;
this.draw(); this.status.set(this.model && !this.model.vacio ? 'ready' : 'empty');
}
changePeriod(step: number) {
@@ -127,7 +127,7 @@ export class IndicadorConfirmacionCitologia implements OnChanges, OnDestroy {
}
select(trace: string, index = 0) {
if (!this.model || !this.selection || this.status() !== 'ready') return;
- this.selection = clicConfirmacion(this.model, this.selection, trace, index); this.draw();
+ this.selection = (this.vista.botones ? clicConfirmacion : clicDona)(this.model, this.selection, trace, index); this.draw();
}
plotClicked(event: unknown) {
const point = (event as { points?: { data?: { name?: string }; pointNumber?: number }[] } | null)?.points?.[0];
@@ -135,7 +135,7 @@ export class IndicadorConfirmacionCitologia implements OnChanges, OnDestroy {
}
private draw() {
if (!this.model || !this.selection) return;
- this.donutFigure = donaConfirmacion(this.model, this.selection, this.tema);
+ this.donutFigure = (this.vista.botones ? donaConfirmacion : donaExpandible)(this.model, this.selection, this.tema);
this.ratesFigure = figuraTasas(this.model, this.selection, this.tema);
this.changeDetector.markForCheck();
}
diff --git a/src/app/features/indicadores/indicadores-confirmacion-citologia.spec.ts b/src/app/features/indicadores/indicadores-confirmacion-citologia.spec.ts
index 92e8d20..a2e74f6 100644
--- a/src/app/features/indicadores/indicadores-confirmacion-citologia.spec.ts
+++ b/src/app/features/indicadores/indicadores-confirmacion-citologia.spec.ts
@@ -9,7 +9,7 @@ import { IndicadorFigurePanel } from './indicador-figure-panel';
import { PlotlyChart } from '../../shared/plotly/plotly-chart';
import { GlobalApplied } from './indicadores-memory';
import { Indicador, IndicadorDatos } from './indicadores.models';
-import { clicConfirmacion, ConfirmacionIncompatible, CONFIRMACION_CACU, CONFIRMACION_CAMA, donaConfirmacion, estadoTasa, figuraTasas, lectura, modeloConfirmacion,
+import { clicConfirmacion, clicDona, ConfirmacionIncompatible, CONFIRMACION_CACU, CONFIRMACION_CAMA, donaConfirmacion, donaExpandible, estadoTasa, figuraTasas, lectura, modeloConfirmacion,
periodosConfirmacion, rangoTasas, seleccionBase, seleccionEtiqueta, tasas, vistaConfirmacion, wilson } from './indicadores-confirmacion-citologia';
@Component({ selector: 'app-plotly-chart', template: '' })
@@ -259,13 +259,29 @@ describe('Confirmación histopatológica de cáncer de mama', () => {
});
});
-describe('Confirmación sin botones visibles', () => {
- it('el centro de la dona nombra la elección solo cuando no hay botones', () => {
- // Fails if the donut stops saying what it counts once the buttons are hidden, or CaCu's centre changes.
- const cama = { ...CONFIRMACION_CAMA, id: 'cacu_confirmacion_citologia', estrato: 'citologia_alto_grado' as const, filas: CONFIRMACION_CACU.filas, base: 'LIEAG' };
- const m = modeloConfirmacion(respuesta(), '2026-S2', cama);
- expect(donaConfirmacion(m, seleccionBase(m), 'claro').data[0]['text']).toEqual(['63
de 108 con biopsia
' + seleccionEtiqueta(m, seleccionBase(m))]);
- const c = modeloConfirmacion(respuesta(), '2026-S2');
- expect(donaConfirmacion(c, seleccionBase(c), 'claro').data[0]['text']).toEqual(['63
de 108 con biopsia']);
+describe('Dona interactiva como la de CaCu (sin botones)', () => {
+ const vista = { ...CONFIRMACION_CAMA, id: 'cacu_confirmacion_citologia', estrato: 'citologia_alto_grado' as const, filas: CONFIRMACION_CACU.filas, base: 'LIEAG' };
+ const modelo = () => modeloConfirmacion(respuesta(), '2026-S2', vista);
+ it('total → grupo → resultado y el centro regresa un paso hasta el total', () => {
+ // Fails if the centre stops returning to the total, or a group click no longer narrows to it.
+ const m = modelo(), g = m.grupos.findIndex(x => x.id === m.base), c = m.grados.findIndex(x => x.grupo === m.base);
+ let s = clicDona(m, {}, 'grupos', g); expect(s).toEqual({ grupo: m.base });
+ s = clicDona(m, s, 'categorias', c); expect(s).toEqual({ grupo: m.base, categoria: m.grados[c].id });
+ s = clicDona(m, s, 'centro', 0); expect(s).toEqual({ grupo: m.base });
+ s = clicDona(m, s, 'centro', 0); expect(s).toEqual({});
+ expect(clicDona(m, { grupo: m.base }, 'grupos', g)).toEqual({});
+ const otra = m.grados.findIndex(x => x.grupo !== m.base);
+ expect(clicDona(m, { grupo: m.base }, 'categorias', otra)).toEqual({ grupo: m.base });
+ });
+ it('el grupo elegido llena los dos anillos y el total cuenta el grupo base en las tasas', () => {
+ // Fails if the other group's slices stay (no expansion), or the total stops reading as the base rate.
+ const m = modelo(), base = m.grupos.find(x => x.id === m.base)!;
+ const d = donaExpandible(m, { grupo: m.base }, 'claro');
+ const exterior = d.data[2]['values'] as number[];
+ m.grados.forEach((g, i) => expect(exterior[i] === 0).toBe(g.grupo !== m.base));
+ expect((d.data[1]['values'] as number[]).filter(v => v > 0)).toHaveLength(1);
+ expect(d.data[0]['text']).toEqual([`${base.grados.reduce((s, c) => s + m.totales[c]!, 0)}
${base.etiqueta}`]);
+ expect(tasas(m, {}).map(t => t.k)).toEqual(tasas(m, seleccionBase(m)).map(t => t.k));
+ expect(lectura(m, {})).toBe(vista.textos.base);
});
});
diff --git a/src/app/features/indicadores/indicadores-confirmacion-citologia.ts b/src/app/features/indicadores/indicadores-confirmacion-citologia.ts
index 32624f6..1cbe087 100644
--- a/src/app/features/indicadores/indicadores-confirmacion-citologia.ts
+++ b/src/app/features/indicadores/indicadores-confirmacion-citologia.ts
@@ -29,7 +29,7 @@ export const Z95 = 1.959963984540054;
export interface VistaConfirmacion {
id: string; estrato: DimensionEstrato; filas: readonly { id: string; etiqueta: string }[];
base: string; falsoPositivo: string;
- // With buttons, the choice is made on them; without, on the donut, whose centre then names it.
+ // With buttons, the choice is made on them; without, on the donut (donaExpandible), whose centre names it.
botones: boolean;
textos: { base: string; falsoPositivo: string; sinConfirmacion: string; filas: string; encabezado: string; sujetos: string; vacio: string };
}
@@ -69,7 +69,8 @@ export interface ModeloConfirmacion {
filas: FilaCitologia[]; totales: Record; conBiopsia: number | null;
aparte: { id: string; etiqueta: string }[]; vacio: boolean; notas: string[]; vista: VistaConfirmacion;
}
-export interface SeleccionConfirmacion { grupo: string; categoria?: string; }
+// Without a group, the total: every result is shown and the rates count the base group.
+export interface SeleccionConfirmacion { grupo?: string; categoria?: string; }
export interface Tasa { fila: FilaCitologia; k: number | null; valor: number | null; bajo: number | null; alto: number | null; }
export class ConfirmacionIncompatible extends Error {}
@@ -183,10 +184,21 @@ export function modeloConfirmacion(datos: IndicadorDatos, periodo: string, vista
export function seleccionBase(m: ModeloConfirmacion): SeleccionConfirmacion { return { grupo: m.base }; }
export function seleccionados(m: ModeloConfirmacion, sel: SeleccionConfirmacion): string[] {
- return sel.categoria ? [sel.categoria] : m.grupos.find(g => g.id === sel.grupo)?.grados ?? [];
+ return sel.categoria ? [sel.categoria] : m.grupos.find(g => g.id === (sel.grupo ?? m.base))?.grados ?? [];
}
export function seleccionEtiqueta(m: ModeloConfirmacion, sel: SeleccionConfirmacion): string {
- return sel.categoria ? m.grados.find(g => g.id === sel.categoria)!.etiqueta : m.grupos.find(g => g.id === sel.grupo)!.etiqueta;
+ return sel.categoria ? m.grados.find(g => g.id === sel.categoria)!.etiqueta
+ : sel.grupo ? m.grupos.find(g => g.id === sel.grupo)!.etiqueta : 'Todos los resultados';
+}
+/** CaCu's interactive donut: a group narrows to it, a result is chosen inside its group, the centre steps back
+ * (result -> its group -> the total), and choosing the chosen entry again also steps back. */
+export function clicDona(m: ModeloConfirmacion, sel: SeleccionConfirmacion, traza: string, indice: number): SeleccionConfirmacion {
+ if (traza === 'centro') return sel.categoria && sel.grupo ? { grupo: sel.grupo } : {};
+ if (traza === 'grupos') { const g = m.grupos[indice]?.id; return !g ? sel : sel.grupo === g && !sel.categoria ? {} : { grupo: g }; }
+ if (traza !== 'categorias') return sel;
+ const c = m.grados[indice];
+ if (!c || (sel.grupo && c.grupo !== sel.grupo)) return sel;
+ return sel.categoria === c.id ? { grupo: c.grupo } : { grupo: c.grupo, categoria: c.id };
}
/** Group selects the group; a grade selects it and a second click returns to its group; the centre returns to the base. */
export function clicConfirmacion(m: ModeloConfirmacion, sel: SeleccionConfirmacion, traza: string, indice: number): SeleccionConfirmacion {
@@ -199,7 +211,7 @@ export function clicConfirmacion(m: ModeloConfirmacion, sel: SeleccionConfirmaci
}
/** The axis title says what the rate reads. */
export function lectura(m: ModeloConfirmacion, sel: SeleccionConfirmacion): string {
- if (!sel.categoria && sel.grupo === m.base) return m.vista.textos.base;
+ if (!sel.categoria && (sel.grupo ?? m.base) === m.base) return m.vista.textos.base;
if (sel.categoria === m.vista.falsoPositivo) return m.vista.textos.falsoPositivo;
if (!sel.categoria) return m.vista.textos.sinConfirmacion;
return 'Proporción con biopsia ' + seleccionEtiqueta(m, sel);
@@ -229,7 +241,7 @@ export function rangoTasas(valores: Tasa[]): [number, number] {
export function figuraTasas(m: ModeloConfirmacion, sel: SeleccionConfirmacion, tema: Tema): PlotlyFigure {
const p = c2Theme(tema);
const valores = tasas(m, sel);
- const color = sel.categoria ? m.grados.find(g => g.id === sel.categoria)!.color : m.grupos.find(g => g.id === sel.grupo)!.color;
+ const color = sel.categoria ? m.grados.find(g => g.id === sel.categoria)!.color : m.grupos.find(g => g.id === (sel.grupo ?? m.base))!.color;
const y = valores.map(t => t.fila.etiqueta);
return { data: [{
type: 'scatter', mode: 'markers', uid: 'tasas', name: 'tasas', y, x: valores.map(t => t.valor),
@@ -261,8 +273,7 @@ export function donaConfirmacion(m: ModeloConfirmacion, sel: SeleccionConfirmaci
const custom = (values: number[]) => values.map(n => [miles(n), shareText(n, total)]);
return { data: [
{ ...comun, name: 'centro', values: [1], labels: ['centro'], domain: { x: [.32, .68], y: [.32, .68] }, textinfo: 'text', textposition: 'inside',
- text: [`${miles(k)}
de ${miles(total)} con biopsia` + (m.vista.botones ? '' : '
' + escapar(seleccionEtiqueta(m, sel)))],
- textfont: { size: 16, color: p.text },
+ text: [`${miles(k)}
de ${miles(total)} con biopsia`], textfont: { size: 16, color: p.text },
marker: { colors: [p.background] }, hovertemplate: 'Volver a ' + escapar(m.grupos.find(g => g.id === m.base)!.etiqueta) + '' },
{ ...comun, ...hover, name: 'grupos', values: interior, hole: .62, domain: { x: [.16, .84], y: [.16, .84] },
labels: m.grupos.map(g => escapar(g.etiqueta)), customdata: custom(interior),
@@ -273,3 +284,38 @@ export function donaConfirmacion(m: ModeloConfirmacion, sel: SeleccionConfirmaci
], layout: { autosize: true, height: 360, margin: { t: 10, l: 10, r: 10, b: 10 }, paper_bgcolor: p.background, font: { color: p.text } },
config: { displayModeBar: false } };
}
+
+/** Donut without buttons, drawn like CaCu's interactive one: the chosen group fills both rings (the other's
+ * slices are zero, so its results expand), a chosen result keeps its colour and its siblings fade, and the
+ * centre names the choice. The traces keep their names and counts, so a choice animates. */
+export function donaExpandible(m: ModeloConfirmacion, sel: SeleccionConfirmacion, tema: Tema): PlotlyFigure {
+ if (m.conBiopsia === null || m.conBiopsia === 0) return { data: [], layout: {} };
+ const p = c2Theme(tema), total = m.conBiopsia;
+ const nGrupo = (g: GrupoGrados) => g.grados.reduce((s, c) => s + m.totales[c]!, 0);
+ const interior = m.grupos.map(g => !sel.grupo || sel.grupo === g.id ? nGrupo(g) : 0);
+ const exterior = m.grados.map(g => !sel.grupo || sel.grupo === g.grupo ? m.totales[g.id]! : 0);
+ const centro = sel.categoria ? m.totales[sel.categoria]! : sel.grupo ? nGrupo(m.grupos.find(g => g.id === sel.grupo)!) : total;
+ const rotulos = (values: number[], labels: string[], pct: boolean) => {
+ const suma = values.reduce((s, n) => s + n, 0);
+ return values.map((v, i) => !suma || v / suma < .05 ? '' : escapar(labels[i]) + (pct ? '
' + shareText(v, suma) : ''));
+ };
+ const comun = { type: 'pie', sort: false, direction: 'clockwise', rotation: 0, showlegend: false, textinfo: 'text', textposition: 'inside',
+ insidetextorientation: 'horizontal' };
+ const hover = { hovertemplate: `%{label}
%{customdata[0]} ${m.vista.textos.sujetos} con biopsia, %{customdata[1]}` };
+ const custom = (values: number[]) => values.map(n => [miles(n), shareText(n, total)]);
+ return { data: [
+ { ...comun, name: 'centro', values: [1], labels: ['centro'], domain: { x: [.32, .68], y: [.32, .68] },
+ text: [`${miles(centro)}
${escapar(sel.grupo || sel.categoria ? seleccionEtiqueta(m, sel) : 'Con biopsia')}`],
+ textfont: { size: 16, color: p.text }, marker: { colors: [p.background] },
+ hovertemplate: (sel.grupo || sel.categoria ? 'Volver' : 'Todos los resultados') + '' },
+ { ...comun, ...hover, name: 'grupos', values: interior, hole: .62, domain: { x: [.16, .84], y: [.16, .84] },
+ labels: m.grupos.map(g => escapar(g.etiqueta)), text: rotulos(interior, m.grupos.map(g => g.etiqueta), false),
+ textfont: { color: '#FFFFFF' }, customdata: custom(interior),
+ marker: { colors: m.grupos.map(g => rgba(g.color, sel.categoria ? .3 : 1)), line: { color: p.background, width: 2 } } },
+ { ...comun, ...hover, name: 'categorias', values: exterior, hole: .74, domain: { x: [0, 1], y: [0, 1] },
+ labels: m.grados.map(g => escapar(g.etiqueta)), text: rotulos(exterior, m.grados.map(g => g.etiqueta), true),
+ textfont: { size: 11 }, customdata: custom(exterior),
+ marker: { colors: m.grados.map(g => rgba(g.color, sel.categoria && g.id !== sel.categoria ? .3 : 1)), line: { color: p.background, width: 2 } } },
+ ], layout: { autosize: true, height: 400, margin: { t: 10, l: 10, r: 10, b: 10 }, paper_bgcolor: p.background, font: { color: p.text } },
+ config: { displayModeBar: false } };
+}