react-force-graph icon indicating copy to clipboard operation
react-force-graph copied to clipboard

Resize (width and height of viewport) not working

Open danielbakas opened this issue 2 years ago • 5 comments

Describe the bug I tried hooks and SizeMe but neither worked. I'd just like to make the graph responsive to the height and width of the viewport.

To Reproduce Steps to reproduce the behavior:

  1. Pass any combination of hooks and variables as width or height props to the ForceGraph3D component
  2. Trying to pass dependencies to useEffect
  3. More

Expected behavior For the graph to adapt to the parent container width and height.

Screenshots Here's a screenshot of the graph after resizing. It's gets cropped instead of resizing with the window. Captura de pantalla 2022-12-28 a la(s) 8 31 24 a m

Desktop (please complete the following information):

  • OS: MacOS Ventura
  • Browser Chrome
  • Version 108.0.5359.124 (official Build) (arm64)

Additional context I tried reading through the issues but none seemed to fix it.

Thanks so much @vasturiano!

danielbakas avatar Dec 28 '22 14:12 danielbakas

Did you Know how to solve this problem🤔🤔🤔

Dola97 avatar Dec 29 '22 10:12 Dola97

Not yet 🥲

danielbakas avatar Dec 30 '22 10:12 danielbakas

I've made a simple responsive example here, using SizeMe: https://codesandbox.io/s/responsive-force-graph-jlh2xb?file=/src/App.js

vasturiano avatar Dec 31 '22 00:12 vasturiano

Hmm. Not sure why it didn't work. Here's the code:

import { SizeMe } from "react-sizeme";
/* {...} */
<SizeMe>
    {({ size: { width } }) =>
        <ForceGraph3D
           /* {...} */
            width={width}
        />
    }
</SizeMe>

danielbakas avatar Jan 14 '23 21:01 danielbakas

this fixed it for me @react-hook/window-size https://www.npmjs.com/package/@react-hook/window-size

import { useWindowSize } from "@react-hook/window-size";

 const [width, height] = useWindowSize();   
 <ForceGraph3D
           /* {...} */
            width={width}
        />

extreox avatar Mar 30 '23 10:03 extreox