@@ -385,29 +385,28 @@ class Tree extends React.Component<TreeProps, TreeState> {
385385
386386 /**
387387 * Takes a hierarchy point node and centers the node on the screen
388- * if the dimensions parameter is passed to the tree .
388+ * if the dimensions parameter is passed to `Tree` .
389389 *
390390 * This code is adapted from Rob Schmuecker's centerNode method.
391- * Link: http://www.robschmuecker.com/d3-js-drag-and-drop-zoomable-tree/
392- *
393- * @param hierarchyPointNode
391+ * Link: http://bl.ocks.org/robschmuecker/7880033
394392 */
395393 centerNode = ( hierarchyPointNode : HierarchyPointNode < TreeNodeDatum > ) => {
396- // if the dimensions are given
397- if ( this . props . dimensions ) {
394+ const { dimensions, orientation , zoom } = this . props ;
395+ if ( dimensions ) {
398396 const g = select ( `.${ this . gInstanceRef } ` ) ;
399397 const svg = select ( `.${ this . svgInstanceRef } ` ) ;
400398 const scale = this . state . d3 . scale ;
401399
402- let x , y ;
400+ let x : number ;
401+ let y : number ;
403402 // if the orientation is horizontal, calculate the variables inverted (x->y, y->x)
404- if ( this . props . orientation === 'horizontal' ) {
405- y = - hierarchyPointNode . x * scale + this . props . dimensions . width / 2 ;
406- x = - hierarchyPointNode . y * scale + this . props . dimensions . height / 2 ;
403+ if ( orientation === 'horizontal' ) {
404+ y = - hierarchyPointNode . x * scale + dimensions . width / 2 ;
405+ x = - hierarchyPointNode . y * scale + dimensions . height / 2 ;
407406 } else {
408407 // else, calculate the variables normally (x->x, y->y)
409- x = - hierarchyPointNode . x * scale + this . props . dimensions . width / 2 ;
410- y = - hierarchyPointNode . y * scale + this . props . dimensions . height / 2 ;
408+ x = - hierarchyPointNode . x * scale + dimensions . width / 2 ;
409+ y = - hierarchyPointNode . y * scale + dimensions . height / 2 ;
411410 }
412411 //@ts -ignore
413412 g . transition ( )
@@ -416,7 +415,7 @@ class Tree extends React.Component<TreeProps, TreeState> {
416415 // Sets the viewport to the new center so that it does not jump back to original
417416 // coordinates when dragged/zoomed
418417 //@ts -ignore
419- svg . call ( d3zoom ( ) . transform , zoomIdentity . translate ( x , y ) . scale ( this . props . zoom ) ) ;
418+ svg . call ( d3zoom ( ) . transform , zoomIdentity . translate ( x , y ) . scale ( zoom ) ) ;
420419 }
421420 } ;
422421
@@ -500,7 +499,6 @@ class Tree extends React.Component<TreeProps, TreeState> {
500499 orientation,
501500 pathFunc,
502501 transitionDuration,
503- zoomable,
504502 nodeSize,
505503 depthFactor,
506504 initialDepth,
0 commit comments