Elegir los ajustes de supervivencia que se comparan
This commit is contained in:
@@ -616,7 +616,7 @@
|
||||
Greenwood; n =
|
||||
{{ c.n }}, fallecidos = {{ c.fallecidos }}).
|
||||
</p>
|
||||
<app-plot [figure]="c.figure" [height]="340" [toolbar]="false" />
|
||||
<app-survival-curves [figure]="c.figure" />
|
||||
} @else {
|
||||
<p class="muted">{{ c.missing }}</p>
|
||||
}
|
||||
|
||||
@@ -50,6 +50,7 @@ import type { Relation } from '../api/models/relation';
|
||||
import { Figure, PALETTE, Plot } from '../plot';
|
||||
import { Loading } from '../loading';
|
||||
import { Factores, ScenarioFactors } from './factores';
|
||||
import { SurvivalCurves } from './survival-curves';
|
||||
|
||||
/** An Observation's value as the screens say it, whatever its type. */
|
||||
function shown(o: Observation): string {
|
||||
@@ -103,6 +104,7 @@ function modelInputs(value: string | undefined): Record<string, unknown> | undef
|
||||
selector: 'app-paciente',
|
||||
imports: [
|
||||
Factores,
|
||||
SurvivalCurves,
|
||||
Loading,
|
||||
DecimalPipe,
|
||||
MatButtonModule,
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
import { curveGroups } from './survival-curves';
|
||||
|
||||
describe('curveGroups', () => {
|
||||
it('keeps each band with its line, one choice per curve', () => {
|
||||
const data = [{ showlegend: false }, { name: 'Kaplan-Meier' }, { name: 'Weibull' }];
|
||||
const groups = curveGroups({ data: data as never });
|
||||
expect(groups.map((g) => [g.name, g.traces.length])).toEqual([
|
||||
['Kaplan-Meier', 2],
|
||||
['Weibull', 1],
|
||||
]);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,67 @@
|
||||
import { Component, computed, input, signal } from '@angular/core';
|
||||
import { MatCheckboxModule } from '@angular/material/checkbox';
|
||||
import { Figure, Plot } from '../plot';
|
||||
|
||||
type Trace = Figure['data'][number];
|
||||
|
||||
/** The figure's curves by name; a band has no name of its own and goes with the line after it. */
|
||||
export function curveGroups(figure: Figure): { name: string; traces: Trace[] }[] {
|
||||
const groups: { name: string; traces: Trace[] }[] = [];
|
||||
let pending: Trace[] = [];
|
||||
for (const trace of figure.data) {
|
||||
pending.push(trace);
|
||||
const { name, showlegend } = trace as { name?: string; showlegend?: boolean };
|
||||
if (name && showlegend !== false) {
|
||||
groups.push({ name, traces: pending });
|
||||
pending = [];
|
||||
}
|
||||
}
|
||||
return groups;
|
||||
}
|
||||
|
||||
/** The survival fits, each one chosen or not, to compare them on one plot. */
|
||||
@Component({
|
||||
selector: 'app-survival-curves',
|
||||
imports: [MatCheckboxModule, Plot],
|
||||
template: `
|
||||
<div class="choices">
|
||||
@for (g of groups(); track g.name) {
|
||||
<mat-checkbox [checked]="!hidden().has(g.name)" (change)="toggle(g.name)">
|
||||
{{ g.name }}
|
||||
</mat-checkbox>
|
||||
}
|
||||
</div>
|
||||
@if (shown().data.length) {
|
||||
<app-plot [figure]="shown()" [height]="340" [toolbar]="false" />
|
||||
}
|
||||
`,
|
||||
styles: `
|
||||
:host {
|
||||
display: block;
|
||||
}
|
||||
.choices {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 0 16px;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
`,
|
||||
})
|
||||
export class SurvivalCurves {
|
||||
readonly figure = input.required<Figure>();
|
||||
protected readonly groups = computed(() => curveGroups(this.figure()));
|
||||
private readonly hidden_ = signal(new Set<string>());
|
||||
protected readonly hidden = this.hidden_.asReadonly();
|
||||
protected readonly shown = computed<Figure>(() => ({
|
||||
...this.figure(),
|
||||
data: this.groups()
|
||||
.filter((g) => !this.hidden().has(g.name))
|
||||
.flatMap((g) => g.traces),
|
||||
}));
|
||||
|
||||
protected toggle(name: string) {
|
||||
const next = new Set(this.hidden());
|
||||
if (!next.delete(name)) next.add(name);
|
||||
this.hidden_.set(next);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user