elk
elk copied to clipboard
Allow port labels to be centered in insufficient-space conditions
Given the following graph:
algorithm: layered
node n {
layout [ size: 20, 20 ]
portConstraints: FIXED_SIDE
portLabels.placement: INSIDE
port p {
^port.side: SOUTH
label "long label"
}
}
This is the result:

There is clearly not enough space for the label. Centering it above its port would produce an additional crossing between the label and the node's left border. The port label placement code currently optimizes for such crossings and thus does not centre the label.
There could be an additional option to force centred port labels in such cases.
This is solved by setting node size constraints to PORTS and PORT_LABELS.
I guess it should be enough to only set PORT_LABELS for the node to resize to accommodate the label.
algorithm: layered
node n {
layout [ size: 20, 20 ]
nodeSize.constraints: "PORTS PORT_LABELS"
nodeSize.options: ASYMMETRICAL
portConstraints: FIXED_SIDE
portLabels.placement: "INSIDE ALWAYS_SAME_SIDE"
port p {
^port.side: SOUTH
label "long label"
}
}