@@ -21,9 +21,6 @@ type TreeState = {
2121 isInitialRenderForDataset : boolean ;
2222} ;
2323
24- const rd3tSvgClassName = 'rd3t-svg' ;
25- const rd3tGClassName = 'rd3t-g' ;
26-
2724class Tree extends React . Component < TreeProps , TreeState > {
2825 static defaultProps : Partial < TreeProps > = {
2926 onNodeClick : undefined ,
@@ -68,6 +65,9 @@ class Tree extends React.Component<TreeProps, TreeState> {
6865 isTransitioning : false ,
6966 } ;
7067
68+ svgInstanceRef = `rd3t-svg-${ uuidv4 ( ) } ` ;
69+ gInstanceRef = `rd3t-g-${ uuidv4 ( ) } ` ;
70+
7171 static getDerivedStateFromProps ( nextProps : TreeProps , prevState : TreeState ) {
7272 let derivedState : Partial < TreeState > = null ;
7373 // Clone new data & assign internal properties if `data` object reference changed.
@@ -138,8 +138,8 @@ class Tree extends React.Component<TreeProps, TreeState> {
138138 */
139139 bindZoomListener ( props : TreeProps ) {
140140 const { zoomable, scaleExtent, translate, zoom, onUpdate } = props ;
141- const svg = select ( `.${ rd3tSvgClassName } ` ) ;
142- const g = select ( `.${ rd3tGClassName } ` ) ;
141+ const svg = select ( `.${ this . svgInstanceRef } ` ) ;
142+ const g = select ( `.${ this . gInstanceRef } ` ) ;
143143 if ( zoomable ) {
144144 // Sets initial offset, so that first pan and zoom does not jump back to default [0,0] coords.
145145 // @ts -ignore
@@ -481,11 +481,15 @@ class Tree extends React.Component<TreeProps, TreeState> {
481481 return (
482482 < div className = { `rd3t-tree-container ${ zoomable ? 'rd3t-grabbable' : undefined } ` } >
483483 < style > { globalCss } </ style >
484- < svg className = { [ rd3tSvgClassName , svgClassName ] . join ( ' ' ) } width = "100%" height = "100%" >
484+ < svg
485+ className = { `rd3t-svg ${ this . svgInstanceRef } ${ svgClassName } ` }
486+ width = "100%"
487+ height = "100%"
488+ >
485489 < TransitionGroupWrapper
486490 enableLegacyTransitions = { enableLegacyTransitions }
487491 component = "g"
488- className = { rd3tGClassName }
492+ className = { `rd3t-g ${ this . gInstanceRef } ` }
489493 transform = { `translate(${ translate . x } ,${ translate . y } ) scale(${ scale } )` }
490494 >
491495 { links . map ( ( linkData , i ) => {
0 commit comments