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.

How to limit out-ports to only have a single link, allow moving of links, and how to delete a link

See original GitHub issue

I am using v6.2.0 of this amazing library. I want a system with nodes that have a single in-port and multiple out-ports. I want to restrict this such that the user can only link an out-port to an in-port (i.e. the source port of a link must be an out-port and the target port must be an in-port). The user should not be able to create “loose links” (i.e. links that have one end not connected to any port). In addition, each out-port can only have a single link attached to it. I have managed to achieve this by doing the following:

...
  const engine = createEngine();
  const state = engine.getStateMachine().getCurrentState();
  if (state instanceof DefaultDiagramState) {
    state.dragNewLink.config.allowLooseLinks = false;
  }
...
  const model = new DiagramModel();
  ...
  model.registerListener({
    linksUpdated: (e: any) => {
      if (e.isCreated) {
        const link = e.link;
        const sourcePort = link.getSourcePort() as DefaultPortModel;

        if (Object.keys(sourcePort.getLinks()).length > 1) {
          link.remove();
        } else if (sourcePort.getOptions().in) {
          link.remove();
        }
      }
    }
  });
  engine.setModel(model);
...

Here is an example of what I can create so far: Screenshot 2020-08-16 at 17 37 59

Questions

  1. Is this the best way of achieving this?

  2. I also want the ability for the user to drag the endpoint of a link from one out-port to another out-port (or from one in-port to another in-port). How can this be done?

  3. I am using the DefaultLinkModel and see that when you click on a link it adds a new control point to it. However, the nice Bezier curves then turn into straight lines. Is there a way to keep these lines as curves when additional control points are added? With a new point added, I can press the delete key on the keyboard to delete that point if I want to. However, I cannot work out how to just select a link so that I can delete it using the same mechanism. Could you please explain how to delete links?

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:2
  • Comments:17 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
asnaseer-resilientcommented, Feb 17, 2022

@ShrutiChandak19 I have managed to restrict the number of links to 1 by providing my own port model that extends this libraries PortModel. In the constructor of this, I call the super class and pass it some options, one of which is maximumLinks: 1.

Here is some sample code that might illustrate this better:

import { PortModel, PortModelGenerics, PortModelOptions } from '@projectstorm/react-diagrams';
...

export class MyPortModel extends PortModel<PortModelGenerics> {
  constructor(options: PortModelOptions) {
    super({ ...options, maximumLinks: 1 });
  }
  ...
}

Hope that helps.

0reactions
vivek-versecommented, Jun 14, 2022

That’s how I did it

const model = new DiagramModel();
model.registerListener({
	linksUpdated:(event : any) => {
		const { link, isCreated } = event;
		link.registerListener({
			targetPortChanged:(link  :any) => {
				if(isCreated){
					const {sourcePort, targetPort} = link.entity;
					if(Object.keys(targetPort.getLinks()).length > 1){
						model.removeLink(link.entity);
					}else{
						let { parent : 
								{ options : sourceOptions }
							} = sourcePort;

						let { parent : 
								{ options : targetOptions }
							} = targetPort;

						if(sourceOptions.dataType === 'start' && targetOptions.dataType === 'value'){
							model.removeLink(link.entity);
						}
					}
				}
			}
		});				
	  }
})

Thanks

Read more comments on GitHub >

github_iconTop Results From Across the Web

Remove or turn off hyperlinks - Microsoft Support
Remove a hyperlink. To remove a hyperlink but keep the text, right-click the hyperlink and click Remove Hyperlink. Right click menu, Remove Hyperlink....
Read more >
Understanding SC 2.4.4:Link Purpose (In Context) (Level A)
Intent. The intent of this Success Criterion is to help users understand the purpose of each link so they can decide whether they...
Read more >
Disavow links to your site - Search Console Help
Step 1: Create a list of links to disavow · Specify one URL or domain to disavow per line. · To disavow a...
Read more >
Configure Hosting behavior | Firebase Hosting - Google
You can find a full firebase.json configuration example (covering only Firebase ... Use a URL redirect to prevent broken links if you've moved...
Read more >
Zoom Whiteboard user guide
Users can also manage whiteboards they have created, or that have been shared with them, from the desktop client and the web portal....
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