react-diagrams icon indicating copy to clipboard operation
react-diagrams copied to clipboard

Update links after re-positioning node

Open bknill opened this issue 2 years ago • 1 comments

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?

bknill avatar Aug 17 '21 01:08 bknill

Maybe this helps?

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

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

donkeyDau avatar Sep 28 '21 08:09 donkeyDau