Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't remove force with TypeScript interface for d3Force #516

Closed
julianZeitler opened this issue May 18, 2024 · 1 comment
Closed

Can't remove force with TypeScript interface for d3Force #516

julianZeitler opened this issue May 18, 2024 · 1 comment

Comments

@julianZeitler
Copy link

julianZeitler commented May 18, 2024

I want to remove the centering force like shown below using TypeScript:

function Component({}) {
  const fgRef = useRef<ForceGraphMethods>();

  useEffect(() => {
    if (fgRef.current) {
      const fg = fgRef.current;
      fg.d3Force("center", null);
    }
  }, [])

  return (
    <div>
      <ForceGraph2D ref={fgRef} graphData={exampleData} width={size?.width} height={size?.height}/>
    </div>
  );
};

The interface exposed for the d3Force method does not allow the second argument to be null.
Interface exposed in src/packages/react-force-graph-2d/index.d.ts (lines 136-138):

// Force engine (d3-force) configuration
d3Force(forceName: 'link' | 'charge' | 'center' | string): ForceFn<NodeObject<NodeType>> | undefined;
d3Force(forceName: 'link' | 'charge' | 'center' | string, forceFn: ForceFn<NodeObject<NodeType>>): ForceGraphKapsuleInstance;

Thank you very much!

@vasturiano
Copy link
Owner

Thanks for flagging this @julianZeitler. 👍

Indeed the types weren't allowing for the null value to be used. This is now fixed in the latest version, so you should be able to proceed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants