projectstorm / react-diagrams

a super simple, no-nonsense diagramming library written in react that just works
https://projectstorm.cloud/react-diagrams
MIT License
8.51k stars 1.17k forks source link

Update links after re-positioning node #878

Open bknill opened 2 years ago

bknill commented 2 years ago

Hi,

I'm trying to do something similar to this https://github.com/projectstorm/react-diagrams/issues/107

However the answer is 4 years old and doesn't appear to be valid anymore.

I'm moving nodes via a websocket update,

        node.getPosition().x = position.x
        node.getPosition().y = position.y

I'm trying to update the links after moving the node.

I've tried removing them

        Object.values(node.getPorts()).map((port:PortModel) => 
            Object.values(port.getLinks()).map((link:LinkModel) => 
                this.diagramModel.removeLink(link)))

And then re-adding them but they're still going to the old port positions when I repaint.

How can I get the engine to re-draw the links?

donkeyDau commented 2 years ago

Maybe this helps?

import { PathFindingLinkFactory } from '@projectstorm/react-diagrams';

const reroute = (engine) => {
  engine
    .getLinkFactories()
    .getFactory(PathFindingLinkFactory.NAME)
    .calculateRoutingMatrix();
};