Skip to content

Commit 460fd5a

Browse files
committed
style: minor code style and docs tweaks (#384)
1 parent c451295 commit 460fd5a

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

demo/src/App.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ class App extends Component {
8181
data: orgChartJson,
8282
totalNodeCount: countNodes(0, Array.isArray(orgChartJson) ? orgChartJson[0] : orgChartJson),
8383
orientation: 'horizontal',
84+
dimensions: undefined,
8485
translateX: 200,
8586
translateY: 300,
8687
collapsible: true,
@@ -94,7 +95,6 @@ class App extends Component {
9495
nodeSize: { x: 200, y: 200 },
9596
enableLegacyTransitions: false,
9697
transitionDuration: 500,
97-
dimensions: undefined,
9898
renderCustomNodeElement: customNodeFnMapping['svg'].fn,
9999
styles: {
100100
nodes: {
@@ -209,11 +209,11 @@ class App extends Component {
209209
});
210210
} else {
211211
if (this.treeContainer) {
212-
const dimensions = this.treeContainer.getBoundingClientRect();
212+
const { width, height } = this.treeContainer.getBoundingClientRect();
213213
this.setState({
214214
dimensions: {
215-
width: dimensions.width,
216-
height: dimensions.height,
215+
width,
216+
height,
217217
},
218218
});
219219
}
@@ -414,7 +414,9 @@ class App extends Component {
414414
</div>
415415

416416
<div className="prop-container">
417-
<h4 className="prop">Center Nodes on Click</h4>
417+
<h4 className="prop">
418+
Center Nodes on Click (via <code>dimensions</code> prop)
419+
</h4>
418420
<Switch
419421
name="centerNodesBtn"
420422
checked={this.state.dimensions !== undefined}
@@ -640,6 +642,7 @@ class App extends Component {
640642
rootNodeClassName="demo-node"
641643
branchNodeClassName="demo-node"
642644
orientation={this.state.orientation}
645+
dimensions={this.state.dimensions}
643646
translate={{ x: this.state.translateX, y: this.state.translateY }}
644647
pathFunc={this.state.pathFunc}
645648
collapsible={this.state.collapsible}
@@ -674,7 +677,6 @@ class App extends Component {
674677
onLinkMouseOut={(...args) => {
675678
console.log('onLinkMouseOut', args);
676679
}}
677-
dimensions={this.state.dimensions}
678680
/>
679681
</div>
680682
</div>

src/Tree/index.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,8 +400,7 @@ class Tree extends React.Component<TreeProps, TreeState> {
400400
let x: number;
401401
let y: number;
402402
// if the orientation is horizontal, calculate the variables inverted (x->y, y->x)
403-
if (this.props.orientation === 'horizontal') {
404-
//The width and height must also be added inverted to the x and y as well.
403+
if (orientation === 'horizontal') {
405404
y = -hierarchyPointNode.x * scale + dimensions.height / 2;
406405
x = -hierarchyPointNode.y * scale + dimensions.width / 2;
407406
} else {

0 commit comments

Comments
 (0)