Is there anyway to have a frame, in the class diagram, contain it's own layout?

0 votes
asked Nov 25, 2020 in Question / help by awschult (360 points)

in the following example:

http://www.plantuml.com/plantuml/uml/jP0z2iCm38NtTuhinOJ-T3M17g4dK1oP1cm5R6Ke8NUlquP2mMkN9_WqwDFhibBIEGRuH96RKPIJ9ySBNA2Sc_YyRNC1sjPDCR9eni7FudISv5Z7fpe-r_6bZgzOyPMuHmhXO_9FaHNO7swCiJztjntsbaWcVN1QGCRsw8rr9OmTC9JaTtgiw5Y6KkqB

Note that there are 2 "features" present with the layout engine. 

  • layout is generated from the "inside out"
  • frames are built after the dot layout and simply bound the boxes

The first item is that the layout engine is fed the "smallest" items. In this case, all of the class objects are fed to the layout engine and graphed accordingly. This results in each class being placed on a rank with others of the same rank, that is, centered on the same line. So if one object is much bigger than another, the the smaller one will be stretched until it reaches the center alignment of all others of the same rank. We can see that with `class d` and `mySmallClass`. They have the same rank, so they are placed on the same horizontal line. This results in an unsightly stretching of the graph on the left. Notice that the space between abc and d is greater than the space between d and ef. 

The second item is that the frame surrounding our objects is created after the layout engine has completed. and is just a box that surround each object plus some buffer space. The buffer space is constant and the frame has no impact on the layout of the class objects. With the layout of class objects being centered on rank, and the frame being a constant offset from the largest box in that group; we can see that there are cases in which the frames are also offset from each other. notice how "another" is much lower that "interface". This again, results in an unsightly layout.

I think that each frame having the ability to encapsulate it's own layout, would help in "cleaning" up an image. That is, the frame "another" would send all of its classes to the layout engine, thus resulting in a nice, compact layout meant only for it. Then the "interface" frame would send it's components to the layout engine, and result in it's own compact layout. Then the frames can be aligned with each other however the user wants (top align, left align, etc).

Is any of this even possible at the moment? Or am I just looking at some XY problem?

1 Answer

0 votes
answered Nov 25, 2020 by The-Lu (64,340 points)
selected Jun 3, 2022 by awschult
 
Best answer

Hello A.,

In order to have a specific layout for each frame (and to compact the diagram), only if the classes are independents (not link between class from in to out or the inverse), you can use sub-diagram ('{{' and '}}')  as:

frame another [
{{
class a
a->b
b->c
b-->d
d-->e
d-->f
}}
]


[See on PlantUML server]

If that can help,
Regards,
Th.

commented Nov 25, 2020 by awschult (360 points)
That does help tremendously!! Thank you very much!

Although not detrimental, I do notice that the sub-diagram frame was not named, and I can't seem to find a syntax to get a name placed. Any suggestions?
commented Nov 26, 2020 by The-Lu (64,340 points)

Hello A.,

Here is a tricky workaround:
The sub-diagram definition must be on a string context, and to add name on the top of the frame, it is necessary to use nested frame ('{', '}'), then the minimal object (natively without shape or contour) within the frame will be, for example, a label as:

frame another {
label l [
{{
class a
a->b
b->c
b-->d
d-->e
d-->f
}}
]
}

Then with that, we observe:


[See on PlantUML server]

Regards,
Th.

...