Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ const NODE_SIZE = 16;
const PEM = 5;
const ctx = document.getElementById('id-of-canvas-element').getContext('2d');
const rootNode = Hierarchy.compactBox(root, {
direction: 'H', // H / V / LR / RL / TB / BT
direction: 'H', // H / V / LR / RL / TB / BT,
forceCompact: true, // 开启强制紧凑,节点会以最小宽度和最小高度排列,不论节点在布局过程中是否重叠都会执行子树移动的行为
getId(d) {
return d.id;
},
Expand Down
8 changes: 5 additions & 3 deletions src/layout/non-layered-tidy.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ function layer(node, isHorizontal, d = 0) {

module.exports = (root, options = {}) => {
const isHorizontal = options.isHorizontal;
const forceCompact = options.forceCompact;
function firstWalk(t) {
if (t.cs === 0) {
setExtremes(t);
Expand All @@ -103,7 +104,7 @@ module.exports = (root, options = {}) => {
for (let i = 1; i < t.cs; ++i) {
firstWalk(t.c[i]);
const min = bottom(t.c[i].er);
separate(t, i, ih);
separate(t, i, ih, forceCompact);
ih = updateIYL(min, i, ih);
}
positionRoot(t);
Expand All @@ -123,15 +124,16 @@ module.exports = (root, options = {}) => {
}
}

function separate(t, i, ih) {
function separate(t, i, ih, forceCompact) {
let sr = t.c[i - 1];
let mssr = sr.mod;
let cl = t.c[i];
let mscl = cl.mod;
while (sr !== null && cl !== null) {
if (bottom(sr) > ih.low) ih = ih.nxt;
const dist = (mssr + sr.prelim + sr.w) - (mscl + cl.prelim);
if (dist > 0) {
// if forceCompact, the moveSubTree method is executed no matter what
if (forceCompact || dist > 0) {
mscl += dist;
moveSubtree(t, i, ih.index, dist);
}
Expand Down