crubier / react-graph-vis

A react component to render nice graphs using vis.js

Home Page:http://crubier.github.io/react-graph-vis/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Resizing graph using network.fit()?

lorinerosenberg opened this issue · comments

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!

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);

commented

Here is an es6 demo

  state = { network: {} };

<Graph
        getNetwork={network =>
          this.setState({network }) }
      />

Indeed it works like this, thanks!