@@ -48,6 +48,7 @@ import {
4848import { Visualization } from './visualization/Visualization'
4949import { WheelZoomInfoOverlay } from './WheelZoomInfoOverlay'
5050import { StyledSvgWrapper , StyledZoomButton , StyledZoomHolder } from './styled'
51+ import { ResizeObserver } from '@juggle/resize-observer'
5152
5253export type GraphProps = {
5354 isFullscreen : boolean
@@ -80,6 +81,8 @@ type GraphState = {
8081
8182export class Graph extends React . Component < GraphProps , GraphState > {
8283 svgElement : React . RefObject < SVGSVGElement >
84+ wrapperElement : React . RefObject < HTMLDivElement >
85+ wrapperResizeObserver : ResizeObserver
8386 visualization : Visualization | null = null
8487
8588 constructor ( props : GraphProps ) {
@@ -90,6 +93,14 @@ export class Graph extends React.Component<GraphProps, GraphState> {
9093 displayingWheelZoomInfoMessage : false
9194 }
9295 this . svgElement = React . createRef ( )
96+ this . wrapperElement = React . createRef ( )
97+
98+ this . wrapperResizeObserver = new ResizeObserver ( ( ) => {
99+ this . visualization ?. resize (
100+ this . props . isFullscreen ,
101+ ! ! this . props . wheelZoomRequiresModKey
102+ )
103+ } )
93104 }
94105
95106 componentDidMount ( ) : void {
@@ -170,6 +181,8 @@ export class Graph extends React.Component<GraphProps, GraphState> {
170181 if ( assignVisElement ) {
171182 assignVisElement ( this . svgElement . current , this . visualization )
172183 }
184+
185+ this . wrapperResizeObserver . observe ( this . svgElement . current )
173186 }
174187
175188 componentDidUpdate ( prevProps : GraphProps ) : void {
@@ -185,6 +198,10 @@ export class Graph extends React.Component<GraphProps, GraphState> {
185198 }
186199 }
187200
201+ componentWillUnmount ( ) : void {
202+ this . wrapperResizeObserver . disconnect ( )
203+ }
204+
188205 handleZoomEvent = ( limitsReached : ZoomLimitsReached ) : void => {
189206 if (
190207 limitsReached . zoomInLimitReached !== this . state . zoomInLimitReached ||
@@ -236,7 +253,7 @@ export class Graph extends React.Component<GraphProps, GraphState> {
236253 displayingWheelZoomInfoMessage
237254 } = this . state
238255 return (
239- < StyledSvgWrapper >
256+ < StyledSvgWrapper ref = { this . wrapperElement } >
240257 < svg className = "neod3viz" ref = { this . svgElement } />
241258 < StyledZoomHolder offset = { offset } isFullscreen = { isFullscreen } >
242259 < StyledZoomButton
0 commit comments