76 lines
1.8 KiB
TypeScript
76 lines
1.8 KiB
TypeScript
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) {
|
||
<div class="scale">
|
||
<span>{{ s.label }}</span>
|
||
<div class="line">
|
||
@if (s.risk; as r) {
|
||
<span class="mark" [style.left.%]="r.p * 100"></span>
|
||
}
|
||
</div>
|
||
@if (s.risk; as r) {
|
||
<strong>{{ r.p * 100 | number: '1.1-2' }} %</strong>
|
||
@if (r.low !== undefined) {
|
||
<span>
|
||
IC 95 %: {{ r.low * 100 | number: '1.1-2' }}–{{ r.high! * 100 | number: '1.1-2' }} %
|
||
</span>
|
||
}
|
||
} @else {
|
||
<strong>No disponible</strong>
|
||
}
|
||
</div>
|
||
}
|
||
`,
|
||
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<RiskScale[]>();
|
||
}
|