diff --git a/src/app/features/indicadores/indicador-histopatologia-cama.ts b/src/app/features/indicadores/indicador-histopatologia-cama.ts index c78083d..a2b3760 100644 --- a/src/app/features/indicadores/indicador-histopatologia-cama.ts +++ b/src/app/features/indicadores/indicador-histopatologia-cama.ts @@ -49,6 +49,10 @@ export class IndicadorHistopatologiaCama implements OnChanges, OnDestroy { private key = ''; private loaded = false; private pages: ModeloHistopatologia[] = []; + // The rates figure has a phone-width variant; it is redrawn when the window crosses that width. + private readonly estrecho = typeof matchMedia === 'function' ? matchMedia('(max-width: 600px)') : undefined; + private readonly alCambiarAncho = () => this.draw(); + constructor() { this.estrecho?.addEventListener('change', this.alCambiarAncho); } get appliedSummary() { return describePeriods(this.applied.tipo, this.applied.selection); } get selectionLabel() { return this.model && this.selection ? seleccionEtiqueta(this.model, this.selection) : ''; } @@ -138,8 +142,8 @@ export class IndicadorHistopatologiaCama implements OnChanges, OnDestroy { private draw() { if (!this.model || !this.selection) return; this.donutFigure = donaHistopatologia(this.model, this.selection, this.tema); - this.ratesFigure = figuraTasas(this.model, this.selection, this.tema); + this.ratesFigure = figuraTasas(this.model, this.selection, this.tema, !!this.estrecho?.matches); this.changeDetector.markForCheck(); } - ngOnDestroy() { this.subscription?.unsubscribe(); } + ngOnDestroy() { this.subscription?.unsubscribe(); this.estrecho?.removeEventListener('change', this.alCambiarAncho); } } diff --git a/src/app/features/indicadores/indicadores-histopatologia-cama.spec.ts b/src/app/features/indicadores/indicadores-histopatologia-cama.spec.ts index 48a7535..822c2a6 100644 --- a/src/app/features/indicadores/indicadores-histopatologia-cama.spec.ts +++ b/src/app/features/indicadores/indicadores-histopatologia-cama.spec.ts @@ -149,7 +149,7 @@ describe('Histopatología por BI-RADS: tasas, selección y figuras', () => { 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]); - expect(lectura(m, b3)).toBe('Proporción con resultado lesión de riesgo (b3)'); + expect(lectura(m, b3)).toBe('Proporción con resultado lesión de riesgo (B3)'); expect(clicHistopatologia(m, b3, 'categorias', 1)).toEqual({ grupo: 'NO_MALIGNO' }); expect(clicHistopatologia(m, b3, 'categorias', 3)).toEqual({ grupo: 'MALIGNO', categoria: 'INVASOR' }); expect(clicHistopatologia(m, b3, 'centro', 0)).toEqual(sel); @@ -181,6 +181,16 @@ describe('Histopatología por BI-RADS: tasas, selección y figuras', () => { expect(range).toEqual(rangoTasas(tasas(m, sel))); expect(range[0] % 5).toBe(0); expect(range[1] % 5).toBe(0); expect(figuraTasas(m, sel, 'oscuro').layout['paper_bgcolor']).toBe('#081839'); + expect((f.layout['xaxis'] as { title: { text: string } }).title.text).toBe('Porcentaje con resultado maligno'); + expect((figuraTasas(m, { grupo: 'NO_MALIGNO', categoria: 'RIESGO_B3' }, 'claro').layout['xaxis'] as { title: { text: string } }).title.text).toBe('Porcentaje con resultado lesión de riesgo (B3)'); + }); + it('en un ancho de teléfono las etiquetas se parten, el eje conserva pocas marcas y el título corto; los valores no cambian', () => { + const m = base(), sel = seleccionBase(m), ancho = figuraTasas(m, sel, 'claro'), estrecho = figuraTasas(m, sel, 'claro', true); + expect(estrecho.data[0]['x']).toEqual(ancho.data[0]['x']); + const y = estrecho.layout['yaxis'] as { ticktext: string[]; tickvals: string[] }; + expect(y.tickvals).toEqual(m.filas.map(r => r.etiqueta)); expect(y.ticktext[0]).toBe('BI-RADS 4
sin subtipo'); + expect((estrecho.layout['xaxis'] as { title: { text: string }; nticks: number })).toMatchObject({ title: { text: 'Porcentaje' }, nticks: 3 }); + expect((ancho.layout['yaxis'] as Record)['ticktext']).toBeUndefined(); }); it('dona de dos anillos: grupos dentro, categorías fuera; la selección atenúa sin cambiar valores y el centro dice «k de N con resultado»', () => { const m = base(), d = donaHistopatologia(m, seleccionBase(m), 'claro'); @@ -250,7 +260,7 @@ describe('Histopatología por BI-RADS: componente', () => { const b3 = boton('Lesión de riesgo (B3)'); b3.click(); f.detectChanges(); expect(f.componentInstance.selection).toEqual({ grupo: 'NO_MALIGNO', categoria: 'RIESGO_B3' }); expect(b3.getAttribute('aria-pressed')).toBe('true'); expect(volver().disabled).toBe(false); - expect(f.nativeElement.querySelector('.selection-status').textContent).toContain('Proporción con resultado lesión de riesgo (b3)'); + expect(f.nativeElement.querySelector('.selection-status').textContent).toContain('Proporción con resultado lesión de riesgo (B3)'); b3.click(); f.detectChanges(); expect(f.componentInstance.selection).toEqual({ grupo: 'NO_MALIGNO' }); boton('Carcinoma invasor').click(); f.detectChanges(); expect(f.componentInstance.selection).toEqual({ grupo: 'MALIGNO', categoria: 'INVASOR' }); diff --git a/src/app/features/indicadores/indicadores-histopatologia-cama.ts b/src/app/features/indicadores/indicadores-histopatologia-cama.ts index f52fb11..b2e0339 100644 --- a/src/app/features/indicadores/indicadores-histopatologia-cama.ts +++ b/src/app/features/indicadores/indicadores-histopatologia-cama.ts @@ -59,6 +59,8 @@ const fail = (message: string): never => { throw new HistopatologiaIncompatible( const escapar = (v: string) => v.replace(/&/g, '&').replace(//g, '>'); const miles = (v: number) => v.toLocaleString('es-MX'); const esTotal = (grupo: unknown) => typeof grupo === 'string' && grupo.toUpperCase() === 'TOTAL'; +// A label inside a sentence: «Lesión de riesgo (B3)» reads «lesión de riesgo (B3)», keeping the code's capitals. +const enFrase = (v: string) => v.charAt(0).toLowerCase() + v.slice(1); const etiquetaGrupo = (v: unknown) => texto(v) ? v : registro(v) && texto(v['etiqueta']) ? v['etiqueta'] : undefined; // 0 is a published count; a suppressed cell has no count; a cell the response does not carry is not available. @@ -179,7 +181,7 @@ export function clicHistopatologia(m: ModeloHistopatologia, sel: SeleccionHistop 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'; - return 'Proporción con resultado ' + seleccionEtiqueta(m, sel).toLowerCase(); + 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. */ export function tasas(m: ModeloHistopatologia, sel: SeleccionHistopatologia): Tasa[] { @@ -203,7 +205,8 @@ export function rangoTasas(valores: Tasa[]): [number, number] { } /** Rates on the left: one point and horizontal Wilson interval per BI-RADS stratum, one trace always. */ -export function figuraTasas(m: ModeloHistopatologia, sel: SeleccionHistopatologia, tema: Tema): PlotlyFigure { +// `estrecho`: a phone-width plot, where the labels wrap and the axis keeps only what fits. +export function figuraTasas(m: ModeloHistopatologia, sel: SeleccionHistopatologia, tema: Tema, estrecho = false): PlotlyFigure { const p = c2Theme(tema); const valores = tasas(m, sel); const color = sel.categoria ? m.categorias.find(c => c.id === sel.categoria)!.color : m.grupos.find(g => g.id === sel.grupo)!.color; @@ -217,11 +220,14 @@ export function figuraTasas(m: ModeloHistopatologia, sel: SeleccionHistopatologi hovertemplate: '%{y}
%{customdata[0]} (%{customdata[1]}/%{customdata[2]})
IC 95 %: %{customdata[3]}–%{customdata[4]} %', }], layout: { autosize: true, height: 360, showlegend: false, paper_bgcolor: p.background, plot_bgcolor: p.background, font: { color: p.text }, - margin: { l: 150, r: 96, t: 16, b: 64 }, - yaxis: { type: 'category', categoryorder: 'array', categoryarray: [...y].reverse(), fixedrange: true, automargin: true }, - xaxis: { range: rangoTasas(valores), ticksuffix: ' %', gridcolor: p.grid, zeroline: false, fixedrange: true, title: { text: lectura(m, sel) } }, + // The labels of the categories size their own margin, so the plot keeps its width on a narrow screen. + margin: { l: 8, r: estrecho ? 72 : 84, t: 16, b: 64 }, + yaxis: { type: 'category', categoryorder: 'array', categoryarray: [...y].reverse(), fixedrange: true, automargin: true, + ...(estrecho ? { tickmode: 'array', tickvals: y, ticktext: y.map(v => v.replace(' sin subtipo', '
sin subtipo')) } : {}) }, + xaxis: { range: rangoTasas(valores), ticksuffix: ' %', nticks: estrecho ? 3 : 5, tickangle: 0, gridcolor: p.grid, zeroline: false, fixedrange: true, + title: { text: estrecho ? 'Porcentaje' : 'Porcentaje con resultado ' + enFrase(seleccionEtiqueta(m, sel)), standoff: 8 } }, annotations: valores.map(t => ({ x: 1, xref: 'paper', xanchor: 'left', xshift: 8, y: t.fila.etiqueta, yref: 'y', showarrow: false, align: 'left', - font: { size: 12, color: p.text }, + font: { size: estrecho ? 11 : 12, color: p.text }, text: t.k === null ? estadoTasa(t) : `${shareText(t.k, t.fila.den!)}
${t.k}/${t.fila.den}` })), }, config: { displayModeBar: false } }; }