kieler / elkjs

ELK's layout algorithms for JavaScript
Other
1.81k stars 97 forks source link

[Question] How to add edge labels without increasing space between layers? #308

Closed keyserj closed 1 week ago

keyserj commented 1 week ago

Ask your questions I want to add labels to my layout so that they can avoid overlap, but I don't want to unnecessarily increase the space between node layers when I do so. Is there a way to do this?

Here is a simplest reproduction: elklive. If you remove the edge label, the spacing.nodeNodeBetweenLayers is respected, but with the label, the spacing is much more.

Without edge label vs with: image image

I tried setting a bunch of label-related spacing options, and the label's size to [0, 0], to no avail (see elklive above). I also noticed that it seems like the edge label acts similar to a new node layer. That would explain why no spacing options affects this, but that's not ideal for me.

(Optional) ELK Version ELK snapshot/0.9.1

Eddykasp commented 1 week ago

Your observation that they act like nodes is correct. During the layout edge labels are treated as nodes and laid out as such.

Depending on what your graphs generally look like, nodeNodeBetweenLayerSpacing may be helpful for you.

keyserj commented 1 week ago

Thanks @Eddykasp for clarifying!

I was able to halve my nodeNodeBetweenLayers (since there will be a label between all nodes, doubling the layers) and set the label height to 0.001 (I guess zero results in some default value in the elklive), here's the elklive with it working.