Skip to content

Commit

Permalink
feat: Indented layoutCfg.indent support function
Browse files Browse the repository at this point in the history
We can set node's horizontal offset dynamically with function,
which allow user to create custom layout.

Closes antvis/G6#3081
  • Loading branch information
powellpeng committed Aug 10, 2021
1 parent 08de5ca commit 0fa41e5
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/layout/indented.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
function positionNode(node, previousNode, dx, dropCap) {
function positionNode(node, previousNode, indent, dropCap) {
// caculate the node's horizontal offset DX, dx's type might be number or function
const DX = typeof dx === 'function' ? dx(node) : dx * node.depth;
const displacementX = typeof indent === 'function' ? indent(node) : indent * node.depth;

if (!dropCap) {
try {
if (node.id === node.parent.children[0].id) {
node.x += DX;
node.x += displacementX;
node.y = previousNode ? previousNode.y : 0;
return;
}
Expand All @@ -14,7 +14,7 @@ function positionNode(node, previousNode, dx, dropCap) {
}
}

node.x += DX;
node.x += displacementX;
node.y = previousNode ? previousNode.y + previousNode.height : 0;
return;
}
Expand Down

0 comments on commit 0fa41e5

Please sign in to comment.