crubier / react-graph-vis

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

re-layout when updating graph labels #110

Closed reggev closed 3 years ago

reggev commented 3 years ago

If an edge has a label (in my case it shows an updating percentage) and the label changed it updates the whole layout each time there's an update I worked through the code and found that shouldComponentUpdate analyzes the changed nodes and edges but it has a bug

 if (edgesChange) {
      const edgesRemoved = differenceWith(this.props.graph.edges, nextProps.graph.edges, isEqual);
      const edgesAdded = differenceWith(nextProps.graph.edges, this.props.graph.edges, isEqual);
      const edgesChanged = differenceWith(
        differenceWith(nextProps.graph.edges, this.props.graph.edges, isEqual),
        edgesAdded
      );
      this.patchEdges({ edgesRemoved, edgesAdded, edgesChanged });
    }

edgesChanged is always empty, and an actual updated edge is always removed, and than inserted again - which causes re-layout I have fixed that with a better diffing method and opened a PR for that issue, I have tested it on my project with an updating stream of data and it works.

crubier commented 3 years ago

Nice thanks!