diff --git a/src/app/indicadores/figures.ts b/src/app/indicadores/figures.ts
index 0c7308e..1ba212f 100644
--- a/src/app/indicadores/figures.ts
+++ b/src/app/indicadores/figures.ts
@@ -512,8 +512,7 @@ export function sexCountBars(r: Reading, catalog: Catalog, axis: string, period:
};
}
-const SANKEY_X = [0.001, 0.25, 0.5, 0.75, 0.999, 0.999, 0.999];
-const SANKEY_Y = [0.2, 0.2, 0.2, 0.2, 0.95, 0.7, 0.45];
+const STOPPED = '#888888';
export function teaSankey(r: Reading): Figure {
const [mchat, psychology, neuro, eeg] = [
@@ -522,42 +521,53 @@ export function teaSankey(r: Reading): Figure {
'neuropediatrics',
'eeg',
].map((code) => counted(r, code));
- const labels = [
- 'M-CHAT',
- 'Evaluación psicológica',
- 'Evaluación neuropediátrica',
- 'EEG de buena calidad',
- 'Se quedó en M-CHAT',
- 'Se quedó en evaluación psicológica',
- 'Se quedó en evaluación neuropediátrica',
+ const nodes = [
+ { label: 'M-CHAT', color: '#B8433A', value: mchat + psychology + neuro + eeg },
+ { label: 'Evaluación
psicológica', color: '#D0B778', value: psychology + neuro + eeg },
+ { label: 'Evaluación
neuropediátrica', color: '#7184A2', value: neuro + eeg },
+ { label: 'EEG de
buena calidad', color: OLIVE, value: eeg },
+ { label: 'Se quedó en evaluación
neuropediátrica', color: STOPPED, value: neuro },
+ { label: 'Se quedó en evaluación
psicológica', color: STOPPED, value: psychology },
+ { label: 'Se quedó en M-CHAT', color: STOPPED, value: mchat },
];
- const colors = ['#B8433A', '#D0B778', '#7184A2', OLIVE, '#888888', '#888888', '#888888'];
- const links = [
- { source: 0, target: 1, value: psychology + neuro + eeg },
- { source: 0, target: 4, value: mchat },
- { source: 1, target: 2, value: neuro + eeg },
- { source: 1, target: 5, value: psychology },
- { source: 2, target: 3, value: eeg },
- { source: 2, target: 6, value: neuro },
- ].filter(({ value }) => value > 0);
+ const shown = nodes.flatMap((node, index) => (node.value > 0 ? [index] : []));
+ const position = new Map(shown.map((index, place) => [index, place]));
+ const flows: [number, number][] = [
+ [0, 1],
+ [0, 6],
+ [1, 2],
+ [1, 5],
+ [2, 3],
+ [2, 4],
+ ];
+ const links = flows.flatMap(([source, target]) =>
+ nodes[target].value > 0
+ ? [{ source: position.get(source)!, target: position.get(target)!, index: target }]
+ : [],
+ );
const hovertemplate = '%{label}
%{value} pacientes';
return {
data: [
{
type: 'sankey',
arrangement: 'fixed',
- node: { label: labels, color: colors, x: SANKEY_X, y: SANKEY_Y, pad: 24, hovertemplate },
+ node: {
+ label: shown.map((index) => nodes[index].label),
+ color: shown.map((index) => nodes[index].color),
+ pad: 36,
+ hovertemplate,
+ },
link: {
source: links.map(({ source }) => source),
target: links.map(({ target }) => target),
- value: links.map(({ value }) => value),
- color: links.map(({ target }) => rgba(colors[target], 0.45)),
- label: links.map(({ target }) => labels[target]),
+ value: links.map(({ index }) => nodes[index].value),
+ color: links.map(({ index }) => rgba(nodes[index].color, 0.45)),
+ label: links.map(({ index }) => nodes[index].label.replace('
', ' ')),
hovertemplate,
},
} as Partial,
],
- layout: { margin: { l: 20, r: 20, t: 24, b: 24 } },
+ layout: { font: { size: 12 }, margin: { l: 20, r: 20, t: 24, b: 24 } },
};
}
diff --git a/src/app/indicadores/tab-indicadores.scss b/src/app/indicadores/tab-indicadores.scss
index 54c6775..e890215 100644
--- a/src/app/indicadores/tab-indicadores.scss
+++ b/src/app/indicadores/tab-indicadores.scss
@@ -129,10 +129,6 @@ h2.figure-card-title {
}
}
-.figure[data-figure='sankey'] {
- grid-column: 1 / -1;
-}
-
.figure h3 {
font-size: 16px;
font-weight: 700;
@@ -234,6 +230,10 @@ h2.box-subtitle {
grid-template-columns: 1fr;
}
+.grid-figures > [data-figure='sankey'] {
+ grid-column: 1 / -1;
+}
+
@media (min-width: 1100px) {
.grid-figures {
grid-template-columns: 1fr 1fr;
diff --git a/src/app/indicadores/tea-indicators.spec.ts b/src/app/indicadores/tea-indicators.spec.ts
index 6081a10..228deeb 100644
--- a/src/app/indicadores/tea-indicators.spec.ts
+++ b/src/app/indicadores/tea-indicators.spec.ts
@@ -369,7 +369,7 @@ describe('TEA clinical figures', () => {
});
expect(figure.data[0]).toMatchObject({
type: 'sankey',
- link: { source: [0, 0, 1, 2, 2], target: [1, 4, 2, 3, 6], value: [7, 2, 7, 4, 3] },
+ link: { source: [0, 0, 1, 2, 2], target: [1, 5, 2, 3, 4], value: [7, 2, 7, 4, 3] },
});
});