Adjust CaMa indicator labels
This commit is contained in:
@@ -44,4 +44,4 @@ export const CATEGORIA_HISTOPATOLOGIA_PAGINA: Readonly<Record<string, { id: stri
|
||||
SIN_BIOPSIA: { id: 'SIN_BIOPSIA', grupo: null, gravedad: null },
|
||||
SIN_DATO: { id: 'SIN_DATO', grupo: 'SIN_DATO', gravedad: null },
|
||||
};
|
||||
export const GRUPOS_HISTOPATOLOGIA_PAGINA: Readonly<Record<string, string>> = { NO_MALIGNO: 'No maligno', MALIGNO: 'Maligno', SIN_DATO: 'Sin dato' };
|
||||
export const GRUPOS_HISTOPATOLOGIA_PAGINA: Readonly<Record<string, string>> = { NO_MALIGNO: 'No metástasis', MALIGNO: 'Metástasis', SIN_DATO: 'Sin dato' };
|
||||
|
||||
@@ -95,30 +95,23 @@ describe('Conteos pareados de CaMa: etiquetas de la dona', () => {
|
||||
type Figura = { data: Record<string, any>[]; layout: { annotations: Record<string, any>[]; margin: Record<string, number>; showlegend: boolean } };
|
||||
const dona = (compacta = false) => donaConteos(modelo(examenes(LAB_E), pacientes(LAB_P)), PAR, 'claro', compacta) as unknown as Figura;
|
||||
|
||||
// Fails if the long label of the 4 without subcategory goes back inside the ring (where it is cut), loses its
|
||||
// percentage or its guide line, or if the short labels or the centre total change.
|
||||
it('2025-S2: la etiqueta larga sale del anillo, horizontal y con línea guía; las cortas y el total se conservan', () => {
|
||||
const f = dona(), t = f.data[0], llamada = f.layout.annotations[1];
|
||||
expect(t['text'][0]).toBe('');
|
||||
// Fails if the 4 without subcategory goes back outside the ring with a guide line instead of inside its slice on two
|
||||
// lines like BI-RADS 5, loses its percentage, or if the short labels or the centre total change.
|
||||
it('2025-S2: la etiqueta del 4 sin subcategoría va dentro de su segmento, en dos líneas; las cortas y el total se conservan', () => {
|
||||
const f = dona(), t = f.data[0];
|
||||
expect(t['text'][0]).toBe('BI-RADS 4<br>(sin subcategoría)<br>45.5 %');
|
||||
expect(t['text'][1]).toBe('');
|
||||
expect(t['text'][4]).toMatch(/^BI-RADS 5<br>54[.,]5 %$/);
|
||||
expect(t['textposition']).toBe('inside');
|
||||
expect(t['values']).toEqual([15, 0, 0, 0, 18, 0]);
|
||||
expect(f.layout.annotations).toHaveLength(1);
|
||||
expect(f.layout.annotations[0]['text']).toBe('<b>33</b><br>mastografías');
|
||||
expect(f.layout.annotations).toHaveLength(2);
|
||||
expect(llamada['text']).toBe('BI-RADS 4<br>(sin subcategoría)<br>45.5 %');
|
||||
// A guide line: an arrow without head from the label to a point inside the slice, and no text rotation.
|
||||
expect(llamada['showarrow']).toBe(true);
|
||||
expect(llamada['arrowhead']).toBe(0);
|
||||
expect(llamada['textangle']).toBeUndefined();
|
||||
});
|
||||
|
||||
// Fails if the label can reach the neighbouring chart: its side must keep a margin, and it sits on the side of its slice.
|
||||
it('reserva espacio del lado de la etiqueta y la coloca del lado de su segmento', () => {
|
||||
const f = dona(), llamada = f.layout.annotations[1];
|
||||
// The slice is 45 % of a clockwise ring: its middle points right, so label and margin are on the right.
|
||||
expect(llamada['xanchor']).toBe('left');
|
||||
expect(llamada['ax']).toBeGreaterThan(0);
|
||||
expect(f.layout.margin['r']).toBeGreaterThanOrEqual(110);
|
||||
// Fails if an inside label still reserves side margins, as a callout would.
|
||||
it('sin llamada exterior no se reservan márgenes laterales', () => {
|
||||
const f = dona();
|
||||
expect(f.layout.margin['r']).toBeLessThan(20);
|
||||
expect(f.layout.margin['l']).toBeLessThan(20);
|
||||
expect(f.layout.showlegend).toBe(false);
|
||||
});
|
||||
|
||||
@@ -124,7 +124,9 @@ export function donaConteos(m: ModeloConteos, par: ParConteos, tema: Tema, compa
|
||||
const total = totalExamenes(m);
|
||||
if (!total) return { data: [], layout: {} };
|
||||
const p = c2Theme(tema), n = m.examenes.map(c => c.n!);
|
||||
const larga = (i: number) => m.examenes[i].etiqueta.length > LARGO_ETIQUETA_INTERIOR && n[i] > 0;
|
||||
// «BI-RADS 4 (sin subcategoría)» is long but is drawn inside its slice on two lines, like the short labels.
|
||||
const sinSubcategoria = (i: number) => m.examenes[i].etiqueta.endsWith(' (sin subcategoría)');
|
||||
const larga = (i: number) => m.examenes[i].etiqueta.length > LARGO_ETIQUETA_INTERIOR && n[i] > 0 && !sinSubcategoria(i);
|
||||
const porcentaje = (i: number) => percentNumber(100 * n[i] / total) + ' %';
|
||||
const dibujadas = (i: number) => !larga(i) && n[i] / total >= .05;
|
||||
// Each long label is a callout whose guide line ends inside its slice.
|
||||
@@ -143,7 +145,7 @@ export function donaConteos(m: ModeloConteos, par: ParConteos, tema: Tema, compa
|
||||
const lado = (l: string) => llamadas.some(a => a.lado === l) ? MARGEN_ROTULO : 10;
|
||||
return { data: [{ type: 'pie', hole: .6, sort: false, direction: 'clockwise', values: n, labels: m.examenes.map(c => escapar(c.etiqueta)),
|
||||
marker: { colors: m.examenes.map(c => c.color), line: { color: p.background, width: 2 } }, textinfo: 'text', textposition: 'inside',
|
||||
text: n.map((_, i) => dibujadas(i) ? escapar(m.examenes[i].etiqueta) + '<br>' + porcentaje(i) : ''),
|
||||
text: n.map((_, i) => dibujadas(i) ? (sinSubcategoria(i) ? escapar(m.examenes[i].etiqueta).replace(' (', '<br>(') : escapar(m.examenes[i].etiqueta)) + '<br>' + porcentaje(i) : ''),
|
||||
domain: { x: [0, 1], y: [.05, .95] },
|
||||
customdata: n.map(v => [miles(v), percentNumber(100 * v / total)]),
|
||||
hovertemplate: `%{label}<br>%{customdata[0]} ${par.unidades.examenes}, %{customdata[1]} %<extra></extra>` }],
|
||||
|
||||
@@ -138,14 +138,14 @@ describe('Histopatología por BI-RADS: tasas, selección y figuras', () => {
|
||||
expect(tasas(m, sel).map(t => [t.k, t.fila.den])).toEqual([[2, 4], [3, 5], [2, 4], [2, 4], [2, 4], [2, 4]]);
|
||||
const [bajo, alto] = wilson(3, 5);
|
||||
expect(tasas(m, sel)[1]).toMatchObject({ valor: 60, bajo, alto });
|
||||
expect(lectura(m, sel)).toBe('Pacientes con resultado maligno entre las que tienen resultado de biopsia');
|
||||
expect(lectura(m, sel)).toBe('Pacientes con resultado metástasis entre las que tienen resultado de biopsia');
|
||||
});
|
||||
it('grupo, categoría, segundo clic al grupo y centro a la base', () => {
|
||||
const m = base(), sel = seleccionBase(m);
|
||||
const noMaligno = clicHistopatologia(m, sel, 'grupos', 0);
|
||||
expect(noMaligno).toEqual({ grupo: 'NO_MALIGNO' });
|
||||
expect(tasas(m, noMaligno).map(t => t.k)).toEqual([2, 2, 2, 2, 2, 2]);
|
||||
expect(lectura(m, noMaligno)).toBe('Pacientes con resultado no maligno entre las que tienen resultado de biopsia');
|
||||
expect(lectura(m, noMaligno)).toBe('Pacientes con resultado no metástasis entre las que tienen resultado de biopsia');
|
||||
const b3 = clicHistopatologia(m, noMaligno, 'categorias', 1);
|
||||
expect(b3).toEqual({ grupo: 'NO_MALIGNO', categoria: 'RIESGO_B3' });
|
||||
expect(tasas(m, b3).map(t => t.k)).toEqual([0, 1, 1, 1, 1, 1]);
|
||||
|
||||
@@ -181,8 +181,8 @@ export function clicHistopatologia(m: ModeloHistopatologia, sel: SeleccionHistop
|
||||
}
|
||||
/** The axis title says what the rate reads. */
|
||||
export function lectura(m: ModeloHistopatologia, sel: SeleccionHistopatologia): string {
|
||||
if (!sel.categoria && sel.grupo === m.base) return 'Pacientes con resultado maligno entre las que tienen resultado de biopsia';
|
||||
if (!sel.categoria) return 'Pacientes con resultado no maligno entre las que tienen resultado de biopsia';
|
||||
if (!sel.categoria && sel.grupo === m.base) return 'Pacientes con resultado metástasis entre las que tienen resultado de biopsia';
|
||||
if (!sel.categoria) return 'Pacientes con resultado no metástasis entre las que tienen resultado de biopsia';
|
||||
return 'Proporción con resultado ' + enFrase(seleccionEtiqueta(m, sel));
|
||||
}
|
||||
/** Per BI-RADS stratum: the selected categories over the patients with a biopsy result. No biopsy and no data never enter. */
|
||||
|
||||
Reference in New Issue
Block a user