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
@@ -18,41 +18,55 @@ function loadSvg(path: string): SVGSVGElement {
|
||||
describe('real Horse.svg', () => {
|
||||
const map = parseSvgBones(loadSvg(HORSE_PATH))
|
||||
|
||||
it('parses without throwing', () => {
|
||||
expect(map.size).toBeGreaterThan(10)
|
||||
it('parses 18 unique annotations', () => {
|
||||
expect(map.size).toBe(18)
|
||||
})
|
||||
|
||||
it('contains all 5 spine-zone bones', () => {
|
||||
const spine = [...map.values()].filter((b) => b.category === 'spine-zone')
|
||||
it('contains 5 zone-colonne annotations (cervical / thoracic / lumbar / sacral / caudal)', () => {
|
||||
const spine = [...map.values()].filter(
|
||||
(b) => b.category === 'zone-colonne',
|
||||
)
|
||||
expect(spine.length).toBe(5)
|
||||
})
|
||||
|
||||
it('contains the head zone with opensDetail=head', () => {
|
||||
const head = [...map.values()].find((b) => b.category === 'head')
|
||||
expect(head?.opensDetail).toBe('head')
|
||||
it('contains exactly one opens-detail trigger pointing at the head SVG', () => {
|
||||
const triggers = [...map.values()].filter((b) => b.opensDetail === 'head')
|
||||
expect(triggers.length).toBe(1)
|
||||
})
|
||||
|
||||
it('contains the 3 vertebral hinges', () => {
|
||||
const charn = [...map.values()].filter((b) => b.category === 'charniere')
|
||||
expect(charn.map((b) => b.id).sort()).toEqual(['c7-t1', 'l6-s1', 't18-l1'])
|
||||
it('contains 9 articulations', () => {
|
||||
const arts = [...map.values()].filter(
|
||||
(b) => b.category === 'articulations',
|
||||
)
|
||||
expect(arts.length).toBe(9)
|
||||
})
|
||||
|
||||
it('contains main joint articulations', () => {
|
||||
for (const id of ['epaule', 'coude', 'hanche', 'grasset', 'jarret']) {
|
||||
expect(map.get(id)?.category).toBe('articulation')
|
||||
}
|
||||
it('contains 3 vertebral hinges', () => {
|
||||
const ch = [...map.values()].filter(
|
||||
(b) => b.category === 'charni-res-vert-brales',
|
||||
)
|
||||
expect(ch.length).toBe(3)
|
||||
})
|
||||
})
|
||||
|
||||
describe('real Horse_head.svg', () => {
|
||||
const map = parseSvgBones(loadSvg(HEAD_PATH))
|
||||
|
||||
it('parses without throwing', () => {
|
||||
expect(map.size).toBeGreaterThan(5)
|
||||
it('parses 9 unique annotations', () => {
|
||||
expect(map.size).toBe(9)
|
||||
})
|
||||
|
||||
it('contains cadran-crane categories', () => {
|
||||
const cadran = [...map.values()].filter((b) => b.category === 'cadran-crane')
|
||||
expect(cadran.length).toBeGreaterThan(0)
|
||||
it('contains 5 cadrans-du-cr-ne annotations', () => {
|
||||
const cadrans = [...map.values()].filter(
|
||||
(b) => b.category === 'cadrans-du-cr-ne',
|
||||
)
|
||||
expect(cadrans.length).toBe(5)
|
||||
})
|
||||
|
||||
it('contains 2 articulations (ATM + SSB equivalents)', () => {
|
||||
const arts = [...map.values()].filter(
|
||||
(b) => b.category === 'articulations',
|
||||
)
|
||||
expect(arts.length).toBe(2)
|
||||
})
|
||||
})
|
||||
@@ -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