Arbre : conjoints isolés en petit, renvoi vers les parents, fil en accolade

- Conjoint marié sans parent ni enfant dans l'arbre : petit portrait collé à son partenaire, sans emplacement de nœud ni orbite
- Enfant placé sous l'autre lignée : pastilles « Voir les parents » et « Voir <prénom> » cliquables au lieu du trait qui traverse l'arbre
- Fil terracotta clair en accolade arrondie, union marquée du rond terracotta

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
IliesAllaliandClaude Opus 5.5 committed 2026-09-25 18:07:56 +02:00
1 parent 92a4e5e1b9
commit 8a63943497
7 files changed
+331 -93

No files matched your search

+3 -2
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 } from './galaxy/renderers'
import { drawBackground, drawCoupleLinks, drawFiliations, drawAnnotations, drawPathHighlight, drawNodes, drawRenvoiPills } from './galaxy/renderers'
import { annotations as annotationData } from '../data/mockData'
import { useImageCache } from './galaxy/useImageCache'
import { useGalaxyInteractions } from './galaxy/useGalaxyInteractions'
@@ -209,7 +209,7 @@ const Galaxy = ({ onPersonSelect, onMediaSelect, selectedPersonId, searchHighlig
initialTransformRef.current = init
transformRef.current = init
targetTransformRef.current = init
nodeRandomDataRef.current = generateNodeRandomData(result.children)
nodeRandomDataRef.current = generateNodeRandomData(result.children, result.edges)
// Construire le schedule d'animation d'entrée
const genGroups = new Map()
@@ -530,6 +530,7 @@ const Galaxy = ({ onPersonSelect, onMediaSelect, selectedPersonId, searchHighlig
entrance, entranceActive, elapsed,
view,
})
drawRenvoiPills(ctx)
// 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()
+19 -4
View File
@@ -1,4 +1,5 @@
import { computeLayout, componentOrderPerGen } from './elkLayout'
import { computeLayout, componentOrderPerGen, chainGap } from './elkLayout'
import { RENVOI_MIN_DX } from './constants'
// ============================================================
// Layout par blocs familiaux (Reingold-Tilford adapté aux couples)
@@ -64,16 +65,18 @@ export function computeBlockLayout(graphData = null) {
return n
}
const chainWidth = (chain) => chain.reduce((s, id) => s + byId.get(id).width, 0) + (chain.length - 1) * NODE_SPACING
const gapAfter = (chain, i) => chainGap(byId.get(chain[i]), byId.get(chain[i + 1]), NODE_SPACING)
const chainWidth = (chain) => chain.reduce((s, id, i) => s + byId.get(id).width + (i < chain.length - 1 ? gapAfter(chain, i) : 0), 0)
const chainOffsets = (chain) => {
const offsets = new Map()
let x = 0
for (const id of chain) { offsets.set(id, x); x += byId.get(id).width + NODE_SPACING }
chain.forEach((id, i) => { offsets.set(id, x); x += byId.get(id).width + (i < chain.length - 1 ? gapAfter(chain, i) : 0) })
return offsets
}
const pos = new Map()
const placed = new Set()
const externalEdges = new Set() // `${union}>${enfant}` : enfant placé sous une autre lignée
// Imbrique des blocs de gauche à droite, génération par génération
function packBlocks(blocks, gap) {
@@ -106,7 +109,7 @@ export function computeBlockLayout(graphData = null) {
for (const k of (childrenOfUnion.get(id) || [])) {
const kc = chainOf.get(k)
if (!placed.has(kc)) childBlocks.push(buildBlock(kc))
else external.push({ kid: k, unionId: id })
else { external.push({ kid: k, unionId: id }); externalEdges.add(`${id}>${k}`) }
}
}
const packed = packBlocks(childBlocks, FAMILY_GAP)
@@ -201,5 +204,17 @@ export function computeBlockLayout(graphData = null) {
for (const n of nodes) if (pos.has(n.id)) minX = Math.min(minX, pos.get(n.id))
for (const n of nodes) if (pos.has(n.id)) n.x = pos.get(n.id) - minX
// Arête longue vers un enfant placé sous l'autre lignée : dessinée en renvoi (voir drawFiliations)
// Plusieurs renvois sous la même union : pastilles empilées (_renvoiIndex)
const centerX = (id) => byId.get(id).x + byId.get(id).width / 2
const renvoisByUnion = new Map()
for (const e of result.edges) {
const u = e.sources[0], c = e.targets[0]
if (!externalEdges.has(`${u}>${c}`) || Math.abs(centerX(u) - centerX(c)) <= RENVOI_MIN_DX) continue
e._renvoi = true
e._renvoiIndex = renvoisByUnion.get(u) || 0
renvoisByUnion.set(u, e._renvoiIndex + 1)
}
return result
}
@@ -0,0 +1,41 @@
import { describe, it, expect } from 'vitest'
import { computeBlockLayout } from './blockLayout'
import { COMPACT_W, PERSON_W } from './constants'
const person = (id) => ({ id, firstName: id, lastName: '' })
const union = (id, partner1Id, partner2Id) => ({ id, partner1Id, partner2Id, displayOrder: 1 })
const fil = (id, childId, unionId) => ({ id, childId, parentId: null, unionId, parentageType: 'biologique', displayOrder: 1 })
describe('computeBlockLayout, conjoints isolés', () => {
// pa + ma → enfant e, marié à s (sans parent ni enfant dans l'arbre)
const graph = {
persons: ['pa', 'ma', 'e', 's'].map(person),
unions: [union('u1', 'pa', 'ma'), union('u2', 'e', 's')],
filiations: [fil('f1', 'e', 'u1')],
}
it('dessine en petit le conjoint sans parent ni enfant, pas son partenaire', () => {
const { children } = computeBlockLayout(graph)
const byId = new Map(children.map(n => [n.id, n]))
expect(byId.get('p-s')).toMatchObject({ _compact: true, width: COMPACT_W, _compactPartner: 'p-e' })
expect(byId.get('p-e')._compact).toBeUndefined()
expect(byId.get('p-e').width).toBe(PERSON_W)
expect(byId.get('u-u2')).toMatchObject({ _compact: true, width: 0 })
})
it('colle le petit portrait à son partenaire', () => {
const { children } = computeBlockLayout(graph)
const byId = new Map(children.map(n => [n.id, n]))
const center = (id) => byId.get(id).x + byId.get(id).width / 2
expect(Math.abs(center('p-s') - center('p-e'))).toBeLessThan(80)
})
it('garde en taille normale un conjoint qui a des enfants', () => {
const { children } = computeBlockLayout({
...graph,
persons: [...graph.persons, person('k')],
filiations: [...graph.filiations, fil('f2', 'k', 'u2')],
})
expect(children.find(n => n.id === 'p-s')._compact).toBeUndefined()
})
})
@@ -7,6 +7,14 @@ export const UNION_H = PERSON_H
export const UNKNOWN_W = 60
export const UNKNOWN_H = PERSON_H
export const UNKNOWN_R = 18
// Conjoint isolé (marié, sans parent ni enfant dans l'arbre) : petit portrait collé à son partenaire.
// Il ne prend pas un emplacement de nœud : union de largeur nulle, écart négatif vers le partenaire.
export const COMPACT_SCALE = 0.6
export const COMPACT_R = PERSON_R * COMPACT_SCALE
export const COMPACT_W = 40
export const COMPACT_JOIN_GAP = -18
// Filiation qui traverse l'arbre (enfant placé sous l'autre lignée) : renvoi cliquable au lieu du trait
export const RENVOI_MIN_DX = 360
export const MAX_ORBIT_MEDIAS = 3
export const ORBIT_RADIUS = 55
export const ORBIT_MEDIA_SIZE = 22
+87 -19
View File
@@ -1,7 +1,7 @@
import { persons as globalPersons, unions as globalUnions, filiations as globalFiliations } from '../../data/mockData'
import {
PERSON_W, PERSON_H, UNION_W, UNION_H,
UNKNOWN_W, UNKNOWN_H,
UNKNOWN_W, UNKNOWN_H, COMPACT_W, COMPACT_JOIN_GAP,
JITTER_RADIUS, FLOAT_AMPLITUDE, FLOAT_SPEED,
ANGLE_VARIATION, MAX_ORBIT_MEDIAS, ORBIT_RADIUS,
} from './constants'
@@ -25,6 +25,15 @@ function compareByOrderThenId(a, b) {
return String(a.id || '').localeCompare(String(b.id || ''))
}
// Écart entre deux nœuds voisins d'une chaîne de couples. Autour d'une union de conjoint isolé :
// rien côté conjoint, un écart négatif côté partenaire, pour que le petit portrait se colle à lui.
export function chainGap(a, b, spacing) {
const compactUnion = a?._compact && a._type === 'union' ? a : b?._compact && b._type === 'union' ? b : null
if (!compactUnion) return spacing
const other = compactUnion === a ? b : a
return other?._compact ? 0 : COMPACT_JOIN_GAP
}
function makePairKey(a, b) {
const left = String(a)
const right = String(b)
@@ -258,6 +267,35 @@ export function computeLayout(graphData = null) {
}
}
// ----------------------------------------------------------
// Conjoints isolés : mariés une seule fois, sans parent ni enfant dans l'arbre.
// Dessinés en petit à côté du partenaire (voir COMPACT_* dans constants.js).
// Si les deux partenaires sont isolés, seul le second passe en petit.
// ----------------------------------------------------------
const linkedByFiliation = new Set()
normalizedFiliations.forEach(f => {
linkedByFiliation.add(f.childId)
if (f.parentId) linkedByFiliation.add(f.parentId)
const u = f.unionId ? unionsById.get(f.unionId) : null
if (u) { linkedByFiliation.add(u.partner1Id); linkedByFiliation.add(u.partner2Id) }
})
const unionCount = new Map()
unions.forEach(u => {
for (const pid of [u.partner1Id, u.partner2Id]) unionCount.set(pid, (unionCount.get(pid) || 0) + 1)
})
const isLoneSpouse = (pid) => !linkedByFiliation.has(pid) && unionCount.get(pid) === 1
const compactPartnerOf = new Map() // conjoint isolé → partenaire
const compactUnionIds = new Map() // union de conjoint isolé → partenaire
unions.forEach(u => {
if (!u.partner1Id || !u.partner2Id) return
let lone = null, partner = null
if (isLoneSpouse(u.partner2Id)) { lone = u.partner2Id; partner = u.partner1Id }
else if (isLoneSpouse(u.partner1Id) && !isLoneSpouse(u.partner2Id)) { lone = u.partner1Id; partner = u.partner2Id }
if (!lone) return
compactPartnerOf.set(lone, partner)
compactUnionIds.set(`u-${u.id}`, `p-${partner}`)
})
// ----------------------------------------------------------
// PHASE 2 : Créer les nœuds du graphe
// ----------------------------------------------------------
@@ -390,9 +428,11 @@ export function computeLayout(graphData = null) {
if (key.startsWith('p-')) {
const person = personByElkId.get(key)
if (person) {
const compactPartner = compactPartnerOf.get(person.id)
pushNode({
id: key, width: PERSON_W, height: PERSON_H,
id: key, width: compactPartner ? COMPACT_W : PERSON_W, height: PERSON_H,
_type: 'person', _data: person, _generation: gen,
...(compactPartner ? { _compact: true, _compactPartner: `p-${compactPartner}` } : {}),
})
}
} else if (key.startsWith('unknown-')) {
@@ -407,7 +447,8 @@ export function computeLayout(graphData = null) {
for (const { unionElkId, otherKey } of neighbors) {
pushNode({
id: unionElkId, width: UNION_W, height: UNION_H,
id: unionElkId, width: compactUnionIds.has(unionElkId) ? 0 : UNION_W, height: UNION_H,
...(compactUnionIds.has(unionElkId) ? { _compact: true, _compactPartner: compactUnionIds.get(unionElkId) } : {}),
_type: 'union',
_data: unionEntryByElkId.get(unionElkId) || { id: unionElkId },
_generation: gen,
@@ -513,17 +554,16 @@ export function computeLayout(graphData = null) {
function getComponentWidth(compNodeIds, nodeSpacing) {
const nodes = compNodeIds.map(id => nodeById.get(id)).filter(Boolean)
return nodes.reduce((sum, n) => sum + n.width, 0) + Math.max(0, nodes.length - 1) * nodeSpacing
return nodes.reduce((sum, n, i) => sum + n.width + (i ? chainGap(nodes[i - 1], n, nodeSpacing) : 0), 0)
}
function placeComponentAt(compNodeIds, left, nodeSpacing) {
const nodes = compNodeIds.map(id => nodeById.get(id)).filter(Boolean)
let x = left
for (const nodeId of compNodeIds) {
const node = nodeById.get(nodeId)
if (!node) continue
nodes.forEach((node, i) => {
node.x = x
x += node.width + nodeSpacing
}
x += node.width + chainGap(node, nodes[i + 1], nodeSpacing)
})
}
// Helper : trier avec regroupement des fratries (union-find)
@@ -735,8 +775,29 @@ export function computeLayout(graphData = null) {
// ============================================================
// Données aléatoires par nœud (offset, flottement, angle)
// ============================================================
export function generateNodeRandomData(children) {
export function generateNodeRandomData(children, edges = []) {
const data = new Map()
// Enfant d'un renvoi : la pastille « Voir les parents » occupe le haut du portrait, l'orbite reste sur les côtés
const renvoiChildren = new Set(edges.filter(e => e._renvoi).map(e => e.targets[0]))
const deg = (d) => d * Math.PI / 180
// Partenaire d'un conjoint isolé : ses souvenirs en orbite passent du côté opposé au petit portrait
const compactSide = new Map()
const byId = new Map(children.map(n => [n.id, n]))
children.forEach(node => {
const partner = node._compact && node._type === 'person' ? byId.get(node._compactPartner) : null
if (partner) compactSide.set(partner.id, node.x > partner.x ? 1 : -1)
})
const orbitAngle = (nodeId, i) => {
const side = compactSide.get(nodeId)
if (renvoiChildren.has(nodeId)) {
const angles = side ? [180, 152, 208] : [175, 5, 150]
return deg(side < 0 ? 180 - angles[i] : angles[i])
}
if (!side) return (3 * Math.PI / 4) + (Math.PI * 1.5 * (i + 0.5) / MAX_ORBIT_MEDIAS)
const a = (3 * Math.PI / 4) + (Math.PI * (i + 0.5) / MAX_ORBIT_MEDIAS)
return side > 0 ? a : Math.PI - a
}
children.forEach(node => {
const angle = Math.random() * Math.PI * 2
const radius = Math.random() * JITTER_RADIUS
@@ -752,16 +813,23 @@ export function generateNodeRandomData(children) {
anchorAngleOffset: (Math.random() - 0.5) * ANGLE_VARIATION * 2,
labelRotation: (Math.random() - 0.5) * 0.12,
frameRotation: (Math.random() - 0.5) * 0.15,
orbitSlots: Array.from({ length: MAX_ORBIT_MEDIAS }, (_, i) => {
const safeArc = Math.PI * 1.5
const baseAngle = (3 * Math.PI / 4) + (safeArc * (i + 0.5) / MAX_ORBIT_MEDIAS)
return {
angle: baseAngle + (Math.random() - 0.5) * 0.5,
dist: ORBIT_RADIUS + (Math.random() - 0.5) * 12,
rot: (Math.random() - 0.5) * 0.3,
}
}),
// Conjoint isolé : pas d'orbite (ses souvenirs restent dans sa fiche)
orbitSlots: node._compact ? [] : Array.from({ length: MAX_ORBIT_MEDIAS }, (_, i) => ({
angle: orbitAngle(node.id, i) + (Math.random() - 0.5) * (renvoiChildren.has(node.id) ? 0.2 : 0.5),
dist: ORBIT_RADIUS + (Math.random() - 0.5) * 12,
rot: (Math.random() - 0.5) * 0.3,
})),
})
})
// Le petit portrait suit le décalage de son partenaire, sinon l'écart entre eux varie du simple au triple
children.forEach(node => {
if (!node._compact) return
const rdPartner = data.get(node._compactPartner)
if (!rdPartner) return
const rd = data.get(node.id)
rd.offsetX = rdPartner.offsetX
rd.offsetY = rdPartner.offsetY
rd.anchorAngleOffset = 0
})
return data
}
+153 -64
View File
@@ -3,7 +3,7 @@ import { __iconNode as mapIconNode } from 'lucide-react/dist/esm/icons/map.js'
import { __iconNode as mapPinIconNode } from 'lucide-react/dist/esm/icons/map-pin.js'
import { __iconNode as routeIconNode } from 'lucide-react/dist/esm/icons/route.js'
import {
PERSON_R, UNKNOWN_R, UNION_W, UNION_H,
PERSON_R, UNKNOWN_R, UNION_W, UNION_H, COMPACT_R, COMPACT_SCALE,
MAX_ORBIT_MEDIAS, ORBIT_MEDIA_SIZE,
COLORS,
LOD_SHADOW_MIN_SCALE, LOD_DETAIL_MIN_SCALE, LOD_LABEL_FADE_IN, LOD_LABEL_FADE_OUT, CULL_MARGIN,
@@ -15,6 +15,13 @@ import { getEntranceProgress, drawPartialBezier } from './utils'
// (null = tout dessiner). Un élément hors écran, marge comprise,
// n'est pas dessiné.
// ============================================================
// Rayon d'un nœud : inconnu, conjoint isolé (petit) ou personne
export function nodeRadius(node) {
if (node?._type === 'unknown') return UNKNOWN_R
if (node?._compact) return COMPACT_R
return PERSON_R
}
function rectInView(view, minX, minY, maxX, maxY) {
if (!view) return true
return maxX >= view.x0 - CULL_MARGIN && minX <= view.x1 + CULL_MARGIN &&
@@ -51,7 +58,7 @@ export function drawBackground(ctx, canvas) {
// Helper: calcul des points Bézier couple (partagé entre
// drawCoupleLinks et drawPathHighlight)
// ============================================================
function computeCouplePoints(p1Pos, p2Pos, unionPos, p1R, p2R, nodeRandomData) {
function computeCouplePoints(p1Pos, p2Pos, unionPos, p1R, p2R, nodeRandomData, straight = false) {
const p1Key = p1Pos._key
const p2Key = p2Pos._key
const rd1 = nodeRandomData.get(p1Key)
@@ -65,11 +72,11 @@ function computeCouplePoints(p1Pos, p2Pos, unionPos, p1R, p2R, nodeRandomData) {
const rdLeft = isP1Left ? rd1 : rd2
const rdRight = isP1Left ? rd2 : rd1
const aL = 0 + (rdLeft?.anchorAngleOffset || 0)
const aL = straight ? 0 : (rdLeft?.anchorAngleOffset || 0)
const sLx = leftPos.cx + Math.cos(aL) * leftR
const sLy = leftPos.cy + Math.sin(aL) * leftR
const aR = Math.PI + (rdRight?.anchorAngleOffset || 0)
const aR = Math.PI + (straight ? 0 : (rdRight?.anchorAngleOffset || 0))
const sRx = rightPos.cx + Math.cos(aR) * rightR
const sRy = rightPos.cy + Math.sin(aR) * rightR
@@ -79,24 +86,48 @@ function computeCouplePoints(p1Pos, p2Pos, unionPos, p1R, p2R, nodeRandomData) {
return { sLx, sLy, sRx, sRy, jx, jy }
}
function computeFiliationCurvePoints(sourcePos, targetPos, childR, anchorAngleOffset = 0) {
const sx = sourcePos.cx
const sy = sourcePos.cy
const angleChild = -Math.PI / 2 + anchorAngleOffset
const ex = targetPos.cx + Math.cos(angleChild) * childR
const ey = targetPos.cy + Math.sin(angleChild) * childR
const dy = ey - sy
// ============================================================
// Fil : terracotta clair, union en rond terracotta (le rond du logo).
// Filiation en accolade souple : l'union descend vers une ligne
// commune à la fratrie, chaque enfant s'en détache par une courbe.
// Les virages sont des quadratiques larges, pas des coins.
// ============================================================
export const FIL = { color: '#E3A590', width: 1.1, dot: '#D2694A', dotR: 2.6 }
// Ligne de la fratrie : sous les prénoms et années des parents, au-dessus des enfants
const BUS_DY = 100
// Rayon horizontal des virages (plafonné à la moitié de l'écart union → enfant)
const BUS_TURN = 56
return {
sx,
sy,
ex,
ey,
cp1x: sx,
cp1y: sy + dy * 0.88,
cp2x: ex,
cp2y: ey - dy * 0.06,
}
function busY(sourceId, sy) {
let h = 0
for (let i = 0; i < sourceId.length; i++) h = (h * 31 + sourceId.charCodeAt(i)) | 0
// Léger décalage par union : deux fratries voisines ne fusionnent pas leurs lignes
return sy + BUS_DY + (Math.abs(h) % 3) * 4
}
function traceBus(ctx, sx, sy, by, ex, ey) {
const dx = ex - sx
ctx.beginPath()
ctx.moveTo(sx, sy)
if (Math.abs(dx) < 1) { ctx.lineTo(ex, ey); ctx.stroke(); return }
const dir = Math.sign(dx)
const turn = Math.min(BUS_TURN, Math.abs(dx) / 2)
// Descente de l'union, virage large vers la ligne de la fratrie
const drop = Math.min(by - sy, 64)
ctx.lineTo(sx, by - drop)
ctx.quadraticCurveTo(sx, by, sx + dir * turn, by)
// Ligne de la fratrie, puis courbe jusqu'au portrait de l'enfant
ctx.lineTo(ex - dir * turn, by)
ctx.quadraticCurveTo(ex, by, ex, ey)
ctx.stroke()
}
// Trace une filiation union → enfant. progress < 1 : entrée en fondu
function traceFiliation(ctx, sourceId, sourcePos, targetPos, childR, progress) {
const a = ctx.globalAlpha
ctx.globalAlpha = a * progress
traceBus(ctx, sourcePos.cx, sourcePos.cy, busY(sourceId, sourcePos.cy), targetPos.cx, targetPos.cy - childR)
ctx.globalAlpha = a
}
// ============================================================
@@ -112,8 +143,8 @@ export function drawCoupleLinks(ctx, coupleBarMeta, posMap, nodeMap, nodeRandomD
const p1Node = nodeMap.get(p1Key)
const p2Node = nodeMap.get(p2Key)
const p1R = p1Node?._type === 'unknown' ? UNKNOWN_R : PERSON_R
const p2R = p2Node?._type === 'unknown' ? UNKNOWN_R : PERSON_R
const p1R = nodeRadius(p1Node)
const p2R = nodeRadius(p2Node)
// Entrance animation
let coupleProgress = 1
@@ -129,11 +160,11 @@ export function drawCoupleLinks(ctx, coupleBarMeta, posMap, nodeMap, nodeRandomD
const p1PosKeyed = { ...p1Pos, _key: p1Key }
const p2PosKeyed = { ...p2Pos, _key: p2Key }
const { sLx, sLy, sRx, sRy, jx, jy } = computeCouplePoints(
p1PosKeyed, p2PosKeyed, unionPos, p1R, p2R, nodeRandomData
p1PosKeyed, p2PosKeyed, unionPos, p1R, p2R, nodeRandomData, nodeMap.get(elkId)?._compact
)
ctx.strokeStyle = virtual ? COLORS.linkUnknown : COLORS.link
ctx.lineWidth = 0.5
ctx.strokeStyle = virtual ? COLORS.linkUnknown : FIL.color
ctx.lineWidth = FIL.width
ctx.setLineDash(virtual ? [4, 4] : [])
ctx.lineCap = 'round'
ctx.globalAlpha = coupleProgress
@@ -148,10 +179,73 @@ export function drawCoupleLinks(ctx, coupleBarMeta, posMap, nodeMap, nodeRandomD
})
}
// ============================================================
// Renvoi : filiation vers un enfant placé sous l'autre lignée.
// Au lieu d'un trait qui traverse l'arbre, un bout de trait à
// chaque extrémité et une pastille cliquable qui mène à l'autre.
// Les zones cliquables de la dernière frame sont lues par
// useGalaxyInteractions.
// ============================================================
export const renvoiHitAreas = []
const renvoiPills = []
const RENVOI_FONT = '500 11px "DM Sans", system-ui, sans-serif'
// Pastilles collées aux personnes : juste sous le couple, juste au-dessus du portrait de l'enfant
const RENVOI_PARENT_DY = 38
const RENVOI_CHILD_GAP = 13
function drawRenvoiPill(ctx, { text, cx, cy, target, alpha }) {
ctx.save()
ctx.font = RENVOI_FONT
const w = measureTextCached(ctx, text, 'renvoi').width + 20
const h = 20
ctx.globalAlpha = alpha
ctx.setLineDash([])
ctx.fillStyle = '#FCF3EF'
ctx.strokeStyle = '#EDB6A4'
ctx.lineWidth = 0.75
ctx.beginPath()
ctx.roundRect(cx - w / 2, cy - h / 2, w, h, h / 2)
ctx.fill()
ctx.stroke()
ctx.fillStyle = '#93402A'
ctx.textAlign = 'center'
ctx.textBaseline = 'middle'
ctx.fillText(text, cx, cy + 0.5)
ctx.restore()
if (alpha > 0.5) renvoiHitAreas.push({ x0: cx - w / 2, y0: cy - h / 2, x1: cx + w / 2, y1: cy + h / 2, ...target })
}
function drawRenvoi(ctx, edge, sourcePos, targetPos, targetNode, childR, view) {
const scale = view?.scale ?? 1
const labelAlpha = Math.min(1, Math.max(0, (scale - LOD_LABEL_FADE_OUT) / (LOD_LABEL_FADE_IN - LOD_LABEL_FADE_OUT)))
const baseAlpha = ctx.globalAlpha
// Côté enfant : pastille « Voir les parents » posée sur le haut du portrait (l'orbite évite le haut)
const childPillY = targetPos.cy - childR - RENVOI_CHILD_GAP
// Côté parents : pastille au prénom de l'enfant juste sous l'union, empilées s'il y en a plusieurs
const parentPillY = sourcePos.cy + RENVOI_PARENT_DY + (edge._renvoiIndex || 0) * 24
if (labelAlpha <= 0) return
const firstName = targetNode?._data?.firstName || ''
const alpha = baseAlpha * labelAlpha
renvoiPills.push(
{ text: 'Voir les parents', cx: targetPos.cx, cy: childPillY, target: { targetX: sourcePos.cx, targetY: sourcePos.cy }, alpha },
{ text: firstName ? `Voir ${firstName}` : 'Voir l’enfant', cx: sourcePos.cx, cy: parentPillY, target: { targetX: targetPos.cx, targetY: targetPos.cy }, alpha },
)
}
// Après drawNodes : les pastilles passent au-dessus des portraits et des souvenirs
export function drawRenvoiPills(ctx) {
renvoiPills.forEach(p => drawRenvoiPill(ctx, p))
renvoiPills.length = 0
}
// ============================================================
// Filiations (Bézier union → enfant)
// ============================================================
export function drawFiliations(ctx, edges, posMap, nodeMap, nodeRandomData, entrance, entranceActive, elapsed, view = null) {
renvoiHitAreas.length = 0
renvoiPills.length = 0
if (!edges) return
edges.forEach(edge => {
@@ -172,32 +266,30 @@ export function drawFiliations(ctx, edges, posMap, nodeMap, nodeRandomData, entr
}
const targetNode = nodeMap.get(targetId)
const rdChild = nodeRandomData.get(targetId)
const pType = edge._parentageType || 'biologique'
if (pType === 'adoption') {
ctx.setLineDash([8, 5])
ctx.strokeStyle = COLORS.link
ctx.strokeStyle = FIL.color
} else if (pType === 'inconnu') {
ctx.setLineDash([3, 3])
ctx.strokeStyle = COLORS.linkUnknown
} else {
ctx.setLineDash([])
ctx.strokeStyle = COLORS.link
ctx.strokeStyle = FIL.color
}
ctx.lineWidth = 0.5
ctx.lineWidth = FIL.width
ctx.lineCap = 'round'
ctx.globalAlpha = Math.min(1, edgeProgress * 1.5)
const childR = targetNode?._type === 'unknown' ? UNKNOWN_R : PERSON_R
const { sx, sy, ex, ey, cp1x, cp1y, cp2x, cp2y } = computeFiliationCurvePoints(
sourcePos,
targetPos,
childR,
rdChild?.anchorAngleOffset || 0,
)
drawPartialBezier(ctx, sx, sy, cp1x, cp1y, cp2x, cp2y, ex, ey, edgeProgress)
const childR = nodeRadius(targetNode)
if (edge._renvoi) {
drawRenvoi(ctx, edge, sourcePos, targetPos, targetNode, childR, view)
ctx.globalAlpha = 1
ctx.setLineDash([])
return
}
traceFiliation(ctx, sourceId, sourcePos, targetPos, childR, edgeProgress)
ctx.globalAlpha = 1
ctx.setLineDash([])
})
@@ -233,13 +325,13 @@ export function drawPathHighlight(ctx, {
const p1Node = nodeMap.get(p1Key)
const p2Node = nodeMap.get(p2Key)
const p1R = p1Node?._type === 'unknown' ? UNKNOWN_R : PERSON_R
const p2R = p2Node?._type === 'unknown' ? UNKNOWN_R : PERSON_R
const p1R = nodeRadius(p1Node)
const p2R = nodeRadius(p2Node)
const p1PosKeyed = { ...p1Pos, _key: p1Key }
const p2PosKeyed = { ...p2Pos, _key: p2Key }
const { sLx, sLy, sRx, sRy, jx, jy } = computeCouplePoints(
p1PosKeyed, p2PosKeyed, unionPos, p1R, p2R, nodeRandomData
p1PosKeyed, p2PosKeyed, unionPos, p1R, p2R, nodeRandomData, nodeMap.get(elkId)?._compact
)
ctx.strokeStyle = `rgba(147, 64, 42, ${0.55 + 0.25 * hp})`
@@ -266,22 +358,14 @@ export function drawPathHighlight(ctx, {
if (!sourcePos || !targetPos) return
const targetNode = nodeMap.get(edge.targets[0])
const rdChild = nodeRandomData.get(edge.targets[0])
const childR = targetNode?._type === 'unknown' ? UNKNOWN_R : PERSON_R
const { sx, sy, ex, ey, cp1x, cp1y, cp2x, cp2y } = computeFiliationCurvePoints(
sourcePos,
targetPos,
childR,
rdChild?.anchorAngleOffset || 0,
)
const childR = nodeRadius(targetNode)
ctx.strokeStyle = `rgba(147, 64, 42, ${0.55 + 0.25 * hp})`
ctx.lineWidth = 1.5 + 1.5 * hp
ctx.setLineDash([])
ctx.lineCap = 'round'
ctx.globalAlpha = 1
drawPartialBezier(ctx, sx, sy, cp1x, cp1y, cp2x, cp2y, ex, ey, hp)
traceFiliation(ctx, edge.sources[0], sourcePos, targetPos, childR, hp)
})
}
@@ -293,8 +377,9 @@ export function drawPathHighlight(ctx, {
if (hp < 0.01) continue
const pos = posMap.get(nodeId)
if (!pos) continue
const pathGlowR = PERSON_R + 10
const pathGlow = ctx.createRadialGradient(pos.cx, pos.cy, PERSON_R * 0.7, pos.cx, pos.cy, pathGlowR)
const r = nodeRadius(nodeMap.get(nodeId))
const pathGlowR = r + 10
const pathGlow = ctx.createRadialGradient(pos.cx, pos.cy, r * 0.7, pos.cx, pos.cy, pathGlowR)
pathGlow.addColorStop(0, `rgba(147, 64, 42, ${0.12 * hp})`)
pathGlow.addColorStop(1, 'rgba(147, 64, 42, 0)')
ctx.fillStyle = pathGlow
@@ -405,17 +490,19 @@ function drawPersonNode(ctx, node, pos, nodeProgress, {
ctx.restore()
}
// --- Hover scale + entrance scale ---
// --- Hover scale + entrance scale (conjoint isolé : en petit) ---
const k = node._compact ? COMPACT_SCALE : 1
const R = PERSON_R * k
const hs = hoverScales.get(node.id) || 0
const entranceScale = 0.3 + nodeProgress * 0.7
const personScale = entranceScale * (1 + hs * 0.1)
const personScale = entranceScale * (1 + hs * 0.1) * k
// --- Glow sélection ---
const sg = selectedGlowScales.get(node.id) || 0
if (sg > 0.001) {
const selGlowR = PERSON_R + 24 + sg * 14
const selGlowR = R + (24 + sg * 14) * k
const selAlpha = sg * 0.38 * nodeProgress
const selGlow = ctx.createRadialGradient(cx, cy, PERSON_R * 0.3, cx, cy, selGlowR)
const selGlow = ctx.createRadialGradient(cx, cy, R * 0.3, cx, cy, selGlowR)
selGlow.addColorStop(0, `rgba(210, 105, 74, ${selAlpha})`)
selGlow.addColorStop(0.5, `rgba(210, 105, 74, ${selAlpha * 0.45})`)
selGlow.addColorStop(1, 'rgba(210, 105, 74, 0)')
@@ -428,9 +515,9 @@ function drawPersonNode(ctx, node, pos, nodeProgress, {
// --- Glow recherche (jaune) ---
const srch = (searchGlowScales || new Map()).get(node.id) || 0
if (srch > 0.001) {
const searchGlowR = PERSON_R + 28 + srch * 18
const searchGlowR = R + (28 + srch * 18) * k
const searchAlpha = srch * 0.55 * nodeProgress
const searchGlow = ctx.createRadialGradient(cx, cy, PERSON_R * 0.25, cx, cy, searchGlowR)
const searchGlow = ctx.createRadialGradient(cx, cy, R * 0.25, cx, cy, searchGlowR)
searchGlow.addColorStop(0, `rgba(210, 105, 74, ${searchAlpha})`)
searchGlow.addColorStop(0.5, `rgba(210, 105, 74, ${searchAlpha * 0.55})`)
searchGlow.addColorStop(1, 'rgba(210, 105, 74, 0)')
@@ -443,9 +530,9 @@ function drawPersonNode(ctx, node, pos, nodeProgress, {
// --- Halo glow ---
if (withDetail) {
const glowR = PERSON_R + 12 + hs * 6
const glowR = R + (12 + hs * 6) * k
const glowAlpha = (person.isAlive ? 0.15 + hs * 0.1 : 0.08 + hs * 0.06) * nodeProgress
const glow = ctx.createRadialGradient(cx, cy, PERSON_R * 0.6, cx, cy, glowR)
const glow = ctx.createRadialGradient(cx, cy, R * 0.6, cx, cy, glowR)
glow.addColorStop(0, `rgba(147, 64, 42, ${glowAlpha})`)
glow.addColorStop(1, 'rgba(147, 64, 42, 0)')
ctx.fillStyle = glow
@@ -482,6 +569,8 @@ function drawPersonNode(ctx, node, pos, nodeProgress, {
ctx.globalAlpha = nodeProgress * labelAlpha
ctx.translate(cx, cy + labelOffsetY)
ctx.rotate(labelRot)
// Libellés du petit portrait : un peu réduits, pas autant que le portrait pour rester lisibles
if (node._compact) ctx.scale(0.85, 0.85)
ctx.font = '400 13px "Newsreader", Georgia, serif'
ctx.textAlign = 'center'
@@ -934,9 +1023,9 @@ export function drawNodes(ctx, layoutData, posMap, entrance, entranceActive, ela
drawPersonNode(ctx, node, pos, nodeProgress, renderState)
} else if (node._type === 'union') {
ctx.globalAlpha = nodeProgress
ctx.fillStyle = COLORS.link
ctx.fillStyle = FIL.dot
ctx.beginPath()
ctx.arc(cx, cy, 2 * nodeProgress, 0, Math.PI * 2)
ctx.arc(cx, cy, FIL.dotR * nodeProgress, 0, Math.PI * 2)
ctx.fill()
ctx.globalAlpha = 1
} else if (node._type === 'unknown') {
@@ -1,6 +1,9 @@
import { useRef, useCallback } from 'react'
import { getPersonMedias } from '../../data/mockData'
import { PERSON_R, MAX_ORBIT_MEDIAS, ORBIT_MEDIA_SIZE } from './constants'
import { MAX_ORBIT_MEDIAS, ORBIT_MEDIA_SIZE } from './constants'
import { nodeRadius, renvoiHitAreas } from './renderers'
const hitRenvoi = (x, y) => renvoiHitAreas.find(a => x >= a.x0 && x <= a.x1 && y >= a.y0 && y <= a.y1)
import { getEntranceProgress } from './utils'
const CURSOR_GRAB = 'default'
@@ -128,12 +131,13 @@ export function useGalaxyInteractions({
}
}
if (isOverClickable) break
if (Math.sqrt((pos.cx - mouseWorldPosRef.current.x) ** 2 + (pos.cy - mouseWorldPosRef.current.y) ** 2) < PERSON_R) {
if (Math.sqrt((pos.cx - mouseWorldPosRef.current.x) ** 2 + (pos.cy - mouseWorldPosRef.current.y) ** 2) < nodeRadius(node)) {
isOverClickable = true
newHoveredNode = node.id
break
}
}
if (!isOverClickable && hitRenvoi(mouseWorldPosRef.current.x, mouseWorldPosRef.current.y)) isOverClickable = true
hoveredNodeIdRef.current = newHoveredNode
hoveredMediaKeyRef.current = newHoveredMedia
@@ -265,12 +269,24 @@ export function useGalaxyInteractions({
if (ns && getEntranceProgress(now - ent.startTime, ns.startMs, ns.duration) < 0.5) continue
}
const pos = getAnimatedPos(node, now)
if (Math.sqrt((pos.cx - clickX) ** 2 + (pos.cy - clickY) ** 2) < PERSON_R) {
if (Math.sqrt((pos.cx - clickX) ** 2 + (pos.cy - clickY) ** 2) < nodeRadius(node)) {
onPersonSelect(node._data)
return
}
}
}, [canvasRef, transformRef, layoutDataRef, nodeRandomDataRef, entranceRef, getAnimatedPos, onPersonSelect, onMediaSelect, annotationHandlers])
// Renvoi : on glisse vers l'autre extrémité (parents ou enfant), sans dézoomer en dessous de la lecture des prénoms
const renvoi = hitRenvoi(clickX, clickY)
if (renvoi) {
const rect2 = canvasRef.current.getBoundingClientRect()
const scale = Math.max(t.scale, 0.8)
targetTransformRef.current = {
scale,
x: rect2.width / 2 - renvoi.targetX * scale,
y: rect2.height / 2 - renvoi.targetY * scale,
}
}
}, [canvasRef, transformRef, targetTransformRef, layoutDataRef, nodeRandomDataRef, entranceRef, getAnimatedPos, onPersonSelect, onMediaSelect, annotationHandlers])
return {
isDragging, isZooming, zoomTimeoutRef, hasDragged,