mirror of
https://github.com/IliesAllali/parenthese.git
synced 2026-11-16 00:32:04 +00:00
Placement : la fratrie suit l'ordre choisi (displayOrder)
Le placement par blocs rangeait les enfants dans l'ordre des identifiants, displayOrder n'avait donc aucun effet. Les enfants d'une union sont maintenant triés sur displayOrder, avec un tri stable : un arbre jamais réordonné garde exactement son placement. Dans l'arbre de démo, Sophie (ordre 1) repasse devant Thomas (ordre 2). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
588ac0c4e9
commit
5f968a9f22
3 files changed
+27
No files matched your search
@@ -52,6 +52,11 @@ export function computeBlockLayout(graphData = null) {
|
||||
childrenOfUnion.get(u).push(c)
|
||||
if (!parentUnionOf.has(c)) parentUnionOf.set(c, u)
|
||||
}
|
||||
// Fratrie dans l'ordre choisi par la famille (displayOrder) ; à ordre égal, l'ordre d'arrivée
|
||||
// est gardé (tri stable), donc un arbre jamais réordonné ne bouge pas
|
||||
const toOrder = (v) => (Number.isFinite(v) ? v : Number.MAX_SAFE_INTEGER)
|
||||
const edgeOrder = new Map(result.edges.map(e => [`${e.sources[0]}>${e.targets[0]}`, toOrder(e._displayOrder)]))
|
||||
for (const [u, kids] of childrenOfUnion) kids.sort((a, b) => edgeOrder.get(`${u}>${a}`) - edgeOrder.get(`${u}>${b}`))
|
||||
const hasParents = (chain) => chain.some(id => parentUnionOf.has(id))
|
||||
|
||||
const descCount = new Map()
|
||||
|
||||
@@ -39,3 +39,24 @@ describe('computeBlockLayout, conjoints isolés', () => {
|
||||
expect(children.find(n => n.id === 'p-s')._compact).toBeUndefined()
|
||||
})
|
||||
})
|
||||
|
||||
describe('computeBlockLayout, ordre de la fratrie', () => {
|
||||
const kids = ['a', 'b', 'c']
|
||||
const graphWith = (orders) => ({
|
||||
persons: ['pa', 'ma', ...kids].map(person),
|
||||
unions: [union('u1', 'pa', 'ma')],
|
||||
filiations: kids.map((k, i) => ({ ...fil(`f-${k}`, k, 'u1'), displayOrder: orders[i] })),
|
||||
})
|
||||
const order = (graph) => {
|
||||
const { children } = computeBlockLayout(graph)
|
||||
return children.filter(n => kids.includes(n._data?.id)).sort((l, r) => l.x - r.x).map(n => n._data.id)
|
||||
}
|
||||
|
||||
it('place les enfants selon displayOrder', () => {
|
||||
expect(order(graphWith([3, 1, 2]))).toEqual(['b', 'c', 'a'])
|
||||
})
|
||||
|
||||
it("garde l'ordre d'arrivée quand displayOrder est égal partout", () => {
|
||||
expect(order(graphWith([1, 1, 1]))).toEqual(['a', 'b', 'c'])
|
||||
})
|
||||
})
|
||||
@@ -524,6 +524,7 @@ export function computeLayout(graphData = null) {
|
||||
allEdges.push({
|
||||
id: `e-${f.id}`, sources: [sourceId], targets: [targetId],
|
||||
_parentageType: f.parentageType,
|
||||
_displayOrder: f.displayOrder,
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
Reference in new issue
Block a user