F1: training form driven by the API schema; Sankey stopped nodes at the left

The training form flattens the discriminated source union generically: the discriminator becomes a select labelled by each variant's title, a variant's fields hide unless it is chosen, and the payload keeps only the chosen variant's fields. No variant names, option labels or Hz labels live in the WebApp. The Sankey places the three 'Se quedó en' nodes in the leftmost column, every node at its own position.
This commit is contained in:
2026-12-01 13:32:26 -06:00
parent f57a42b22a
commit 5bf022b36f
4 changed files with 103 additions and 47 deletions
+4 -1
View File
@@ -490,6 +490,9 @@ export function sexCountBars(r: Reading, catalog: Catalog, axis: string, period:
};
}
export const SANKEY_X = [0.22, 0.5, 0.78, 0.999, 0.001, 0.001, 0.001];
export const SANKEY_Y = [0.2, 0.2, 0.2, 0.2, 0.5, 0.75, 0.999];
export function teaSankey(r: Reading): Figure {
const [mchat, psychology, neuro, eeg] = [
'mchat_only',
@@ -521,7 +524,7 @@ export function teaSankey(r: Reading): Figure {
{
type: 'sankey',
arrangement: 'fixed',
node: { label: labels, color: colors, align: 'left', pad: 24, hovertemplate },
node: { label: labels, color: colors, x: SANKEY_X, y: SANKEY_Y, pad: 24, hovertemplate },
link: {
source: links.map(({ source }) => source),
target: links.map(({ target }) => target),
@@ -339,6 +339,21 @@ describe('TEA clinical figures', () => {
});
});
it('places the stopped nodes at the left and gives every node its own position', () => {
const node = teaSankey({ populations: {}, strata: {} }).data[0] as unknown as {
node: { label: string[]; x: number[]; y: number[] };
};
const stopped = node.node.label.flatMap((label, index) =>
label.startsWith('Se quedó en') ? [index] : [],
);
expect(stopped).toHaveLength(3);
expect(Math.max(...stopped.map((index) => node.node.x[index]))).toBeLessThan(
Math.min(...node.node.x.filter((_, index) => !stopped.includes(index))),
);
const places = node.node.x.map((x, index) => `${x}|${node.node.y[index]}`);
expect(new Set(places).size).toBe(places.length);
});
it('splits prevalence by sex and diagnosis and includes children without a recorded sex', () => {
const r = {
populations: { 'initial-population': 7 },