feat(tea): botones y rótulos en la dona C2 de un solo anillo

Sin grupos de categorías (M23), la dona de TEA se dibuja como la de M21: un
anillo con rótulos, el total al centro y un botón por categoría.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-04 23:56:54 -06:00
parent 737c6f9f14
commit 3bb9c2121d
2 changed files with 43 additions and 4 deletions
@@ -0,0 +1,28 @@
import { C2Distribution } from './indicadores-c2-adapter';
import { highlightFigure } from './indicadores-highlight';
import { teaC2Donut } from './indicadores-tea-c2';
const categoria = (id: string, label: string, value: number, color: string, parentId?: string) => ({ id, label, value, color, parentId });
const modelo = (extra: object = {}) => ({ period: '2025-S2', unit: 'paciente', title: 'T', total: 380, notes: [], nodes: [], parents: [],
categories: [categoria('CONFIRMADO', 'Diagnóstico confirmado', 338, '#A8C243'), categoria('EN_PROCESO', 'En proceso', 42, '#B8433A')], ...extra }) as unknown as C2Distribution;
describe('Dona C2 de TEA', () => {
it('sin grupos dibuja un anillo con rótulos, el total al centro y un botón por categoría', () => {
const { figure, highlight } = teaC2Donut(modelo(), 'claro', { text: 'T' })!;
expect(figure.data).toHaveLength(1);
expect(figure.data[0]).toMatchObject({ type: 'pie', values: [338, 42], labels: ['Diagnóstico confirmado', 'En proceso'] });
expect(figure.data[0]['text']).toEqual(['Diagnóstico confirmado<br>88.9 %', 'En proceso<br>11.1 %']);
expect((figure.layout['annotations'] as { text: string }[])[0].text).toBe('<b>380</b><br>TOTAL');
expect(highlight.groups).toEqual([]);
expect(highlight.items.map(i => [i.label, i.color])).toEqual([['Diagnóstico confirmado', '#A8C243'], ['En proceso', '#B8433A']]);
});
it('al elegir una categoría atenúa la otra y muestra su número al centro', () => {
const { figure, highlight } = teaC2Donut(modelo(), 'claro', { text: 'T' })!;
const elegida = highlightFigure(figure, highlight, { item: 'EN_PROCESO' });
expect((elegida.data[0]['marker'] as { colors: string[] }).colors).toEqual(['rgba(168, 194, 67, 0.3)', 'rgba(184,67,58,1)']);
expect((elegida.layout['annotations'] as { text: string }[])[0].text).toBe('<b>42</b><br>En proceso');
});
it('sin pacientes no dibuja nada', () => {
expect(teaC2Donut(modelo({ total: 0 }), 'claro', {})).toBeUndefined();
});
});