@@ -81,6 +81,7 @@ class App extends Component {
81
81
data : orgChartJson ,
82
82
totalNodeCount : countNodes ( 0 , Array . isArray ( orgChartJson ) ? orgChartJson [ 0 ] : orgChartJson ) ,
83
83
orientation : 'horizontal' ,
84
+ dimensions : undefined ,
84
85
translateX : 200 ,
85
86
translateY : 300 ,
86
87
collapsible : true ,
@@ -125,6 +126,7 @@ class App extends Component {
125
126
this . handleFloatChange = this . handleFloatChange . bind ( this ) ;
126
127
this . toggleCollapsible = this . toggleCollapsible . bind ( this ) ;
127
128
this . toggleZoomable = this . toggleZoomable . bind ( this ) ;
129
+ this . toggleCenterNodes = this . toggleCenterNodes . bind ( this ) ;
128
130
this . setScaleExtent = this . setScaleExtent . bind ( this ) ;
129
131
this . setSeparation = this . setSeparation . bind ( this ) ;
130
132
this . setNodeSize = this . setNodeSize . bind ( this ) ;
@@ -200,6 +202,24 @@ class App extends Component {
200
202
this . setState ( prevState => ( { zoomable : ! prevState . zoomable } ) ) ;
201
203
}
202
204
205
+ toggleCenterNodes ( ) {
206
+ if ( this . state . dimensions !== undefined ) {
207
+ this . setState ( {
208
+ dimensions : undefined ,
209
+ } ) ;
210
+ } else {
211
+ if ( this . treeContainer ) {
212
+ const { width, height } = this . treeContainer . getBoundingClientRect ( ) ;
213
+ this . setState ( {
214
+ dimensions : {
215
+ width,
216
+ height,
217
+ } ,
218
+ } ) ;
219
+ }
220
+ }
221
+ }
222
+
203
223
setScaleExtent ( scaleExtent ) {
204
224
this . setState ( { scaleExtent } ) ;
205
225
}
@@ -393,6 +413,17 @@ class App extends Component {
393
413
/>
394
414
</ div >
395
415
416
+ < div className = "prop-container" >
417
+ < h4 className = "prop" >
418
+ Center Nodes on Click (via < code > dimensions</ code > prop)
419
+ </ h4 >
420
+ < Switch
421
+ name = "centerNodesBtn"
422
+ checked = { this . state . dimensions !== undefined }
423
+ onChange = { this . toggleCenterNodes }
424
+ />
425
+ </ div >
426
+
396
427
< div className = "prop-container" >
397
428
< h4 className = "prop" > Collapse neighbor nodes</ h4 >
398
429
< Switch
@@ -611,6 +642,7 @@ class App extends Component {
611
642
rootNodeClassName = "demo-node"
612
643
branchNodeClassName = "demo-node"
613
644
orientation = { this . state . orientation }
645
+ dimensions = { this . state . dimensions }
614
646
translate = { { x : this . state . translateX , y : this . state . translateY } }
615
647
pathFunc = { this . state . pathFunc }
616
648
collapsible = { this . state . collapsible }
0 commit comments