@@ -100,6 +100,7 @@ class Tree extends React.Component<TreeProps, TreeState> {
100100 if (
101101 ! deepEqual ( this . props . translate , prevProps . translate ) ||
102102 ! deepEqual ( this . props . scaleExtent , prevProps . scaleExtent ) ||
103+ this . props . zoomable !== prevProps . zoomable ||
103104 this . props . zoom !== prevProps . zoom ||
104105 this . props . enableLegacyTransitions !== prevProps . enableLegacyTransitions
105106 ) {
@@ -140,35 +141,34 @@ class Tree extends React.Component<TreeProps, TreeState> {
140141 const { zoomable, scaleExtent, translate, zoom, onUpdate } = props ;
141142 const svg = select ( `.${ this . svgInstanceRef } ` ) ;
142143 const g = select ( `.${ this . gInstanceRef } ` ) ;
143- if ( zoomable ) {
144- // Sets initial offset, so that first pan and zoom does not jump back to default [0,0] coords.
145- // @ts -ignore
146- svg . call ( d3zoom ( ) . transform , zoomIdentity . translate ( translate . x , translate . y ) . scale ( zoom ) ) ;
147- svg . call (
148- d3zoom ( )
149- . scaleExtent ( [ scaleExtent . min , scaleExtent . max ] )
150- // TODO: break this out into a separate zoom handler fn, rather than inlining it.
151- . on ( 'zoom' , ( ) => {
152- g . attr ( 'transform' , event . transform ) ;
153- if ( typeof onUpdate === 'function' ) {
154- // This callback is magically called not only on "zoom", but on "drag", as well,
155- // even though event.type == "zoom".
156- // Taking advantage of this and not writing a "drag" handler.
157- onUpdate ( {
158- node : null ,
159- zoom : event . transform . k ,
160- translate : { x : event . transform . x , y : event . transform . y } ,
161- } ) ;
162- // TODO: remove this? Shouldn't be mutating state keys directly.
163- this . state . d3 . scale = event . transform . k ;
164- this . state . d3 . translate = {
165- x : event . transform . x ,
166- y : event . transform . y ,
167- } ;
168- }
169- } )
170- ) ;
171- }
144+
145+ // Sets initial offset, so that first pan and zoom does not jump back to default [0,0] coords.
146+ // @ts -ignore
147+ svg . call ( d3zoom ( ) . transform , zoomIdentity . translate ( translate . x , translate . y ) . scale ( zoom ) ) ;
148+ svg . call (
149+ d3zoom ( )
150+ . scaleExtent ( zoomable ? [ scaleExtent . min , scaleExtent . max ] : [ zoom , zoom ] )
151+ // TODO: break this out into a separate zoom handler fn, rather than inlining it.
152+ . on ( 'zoom' , ( ) => {
153+ g . attr ( 'transform' , event . transform ) ;
154+ if ( typeof onUpdate === 'function' ) {
155+ // This callback is magically called not only on "zoom", but on "drag", as well,
156+ // even though event.type == "zoom".
157+ // Taking advantage of this and not writing a "drag" handler.
158+ onUpdate ( {
159+ node : null ,
160+ zoom : event . transform . k ,
161+ translate : { x : event . transform . x , y : event . transform . y } ,
162+ } ) ;
163+ // TODO: remove this? Shouldn't be mutating state keys directly.
164+ this . state . d3 . scale = event . transform . k ;
165+ this . state . d3 . translate = {
166+ x : event . transform . x ,
167+ y : event . transform . y ,
168+ } ;
169+ }
170+ } )
171+ ) ;
172172 }
173173
174174 /**
@@ -470,7 +470,7 @@ class Tree extends React.Component<TreeProps, TreeState> {
470470 } ;
471471
472472 return (
473- < div className = { ` rd3t-tree-container ${ zoomable ? ' rd3t-grabbable' : undefined } ` } >
473+ < div className = " rd3t-tree-container rd3t-grabbable" >
474474 < style > { globalCss } </ style >
475475 < svg
476476 className = { `rd3t-svg ${ this . svgInstanceRef } ${ svgClassName } ` }
0 commit comments