Carte des familles : au dézoom, chaque famille devient une tuile

Maquette J retenue par Patch le 19/10 (« quand on dézoome pas mal, une
famille devient un gros bloc »). Entre les échelles 0,3 et 0,2 l'arbre
s'efface et les tuiles apparaissent : une par famille (la lignée principale
et chaque cluster), de taille constante à l'écran, avec le nom, six
portraits et le nombre de personnes ; un trait par mariage entre familles,
avec le prénom de la personne qui relie. Les tuiles se rangent autour de la
famille principale à distance d'écran fixe, quel que soit l'éloignement réel
des familles sur la toile. Un clic sur une tuile s'approche de la famille
(même mécanique que les pastilles). Le placement expose `result.families`.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
IliesAllaliandClaude Fable 5.1 committed 2026-10-19 17:11:22 +02:00
1 parent fb02139929
commit 71c8e1a93d
3 files changed
+99 -2

No files matched your search

+10 -1
View File
@@ -8,7 +8,7 @@ import { computeBlockLayout } from './galaxy/blockLayout'
// Placement par blocs familiaux par défaut (mesures : tools/layout-bench). ?layout=sugiyama = placement Sugiyama.
const USE_BLOCK_LAYOUT = typeof window === 'undefined' || new URLSearchParams(window.location.search).get('layout') !== 'sugiyama'
import { findPathBFS } from './galaxy/pathfinding'
import { drawBackground, drawCoupleLinks, drawFiliations, drawAnnotations, drawPathHighlight, drawNodes, drawRenvoiPills, nodeRadius } from './galaxy/renderers'
import { drawBackground, drawCoupleLinks, drawFiliations, drawAnnotations, drawPathHighlight, drawNodes, drawRenvoiPills, nodeRadius, drawFamilyMap } from './galaxy/renderers'
import { buildSiblingGroups, moveInOrder, pickSlot, rubberBand, springStep, isSettled, buildOrderPayload, filiationsWithOrder } from './galaxy/siblingReorder'
import { annotations as annotationData } from '../data/mockData'
import { useImageCache } from './galaxy/useImageCache'
@@ -26,6 +26,9 @@ function approach(prev, target, k, eps = 1e-3) {
return Math.abs(target - next) < eps ? target : next
}
const MAX_SCALE = 3.2
// Carte des familles : l'arbre s'efface entre ces deux échelles, les tuiles de familles apparaissent
const MAP_HI = 0.3
const MAP_LO = 0.2
// Ouverture sur la personne de départ quand l'arbre entier serait illisible
const FOCUS_MIN_READABLE_SCALE = 0.5
const FOCUS_SCALE = 0.95
@@ -811,6 +814,10 @@ const Galaxy = ({ onPersonSelect, onMediaSelect, selectedPersonId, searchHighlig
const cssW = canvas.width / dprRef.current
const cssH = canvas.height / dprRef.current
const view = { x0: -x / scale, y0: -y / scale, x1: (cssW - x) / scale, y1: (cssH - y) / scale, scale }
// Carte des familles : au dézoom, l'arbre laisse la place aux tuiles de familles
const families = layoutData.families || []
const mapAlpha = families.length > 1 ? Math.min(1, Math.max(0, (MAP_HI - scale) / (MAP_HI - MAP_LO))) : 0
if (mapAlpha < 1) {
drawCoupleLinks(ctx, coupleBarMeta, posMap, nodeMap, nodeRandomDataRef.current, entrance, entranceActive, elapsed, view)
drawFiliations(ctx, layoutData.edges, posMap, nodeMap, nodeRandomDataRef.current, entrance, entranceActive, elapsed, view)
drawPathHighlight(ctx, {
@@ -838,6 +845,8 @@ const Galaxy = ({ onPersonSelect, onMediaSelect, selectedPersonId, searchHighlig
liftScales: liftScalesRef.current,
})
drawRenvoiPills(ctx)
}
if (mapAlpha > 0) drawFamilyMap(ctx, families, view, mapAlpha)
// Annotations dessinées APRES les noeuds pour que stickers/texte soient au-dessus
// Annotations : ancrer aux personnes proches pour qu'elles suivent le layout
const personPosMap = new Map()
+21 -1
View File
@@ -324,7 +324,7 @@ export function computeBlockLayout(graphData = null, referenceId = null) {
nodes.push({ id: cardId, _type: 'family', width: FAMILY_CARD_W, height: FAMILY_CARD_H, _generation: gen - 1, y: A.y - rowStep + (PERSON_H - FAMILY_CARD_H) / 2, _data: { label, count: people.length, portraits, targetId: echoId, stem: 'down', stemTo: id } })
byId.set(cardId, nodes[nodes.length - 1])
const card = { rows: new Map([[gen - 1, [[0, FAMILY_CARD_W]]]]), members: new Set([cardId]), external: [], gen: gen - 1, rel: (x) => (x === cardId ? 0 : null), chain: [0, FAMILY_CARD_W], width: FAMILY_CARD_W, place(x0) { pos.set(cardId, x0) } }
clusters.push({ block, anchorId: id, pu, cardId, echoId, mainCardId })
clusters.push({ block, anchorId: id, pu, cardId, echoId, mainCardId, label, people })
built.push({ block: card, anchorId: id, side })
if (chain.length === 3) orient(chain, chain[0] === id ? chain[2] : chain[0], side)
continue
@@ -631,5 +631,25 @@ export function computeBlockLayout(graphData = null, referenceId = null) {
for (const r of list) byId.get(r.id)._railLift = Math.min(4, liftOf(r.id))
}
// Carte des familles (maquette J, 19/10) : au dézoom, chaque famille (la lignée principale, chaque cluster)
// devient une tuile, et chaque mariage entre familles un trait. Le dessin se fait dans Galaxy / renderers.
const familyOf = new Map()
clusters.forEach(c => { for (const m of c.block.members) familyOf.set(m, c.cardId); familyOf.set(c.echoId, c.cardId); familyOf.set(c.mainCardId, c.cardId) })
const bboxOf = (ids) => {
const ps = ids.map(id => byId.get(id)).filter(n => n && n._type === 'person' && n.x != null)
if (!ps.length) return null
return { x0: Math.min(...ps.map(n => n.x)), y0: Math.min(...ps.map(n => n.y)), x1: Math.max(...ps.map(n => n.x + n.width)), y1: Math.max(...ps.map(n => n.y + n.height)) }
}
const portraitsOf = (ids) => {
const ps = ids.map(id => byId.get(id)).filter(n => n?._type === 'person' && !n._echo)
return [...ps.filter(n => n._data?.photo), ...ps.filter(n => !n._data?.photo)].slice(0, 6).map(n => n._data)
}
const mainIds = nodes.filter(n => !familyOf.has(n.id)).map(n => n.id)
nodes.forEach(n => { n._family = familyOf.get(n.id) || 'main' })
result.families = [
{ id: 'main', label: referenceNode?._data?.lastName || '', count: mainPeople.length, portraits: portraitsOf(mainIds), bbox: bboxOf(mainIds), links: [] },
...clusters.map(c => ({ id: c.cardId, label: c.label, count: c.people.length, portraits: portraitsOf([...c.block.members]), bbox: bboxOf([...c.block.members]), links: [{ to: 'main', label: byId.get(c.anchorId)?._data?.firstName || '' }] })),
].filter(f => f.bbox)
return result
}
@@ -318,6 +318,74 @@ function drawFamilyCard(ctx, node, pos, posMap, progress, view) {
if (target && alpha > 0.5) renvoiHitAreas.push({ x0: cx - w / 2, y0: cy - h / 2, x1: cx + w / 2, y1: cy + h / 2, targetX: target.cx, targetY: target.cy })
}
// ============================================================
// Carte des familles (maquette J, 19/10) : au dézoom, l'arbre s'efface et chaque famille devient une tuile
// de taille constante à l'écran (nom, mosaïque de portraits, nombre), les mariages entre familles des traits.
// Un clic sur une tuile s'approche de la famille (même mécanique que les pastilles).
// ============================================================
export function drawFamilyMap(ctx, families, view, alpha) {
if (!families?.length || alpha <= 0) return
const s = view?.scale || 1
const px = (v) => v / s
const real = (f) => ({ x: (f.bbox.x0 + f.bbox.x1) / 2, y: (f.bbox.y0 + f.bbox.y1) / 2 })
// Les tuiles se rangent autour de la famille principale, à distance d'écran constante, quel que soit
// l'éloignement réel des familles sur la toile ; un clic mène à la vraie place de la famille
const main = families.find((f) => f.id === 'main') || families[0]
const origin = real(main)
const others = families.filter((f) => f !== main)
const tilePos = new Map([[main.id, origin]])
others.forEach((f, i) => {
const angle = -Math.PI / 2 + (i / Math.max(1, others.length)) * Math.PI * 2 + Math.PI / others.length
tilePos.set(f.id, { x: origin.x + Math.cos(angle) * px(380), y: origin.y + Math.sin(angle) * px(230) })
})
const center = (f) => tilePos.get(f.id)
if (alpha >= 1) renvoiHitAreas.length = 0
ctx.save()
ctx.globalAlpha = alpha
ctx.lineCap = 'round'
for (const f of families) for (const l of (f.links || [])) {
const g = families.find((x) => x.id === l.to)
if (!g) continue
const a = center(f), b = center(g)
ctx.strokeStyle = FIL.color
ctx.lineWidth = px(1.6)
ctx.beginPath(); ctx.moveTo(a.x, a.y); ctx.lineTo(b.x, b.y); ctx.stroke()
if (l.label) {
ctx.fillStyle = COLORS.textLight
ctx.font = `400 ${px(11)}px "DM Sans", system-ui, sans-serif`
ctx.textAlign = 'center'; ctx.textBaseline = 'bottom'
ctx.fillText(l.label, (a.x + b.x) / 2, (a.y + b.y) / 2 - px(6))
}
}
for (const f of families) {
const c = center(f)
const w = px(290), h = px(112)
ctx.fillStyle = '#FFFFFF'
ctx.strokeStyle = '#E3DED6'
ctx.lineWidth = px(1)
ctx.beginPath(); ctx.roundRect(c.x - w / 2, c.y - h / 2, w, h, px(18)); ctx.fill(); ctx.stroke()
;(f.portraits || []).forEach((p, i) => {
const cx = c.x - w / 2 + px(24) + (i % 3) * px(30), cy = c.y - px(16) + Math.floor(i / 3) * px(30)
ctx.fillStyle = '#F2EFEA'; ctx.strokeStyle = '#E3DED6'; ctx.lineWidth = px(0.8)
ctx.beginPath(); ctx.roundRect(cx - px(11), cy - px(11), px(22), px(22), px(4)); ctx.fill(); ctx.stroke()
ctx.fillStyle = COLORS.textLight
ctx.font = `400 ${px(9)}px "Newsreader", Georgia, serif`
ctx.textAlign = 'center'; ctx.textBaseline = 'middle'
ctx.fillText(`${(p.firstName || '')[0] || ''}${(p.lastName || '')[0] || ''}`, cx, cy + px(0.5))
})
ctx.fillStyle = COLORS.text
ctx.font = `500 ${px(18)}px "Newsreader", Georgia, serif`
ctx.textAlign = 'left'; ctx.textBaseline = 'middle'
ctx.fillText(f.label ? t('Famille {name}', { name: f.label }) : t('Famille'), c.x - w / 2 + px(118), c.y - px(12))
ctx.fillStyle = '#93402A'
ctx.font = `400 ${px(12)}px "DM Sans", system-ui, sans-serif`
ctx.fillText(t('{n} personnes', { n: f.count }), c.x - w / 2 + px(118), c.y + px(14))
const target = real(f)
if (alpha > 0.5) renvoiHitAreas.push({ x0: c.x - w / 2, y0: c.y - h / 2, x1: c.x + w / 2, y1: c.y + h / 2, targetX: target.x, targetY: target.y })
}
ctx.restore()
}
// Après drawNodes : les pastilles passent au-dessus des portraits et des souvenirs
export function drawRenvoiPills(ctx) {
renvoiPills.forEach(p => drawRenvoiPill(ctx, p))