@@ -94,6 +94,7 @@ class App extends Component {
9494 nodeSize : { x : 200 , y : 200 } ,
9595 enableLegacyTransitions : false ,
9696 transitionDuration : 500 ,
97+ dimensions : undefined ,
9798 renderCustomNodeElement : customNodeFnMapping [ 'svg' ] . fn ,
9899 styles : {
99100 nodes : {
@@ -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 dimensions = this . treeContainer . getBoundingClientRect ( ) ;
213+ this . setState ( {
214+ dimensions : {
215+ width : dimensions . width ,
216+ height : dimensions . height ,
217+ } ,
218+ } ) ;
219+ }
220+ }
221+ }
222+
203223 setScaleExtent ( scaleExtent ) {
204224 this . setState ( { scaleExtent } ) ;
205225 }
@@ -393,6 +413,15 @@ class App extends Component {
393413 />
394414 </ div >
395415
416+ < div className = "prop-container" >
417+ < h4 className = "prop" > Center Nodes on Click</ h4 >
418+ < Switch
419+ name = "centerNodesBtn"
420+ checked = { this . state . dimensions !== undefined }
421+ onChange = { this . toggleCenterNodes }
422+ />
423+ </ div >
424+
396425 < div className = "prop-container" >
397426 < h4 className = "prop" > Collapse neighbor nodes</ h4 >
398427 < Switch
@@ -645,6 +674,7 @@ class App extends Component {
645674 onLinkMouseOut = { ( ...args ) => {
646675 console . log ( 'onLinkMouseOut' , args ) ;
647676 } }
677+ dimensions = { this . state . dimensions }
648678 />
649679 </ div >
650680 </ div >
0 commit comments