Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Prevent Multiple Links With The Same Origin and Destination Nodes (Read 1006 times)
alukes
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 61
Joined: Jul 1st, 2011
Prevent Multiple Links With The Same Origin and Destination Nodes
Dec 22nd, 2022 at 4:35am
Print Post  
As an example:

If A user draws a true link from a decision node to a destination node, I want to prevent the user from drawing a false link to the same destination node.


The following code doesn't remove the new link. The tag contains an ID number.

function onLinkCreated(sender, args) {
let linkCount = 0;
let createdLink = args.getLink();
let tempShapeName = createdLink.getOrigin().getShape().getId();
if ( tempShapeName === "Decision" )
{
let newDest = createdLink.getDestination();
let newDestTag = newDest.getTag();
let selLinks = createdLink.getOrigin().getOutgoingLinks();
for (var i = 0; i < selLinks.length; i++) {
let checkLink = selLinks[i];
let checkDestTag = checkLink.getDestination().getTag();
if (checkDestTag === newDestTag) {
linkCount = linkCount + 1;
}
}
if (linkCount >1)
{
miFu.diagram.startCompositeOperation();
miFu.diagram.removeItem(createdLink); Also tried (selLinks[1]) same result
miFu.diagram.commitCompositeOperaton();
miFu.diagram.getSelection().clear();
}
}
« Last Edit: Dec 22nd, 2022 at 5:15pm by alukes »  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3152
Joined: Oct 19th, 2005
Re: Prevent Multiple Links With The Same Origin and Destination Nodes
Reply #1 - Dec 22nd, 2022 at 2:10pm
Print Post  
The best place to prevent creation is linkCreating validation event:
https://www.mindfusion.eu/onlinehelp/jsdiagram/P_MindFusion_Diagramming_Events_l...

Code
Select All
diagram.addEventListener(Events.linkCreating, onLinkCreating);

function onLinkCreating(diagram, args)
{
	if (args.origin.shape.id == "Decision" && args.destination)
	{
		var destNodes = args.origin.outgoingLinks.map(l => l.destination);
		args.cancel = destNodes.includes(args.destination);
	}
} 



I don't keep version 3 of the control to try your code. Try tracing with debugger to verify you aren't deleting the first link too, and check in browser console if there aren't some exceptions reported leading to repaint problems.

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
alukes
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 61
Joined: Jul 1st, 2011
Re: Prevent Multiple Links With The Same Origin and Destination Nodes
Reply #2 - Dec 23rd, 2022 at 4:55am
Print Post  
Thanks!

I got it to work.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint