eclipse / elk

Eclipse Layout Kernel - Automatic layout for Java applications.
https://www.eclipse.org/elk/
Other
248 stars 83 forks source link

Allow port labels to be centered in insufficient-space conditions #424

Open le-cds opened 5 years ago

le-cds commented 5 years ago

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:

graph

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.

soerendomroes commented 2 weeks ago

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"
  }
}