Implement custom portSpreading

Hi,

I want to implement a custom function that handles te portspreading of links on a node. What would be the best practise to do this?

Thanks,
Tim

First, you should know about this property and its options:

Second, what behavior do you want to customize, and how, and when?

Hi Walter,

Yes i saw, and (by default) i’m using it. But i was hoping to set a custom functionality for it.

What i want to change is to have the links spread out on a node, but have it snapped to the grid. And that should happen when a new link is connected, or when 1 or more link(s) move from one side to another. So in essence the current portSpreading functionality, but then with positions according to the grid. Hope that makes sense (i’ll add a screenshot below).

The SpreadingEvenly function as it is now, as you can see, it spreads out over the side but it does not snap to the grid

What i want to change in the function, now the links are connected to the node with positions that are relative to (half the size of) the grid

OK, but what do you want to happen when there are four or 17 links connecting with the right side of your example node and grid?

Or if there are only 2?

if there are too many links attached to spread out they should overlap (connect to the same spot/position) like this

two links should connect like this

four links should propably connect like this (depending on the position of the other node(s) to which the links are connected

I don’t think there is a good and easy answer for this that provides automatic positioning of links.

I think if you use Node.SpreadingPacked as the value for Node.portSpreading you can override Link.computeThickness to return different values, such as zero or the grid size. The problem is that at that time you do not know which side it is on nor how wide/tall that side is nor how many links there are connecting on that side.

So I think it might be best if you did not use the port-spreading mechanisms at all but instead computed the Link.fromSpot and Link.toSpot yourself. Basically this is the same mechanism that the extensions/LinkShiftingTool uses. However when the user moves a node, you’ll need to recompute all of the link spots again.

Ok, i was already afraid that would be the case. thanks for your help!