File tree Expand file tree Collapse file tree 3 files changed +24
-2
lines changed
Expand file tree Collapse file tree 3 files changed +24
-2
lines changed Original file line number Diff line number Diff line change @@ -82,6 +82,7 @@ class App extends Component {
8282 totalNodeCount : countNodes ( 0 , Array . isArray ( orgChartJson ) ? orgChartJson [ 0 ] : orgChartJson ) ,
8383 orientation : 'horizontal' ,
8484 dimensions : undefined ,
85+ centeringTransitionDuration : 800 ,
8586 translateX : 200 ,
8687 translateY : 300 ,
8788 collapsible : true ,
@@ -623,6 +624,18 @@ class App extends Component {
623624 onChange = { this . handleChange }
624625 />
625626 </ div >
627+ < div className = "prop-container" >
628+ < label className = "prop" htmlFor = "centeringTransitionDuration" >
629+ Centering Transition Duration
630+ </ label >
631+ < input
632+ className = "form-control"
633+ name = "centeringTransitionDuration"
634+ type = "number"
635+ value = { this . state . centeringTransitionDuration }
636+ onChange = { this . handleChange }
637+ />
638+ </ div >
626639 </ div >
627640 </ div >
628641
@@ -643,6 +656,7 @@ class App extends Component {
643656 branchNodeClassName = "demo-node"
644657 orientation = { this . state . orientation }
645658 dimensions = { this . state . dimensions }
659+ centeringTransitionDuration = { this . state . centeringTransitionDuration }
646660 translate = { { x : this . state . translateX , y : this . state . translateY } }
647661 pathFunc = { this . state . pathFunc }
648662 collapsible = { this . state . collapsible }
Original file line number Diff line number Diff line change @@ -52,6 +52,7 @@ class Tree extends React.Component<TreeProps, TreeState> {
5252 enableLegacyTransitions : false ,
5353 hasInteractiveNodes : false ,
5454 dimensions : undefined ,
55+ centeringTransitionDuration : 800 ,
5556 } ;
5657
5758 state : TreeState = {
@@ -391,7 +392,7 @@ class Tree extends React.Component<TreeProps, TreeState> {
391392 * Link: http://bl.ocks.org/robschmuecker/7880033
392393 */
393394 centerNode = ( hierarchyPointNode : HierarchyPointNode < TreeNodeDatum > ) => {
394- const { dimensions, orientation, zoom } = this . props ;
395+ const { dimensions, orientation, zoom, centeringTransitionDuration } = this . props ;
395396 if ( dimensions ) {
396397 const g = select ( `.${ this . gInstanceRef } ` ) ;
397398 const svg = select ( `.${ this . svgInstanceRef } ` ) ;
@@ -410,7 +411,7 @@ class Tree extends React.Component<TreeProps, TreeState> {
410411 }
411412 //@ts -ignore
412413 g . transition ( )
413- . duration ( 800 )
414+ . duration ( centeringTransitionDuration )
414415 . attr ( 'transform' , 'translate(' + x + ',' + y + ')scale(' + scale + ')' ) ;
415416 // Sets the viewport to the new center so that it does not jump back to original
416417 // coordinates when dragged/zoomed
Original file line number Diff line number Diff line change @@ -133,6 +133,13 @@ export interface TreeProps {
133133 height : number ;
134134 } ;
135135
136+ /**
137+ * Sets the time (in milliseconds) for the transition to center a node once clicked.
138+ *
139+ * {@link Tree.defaultProps.centeringTransitionDuration | Default value}
140+ */
141+ centeringTransitionDuration ?: number ;
142+
136143 /**
137144 * The draw function (or `d`) used to render `path`/`link` elements. Accepts a predefined
138145 * `PathFunctionOption` or a user-defined `PathFunction`.
You can’t perform that action at this time.
0 commit comments