question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Adding a link targeting new node

See original GitHub issue

Hi ! First of all, thank you for this amazing project 😃

I have an issue when I try to add a new node and a new link at the same time.

buttonAddRefus() {
    //Create a new node
    const newNode = new DefaultNodeModel("Node 3","rgb(192,255,0)");
    newNode.x = 500;
    newNode.y = 100;

    //Create new link
    let newLink = new LinkModel();

    //Set source on existing port : all is fine
    let portStep = _.find(this.props.engine.diagramModel.getNodes(), {"name":"Node 2"})
    newLink.setSourcePort(portStep.ports["out-1"]);

    //Set target on new node : will generate exception
    let newPort = newNode.addPort(new DefaultPortModel(true,"out-1", 'In'));
    newLink.setTargetPort(newPort);

    //Add node and link to model
    let model = this.props.engine.diagramModel;
    model.addNode(newNode);
    model.addLink(newLink);

    //refresh
    this.props.engine.repaintCanvas()
} 

this generates this error on console : \node_modules\storm-react-diagrams\dist\main.js:1 Cannot find Node Port element with nodeID: [1985738d-ccad-41cb-ac80-293d56b79d57] and name: [out-1]

This is fine when the target node already exists. I also saw that a setTimeout before adding the link works, but… hum… 😃

How can I fix it ? Thank you 😃

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
ShiroYachacommented, Jun 8, 2019

I am dragging a new link to an empty spot and release to create a node then connect the link to a port. The link is dangling at (0,0) of the node. None of the tricks worked for me (e.g. setTimeout, refresh the canvas)… the only workaround i found is to var newLink = link.clone() and then newLink.setTargetPort() then remove the old link and add the new one… no setTimeout is required… hope this help you…

also might be a workaround for https://github.com/projectstorm/react-diagrams/issues/223

0reactions
PikkaPikkachucommented, Jun 17, 2019

Thanks @ShiroYacha !

Read more comments on GitHub >

github_iconTop Results From Across the Web

Add relationship type—ArcGIS Pro | Documentation
Add a relationship type to the link chart. The link chart will draw links between nodes based on the relationship types.
Read more >
How do I add target="_blank" to a link within a specified div?
Show activity on this post. In this case, the JavaScript would add target="_blank" to all links within the div link_other . How can...
Read more >
Inserting a node on an existing link... automatically - GoJS
Now, I want to drag and drop C over the existing "A-to-B" link, ... Link to the Node, add a new link from...
Read more >
Add links to map nodes - MindMup
How to add links to nodes, and cross-link maps. ... You can click on the link widget and the browser will open the...
Read more >
Add target attribute to LinkNode · Issue #2671 · facebook/lexical
It would be great to support target for LinkNode attribute. It is currently impossible to specify if a link should be open in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found