From 6465165e34d716e6a030d6112b9165f65598d0f7 Mon Sep 17 00:00:00 2001 From: angel Date: Sat, 21 Nov 2026 15:36:00 -0600 Subject: [PATCH] CaMa recurrence figure: the y axis follows the months it draws --- .../cama/cama-analisis.component.spec.ts | 9 +++++++++ .../paciente-detalle/cama/cama-recurrencia-figura.ts | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/app/features/indicadores/paciente-detalle/cama/cama-analisis.component.spec.ts b/src/app/features/indicadores/paciente-detalle/cama/cama-analisis.component.spec.ts index eb14a55..e79a1bf 100644 --- a/src/app/features/indicadores/paciente-detalle/cama/cama-analisis.component.spec.ts +++ b/src/app/features/indicadores/paciente-detalle/cama/cama-analisis.component.spec.ts @@ -12,6 +12,7 @@ import { CamaAnalisisSupervivencia } from './cama-analisis-supervivencia.compone import { CamaCurvasService, respuestaCurvas } from './cama-curvas.service'; import { CamaFactoresRiesgo, entradasDe } from './cama-factores-riesgo.component'; import { CamaRecurrenciaService, respuestaRecurrencia } from './cama-recurrencia.service'; +import { figuraRecurrencia } from './cama-recurrencia-figura'; const meses = Array.from({ length: 25 }, (_, i) => i); const decreciente = (fin: number) => meses.map(m => 1 - (1 - fin) * (m / 24)); @@ -112,6 +113,14 @@ describe('AnĂ¡lisis de supervivencia', () => { }); describe('AnĂ¡lisis de recurrencia', () => { + // Fails if the y axis is scaled by follow-up the axis does not show: a curve that stays above 0.8 in the 72 months drawn must not start its axis at 0.2. + it('scales the y axis to the months it draws', () => { + const largo = { ...figura('metabric', 'Largo'), observado_hasta: 300, months_max: 72, + km: { months: Array.from({ length: 301 }, (_, i) => i), S: Array.from({ length: 301 }, (_, i) => 1 - i / 400), low: Array.from({ length: 301 }, (_, i) => (i <= 72 ? 0.85 : 0.2)), high: Array.from({ length: 301 }, () => 1) } }; + + expect((figuraRecurrencia(respuestaRecurrencia({ modelo: { nombre: 'cama-recurrence', version: '1' }, horizontes: [12, 36, 60], escenarios: [largo], resumen: [], predeterminado: null }).escenarios[0]).layout as any).yaxis.range[0]).toBeGreaterThan(0.5); + }); + const figura = (cohorte: string, escenario: string) => ({ cohorte, cohorte_nombre: cohorte === 'scanb' ? 'SCAN-B' : 'METABRIC', escenario, n: 300, recaidas: 180, horizons_months: [12, 36, 60], observado_hasta: 60, months_max: 72, km: { months: Array.from({ length: 61 }, (_, i) => i), S: Array.from({ length: 61 }, (_, i) => 1 - i / 200), low: Array.from({ length: 61 }, (_, i) => 1 - i / 190), high: Array.from({ length: 61 }, () => 1) }, diff --git a/src/app/features/indicadores/paciente-detalle/cama/cama-recurrencia-figura.ts b/src/app/features/indicadores/paciente-detalle/cama/cama-recurrencia-figura.ts index e2ddebf..74fe118 100644 --- a/src/app/features/indicadores/paciente-detalle/cama/cama-recurrencia-figura.ts +++ b/src/app/features/indicadores/paciente-detalle/cama/cama-recurrencia-figura.ts @@ -26,7 +26,7 @@ export function figuraRecurrencia(f: FiguraRecurrencia, tema: Tema = 'claro'): P const L = ETIQUETAS_RECURRENCIA, d = f.points.COMB, km = f.km; const texto = tema === 'oscuro' ? '#e5e9f0' : '#1f2933', rejilla = tema === 'oscuro' ? 'rgba(229,233,240,.18)' : 'rgba(31,41,51,.12)'; const visibles = (t: number[], S: number[]) => S.filter((_, i) => t[i] <= f.months_max); - const minimo = Math.max(0, Math.floor((Math.min(...km.low, ...visibles(f.weibull.t, f.weibull.S), ...visibles(f.weibull_fractional.t, f.weibull_fractional.S), ...d.low) - 0.02) * 20) / 20); + const minimo = Math.max(0, Math.floor((Math.min(...visibles(km.months, km.low), ...visibles(f.weibull.t, f.weibull.S), ...visibles(f.weibull_fractional.t, f.weibull_fractional.S), ...d.low) - 0.02) * 20) / 20); const data: Record[] = [ { type: 'scatter', mode: 'lines', x: km.months, y: km.high, line: { width: 0, shape: 'hv' }, showlegend: false, hoverinfo: 'skip', legendgroup: 'km' }, { type: 'scatter', mode: 'lines', x: km.months, y: km.low, fill: 'tonexty', fillcolor: COLORES_RECURRENCIA.banda, line: { width: 0, shape: 'hv' }, showlegend: false, hoverinfo: 'skip', legendgroup: 'km' },