Skip to content

Commit adf28ba

Browse files
committed
Fixes issue with dynamic changes in depthFactor
1 parent 4f98430 commit adf28ba

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

src/Node/index.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,7 @@ export default class Node extends React.Component {
3535
}
3636

3737
setTransformOrientation(x, y) {
38-
const { orientation, nodeData, depthFactor } = this.props;
39-
40-
if (depthFactor) {
41-
y = nodeData.depth * depthFactor;
42-
}
43-
44-
return orientation === 'horizontal' ?
38+
return this.props.orientation === 'horizontal' ?
4539
`translate(${y},${x})` :
4640
`translate(${x},${y})`;
4741
}

src/Tree/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ export default class Tree extends React.Component {
192192
* @return {object} Object containing `nodes` and `links` fields.
193193
*/
194194
generateTree() {
195-
const { initialDepth } = this.props;
195+
const { initialDepth, depthFactor } = this.props;
196196
const tree = layout.tree()
197197
.nodeSize([100 + 40, 100 + 40])
198198
.separation((d) => d._children ? 1.2 : 0.9)
@@ -207,6 +207,10 @@ export default class Tree extends React.Component {
207207
this.setInitialTreeDepth(nodes, initialDepth);
208208
}
209209

210+
if (depthFactor) {
211+
nodes.forEach((node) => { node.y = node.depth * depthFactor; });
212+
}
213+
210214
return { nodes, links };
211215
}
212216

0 commit comments

Comments
 (0)