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
@@ -20,11 +20,11 @@ Every clickable zone element must carry these data attributes:
|
||||
|
||||
| Attribute | Required | Notes |
|
||||
|----------------------|----------|-----------------------------------------------------------------|
|
||||
| `data-bone-id` | yes | Stable kebab-case id, unique within the SVG. |
|
||||
| `data-bone-fr` | yes | French anatomical label (used in tooltips and PDF text). |
|
||||
| `data-bone-en` | yes | English anatomical label (used as fallback and a11y hint). |
|
||||
| `data-category` | yes | One of: `articulation`, `charniere`, `spine-zone`, `os`, `os-overlay`, `head`, `cadran-crane`. |
|
||||
| `data-opens-detail` | no | Id of a detail popup SVG to open when the zone is clicked. The id must match a key in the species manifest's `details` map. |
|
||||
| `data-anno-id` | yes | Stable kebab-case id, unique within the SVG. |
|
||||
| `data-anno-name-fr` | yes | French anatomical label (used in tooltips and PDF text). |
|
||||
| `data-anno-name-en` | yes | English anatomical label (used as fallback and a11y hint). |
|
||||
| `data-anno-category` | yes | One of: `articulation`, `charniere`, `spine-zone`, `os`, `os-overlay`, `head`, `cadran-crane`. |
|
||||
| `data-anno-opens-detail` | no | Id of a detail popup SVG to open when the zone is clicked. The id must match a key in the species manifest's `details` map. |
|
||||
|
||||
Reuse the equine SVG patterns:
|
||||
|
||||
@@ -79,7 +79,7 @@ Required fields (see `src/domain/species/types.ts`):
|
||||
- `labelFr` — French display name shown in the species picker.
|
||||
- `mainSvg` — absolute path to the main anatomy SVG.
|
||||
- `details` — map of detail id → SVG path. Keys must match every distinct
|
||||
`data-opens-detail` attribute used in the main SVG.
|
||||
`data-anno-opens-detail` attribute used in the main SVG.
|
||||
- `vertebralFormula` — segment counts for the VertebraPicker (see step 5).
|
||||
- `pathologies` — lazy import returning `{ default: Pathology[] }` (step 6).
|
||||
|
||||
@@ -182,7 +182,7 @@ Mirror `tests/unit/anatomy.horse.test.ts`. Create
|
||||
`public/species/<id>/` and asserts:
|
||||
|
||||
- `parseSvgBones` does not throw and returns a non-empty map.
|
||||
- Every required `data-category` you used is present at least once
|
||||
- Every required `data-anno-category` you used is present at least once
|
||||
(especially the `spine-zone` count, the `head` zone with `opensDetail`,
|
||||
and any `charniere` hinges).
|
||||
- Detail SVGs (one test per detail id) parse cleanly and contain the
|
||||
|
||||
@@ -10,16 +10,16 @@ Every clickable zone element must carry all four attributes:
|
||||
|
||||
| Attribute | Type | Description |
|
||||
|---|---|---|
|
||||
| `data-bone-id` | `string` | Stable kebab-case identifier. Unique per bone. |
|
||||
| `data-bone-fr` | `string` | French anatomical label (e.g. "Colonne cervicale"). |
|
||||
| `data-bone-en` | `string` | English anatomical label (e.g. "Cervical spine"). |
|
||||
| `data-category` | `BoneCategory` | One of the seven valid categories below. |
|
||||
| `data-anno-id` | `string` | Stable kebab-case identifier. Unique per bone. |
|
||||
| `data-anno-name-fr` | `string` | French anatomical label (e.g. "Colonne cervicale"). |
|
||||
| `data-anno-name-en` | `string` | English anatomical label (e.g. "Cervical spine"). |
|
||||
| `data-anno-category` | `BoneCategory` | One of the seven valid categories below. |
|
||||
|
||||
## Optional data attributes
|
||||
|
||||
| Attribute | Type | Description |
|
||||
|---|---|---|
|
||||
| `data-opens-detail` | `string` | Id of the detail popup SVG to open on click. Key must exist in `SpeciesManifest.details`. |
|
||||
| `data-anno-opens-detail` | `string` | Id of the detail popup SVG to open on click. Key must exist in `SpeciesManifest.details`. |
|
||||
|
||||
---
|
||||
|
||||
@@ -43,15 +43,15 @@ Every clickable zone element must carry all four attributes:
|
||||
|
||||
Used for: `articulation`, `charniere`, `os-overlay`, `head`.
|
||||
|
||||
Two sibling SVG elements share the **same** `data-bone-id`:
|
||||
Two sibling SVG elements share the **same** `data-anno-id`:
|
||||
|
||||
```xml
|
||||
<!-- hitbox: transparent fill, receives pointer events -->
|
||||
<polygon
|
||||
data-bone-id="cervical-spine"
|
||||
data-bone-fr="Colonne cervicale"
|
||||
data-bone-en="Cervical spine"
|
||||
data-category="spine-zone"
|
||||
data-anno-id="cervical-spine"
|
||||
data-anno-name-fr="Colonne cervicale"
|
||||
data-anno-name-en="Cervical spine"
|
||||
data-anno-category="spine-zone"
|
||||
class="bone-hitbox"
|
||||
fill="transparent"
|
||||
style="pointer-events: all; cursor: pointer"
|
||||
@@ -59,7 +59,7 @@ Two sibling SVG elements share the **same** `data-bone-id`:
|
||||
|
||||
<!-- visible twin: colored fill, no pointer events -->
|
||||
<polygon
|
||||
data-bone-id="cervical-spine"
|
||||
data-anno-id="cervical-spine"
|
||||
class="bone-visible"
|
||||
fill="#c8d8e8"
|
||||
style="pointer-events: none"
|
||||
@@ -68,7 +68,7 @@ Two sibling SVG elements share the **same** `data-bone-id`:
|
||||
|
||||
- Hitbox must have `class` containing `hitbox` (case-insensitive substring).
|
||||
- Visible twin must have `class` containing `visible`.
|
||||
- Order in DOM does not matter — parser groups by `data-bone-id`.
|
||||
- Order in DOM does not matter — parser groups by `data-anno-id`.
|
||||
|
||||
### Pattern 2 — Single element
|
||||
|
||||
@@ -78,10 +78,10 @@ One polygon carries everything:
|
||||
|
||||
```xml
|
||||
<polygon
|
||||
data-bone-id="thoracic-t1-t18"
|
||||
data-bone-fr="Thoracique T1-T18"
|
||||
data-bone-en="Thoracic T1-T18"
|
||||
data-category="spine-zone"
|
||||
data-anno-id="thoracic-t1-t18"
|
||||
data-anno-name-fr="Thoracique T1-T18"
|
||||
data-anno-name-en="Thoracic T1-T18"
|
||||
data-anno-category="spine-zone"
|
||||
fill="#d4e8d4"
|
||||
style="pointer-events: all; cursor: pointer"
|
||||
/>
|
||||
@@ -91,8 +91,8 @@ One polygon carries everything:
|
||||
|
||||
## Parser behavior (`src/anatomy/svgConvention.ts`)
|
||||
|
||||
1. `parseSvgBones(svgRoot)` — walks all elements with `data-bone-id`.
|
||||
2. Groups by `data-bone-id` → one `Bone` per id.
|
||||
1. `parseSvgBones(svgRoot)` — walks all elements with `data-anno-id`.
|
||||
2. Groups by `data-anno-id` → one `Bone` per id.
|
||||
3. For each group, validates required attributes.
|
||||
4. Classifies elements into `hitboxEls` (class contains "hitbox") and `visibleEls` (class contains "visible"). Elements in neither class land in `visibleEls` by default.
|
||||
5. Returns `Map<string, Bone>`.
|
||||
@@ -100,10 +100,10 @@ One polygon carries everything:
|
||||
|
||||
### Validated rules
|
||||
|
||||
- `data-bone-fr` must be non-empty.
|
||||
- `data-bone-en` must be non-empty.
|
||||
- `data-category` must be one of the seven valid values.
|
||||
- If `data-opens-detail` is present, the value must be a non-empty string (runtime check against species manifest happens in the canvas component).
|
||||
- `data-anno-name-fr` must be non-empty.
|
||||
- `data-anno-name-en` must be non-empty.
|
||||
- `data-anno-category` must be one of the seven valid values.
|
||||
- If `data-anno-opens-detail` is present, the value must be a non-empty string (runtime check against species manifest happens in the canvas component).
|
||||
|
||||
---
|
||||
|
||||
@@ -112,8 +112,8 @@ One polygon carries everything:
|
||||
A single `click` listener on the root `<svg>` element:
|
||||
|
||||
```
|
||||
event.target → walk up ancestors → find data-bone-id
|
||||
→ if data-opens-detail present → emit requestDetail({id})
|
||||
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
|
||||
```
|
||||
@@ -124,7 +124,7 @@ Never attach per-element click listeners — the SVG may have thousands of eleme
|
||||
|
||||
## Zone visual states
|
||||
|
||||
Applied as `data-state` attribute on all elements sharing a `data-bone-id`:
|
||||
Applied as `data-state` attribute on all elements sharing a `data-anno-id`:
|
||||
|
||||
| `data-state` | Condition | Visual |
|
||||
|---|---|---|
|
||||
@@ -140,7 +140,7 @@ terracotta → sauge → bleu canard → ambre → prune → ocre.
|
||||
|
||||
## Detail popup mechanism
|
||||
|
||||
When a zone has `data-opens-detail="head"`:
|
||||
When a zone has `data-anno-opens-detail="head"`:
|
||||
|
||||
1. Canvas emits `requestDetail({ id: 'head' })`.
|
||||
2. `DetailModal` resolves the path via `SpeciesManifest.details['head']`.
|
||||
@@ -152,7 +152,7 @@ When a zone has `data-opens-detail="head"`:
|
||||
|
||||
## Vertebra picker trigger
|
||||
|
||||
When a bone has `data-category="spine-zone"`, clicking it opens `VertebraPicker`:
|
||||
When a bone has `data-anno-category="spine-zone"`, clicking it 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.
|
||||
|
||||
@@ -34,7 +34,7 @@ Allowed scopes: `schema`, `store`, `anatomy`, `pdf`, `editor`, `home`, `new`, `u
|
||||
Examples:
|
||||
- `test(schema): cover Report version literal`
|
||||
- `feat(store): implement addObservation`
|
||||
- `feat(anatomy): parse data-bone-id from SVG`
|
||||
- `feat(anatomy): parse data-anno-id from SVG`
|
||||
```
|
||||
|
||||
- [ ] **Step 2:** Commit
|
||||
@@ -453,19 +453,19 @@ function svgFromString(s: string): SVGSVGElement {
|
||||
|
||||
const FIXTURE = `
|
||||
<svg xmlns="http://www.w3.org/2000/svg">
|
||||
<circle data-bone-id="epaule" data-bone-fr="Épaule" data-bone-en="Shoulder"
|
||||
data-category="articulation" class="bone osteo articulation hitbox bone-epaule" />
|
||||
<circle data-bone-id="epaule" data-bone-fr="Épaule" data-bone-en="Shoulder"
|
||||
data-category="articulation" class="bone osteo articulation visible bone-epaule" />
|
||||
<polygon data-bone-id="cervical-vertebrae-spine-zone" data-bone-fr="Vertèbres cervicales"
|
||||
data-bone-en="Cervical Vertebrae" data-category="spine-zone"
|
||||
<circle data-anno-id="epaule" data-anno-name-fr="Épaule" data-anno-name-en="Shoulder"
|
||||
data-anno-category="articulation" class="bone osteo articulation hitbox bone-epaule" />
|
||||
<circle data-anno-id="epaule" data-anno-name-fr="Épaule" data-anno-name-en="Shoulder"
|
||||
data-anno-category="articulation" class="bone osteo articulation visible bone-epaule" />
|
||||
<polygon data-anno-id="cervical-vertebrae-spine-zone" data-anno-name-fr="Vertèbres cervicales"
|
||||
data-anno-name-en="Cervical Vertebrae" data-anno-category="spine-zone"
|
||||
class="bone osteo spine-zone bone-cervical-vertebrae" />
|
||||
<polygon data-bone-id="zone-head" data-bone-fr="Crane" data-bone-en="Head"
|
||||
data-category="head" data-opens-detail="head" />
|
||||
<polygon data-anno-id="zone-head" data-anno-name-fr="Crane" data-anno-name-en="Head"
|
||||
data-anno-category="head" data-anno-opens-detail="head" />
|
||||
</svg>`
|
||||
|
||||
describe('parseSvgBones', () => {
|
||||
it('groups hitbox + visible by data-bone-id', () => {
|
||||
it('groups hitbox + visible by data-anno-id', () => {
|
||||
const map = parseSvgBones(svgFromString(FIXTURE))
|
||||
const epaule = map.get('epaule')
|
||||
expect(epaule).toBeDefined()
|
||||
@@ -488,16 +488,16 @@ describe('parseSvgBones', () => {
|
||||
})
|
||||
|
||||
describe('parseSvgBones validation', () => {
|
||||
it('throws on missing data-bone-fr', () => {
|
||||
it('throws on missing data-anno-name-fr', () => {
|
||||
const bad = `<svg xmlns="http://www.w3.org/2000/svg">
|
||||
<circle data-bone-id="x" data-bone-en="X" data-category="os" />
|
||||
<circle data-anno-id="x" data-anno-name-en="X" data-anno-category="os" />
|
||||
</svg>`
|
||||
expect(() => parseSvgBones(svgFromString(bad))).toThrow(SvgConventionError)
|
||||
})
|
||||
|
||||
it('throws on unknown category', () => {
|
||||
const bad = `<svg xmlns="http://www.w3.org/2000/svg">
|
||||
<circle data-bone-id="x" data-bone-fr="X" data-bone-en="X" data-category="bogus" />
|
||||
<circle data-anno-id="x" data-anno-name-fr="X" data-anno-name-en="X" data-anno-category="bogus" />
|
||||
</svg>`
|
||||
expect(() => parseSvgBones(svgFromString(bad))).toThrow(SvgConventionError)
|
||||
})
|
||||
@@ -554,36 +554,36 @@ function classList(el: Element): string[] {
|
||||
}
|
||||
|
||||
export function validateBoneElement(el: Element): void {
|
||||
const boneId = el.getAttribute('data-bone-id') ?? ''
|
||||
for (const attr of ['data-bone-fr', 'data-bone-en', 'data-category']) {
|
||||
const boneId = el.getAttribute('data-anno-id') ?? ''
|
||||
for (const attr of ['data-anno-name-fr', 'data-anno-name-en', 'data-anno-category']) {
|
||||
if (!el.getAttribute(attr)) {
|
||||
throw new SvgConventionError(
|
||||
`Element data-bone-id="${boneId}" missing attribute ${attr}`,
|
||||
`Element data-anno-id="${boneId}" missing attribute ${attr}`,
|
||||
boneId,
|
||||
attr,
|
||||
)
|
||||
}
|
||||
}
|
||||
const cat = el.getAttribute('data-category') ?? ''
|
||||
const cat = el.getAttribute('data-anno-category') ?? ''
|
||||
if (!isValidCategory(cat)) {
|
||||
throw new SvgConventionError(
|
||||
`Element data-bone-id="${boneId}" has unknown data-category="${cat}"`,
|
||||
`Element data-anno-id="${boneId}" has unknown data-anno-category="${cat}"`,
|
||||
boneId,
|
||||
'data-category',
|
||||
'data-anno-category',
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export function parseSvgBones(svgRoot: SVGSVGElement): Map<string, Bone> {
|
||||
const map = new Map<string, Bone>()
|
||||
const all = svgRoot.querySelectorAll<Element>('[data-bone-id]')
|
||||
const all = svgRoot.querySelectorAll<Element>('[data-anno-id]')
|
||||
all.forEach((el) => {
|
||||
validateBoneElement(el)
|
||||
const id = el.getAttribute('data-bone-id') as string
|
||||
const fr = el.getAttribute('data-bone-fr') as string
|
||||
const en = el.getAttribute('data-bone-en') as string
|
||||
const category = el.getAttribute('data-category') as BoneCategory
|
||||
const opensDetail = el.getAttribute('data-opens-detail') ?? undefined
|
||||
const id = el.getAttribute('data-anno-id') as string
|
||||
const fr = el.getAttribute('data-anno-name-fr') as string
|
||||
const en = el.getAttribute('data-anno-name-en') as string
|
||||
const category = el.getAttribute('data-anno-category') as BoneCategory
|
||||
const opensDetail = el.getAttribute('data-anno-opens-detail') ?? undefined
|
||||
const classes = classList(el)
|
||||
const isHitbox = classes.includes('hitbox')
|
||||
|
||||
@@ -610,7 +610,7 @@ export function parseSvgBones(svgRoot: SVGSVGElement): Map<string, Bone> {
|
||||
export function getBoneIdFromEvent(event: Event): string | null {
|
||||
let node = event.target as Element | null
|
||||
while (node && node.nodeType === 1) {
|
||||
const id = node.getAttribute?.('data-bone-id')
|
||||
const id = node.getAttribute?.('data-anno-id')
|
||||
if (id) return id
|
||||
node = node.parentElement
|
||||
}
|
||||
@@ -710,7 +710,7 @@ git commit -m "test(anatomy): cover real Horse.svg + Horse_head.svg parsing"
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||
import { loadSvg } from '@/anatomy/svgLoader'
|
||||
|
||||
const SVG = '<svg xmlns="http://www.w3.org/2000/svg"><g data-bone-id="x"/></svg>'
|
||||
const SVG = '<svg xmlns="http://www.w3.org/2000/svg"><g data-anno-id="x"/></svg>'
|
||||
|
||||
describe('loadSvg', () => {
|
||||
beforeEach(() => {
|
||||
@@ -1682,8 +1682,8 @@ body {
|
||||
.svg-canvas [data-state='current'] { fill: var(--color-accent) !important; fill-opacity: 0.85 !important; }
|
||||
.svg-canvas [data-state='linked'] { stroke-dasharray: 4 3; stroke: var(--color-accent); fill-opacity: 0.35 !important; }
|
||||
.svg-canvas [data-state='multi'] { fill: var(--color-accent) !important; fill-opacity: 0.65 !important; stroke: var(--color-ink); stroke-width: 1.5; }
|
||||
.svg-canvas [data-bone-id] { cursor: pointer; }
|
||||
.svg-canvas [data-bone-id]:hover { filter: brightness(1.05); }
|
||||
.svg-canvas [data-anno-id] { cursor: pointer; }
|
||||
.svg-canvas [data-anno-id]:hover { filter: brightness(1.05); }
|
||||
```
|
||||
|
||||
- [ ] **Step 3:** Verify build
|
||||
@@ -1771,10 +1771,10 @@ vi.mock('@/anatomy/svgLoader', () => ({
|
||||
loadSvg: vi.fn(async () => {
|
||||
const doc = new DOMParser().parseFromString(
|
||||
`<svg xmlns="http://www.w3.org/2000/svg">
|
||||
<circle data-bone-id="epaule" data-bone-fr="Épaule" data-bone-en="Shoulder"
|
||||
data-category="articulation" class="bone osteo articulation hitbox bone-epaule" />
|
||||
<circle data-bone-id="epaule" data-bone-fr="Épaule" data-bone-en="Shoulder"
|
||||
data-category="articulation" class="bone osteo articulation visible bone-epaule" />
|
||||
<circle data-anno-id="epaule" data-anno-name-fr="Épaule" data-anno-name-en="Shoulder"
|
||||
data-anno-category="articulation" class="bone osteo articulation hitbox bone-epaule" />
|
||||
<circle data-anno-id="epaule" data-anno-name-fr="Épaule" data-anno-name-en="Shoulder"
|
||||
data-anno-category="articulation" class="bone osteo articulation visible bone-epaule" />
|
||||
</svg>`,
|
||||
'image/svg+xml',
|
||||
)
|
||||
@@ -1788,7 +1788,7 @@ describe('AnatomyCanvas', () => {
|
||||
it('renders the loaded SVG inline', async () => {
|
||||
render(<AnatomyCanvas src="/x.svg" boneStates={new Map()} onZoneClick={() => {}} />)
|
||||
await waitFor(() =>
|
||||
expect(document.querySelector('[data-bone-id="epaule"]')).not.toBeNull(),
|
||||
expect(document.querySelector('[data-anno-id="epaule"]')).not.toBeNull(),
|
||||
)
|
||||
})
|
||||
|
||||
@@ -1796,7 +1796,7 @@ describe('AnatomyCanvas', () => {
|
||||
const onZoneClick = vi.fn()
|
||||
render(<AnatomyCanvas src="/x.svg" boneStates={new Map()} onZoneClick={onZoneClick} />)
|
||||
await waitFor(() => screen.getByTestId('anatomy-canvas'))
|
||||
;(document.querySelector('[data-bone-id="epaule"]') as Element).dispatchEvent(
|
||||
;(document.querySelector('[data-anno-id="epaule"]') as Element).dispatchEvent(
|
||||
new Event('click', { bubbles: true }),
|
||||
)
|
||||
await waitFor(() => expect(onZoneClick).toHaveBeenCalledWith('epaule'))
|
||||
@@ -1854,9 +1854,9 @@ export default function AnatomyCanvas({
|
||||
useEffect(() => {
|
||||
const c = containerRef.current
|
||||
if (!c) return
|
||||
const all = c.querySelectorAll<Element>('[data-bone-id]')
|
||||
const all = c.querySelectorAll<Element>('[data-anno-id]')
|
||||
all.forEach((el) => {
|
||||
const id = el.getAttribute('data-bone-id') as string
|
||||
const id = el.getAttribute('data-anno-id') as string
|
||||
const state = boneStates.get(id)
|
||||
if (state && state !== 'default') el.setAttribute('data-state', state)
|
||||
else el.removeAttribute('data-state')
|
||||
@@ -4224,7 +4224,7 @@ git commit -m "test(qa): document MVP manual QA checklist outcome"
|
||||
- Modify: `docs/ADDING-A-SPECIES.md`
|
||||
|
||||
- [ ] **Step 1:** Rewrite from the placeholder, covering:
|
||||
1. SVG convention (refer to `docs/ANATOMY-SVG-CONVENTION.md`): `data-bone-id`, `data-bone-fr`, `data-bone-en`, `data-category`, optional `data-opens-detail`.
|
||||
1. SVG convention (refer to `docs/ANATOMY-SVG-CONVENTION.md`): `data-anno-id`, `data-anno-name-fr`, `data-anno-name-en`, `data-anno-category`, optional `data-anno-opens-detail`.
|
||||
2. Where to drop the SVG: `public/species/<id>/<Main>.svg` + any detail SVGs.
|
||||
3. Create the species manifest at `src/domain/species/<id>/index.ts` with `id`, `labelFr`, `mainSvg`, `details`, `vertebralFormula`, and a `pathologies` lazy import.
|
||||
4. Wire the manifest into `src/domain/species/registry.ts`.
|
||||
|
||||
@@ -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