Compare commits

...

2 Commits

2 changed files with 10 additions and 1 deletions
@@ -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) },
@@ -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<string, unknown>[] = [
{ 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' },