Arranging blocks side by side in state diagrams

0 votes
asked Oct 4, 2021 in Question / help by Grolribasi (220 points)

Hello! I had a diagram looking like this:

It was drawn manually in some software. I decided to rework it into PlantUML and it turned out like this:

How do I make it more consecutive? I want to mirror the blocks along the red line to make it look more like the source image:

The fact that I can't control the position of the blocks annoys me. The source code is here:

@startuml
skinparam rectangleBorderThickness 1
skinparam defaultTextAlignment center
skinparam lifelineStrategy solid

State "Внешние системы" as ext {

State "Система A" as sysA
State "Хранилище \nсобытий" as store
State "Система B" as sysB

}

State "Служба рабочих процессов" as serv {

State "Фабрика очередей" as queuesFactory #lightgreen
State "Очередь \nгрупп сообщений" as msgGroupQueue
msgGroupQueue : Сообщение 1 \nСообщение 2 \nСообщение N

State "Фабрика задач" as tasksFactory #lightgreen
State "Компонент" as comp #lightgreen

State "Фабрика \nподключений" as connectionsFactory #lightgreen
State "Подключение A" as conA

State "Менеджер задач" as mngr {

State "Задачи \nпо сообщениям" as msgTasks
State "Очередь задач" as tasksQueue

}

}

sysA -> store : Создание сообщения
sysA -[hidden]-> store
store -[hidden]-> sysB
sysA -[hidden]-> sysB

tasksFactory -> tasksQueue : Создание задач
comp -[hidden]-> mngr
tasksFactory -[hidden]-> mngr
queuesFactory -[hidden]-> msgGroupQueue
tasksFactory -[hidden]-> msgGroupQueue

queuesFactory -> msgGroupQueue : Инициализация
msgTasks : Задача 1\n Задача 2 \nЗадача N
tasksQueue : Задача 1\n Задача 2 \nЗадача N
msgGroupQueue -> tasksFactory : Обработка сообщений
comp -> msgTasks : Создание задач

connectionsFactory -[hidden]-> conA
msgGroupQueue -[hidden]-> connectionsFactory
connectionsFactory -> conA : Создание подключения
mngr -> conA : Использование подключения

conA -> sysB
store -> msgGroupQueue : Загрузка сообщений
queuesFactory -[hidden]-> connectionsFactory
queuesFactory -[hidden]-> msgGroupQueue
queuesFactory -[hidden]-> conA

@enduml

1 Answer

+1 vote
answered Oct 4, 2021 by Martin (8,360 points)
selected Oct 5, 2021 by Grolribasi
 
Best answer

Plantuml is not a good tool for heavily controlling layout or for trying to force a specific look.  Its main selling point is that it uses Graphviz to automatically lay out diagrams.  In my experience this works well on simple diagrams and complex diagrams; but on medium diagrams like yours the human brain can do it better which means you rarely get a satisfactory diagram.

Here's my best attempt.  But be aware that it is not very stable, if you make any small tweaks it all goes wrong.  There's some aspects to it that I don't quite understand, like why I can't move SysB down a rank, or why connectionsFactory isn't more centrally positioned, or why when I try to control the direction of arrows with the 'udlr' directions it often totally ignores them.

(click the diagram for the online server source)

commented Oct 5, 2021 by Grolribasi (220 points)
Thanks! This looks better than my variant. I need to learn some tricks with the usage of arrows from your example!
commented Oct 5, 2021 by Martin (8,360 points)
The main 'trick' is knowing that -> is a 'same-rank' arrow, --> is a '+1 rank' arrow, and ---> is a '+2 rank' arrow, etc.  So if you have three vertical boxes A,B,C connected by +1 rank arrows, and you want two boxes D,E to align horizontally with A and C, then you need to connect D and E with a +2 rank arrow.  That's the easy bit.  The main issue is that the same-rank arrows seem to ignore any 'left' and 'right' directives, and the boxes often shuffle themselves around into an unsightly order.  E.g. if you add an extra dash into the hidden arrow between store and sysB, then you'd expect SysB to just drop down a position with no other change to the diagram, but it doesn't...
...