From b9da4fa04a2ca1fa2b7a327d57e7e46e0f27b02c Mon Sep 17 00:00:00 2001 From: Bastien Chanot Date: Tue, 19 May 2026 04:58:04 +0200 Subject: [PATCH] fix(anatomy,editor): detail-popup clicks + spine zones open VertebraPicker via data-anno-special MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Three coupled bugs in zone interaction: 1. Clicks inside the head detail popup were ignored — EditorRoute looked up the clicked id in the main-SVG bones map only, so detail-only ids (point-mpbykomv et al.) returned undefined. 2. Spine zones did not open VertebraPicker on click; the picker was only reachable via the per-zone "Vertèbres…" button. 3. The new SVG hint data-anno-special="vertebral-precision" was present in Horse.svg but unread by the parser/UI. Parser now reads data-anno-special into Bone.special. EditorRoute parses the detail SVG on open and falls back to detailBones for id lookups. When bone.special === 'vertebral-precision', clicking adds the zone (if absent) and opens VertebraPicker for that zone index; toggle-off via main click is disabled for these zones (use ✕). The "Vertèbres…" button in ObservationCard is now shown only on zones that support it. Convention doc updated. Co-Authored-By: Claude --- docs/ANATOMY-SVG-CONVENTION.md | 12 +++-- public/species/equine/Horse.svg | 2 +- src/anatomy/svgConvention.ts | 5 ++ src/anatomy/types.ts | 9 ++++ src/app/routes/EditorRoute.tsx | 51 +++++++++++++++---- .../observation/ObservationCard.tsx | 20 +++++--- tests/unit/anatomy.svgConvention.test.ts | 9 +++- 7 files changed, 86 insertions(+), 22 deletions(-) diff --git a/docs/ANATOMY-SVG-CONVENTION.md b/docs/ANATOMY-SVG-CONVENTION.md index 7f7626a5..cdaf5290 100644 --- a/docs/ANATOMY-SVG-CONVENTION.md +++ b/docs/ANATOMY-SVG-CONVENTION.md @@ -20,6 +20,7 @@ Every clickable zone element must carry all four attributes: | Attribute | Type | Description | |---|---|---| | `data-anno-opens-detail` | `string` | Id of the detail popup SVG to open on click. Key must exist in `SpeciesManifest.details`. | +| `data-anno-special` | `string` | Free-form behavior hint consumed by the app. Known value: `vertebral-precision` → clicking the zone opens VertebraPicker. Opaque to the parser; new values can be added without code changes (just unused). | --- @@ -114,12 +115,16 @@ A single `click` listener on the root `` element: ``` event.target → walk up ancestors → find data-anno-id → if data-anno-opens-detail present → emit requestDetail({id}) - → else if category === 'spine-zone' → open VertebraPicker - → else → add bone to current observation + → else if data-anno-special === 'vertebral-precision' → + add zone to current observation (if absent) and open VertebraPicker + → else → toggle bone in current observation ``` Never attach per-element click listeners — the SVG may have thousands of elements. +Note: `data-anno-category` is opaque to click handling — branching is +driven by `data-anno-opens-detail` and `data-anno-special` only. + --- ## Zone visual states @@ -152,7 +157,8 @@ When a zone has `data-anno-opens-detail="head"`: ## Vertebra picker trigger -When a bone has `data-anno-category="spine-zone"`, clicking it opens `VertebraPicker`: +When a bone has `data-anno-special="vertebral-precision"`, clicking it adds the +zone to the active observation (if absent) and opens `VertebraPicker`: - Region tabs: Cervicales (C1–C7), Thoraciques (T1–T18), Lombaires (L1–L6), Sacrales (S1–S5), Caudales (Cd1–Cd18). - Multi-select chip grid, ≥40 px touch targets. diff --git a/public/species/equine/Horse.svg b/public/species/equine/Horse.svg index 71f75272..d8a7dc39 100644 --- a/public/species/equine/Horse.svg +++ b/public/species/equine/Horse.svg @@ -701,4 +701,4 @@ -Boulet post. (métatarso-phalangien) / Hind fetlockBoulet post. (métatarso-phalangien) / Hind fetlockJarret (tarsien) / HockJarret (tarsien) / HockGrasset (fémoro-tibial) / StifleGrasset (fémoro-tibial) / StifleHanche (coxo-fémorale) / Hip jointHanche (coxo-fémorale) / Hip jointArticulation Sacro-Iliaque / Sacroiliac JointArticulation Sacro-Iliaque / Sacroiliac JointÉpaule (scapulo-humérale) / Shoulder jointÉpaule (scapulo-humérale) / Shoulder jointCoude (huméro-radial) / Elbow jointCoude (huméro-radial) / Elbow jointBoulet ant. (métacarpo-phalangien) / Fore fetlockBoulet ant. (métacarpo-phalangien) / Fore fetlockSésamoïdes ant. (boulet) / Forelimb SesamoidsSésamoïdes ant. (boulet) / Forelimb SesamoidsCharnière L6-S1 (lombo-sacrée) / L6-S1 (Lumbosacral)Charnière L6-S1 (lombo-sacrée) / L6-S1 (Lumbosacral)Charnière T18-L1 (dorso-lombaire) / T18-L1 (Thoracolumbar)Charnière T18-L1 (dorso-lombaire) / T18-L1 (Thoracolumbar)Charnière C7-T1 (cervico-thoracique) / C7-T1 (Cervicothoracic)Charnière C7-T1 (cervico-thoracique) / C7-T1 (Cervicothoracic)Vertèbres caudales / Coccygeal VertebraeVertèbres sacrales / Sacral VertebraeVertèbres lombaires / Lumbar VertebraeVertèbres thoraciques / Thoracic VertebraeVertèbres cervicales / Cervical Vertebrae🔍 Zoom: head \ No newline at end of file +Boulet post. (métatarso-phalangien) / Hind fetlockBoulet post. (métatarso-phalangien) / Hind fetlockJarret (tarsien) / HockJarret (tarsien) / HockGrasset (fémoro-tibial) / StifleGrasset (fémoro-tibial) / StifleHanche (coxo-fémorale) / Hip jointHanche (coxo-fémorale) / Hip jointArticulation Sacro-Iliaque / Sacroiliac JointArticulation Sacro-Iliaque / Sacroiliac JointÉpaule (scapulo-humérale) / Shoulder jointÉpaule (scapulo-humérale) / Shoulder jointCoude (huméro-radial) / Elbow jointCoude (huméro-radial) / Elbow jointBoulet ant. (métacarpo-phalangien) / Fore fetlockBoulet ant. (métacarpo-phalangien) / Fore fetlockSésamoïdes ant. (boulet) / Forelimb SesamoidsSésamoïdes ant. (boulet) / Forelimb SesamoidsCharnière L6-S1 (lombo-sacrée) / L6-S1 (Lumbosacral)Charnière L6-S1 (lombo-sacrée) / L6-S1 (Lumbosacral)Charnière T18-L1 (dorso-lombaire) / T18-L1 (Thoracolumbar)Charnière T18-L1 (dorso-lombaire) / T18-L1 (Thoracolumbar)Charnière C7-T1 (cervico-thoracique) / C7-T1 (Cervicothoracic)Charnière C7-T1 (cervico-thoracique) / C7-T1 (Cervicothoracic)Vertèbres caudales / Coccygeal VertebraeVertèbres sacrales / Sacral VertebraeVertèbres lombaires / Lumbar VertebraeVertèbres thoraciques / Thoracic VertebraeVertèbres cervicales / Cervical Vertebrae🔍 Zoom: head \ No newline at end of file diff --git a/src/anatomy/svgConvention.ts b/src/anatomy/svgConvention.ts index 53bbcce7..df45d23a 100644 --- a/src/anatomy/svgConvention.ts +++ b/src/anatomy/svgConvention.ts @@ -52,6 +52,7 @@ export function parseSvgBones(svgRoot: SVGSVGElement): Map { const category = el.getAttribute('data-anno-category') as BoneCategory const opensDetail = el.getAttribute('data-anno-opens-detail') ?? undefined + const special = el.getAttribute('data-anno-special') ?? undefined const existing = map.get(id) if (existing) { @@ -59,6 +60,9 @@ export function parseSvgBones(svgRoot: SVGSVGElement): Map { if (opensDetail && !existing.opensDetail) { existing.opensDetail = opensDetail } + if (special && !existing.special) { + existing.special = special + } if (!existing.fr && fr) existing.fr = fr if (!existing.en && en) existing.en = en } else { @@ -68,6 +72,7 @@ export function parseSvgBones(svgRoot: SVGSVGElement): Map { en, category, opensDetail, + special, els: [el], }) } diff --git a/src/anatomy/types.ts b/src/anatomy/types.ts index c1257939..acb4b7a2 100644 --- a/src/anatomy/types.ts +++ b/src/anatomy/types.ts @@ -24,6 +24,15 @@ export interface Bone { category: BoneCategory /** Detail popup id from data-anno-opens-detail, if present */ opensDetail?: string + /** + * Free-form behavior hint from `data-anno-special`. + * + * Known values consumed by the application: + * - `vertebral-precision`: clicking the zone opens VertebraPicker. + * + * Opaque to the parser; new values are accepted without code changes. + */ + special?: string /** All DOM elements carrying this annotation (used for colorization) */ els: Element[] } diff --git a/src/app/routes/EditorRoute.tsx b/src/app/routes/EditorRoute.tsx index 271f74f4..413e1de4 100644 --- a/src/app/routes/EditorRoute.tsx +++ b/src/app/routes/EditorRoute.tsx @@ -31,6 +31,7 @@ export default function EditorRoute() { const setNextAppointment = useReportStore((s) => s.setNextAppointment) const [bones, setBones] = useState>(new Map()) + const [detailBones, setDetailBones] = useState>(new Map()) const [pathologies, setPathologies] = useState([]) const [detail, setDetail] = useState<{ id: string @@ -55,6 +56,21 @@ export default function EditorRoute() { species.pathologies().then((m) => setPathologies(m.default)) }, [species]) + useEffect(() => { + if (!detail) { + setDetailBones(new Map()) + return + } + let cancelled = false + loadSvg(detail.src).then((root) => { + if (cancelled) return + setDetailBones(parseSvgBones(root)) + }) + return () => { + cancelled = true + } + }, [detail]) + const activeObs = activeIndex >= 0 ? report?.observations[activeIndex] : undefined @@ -82,7 +98,7 @@ export default function EditorRoute() { function onZoneClick(boneId: string, detailSourceId?: string) { if (!report) return - const bone = bones.get(boneId) + const bone = bones.get(boneId) ?? detailBones.get(boneId) if (!bone) return if (bone.opensDetail && species?.details[bone.opensDetail]) { @@ -105,18 +121,35 @@ export default function EditorRoute() { return } + const matches = (z: ObservationZone) => + z.boneId === boneId && z.detailSourceId === detailSourceId + const existingIndex = activeObs.zones.findIndex(matches) + + if (bone.special === 'vertebral-precision') { + // Spine-zone behavior: always open VertebraPicker on click. Add the + // zone if missing; never toggle it off here (use the ✕ button). + let targetIndex = existingIndex + if (existingIndex < 0) { + const newZone: ObservationZone = { + boneId, + ...(detailSourceId ? { detailSourceId } : {}), + } + const nextZones = [...activeObs.zones, newZone] + targetIndex = nextZones.length - 1 + updateObservation(activeIndex, { ...activeObs, zones: nextZones }) + } + setVertebraTarget(targetIndex) + return + } + const newZone: ObservationZone = { boneId, ...(detailSourceId ? { detailSourceId } : {}), } - const exists = activeObs.zones.some( - (z) => z.boneId === boneId && z.detailSourceId === detailSourceId, - ) - const nextZones = exists - ? activeObs.zones.filter( - (z) => !(z.boneId === boneId && z.detailSourceId === detailSourceId), - ) - : [...activeObs.zones, newZone] + const nextZones = + existingIndex >= 0 + ? activeObs.zones.filter((_, k) => k !== existingIndex) + : [...activeObs.zones, newZone] updateObservation(activeIndex, { ...activeObs, zones: nextZones }) } diff --git a/src/components/observation/ObservationCard.tsx b/src/components/observation/ObservationCard.tsx index 20b05c0d..a17b3044 100644 --- a/src/components/observation/ObservationCard.tsx +++ b/src/components/observation/ObservationCard.tsx @@ -187,18 +187,22 @@ export default function ObservationCard({
    {observation.zones.map((z, i) => { const b = bones.get(z.boneId) + const supportsVertebrae = + b?.special === 'vertebral-precision' return (
  • {describeZone(z, bones)} - + {supportsVertebrae && ( + + )}