Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic link newly created node to an existing node (Read 1817 times)
Jessenberg
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 27
Joined: Dec 20th, 2021
link newly created node to an existing node
Feb 14th, 2022 at 8:02am
Print Post  
hi there, i was wondering how could i set the link of a newly created node onto an existing node

here is my code so far :
Code (Javascript)
Select All
nodes.forEach((node) => {
const newNode = new mf.Diagramming.SvgNode(this.state.diagram);

newNode.setAnchorPattern(pattern);
newNode.getBounds().x = boundx;
newNode.getBounds().y = boundy + 40;
this.state.diagram.addItem(newNode);

//var Link = new mf.Diagramming.DiagramLink(newNode, node);
 //this.state.diagram.addItem(Link);
}

 



the code can make a new node below already existing node but the commented part gave me an error and won't create a link between them, how do i do it?
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Online


tech.support

Posts: 3153
Joined: Oct 19th, 2005
Re: link newly created node to an existing node
Reply #1 - Feb 14th, 2022 at 8:11am
Print Post  
Hi,

Pass the diagram as first argument of item constructors, including link's one. You could call diagram.factory.createDiagramLink(node1, node2) instead of constructor and addItem.

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Jessenberg
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 27
Joined: Dec 20th, 2021
Re: link newly created node to an existing node
Reply #2 - Feb 14th, 2022 at 9:10am
Print Post  
so i should do it like this ?

Code (Javascript)
Select All
nodes.forEach((node) => {
const newNode = new mf.Diagramming.SvgNode(this.state.diagram);

newNode.setAnchorPattern(pattern);
newNode.getBounds().x = boundx;
newNode.getBounds().y = boundy + 40;
this.state.diagram.addItem(newNode);

this.state.diagram.factory.createDiagramLink(node, newNode)
}

 

  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Online


tech.support

Posts: 3153
Joined: Oct 19th, 2005
Re: link newly created node to an existing node
Reply #3 - Feb 14th, 2022 at 9:13am
Print Post  
Yes, or diagram.getFactory() for version 3 API.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint