import { DecimalPipe } from '@angular/common'; import { Component, input } from '@angular/core'; interface Prediction { years: number; p: number; low?: number; high?: number; } export interface RiskScale { label: string; risk?: Prediction; } /** Each model's risk at its index visit and at five years; none where it gives no such horizon. */ export function riskScales(models: { text: string; predictions: Prediction[] }[]): RiskScale[] { return models.flatMap((m) => [0, 5].map((years) => ({ label: `${m.text}, riesgo ${years ? 'a 5 años' : 'inmediato'}`, risk: m.predictions.find((p) => p.years === years), })), ); } @Component({ selector: 'app-risk-scales', imports: [DecimalPipe], template: ` @for (s of scales(); track s.label) {
{{ s.label }}
@if (s.risk; as r) { }
@if (s.risk; as r) { {{ r.p * 100 | number: '1.1-2' }} % @if (r.low !== undefined) { IC 95 %: {{ r.low * 100 | number: '1.1-2' }}–{{ r.high! * 100 | number: '1.1-2' }} % } } @else { No disponible }
} `, styles: ` .scale { align-items: center; display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 8px; } .line { background: linear-gradient(to right, #a8c243, #c24269); flex: 1 1 200px; height: 8px; position: relative; } .mark { background: #333; height: 16px; position: absolute; top: -4px; width: 3px; } `, }) export class RiskScales { readonly scales = input.required(); }