F1g: whole-number axes, risk list link, dotted timeline, head map
Share the integer tick rule between Trazabilidad and TEA record figures. Use the plotted extent, including stacked totals or interval bounds, to target four divisions. Round spacing up to a 1/2/5 step with a minimum of one, anchor ticks at zero, ignore nonfinite values, and include integer bounds when a fractional extent contains no integer. Point the existing patient link at the TEA risk route and remove the details accordion and separate risk action. Exercise the link from the risk list in the existing patient page case. Connect completed diamonds in step order on the existing marker trace, using its color for the dotted line and retaining the duration bars and annotations. The scalp figure used the ear electrodes as markers outside the circle, omitted the ears, and masked sample centers without clipping Plotly's rendered contour cells at the scalp boundary. Its interpolation also colored distant areas with no adjacent sample. Use the reference's 19 scalp positions, nose and ear paths, and reverse-wound mask painted in the card's white surface color beneath the outline. Derive the mask and the existing 41-point grid in headMapGeometry. Use the reference's 0.45 interpolation reach with inverse squared distance, taking a coincident sample directly and preserving the existing zone inputs and z color scale. Test mirror positions, scalp bounds, and plotted contour values. Prettier, Ruff check, Ruff format check, and git diff --check passed. Angular and Playwright execution are reserved for the test machines.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { banded } from '../gobernanza/figures';
|
||||
import { wholeNumberAxis } from '../indicadores/figures';
|
||||
import { Figure, PALETTE } from '../plot';
|
||||
import { Metric, Pair, Site, Study, TeaStep, zoneLabel } from './tea-data';
|
||||
|
||||
@@ -32,7 +33,8 @@ export function timeline(steps: TeaStep[]): Figure | null {
|
||||
bars,
|
||||
{
|
||||
type: 'scatter',
|
||||
mode: 'markers',
|
||||
mode: 'lines+markers',
|
||||
line: { dash: 'dot', color: PALETTE[0] },
|
||||
x: done.map((step) => step.date),
|
||||
y: done.map((step) => step.label),
|
||||
marker: {
|
||||
@@ -94,63 +96,83 @@ export function timeline(steps: TeaStep[]): Figure | null {
|
||||
};
|
||||
}
|
||||
|
||||
const electrodes: Record<string, [number, number]> = {
|
||||
Fp1: [-0.3, 0.87],
|
||||
Fpz: [0, 0.93],
|
||||
Fp2: [0.3, 0.87],
|
||||
F7: [-0.78, 0.49],
|
||||
F3: [-0.42, 0.51],
|
||||
Fz: [0, 0.53],
|
||||
F4: [0.42, 0.51],
|
||||
F8: [0.78, 0.49],
|
||||
T3: [-0.93, 0],
|
||||
C3: [-0.49, 0],
|
||||
Cz: [0, 0],
|
||||
C4: [0.49, 0],
|
||||
T4: [0.93, 0],
|
||||
T5: [-0.78, -0.49],
|
||||
P3: [-0.42, -0.51],
|
||||
Pz: [0, -0.53],
|
||||
P4: [0.42, -0.51],
|
||||
T6: [0.78, -0.49],
|
||||
O1: [-0.3, -0.87],
|
||||
Oz: [0, -0.93],
|
||||
O2: [0.3, -0.87],
|
||||
A1: [-1.08, 0],
|
||||
A2: [1.08, 0],
|
||||
};
|
||||
|
||||
const zones: Record<string, [number, number]> = {
|
||||
global: [0, 0],
|
||||
posterior: [0, -0.72],
|
||||
frontal_left: [-0.5, 0.62],
|
||||
frontal_right: [0.5, 0.62],
|
||||
frontal_midline: electrodes['Fz'],
|
||||
central: electrodes['Cz'],
|
||||
parietal: electrodes['Pz'],
|
||||
temporal_left: [-0.82, -0.25],
|
||||
temporal_right: [0.82, -0.25],
|
||||
occipital: [0, -0.86],
|
||||
};
|
||||
export function headMapGeometry() {
|
||||
const electrodes: Record<string, [number, number]> = {
|
||||
Fp1: [-0.25, 0.77],
|
||||
Fp2: [0.25, 0.77],
|
||||
F7: [-0.65, 0.47],
|
||||
F3: [-0.33, 0.4],
|
||||
Fz: [0, 0.38],
|
||||
F4: [0.33, 0.4],
|
||||
F8: [0.65, 0.47],
|
||||
T3: [-0.8, 0],
|
||||
C3: [-0.4, 0],
|
||||
Cz: [0, 0],
|
||||
C4: [0.4, 0],
|
||||
T4: [0.8, 0],
|
||||
T5: [-0.65, -0.47],
|
||||
P3: [-0.33, -0.4],
|
||||
Pz: [0, -0.38],
|
||||
P4: [0.33, -0.4],
|
||||
T6: [0.65, -0.47],
|
||||
O1: [-0.25, -0.77],
|
||||
O2: [0.25, -0.77],
|
||||
};
|
||||
const grid = Array.from({ length: 41 }, (_, i) => (i - 20) / 20);
|
||||
const inside = grid.map((y) => grid.map((x) => x * x + y * y <= 1));
|
||||
const boundary = Array.from({ length: 96 }, (_, i) => {
|
||||
const angle = (-2 * Math.PI * i) / 96;
|
||||
return `${i ? 'L' : 'M'} ${Math.cos(angle).toFixed(4)} ${Math.sin(angle).toFixed(4)}`;
|
||||
}).join(' ');
|
||||
const line = { color: '#17324d', width: 2 };
|
||||
const shapes: NonNullable<NonNullable<Figure['layout']>['shapes']> = [
|
||||
{
|
||||
type: 'path',
|
||||
path: `M -2 -2 L 2 -2 L 2 2 L -2 2 Z ${boundary} Z`,
|
||||
fillcolor: '#ffffff',
|
||||
line: { width: 0 },
|
||||
},
|
||||
{ type: 'circle', x0: -1, x1: 1, y0: -1, y1: 1, line },
|
||||
{ type: 'path', path: 'M -0.13 0.99 L 0 1.13 L 0.13 0.99', line },
|
||||
{ type: 'path', path: 'M -0.99 0.14 Q -1.1 0.12 -1.08 0 Q -1.1 -0.12 -0.99 -0.14', line },
|
||||
{ type: 'path', path: 'M 0.99 0.14 Q 1.1 0.12 1.08 0 Q 1.1 -0.12 0.99 -0.14', line },
|
||||
];
|
||||
return { electrodes, grid, inside, shapes };
|
||||
}
|
||||
|
||||
export function headMap(sites: Site[]): Figure {
|
||||
const { electrodes, grid, inside, shapes } = headMapGeometry();
|
||||
const zones: Record<string, [number, number]> = {
|
||||
global: [0, 0],
|
||||
posterior: [0, -0.72],
|
||||
frontal_left: [-0.5, 0.62],
|
||||
frontal_right: [0.5, 0.62],
|
||||
frontal_midline: electrodes['Fz'],
|
||||
central: electrodes['Cz'],
|
||||
parietal: electrodes['Pz'],
|
||||
temporal_left: [-0.82, -0.25],
|
||||
temporal_right: [0.82, -0.25],
|
||||
occipital: [0, -0.86],
|
||||
};
|
||||
const samples = sites.flatMap((site) => {
|
||||
const point = (site.kind === 'electrode' ? electrodes : zones)[site.name];
|
||||
return point && site.z != null && Number.isFinite(site.z) ? [{ point, z: site.z }] : [];
|
||||
});
|
||||
const grid = Array.from({ length: 41 }, (_, i) => (i - 20) / 20);
|
||||
const data: Figure['data'] = [];
|
||||
if (samples.length) {
|
||||
const surface = grid.map((y) =>
|
||||
grid.map((x) => {
|
||||
if (x * x + y * y > 1) return null;
|
||||
const weights = samples.map(
|
||||
({ point }) => 1 / Math.max(1e-6, (x - point[0]) ** 2 + (y - point[1]) ** 2),
|
||||
);
|
||||
return (
|
||||
samples.reduce((sum, site, i) => sum + site.z * weights[i], 0) /
|
||||
weights.reduce((sum, weight) => sum + weight, 0)
|
||||
);
|
||||
const surface = grid.map((y, row) =>
|
||||
grid.map((x, col) => {
|
||||
if (!inside[row][col]) return null;
|
||||
let total = 0;
|
||||
let weights = 0;
|
||||
for (const { point, z } of samples) {
|
||||
const distanceSquared = (x - point[0]) ** 2 + (y - point[1]) ** 2;
|
||||
if (distanceSquared < 1e-9) return z;
|
||||
if (distanceSquared > 0.45 ** 2) continue;
|
||||
total += z / distanceSquared;
|
||||
weights += 1 / distanceSquared;
|
||||
}
|
||||
return weights ? total / weights : null;
|
||||
}),
|
||||
);
|
||||
const limit = Math.max(2, ...samples.map((site) => Math.abs(site.z)));
|
||||
@@ -166,7 +188,9 @@ export function headMap(sites: Site[]): Figure {
|
||||
[0.5, '#f7f7f7'],
|
||||
[1, '#c24269'],
|
||||
],
|
||||
contours: { coloring: 'heatmap', showlines: false },
|
||||
connectgaps: false,
|
||||
contours: { coloring: 'heatmap', showlines: true },
|
||||
line: { width: 0.5, color: 'rgba(8,24,57,.3)' },
|
||||
hoverinfo: 'skip',
|
||||
colorbar: { title: { text: 'z' } },
|
||||
});
|
||||
@@ -180,6 +204,7 @@ export function headMap(sites: Site[]): Figure {
|
||||
y: markers.map(([, point]) => point[1]),
|
||||
text: markers.map(([name]) => name),
|
||||
textposition: 'top center',
|
||||
textfont: { size: 9, color: '#17324d' },
|
||||
marker: { color: '#17324d', size: 5 },
|
||||
hovertemplate: '%{text}<extra></extra>',
|
||||
});
|
||||
@@ -189,14 +214,7 @@ export function headMap(sites: Site[]): Figure {
|
||||
showlegend: false,
|
||||
xaxis: { visible: false, range: [-1.25, 1.25], constrain: 'domain' },
|
||||
yaxis: { visible: false, range: [-1.13, 1.18], scaleanchor: 'x', scaleratio: 1 },
|
||||
shapes: [
|
||||
{ type: 'circle', x0: -1, x1: 1, y0: -1, y1: 1, line: { color: '#17324d', width: 2 } },
|
||||
{
|
||||
type: 'path',
|
||||
path: 'M -0.13,0.99 L 0,1.12 L 0.13,0.99',
|
||||
line: { color: '#17324d', width: 2 },
|
||||
},
|
||||
],
|
||||
shapes,
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -232,7 +250,13 @@ export function ageNorm(rows: Centile[], metric: Metric, age: number): Figure {
|
||||
],
|
||||
layout: {
|
||||
xaxis: { title: { text: 'Edad (meses)' } },
|
||||
yaxis: { title: { text: metric.unit ?? 'Valor' } },
|
||||
yaxis: {
|
||||
title: { text: metric.unit ?? 'Valor' },
|
||||
...wholeNumberAxis([
|
||||
metric.value,
|
||||
...rows.flatMap(({ p5, median, p95 }) => [p5, median, p95]),
|
||||
]),
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -307,7 +331,11 @@ export function zBars(eeg: Study): SingleTrace {
|
||||
},
|
||||
],
|
||||
layout: {
|
||||
xaxis: { title: { text: 'Puntuación z' }, range: [-limit, limit] },
|
||||
xaxis: {
|
||||
title: { text: 'Puntuación z' },
|
||||
range: [-limit, limit],
|
||||
...wholeNumberAxis([-limit, limit]),
|
||||
},
|
||||
yaxis: { autorange: 'reversed', automargin: true },
|
||||
shapes: [
|
||||
{
|
||||
@@ -366,7 +394,7 @@ export function probabilityCurve(
|
||||
data,
|
||||
layout: {
|
||||
xaxis: { title: { text: 'Puntuación z' } },
|
||||
yaxis: { title: { text: 'Probabilidad (%)' }, range: [0, 100] },
|
||||
yaxis: { title: { text: 'Probabilidad (%)' }, range: [0, 100], ...wholeNumberAxis([0, 100]) },
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user