refactor(anatomy): adapt parser to new SVG convention (categories + single-element)
User dropped new Horse.svg / Horse_head.svg that follow a simpler
convention:
- Categories renamed to longer human strings:
articulation → articulations
charniere → charni-res-vert-brales
spine-zone → zone-colonne
cadran-crane → cadrans-du-cr-ne
head, os-overlay → dropped (head zone is now category="os" + data-anno-opens-detail)
os → unchanged
- No more hitbox / visible class split; multiple elements may still share
the same data-anno-id but they all carry the same role.
- Trigger-only zones (`data-anno-opens-detail="head"`) may omit
`data-anno-name-fr/en`.
Changes:
- `Bone` now exposes a single `els: Element[]` instead of `hitboxEls +
visibleEls`.
- `parseSvgBones` accepts annotations without fr/en labels (defaults to
empty string) but still rejects unknown or missing categories.
- The "interactive vs decorative" filter is gone — every parsed
annotation is interactive, since the new SVGs only annotate the
clickable zones.
- Vertebra-picker trigger: `bone.category === 'zone-colonne'`
(EditorRoute + ObservationCard).
- PDF colorisation in `observationPage.colorizedSvgString` writes the
accent fill to every `els[]` entry (no more hitbox dual-pass).
- Dead `src/components/observation/ObservationEditor.tsx` removed (its
body lives inside ObservationCard since the accordion refactor).
- Tests rewritten for the new vocabulary; synthetic fixture uses the new
categories, real-SVG test asserts 18 + 9 unique zones.
92/92 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
1109e33383
commit
cad94a49db
10 files changed
+325
-428
No files matched your search
@@ -13,26 +13,24 @@ function svgFromString(s: string): SVGSVGElement {
|
||||
|
||||
const FIXTURE = `
|
||||
<svg xmlns="http://www.w3.org/2000/svg">
|
||||
<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-anno-id="zone-head" data-anno-name-fr="Crane" data-anno-name-en="Head"
|
||||
data-anno-category="head" data-anno-opens-detail="head" />
|
||||
<circle data-anno-id="point-shoulder" data-anno-name-fr="Épaule" data-anno-name-en="Shoulder"
|
||||
data-anno-category="articulations" />
|
||||
<circle data-anno-id="point-shoulder" data-anno-name-fr="Épaule" data-anno-name-en="Shoulder"
|
||||
data-anno-category="articulations" />
|
||||
<polygon data-anno-id="zone-cervical" data-anno-name-fr="Vertèbres cervicales"
|
||||
data-anno-name-en="Cervical Vertebrae" data-anno-category="zone-colonne" />
|
||||
<polygon data-anno-id="zone-head" data-anno-category="os" data-anno-opens-detail="head" />
|
||||
</svg>`
|
||||
|
||||
describe('parseSvgBones', () => {
|
||||
it('groups hitbox + visible by data-anno-id', () => {
|
||||
it('groups multiple elements sharing the same data-anno-id', () => {
|
||||
const map = parseSvgBones(svgFromString(FIXTURE))
|
||||
const epaule = map.get('epaule')
|
||||
expect(epaule).toBeDefined()
|
||||
expect(epaule?.fr).toBe('Épaule')
|
||||
expect(epaule?.category).toBe('articulation')
|
||||
expect(epaule?.hitboxEls.length).toBe(1)
|
||||
expect(epaule?.visibleEls.length).toBe(1)
|
||||
const shoulder = map.get('point-shoulder')
|
||||
expect(shoulder).toBeDefined()
|
||||
expect(shoulder?.fr).toBe('Épaule')
|
||||
expect(shoulder?.en).toBe('Shoulder')
|
||||
expect(shoulder?.category).toBe('articulations')
|
||||
expect(shoulder?.els.length).toBe(2)
|
||||
})
|
||||
|
||||
it('captures opensDetail when present', () => {
|
||||
@@ -40,24 +38,32 @@ describe('parseSvgBones', () => {
|
||||
expect(map.get('zone-head')?.opensDetail).toBe('head')
|
||||
})
|
||||
|
||||
it('records spine-zone single-element bones', () => {
|
||||
it('records zone-colonne single-element annotations', () => {
|
||||
const map = parseSvgBones(svgFromString(FIXTURE))
|
||||
const bone = map.get('cervical-vertebrae-spine-zone')
|
||||
expect(bone?.category).toBe('spine-zone')
|
||||
const bone = map.get('zone-cervical')
|
||||
expect(bone?.category).toBe('zone-colonne')
|
||||
expect(bone?.els.length).toBe(1)
|
||||
})
|
||||
|
||||
it('allows annotations without data-anno-name-fr/en (trigger-only zones)', () => {
|
||||
const map = parseSvgBones(svgFromString(FIXTURE))
|
||||
const trigger = map.get('zone-head')
|
||||
expect(trigger?.fr).toBe('')
|
||||
expect(trigger?.en).toBe('')
|
||||
})
|
||||
})
|
||||
|
||||
describe('parseSvgBones validation', () => {
|
||||
it('throws on missing data-anno-name-fr', () => {
|
||||
it('throws on missing data-anno-category', () => {
|
||||
const bad = `<svg xmlns="http://www.w3.org/2000/svg">
|
||||
<circle data-anno-id="x" data-anno-name-en="X" data-anno-category="os" />
|
||||
<circle data-anno-id="x" />
|
||||
</svg>`
|
||||
expect(() => parseSvgBones(svgFromString(bad))).toThrow(SvgConventionError)
|
||||
})
|
||||
|
||||
it('throws on unknown category', () => {
|
||||
const bad = `<svg xmlns="http://www.w3.org/2000/svg">
|
||||
<circle data-anno-id="x" data-anno-name-fr="X" data-anno-name-en="X" data-anno-category="bogus" />
|
||||
<circle data-anno-id="x" data-anno-category="bogus" />
|
||||
</svg>`
|
||||
expect(() => parseSvgBones(svgFromString(bad))).toThrow(SvgConventionError)
|
||||
})
|
||||
@@ -65,18 +71,22 @@ describe('parseSvgBones validation', () => {
|
||||
|
||||
describe('isValidCategory', () => {
|
||||
it('accepts documented categories', () => {
|
||||
expect(isValidCategory('articulation')).toBe(true)
|
||||
expect(isValidCategory('spine-zone')).toBe(true)
|
||||
expect(isValidCategory('cadran-crane')).toBe(true)
|
||||
expect(isValidCategory('articulations')).toBe(true)
|
||||
expect(isValidCategory('zone-colonne')).toBe(true)
|
||||
expect(isValidCategory('cadrans-du-cr-ne')).toBe(true)
|
||||
expect(isValidCategory('charni-res-vert-brales')).toBe(true)
|
||||
expect(isValidCategory('os')).toBe(true)
|
||||
})
|
||||
|
||||
it('rejects unknown values', () => {
|
||||
expect(isValidCategory('nope')).toBe(false)
|
||||
expect(isValidCategory('articulation')).toBe(false) // old singular form
|
||||
expect(isValidCategory('spine-zone')).toBe(false) // old name
|
||||
})
|
||||
})
|
||||
|
||||
describe('getBoneIdFromEvent', () => {
|
||||
it('returns null when no bone in ancestry', () => {
|
||||
it('returns null when no anno in ancestry', () => {
|
||||
const div = document.createElement('div')
|
||||
const evt = new Event('click')
|
||||
Object.defineProperty(evt, 'target', { value: div })
|
||||
|
||||
Reference in new issue
Block a user