Center top-level location boxes on same vertical axis
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -137,7 +137,12 @@
|
|||||||
const node = cy.getElementById(locId);
|
const node = cy.getElementById(locId);
|
||||||
if (node.empty()) return null;
|
if (node.empty()) return null;
|
||||||
const bb = node.boundingBox();
|
const bb = node.boundingBox();
|
||||||
return { id: locId, bb: bb, height: bb.y2 - bb.y1 };
|
return {
|
||||||
|
id: locId,
|
||||||
|
bb: bb,
|
||||||
|
height: bb.y2 - bb.y1,
|
||||||
|
centerX: (bb.x1 + bb.x2) / 2
|
||||||
|
};
|
||||||
}).filter(b => b !== null);
|
}).filter(b => b !== null);
|
||||||
|
|
||||||
if (boxes.length < 2) return;
|
if (boxes.length < 2) return;
|
||||||
@@ -145,9 +150,17 @@
|
|||||||
const minY = Math.min(...boxes.map(b => b.bb.y1));
|
const minY = Math.min(...boxes.map(b => b.bb.y1));
|
||||||
const gap = 50;
|
const gap = 50;
|
||||||
|
|
||||||
|
// Find the widest box and use its center as the target
|
||||||
|
const widest = boxes.reduce((a, b) => (b.bb.x2 - b.bb.x1) > (a.bb.x2 - a.bb.x1) ? b : a);
|
||||||
|
const targetCenterX = widest.centerX;
|
||||||
|
|
||||||
let targetY = minY;
|
let targetY = minY;
|
||||||
const targets = boxes.map(box => {
|
const targets = boxes.map(box => {
|
||||||
const result = { id: box.id, deltaY: targetY - box.bb.y1 };
|
const result = {
|
||||||
|
id: box.id,
|
||||||
|
deltaX: targetCenterX - box.centerX,
|
||||||
|
deltaY: targetY - box.bb.y1
|
||||||
|
};
|
||||||
targetY += box.height + gap;
|
targetY += box.height + gap;
|
||||||
return result;
|
return result;
|
||||||
});
|
});
|
||||||
@@ -156,7 +169,7 @@
|
|||||||
const node = cy.getElementById(target.id);
|
const node = cy.getElementById(target.id);
|
||||||
node.descendants().filter(n => !n.isParent()).forEach(n => {
|
node.descendants().filter(n => !n.isParent()).forEach(n => {
|
||||||
const pos = n.position();
|
const pos = n.position();
|
||||||
n.position({ x: pos.x, y: pos.y + target.deltaY });
|
n.position({ x: pos.x + target.deltaX, y: pos.y + target.deltaY });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user