feat(anatomy): parse data-anno-lateral attribute from SVG

Read data-anno-lateral from annotated SVG elements and expose it as
Bone.lateral ('bilateral' | 'unpaired' | undefined). Follows the same
merge logic used for data-anno-special.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Bastien ChanotandClaude committed 2026-05-23 22:15:02 +02:00
1 parent 2d5ff54b69
commit db50c67bb6
3 files changed
+22

No files matched your search

+8
View File
@@ -53,6 +53,10 @@ export function parseSvgBones(svgRoot: SVGSVGElement): Map<string, Bone> {
const opensDetail = const opensDetail =
el.getAttribute('data-anno-opens-detail') ?? undefined el.getAttribute('data-anno-opens-detail') ?? undefined
const special = el.getAttribute('data-anno-special') ?? undefined const special = el.getAttribute('data-anno-special') ?? undefined
const lateral = (el.getAttribute('data-anno-lateral') ?? undefined) as
| 'bilateral'
| 'unpaired'
| undefined
const existing = map.get(id) const existing = map.get(id)
if (existing) { if (existing) {
@@ -63,6 +67,9 @@ export function parseSvgBones(svgRoot: SVGSVGElement): Map<string, Bone> {
if (special && !existing.special) { if (special && !existing.special) {
existing.special = special existing.special = special
} }
if (lateral && !existing.lateral) {
existing.lateral = lateral
}
if (!existing.fr && fr) existing.fr = fr if (!existing.fr && fr) existing.fr = fr
if (!existing.en && en) existing.en = en if (!existing.en && en) existing.en = en
} else { } else {
@@ -73,6 +80,7 @@ export function parseSvgBones(svgRoot: SVGSVGElement): Map<string, Bone> {
category, category,
opensDetail, opensDetail,
special, special,
lateral,
els: [el], els: [el],
}) })
} }
+2
View File
@@ -33,6 +33,8 @@ export interface Bone {
* Opaque to the parser; new values are accepted without code changes. * Opaque to the parser; new values are accepted without code changes.
*/ */
special?: string special?: string
/** Laterality hint from data-anno-lateral — bilateral or unpaired */
lateral?: 'bilateral' | 'unpaired'
/** All DOM elements carrying this annotation (used for colorization) */ /** All DOM elements carrying this annotation (used for colorization) */
els: Element[] els: Element[]
} }
+12
View File
@@ -22,6 +22,8 @@ const FIXTURE = `
<polygon data-anno-id="zone-head" data-anno-category="os" data-anno-opens-detail="head" /> <polygon data-anno-id="zone-head" data-anno-category="os" data-anno-opens-detail="head" />
<polygon data-anno-id="zone-future" data-anno-name-fr="Catégorie inédite" <polygon data-anno-id="zone-future" data-anno-name-fr="Catégorie inédite"
data-anno-category="something-new-the-parser-has-never-seen" /> data-anno-category="something-new-the-parser-has-never-seen" />
<circle data-anno-id="point-knee" data-anno-name-fr="Genou" data-anno-name-en="Knee"
data-anno-category="articulations" data-anno-lateral="bilateral" />
</svg>` </svg>`
describe('parseSvgBones', () => { describe('parseSvgBones', () => {
@@ -59,6 +61,16 @@ describe('parseSvgBones', () => {
'something-new-the-parser-has-never-seen', 'something-new-the-parser-has-never-seen',
) )
}) })
it('captures data-anno-lateral when present', () => {
const map = parseSvgBones(svgFromString(FIXTURE))
expect(map.get('point-knee')?.lateral).toBe('bilateral')
})
it('leaves lateral undefined when attribute absent', () => {
const map = parseSvgBones(svgFromString(FIXTURE))
expect(map.get('point-shoulder')?.lateral).toBeUndefined()
})
}) })
describe('parseSvgBones validation', () => { describe('parseSvgBones validation', () => {