Better control of the layout of class diagrams

0 votes
asked Feb 13, 2014 in To be sorted by poi (1,200 points)

Hello

I'm making a simple tool to generate UML diagrams from MATLAB code.

I would like more control over the layout. I'm experimenting with the directions of the PlantUML-relation-arrows ([hidden],left,right,up,down). In some cases I'm succesful in others I fail.

This small example illustrates my problem. The code

@startuml
subA -right-|> Super
subB -right-|> Super
subA -[hidden]down-> subB
@enduml

generates a diagram with three boxes in a row. My intention is subA on top of subB and Super to the right of the two. However, GraphViz rules.    

Is there a trick to give more power to the arrows of the code?
 

Best regards

Per Isakson

 

4 Answers

0 votes
answered Feb 13, 2014 by plantuml (294,960 points)

I think that from a graphviz/dot point of view, your example is inconsistent:

subA -right-|> Super
Means that SubA and Super must be on the same row (because of right)

subB -right-|> Super
Means that SubB and Super must be on the same row (because of right)

So yes, the 3 boxes are on the same row.

Maybe you can give us an example of what you are trying to do with dot syntax.
(since PlantUML accept pure dot syntax)

http://www.plantuml.com/plantuml/form?url=IybCBqeio518oyzNgEPIK2WkJNAqXj1E83guj22ro9gh5W00

@startuml
digraph foo {
  subA;
  subB;
  Super;
}
@enduml

asked Oct 4, 2014 in Wanted features by poi (1,200 points)
edited Oct 27, 2014 by poi
New command to better control the layout of class and state diagrams
0 votes
answered Feb 14, 2014 by poi (1,200 points)
edited Feb 15, 2014 by poi

Thank you for the answer.

I use the answer-box rather than a comment because of the formating features.

My knowledge of DOT is from browsing the User's manual and a little bit of experimenting.

I'm probably wanting too much. I should accept this excerpt as an answer 

2.6 Node and Edge Placement
[...]
Fine-tuning should be approached cautiously. dot works best when it can
makes a layout without much “help” or interference in its placement of individual
nodes and edges. Layouts can be adjusted somewhat by increasing the weight of
certain edges, or by creating invisible edges or nodes using style=invis, and
sometimes even by rearranging the order of nodes and edges in the file. But this can
backfire because the layouts are not necessarily stable with respect to changes in
the input graph. One last adjustment can invalidate all previous changes and make
a very bad drawing.

I had though that

subC -right-> Super2
subD -right-> Super2
subC -[hidden]down- subD

would produce three boxes arranged in a triangle as does the code below

subA -up-> Super1
subB -up-> Super1
subA -[hidden]right- subB

but rotated 90 degree.

After some trials and confusing results I produced the arrangement with dot:

@startuml
digraph foo {
rankdir=LR
subA;subB;Super;
subB->Super// [headport=nw;tailport=e];
subA->Super// [headport=sw;tailport=e];
subB->subA [headport=s;tailport=n;style=invis];
}
@enduml

I found that space matters!?! Changing  "subB->Super" to "subB ->Super" produces a somewhat different result. The same applies to changing "subB->Super//" to "subB->Super //".  The examples in the dot-user-guide have typically space before and after edgeop (arrows).  

This simple example with only three nodes illustrates that it is close to impossible for the user to take control over the layout. It is dot that rules. Even if I found a robust way to produce the layout of three nodes I doubt that this way would work when the three nodes were included in a larger class diagram.

With less than ten classes, my  reverse egineering tool together with PlantUML mostly produces useful class diagrams. And often a little interactive help (using [hidden],left,right,up,down) improves the readability. Thanks to PlantUML I've been able to make this useful tool.  I recall "Perfect is the enemy of good" and will accept the DOT way of doing the layout.

Best regards

Per Isakson

0 votes
answered Feb 15, 2014 by poi (1,200 points)
edited Feb 15, 2014 by poi

No, the DOT code in my previous answer was not the version I intended to show. This diagram  , generated by the code below, is more like it

@startuml
digraph foo {
rankdir=LR
subA;subB;Super;
subB->Super // [headport=nw;tailport=e];
subA->Super // [headport=sw;tailport=e];
subB->subA [headport=s;tailport=n;style=invis];
}
@enduml

.

And another diagram

@startuml
digraph foo {
rankdir=LR
subA;subB;Super;
subB -> Super // [headport=nw;tailport=e];
subA -> Super // [headport=sw;tailport=e];
subB -> subA [headport=s;tailport=n;style=invis];
}
@enduml

 

I have difficulties understanding the role of space as delimiter from the dot User's Manual appendix "D Graph File Grammar" .

+2 votes
answered Oct 24, 2014 by Fuhrmanator (1,700 points)
Try playing with "left to right direction" -- I admit there is a lot of trial and error involved.
@startuml
left to right direction
class Super
subA -down-|> Super
subB -down-|> Super
@enduml
commented Oct 26, 2014 by poi (1,200 points)
Thanks for the tip!

"left to right direction" is that documented? If so I've missed it.
commented Oct 27, 2014 by anonymous
Documented in use case diagrams.
commented Nov 7, 2015 by anonymous
6.6 Changing arrows direction
It is also possible to change arrow direction by adding left,right , up or down keywords inside the arrow
@startuml
[Component] -left-> left
[Component] -right-> right
[Component] -up-> up
[Component] -down-> down
@enduml
commented Nov 9, 2018 by David
Can it be used with "*--" or "o-"?
commented Jan 11, 2020 by Tuomas
Yes, you can, but relation code on another side -rigth- "reserd word", like:

@startuml
[Component] o---left- left
[Component] *---right- right
[Component] -up-> up
[Component] -down-> down
@enduml
...