@@ -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 ,
@@ -125,6 +126,7 @@ class App extends Component {
125126 this . handleFloatChange = this . handleFloatChange . bind ( this ) ;
126127 this . toggleCollapsible = this . toggleCollapsible . bind ( this ) ;
127128 this . toggleZoomable = this . toggleZoomable . bind ( this ) ;
129+ this . toggleCenterNodes = this . toggleCenterNodes . bind ( this ) ;
128130 this . setScaleExtent = this . setScaleExtent . bind ( this ) ;
129131 this . setSeparation = this . setSeparation . bind ( this ) ;
130132 this . setNodeSize = this . setNodeSize . bind ( this ) ;
@@ -200,6 +202,24 @@ class App extends Component {
200202 this . setState ( prevState => ( { zoomable : ! prevState . zoomable } ) ) ;
201203 }
202204
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+
203223 setScaleExtent ( scaleExtent ) {
204224 this . setState ( { scaleExtent } ) ;
205225 }
@@ -393,6 +413,17 @@ class App extends Component {
393413 />
394414 </ div >
395415
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+
396427 < div className = "prop-container" >
397428 < h4 className = "prop" > Collapse neighbor nodes</ h4 >
398429 < Switch
@@ -611,6 +642,7 @@ class App extends Component {
611642 rootNodeClassName = "demo-node"
612643 branchNodeClassName = "demo-node"
613644 orientation = { this . state . orientation }
645+ dimensions = { this . state . dimensions }
614646 translate = { { x : this . state . translateX , y : this . state . translateY } }
615647 pathFunc = { this . state . pathFunc }
616648 collapsible = { this . state . collapsible }
0 commit comments