refactor(anatomy): rename SVG data attrs (bone → anno) per new convention
User updated the clickable-zone convention in the source SVGs:
data-bone-id → data-anno-id
data-bone-fr → data-anno-name-fr
data-bone-en → data-anno-name-en
data-category → data-anno-category
data-opens-detail → data-anno-opens-detail
Bulk-renamed across:
- public/species/equine/Horse.svg + Horse_head.svg (86 anno-attrs each)
- src/anatomy/svgConvention.ts (parser + getBoneIdFromEvent)
- src/anatomy/types.ts (doc strings)
- src/components/canvas/AnatomyCanvas.tsx (querySelector + delegated click)
- src/styles/index.css (`[data-bone-id]` selectors → `[data-anno-id]`)
- src/domain/species/types.ts + schema/observation.ts (doc strings)
- docs/{ANATOMY-SVG-CONVENTION,ADDING-A-SPECIES,superpowers/specs,plans}.md
- CLAUDE.md + .claude/{memory/learnings,tasks/TODO}.md
- tests/unit/{anatomy.svgConvention,anatomy.svgLoader,components.AnatomyCanvas}.test.tsx
Internal TS type names and field names (Bone, boneId, parseSvgBones,
getBoneIdFromEvent) are kept intentionally — they're the application's
logical shape and the persisted JSON contract. ObservationZone.boneId is
the identifier seen in already-exported PDFs; renaming it would break
re-import of those PDFs. Only the SVG-side attribute names change.
90/90 tests pass, lint clean, build clean.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
e8c29c1fdf
commit
1109e33383
18 files changed
+308
-308
No files matched your search
@@ -84,7 +84,7 @@ type Severity = 'légère' | 'modérée' | 'sévère';
|
||||
type Vertebra = { region: 'C' | 'T' | 'L' | 'S' | 'Cd'; index: number };
|
||||
|
||||
type ObservationZone = {
|
||||
boneId: string; // matches data-bone-id from SVG
|
||||
boneId: string; // matches data-anno-id from SVG
|
||||
detailSourceId?: string; // when this zone came from a detail pop-up SVG
|
||||
vertebrae?: Vertebra[]; // when boneId is a spine-zone
|
||||
};
|
||||
@@ -139,9 +139,9 @@ All JSON carries `version: 1`. Future migrations bump the version.
|
||||
|
||||
## SVG convention (source of truth)
|
||||
|
||||
A clickable zone is any element carrying `data-bone-id`. Required data
|
||||
attributes: `data-bone-id`, `data-bone-fr`, `data-bone-en`, `data-category`.
|
||||
Optional: `data-opens-detail="<id>"`.
|
||||
A clickable zone is any element carrying `data-anno-id`. Required data
|
||||
attributes: `data-anno-id`, `data-anno-name-fr`, `data-anno-name-en`, `data-anno-category`.
|
||||
Optional: `data-anno-opens-detail="<id>"`.
|
||||
|
||||
Categories: `articulation` · `charniere` · `spine-zone` · `os` · `os-overlay`
|
||||
· `head` · `cadran-crane`.
|
||||
@@ -149,29 +149,29 @@ Categories: `articulation` · `charniere` · `spine-zone` · `os` · `os-overlay
|
||||
Two rendering patterns are tolerated in the SVG:
|
||||
|
||||
1. **hitbox + visible twin** (articulation, charniere, os-overlay, head):
|
||||
two elements share the same `data-bone-id`. One has `class*="hitbox"`,
|
||||
two elements share the same `data-anno-id`. One has `class*="hitbox"`,
|
||||
transparent fill, `pointer-events: all`. The other has `class*="visible"`,
|
||||
colored fill, `pointer-events: none`.
|
||||
2. **single element** (spine-zone, head zone): one polygon carries everything;
|
||||
`pointer-events: all` and `cursor: pointer` directly.
|
||||
|
||||
Parser strategy (`src/anatomy/svgConvention.ts`):
|
||||
- Walk all elements with `data-bone-id`.
|
||||
- Group by `data-bone-id` → one logical `Bone`.
|
||||
- Walk all elements with `data-anno-id`.
|
||||
- Group by `data-anno-id` → one logical `Bone`.
|
||||
- Bone fields: `id`, `fr`, `en`, `category`, `opensDetail?`, `hitboxEls[]`,
|
||||
`visibleEls[]`.
|
||||
- Validate: must have `data-bone-fr`, `data-bone-en`, `data-category` (in
|
||||
- Validate: must have `data-anno-name-fr`, `data-anno-name-en`, `data-anno-category` (in
|
||||
the allowed enum). Throws structured `SvgConventionError` on missing
|
||||
attributes.
|
||||
|
||||
Click handling: a single delegated listener on the root `<svg>` walks up
|
||||
from `event.target` to the nearest element with `data-bone-id`. If
|
||||
`data-opens-detail` is present → open the detail modal mapped via the
|
||||
from `event.target` to the nearest element with `data-anno-id`. If
|
||||
`data-anno-opens-detail` is present → open the detail modal mapped via the
|
||||
species manifest. If the bone's category is `spine-zone` → open the
|
||||
vertebra picker. Otherwise add the bone to the current observation.
|
||||
|
||||
Colorization: when the current observation contains a bone, all elements
|
||||
matching that `data-bone-id` get a `data-state` attribute toggled by JS:
|
||||
matching that `data-anno-id` get a `data-state` attribute toggled by JS:
|
||||
`current` (solid accent), `linked` (faded dashed border, "in another
|
||||
observation"), `multi` (striped pattern, "in ≥2 observations").
|
||||
|
||||
@@ -193,7 +193,7 @@ export const equine = {
|
||||
};
|
||||
```
|
||||
|
||||
When a zone with `data-opens-detail="head"` is clicked, the canvas
|
||||
When a zone with `data-anno-opens-detail="head"` is clicked, the canvas
|
||||
emits a `requestDetail({id: 'head'})` event handled by `DetailModal`, which
|
||||
loads `/species/equine/Horse_head.svg` and renders it inline. Clicks inside
|
||||
the modal add zones with `detailSourceId: 'head'` to the current
|
||||
@@ -202,7 +202,7 @@ persisted in the report.
|
||||
|
||||
## Vertebra picker
|
||||
|
||||
Triggered when a clicked bone has `data-category="spine-zone"`. Modal with
|
||||
Triggered when a clicked bone has `data-anno-category="spine-zone"`. Modal with
|
||||
region tabs (Cervicales C1–C7, Thoraciques T1–T18, Lombaires L1–L6,
|
||||
Sacrales S1–S5, Caudales Cd1–Cd18). Each region renders chips in a grid;
|
||||
multi-select; ≥40 px touch targets; per-region "Tout cocher / décocher".
|
||||
@@ -341,7 +341,7 @@ port.
|
||||
| SVG injection | Fetch text → DOMParser → inline render (consistent + CSS-controllable + sandboxing irrelevant since assets are local). |
|
||||
| Vertebra picker UX | Region tabs + chip grid, multi-select, ≥40 px touch targets. |
|
||||
| Multi-obs zone overlay | current / linked / multi states; striped pattern + tooltip. |
|
||||
| Detail SVG trigger | `data-opens-detail` → modal with inline detail SVG, clicks add to current obs. |
|
||||
| Detail SVG trigger | `data-anno-opens-detail` → modal with inline detail SVG, clicks add to current obs. |
|
||||
| SVG → PDF | canvg → canvas @ 2× → PNG → `embedPng`. |
|
||||
| Pathology sources in PDF | Abbreviated citation list below each obs, no raw URLs. |
|
||||
| Brand env vars | Runtime `window.__APP_CONFIG__` + Vite-define fallback. |
|
||||
|
||||
Reference in new issue
Block a user