diff --git a/app/globals.css b/app/globals.css index ed8e9b48..ae76e551 100644 --- a/app/globals.css +++ b/app/globals.css @@ -1817,6 +1817,8 @@ td.camp-links { flex-direction: column; align-items: flex-start; gap: var(--s1); .tl-fig .tl-drag { position: absolute; top: 0; background: color-mix(in srgb, var(--primary) 15%, transparent); pointer-events: none; } .tl-fig .tl-m { cursor: default; } .tl-fig .tl-h:hover text { fill: var(--accent); } +/* the row under the pointer (PAT-TL-TR-5): the portal's #F2F2F2 band, multiplied over the white figure so the marks stay as drawn */ +.tl-fig .tl-row-hot { position: absolute; left: 0; background: #f2f2f2; mix-blend-mode: multiply; pointer-events: none; } .tl-empty { padding: var(--s3); } .tl-tip { max-width: 340px; } .tl-tip table { border-collapse: collapse; font-size: var(--t-sm); } diff --git a/app/lab/timeline-body.tsx b/app/lab/timeline-body.tsx index 3eca82c9..2181acfc 100644 --- a/app/lab/timeline-body.tsx +++ b/app/lab/timeline-body.tsx @@ -6,7 +6,7 @@ // cohort is the header's picker, as for every view. import React, { useEffect, useLayoutEffect, useMemo, useRef, useState } from "react"; import { DataTable, specQuery } from "../_table/DataTable.tsx"; -import { timelineSvg, timelineSummary, zoomFromDrag } from "../../lib/timeline-svg.ts"; +import { rowAt, timelineSvg, timelineSummary, zoomFromDrag } from "../../lib/timeline-svg.ts"; import { formatDays, sampleMarks, sampleTipRows, attr, SAMPLE_TRACK } from "../../lib/timeline-tracks.ts"; import { canonicalEventName } from "../../lib/event-names.ts"; import type { PatientEvent, TimelineResult } from "../../lib/types"; @@ -37,7 +37,8 @@ export function TimelineBody({ t, spec, vi, updating, docJson, patch, fixed }: { const [width, setWidth] = useState(1000); // the portal's event tooltip (TimelineTrack, TimelineStore): shown on hover, gone 100 ms after the pointer // leaves unless pinned by a click; one event at a time when several share the mark, paged - const [tip, setTip] = useState<{ x: number; y: number; ev: number[]; pinned: boolean; page: number } | null>(null); + // `line`: the mark is a line chart's day, its events simultaneous values of which the highest is plotted + const [tip, setTip] = useState<{ x: number; y: number; ev: number[]; pinned: boolean; page: number; line?: boolean } | null>(null); const linger = useRef | null>(null); const holdTip = () => { if (linger.current) { clearTimeout(linger.current); linger.current = null; } }; const dropTip = () => { holdTip(); linger.current = setTimeout(() => setTip((t) => t && !t.pinned ? null : t), 100); }; @@ -74,6 +75,8 @@ export function TimelineBody({ t, spec, vi, updating, docJson, patch, fixed }: { const [zoom, setZoom] = useState<[number, number] | null>(null); const [drag, setDrag] = useState<{ x0: number; x1: number } | null>(null); const [cursor, setCursor] = useState(null); + // the track row under the pointer, its band drawn #F2F2F2 as the portal highlights a hovered row + const [hotRow, setHotRow] = useState(null); const dragged = useRef(false); useEffect(() => { setZoom(null); setDrag(null); }, [p, spec.expandGaps]); const drawn = useMemo(() => p ? timelineSvg(p, { width, collapsed, expandGaps: !!spec.expandGaps, interactive: true, zoom: zoom ?? undefined }) : null, [p, width, collapsed, spec.expandGaps, zoom]); @@ -106,6 +109,7 @@ export function TimelineBody({ t, spec, vi, updating, docJson, patch, fixed }: { const m = (e.target as Element).closest?.(".tl-m") as SVGGElement | null; return m?.dataset.ev ? m.dataset.ev : null; }; + const onLine = (e: React.MouseEvent) => !!((e.target as Element).closest?.(".tl-m") as SVGGElement | null)?.dataset.line; const onClick = (e: React.MouseEvent) => { // the click that ends a drag to zoom is not a click on what it ends over if (dragged.current) { dragged.current = false; return; } @@ -115,17 +119,19 @@ export function TimelineBody({ t, spec, vi, updating, docJson, patch, fixed }: { const ev = marked(e); if (!ev) return; holdTip(); - setTip((t) => t && t.pinned && t.ev.join(",") === ev ? { ...t, pinned: false } : { x: e.clientX, y: e.clientY, ev: ev.split(",").map(Number), pinned: true, page: t && t.ev.join(",") === ev ? t.page : 0 }); + setTip((t) => t && t.pinned && t.ev.join(",") === ev ? { ...t, pinned: false } : { x: e.clientX, y: e.clientY, ev: ev.split(",").map(Number), pinned: true, page: t && t.ev.join(",") === ev ? t.page : 0, line: onLine(e) }); }; const onMove = (e: React.MouseEvent) => { const at = figX(e); setCursor(at?.inPlot ? at.x : null); + const svg = box.current?.querySelector("svg"); + setHotRow(svg && drawn ? rowAt(drawn.layout, e.clientY - svg.getBoundingClientRect().top) : null); if (drag && at) setDrag({ ...drag, x1: Math.max(drawn!.layout.plot.x, Math.min(drawn!.layout.plot.x + drawn!.layout.plot.width, at.x)) }); if (tip?.pinned) return; const ev = marked(e); if (!ev) { if (tip) dropTip(); return; } holdTip(); - setTip((t) => ({ x: e.clientX, y: e.clientY, ev: ev.split(",").map(Number), pinned: false, page: t && t.ev.join(",") === ev ? t.page : 0 })); + setTip((t) => ({ x: e.clientX, y: e.clientY, ev: ev.split(",").map(Number), pinned: false, page: t && t.ev.join(",") === ev ? t.page : 0, line: onLine(e) })); }; const isSel = (row: { study: string; patient: string }) => p != null && row.study === p.study && row.patient === p.patient; @@ -166,15 +172,17 @@ export function TimelineBody({ t, spec, vi, updating, docJson, patch, fixed }: { ) :

No patient to draw: the cohort's patient list is empty.

} {/* eslint-disable-next-line jsx-a11y-x/click-events-have-key-events, jsx-a11y-x/no-static-element-interactions -- track groups in the drawn SVG expand on click only; there is no keyboard equivalent yet */}
{ setCursor(null); setDrag(null); if (!tip?.pinned) dropTip(); }}> + onMouseLeave={() => { setCursor(null); setHotRow(null); setDrag(null); if (!tip?.pinned) dropTip(); }}> {drawn && (p!.events.length ?
:

{p!.patient} has no timeline events recorded.

)} + {drawn && p!.events.length > 0 && hotRow != null && drawn.layout.rows[hotRow] && +