crubier / react-graph-vis

A react component to render nice graphs using vis.js
http://crubier.github.io/react-graph-vis/
MIT License
958 stars 171 forks source link

Resizing graph using network.fit()? #37

Closed lorinerosenberg closed 3 years ago

lorinerosenberg commented 7 years ago

In vis.js I would resize my graphs on each render using network.fit(). How would I call the .fit function using the react-graph-vis component or are there any alternate ways of doing this?

Thanks!

MrTsunami commented 7 years ago

I had the same problem and could figure it out. So here is my solution: The Graph component has a prop that gives you the actual network as a callback. <Graph graph={this.state.graph} options={options} events={events} getNetwork={this.setNetworkInstance.bind(this) }/>

So, just simply set it as a state of your component and now you can acces these funktions directly. this.state.network.selectNodes(toSelect, true);

willb335 commented 6 years ago

Here is an es6 demo

  state = { network: {} };

<Graph
        getNetwork={network =>
          this.setState({network }) }
      />
crubier commented 3 years ago

Indeed it works like this, thanks!