Files
lan-manager/web/node_modules/@antv/hierarchy/lib/layout/separate-root.js
openclaw 0a5f6a8047 Initial commit: Lan-manager project code
- Go backend (server/)
- Frontend (web/, server/static/)
- Database and deployment files
- Scripts and docs

Co-Authored-By: 狸花猫/Claude-Qwen3.6-Plus 🐾
2026-04-20 00:52:58 +08:00

39 lines
1.0 KiB
JavaScript

var hierarchy = require('./hierarchy');
module.exports = function (root, options) {
// separate into left and right trees
var left = hierarchy(root.data, options, true); // root only
var right = hierarchy(root.data, options, true); // root only
// automatically
var treeSize = root.children.length;
var rightTreeSize = Math.round(treeSize / 2);
// separate left and right tree by meta data
var getSide = options.getSide || function (child, index) {
if (index < rightTreeSize) {
return 'right';
}
return 'left';
};
for (var i = 0; i < treeSize; i++) {
var child = root.children[i];
var side = getSide(child, i);
if (side === 'right') {
right.children.push(child);
} else {
left.children.push(child);
}
}
left.eachNode(function (node) {
if (!node.isRoot()) {
node.side = 'left';
}
});
right.eachNode(function (node) {
if (!node.isRoot()) {
node.side = 'right';
}
});
return {
left: left,
right: right
};
};