52

I created this diagram using the following code. But as you can see, the lines going from (Cancel Order) and (Place Order) to (Publisher) decide to take a terribly rounded path to get their, instead of going straight to the right and then down to publisher. I tried using manual direction commands like "-down" but none of them seemed to help. Does anybody know how to fix this?

And here is my code. I appreciate any help. Thank you.

@startUML EBook Use Case Diagram
left to right direction
Actor Customer as customer
Actor EBook as ebook
Actor Publisher as publisher
rectangle "Book Catalogue" {
    together {
        Actor "Book Database" as bookLog
        (Retrieve Information) as getBook
        customer -- getBook
        getBook -- ebook
        getBook -- bookLog

        (Update Catalogue) as updateCatalogue
        ebook -- updateCatalogue
        updateCatalogue -- bookLog
    }

    together {
        (Place Order) as order
        customer -- order
        order -- ebook
        order--publisher

        (Cancel Order) as cancelOrder
        customer -- cancelOrder
        cancelOrder -- ebook
        cancelOrder--publisher
    }
}

(Ship To EBook) as shipEBook
shipEBook -- publisher
(Ship To Customer) as shipCustomer
customer -- shipCustomer
ebook -- shipEBook
shipCustomer -- ebook

(Return to EBook) as returnCustomer
(Returnto Publisher) as returnPublisher
customer -- returnCustomer
returnCustomer -- ebook
ebook -- returnPublisher
returnPublisher -- publisher

@endUML
Peter Uhnak
  • 9,617
  • 5
  • 38
  • 51
aSamWow
  • 861
  • 1
  • 7
  • 9
  • how do you make the picture so clear? did you first export to svg and then convert to png? – FunkyBaby Aug 02 '18 at 14:33
  • hey, I just did export to image (png probably?) with the vscode plant uml extension. I don't use vscode or plantuml anymore, so I can't be of much help, sorry. – aSamWow Aug 03 '18 at 16:00

5 Answers5

65

There are some tricks that you can try, listed below. The layouting itself is performed by GraphViz (dot layouting iirc), and GraphViz simply does this sometimes. Graph layouting is a NP-complete problem, so algorithms usually take harsh shortcuts.

Typical workarounds that I've seen or used include:

  • adding hidden lines a -[hidden]- b
  • extending the length of a line a --- b (more dashes, longer line)
  • specifying preferred direction of lines (a -left- b)
  • swapping association ends (a -- bb -- a)
  • changing the order of definitions (the order does matter... sometimes)
  • adding empty nodes with background/border colors set to Transparent

So if you really want to have a nice layout, you'll need to put some elbow grease in, but keep in mind that the layout will be still brittle -- if you add/remove items, you might need to redo it again.

Peter Uhnak
  • 9,617
  • 5
  • 38
  • 51
  • 3
    I would like to point out the use of `together` done by @aSamWow. I didn't know this command before but I just successfully use it like following : `together group1 { class a class b } together group2 { class c class d } group1 -[hidden]- group2` – 6pi Aug 01 '19 at 11:31
  • I didn't know about the line length feature! Thank you very much! – Fred Jul 04 '20 at 21:56
48

Try the options suggested by @Peter Uhnak along with linetype :

skinparam linetype polyline
skinparam linetype ortho

Give better options for lines. Using ortho - (Here)

you will get -

enter image description here

Nikhil
  • 849
  • 8
  • 10
  • 1
    Good idea, it does fix the problem, but Ortho lines mess up labels in plant UML so I try to avoid them for more complex diagrams. – aSamWow Feb 15 '18 at 14:04
  • 1
    "label positioning wrong in linetype ortho" - please vote for it: https://github.com/plantuml/plantuml/issues/149 – kinjelom Mar 04 '20 at 11:26
29

To make a connection less important in the layout, use [norank], e.g., a -[norank]-> b

fkleedorfer
  • 525
  • 4
  • 8
  • 3
    My goal with this answer is to document an undocumented PlantUML feature with minimal cognitive load in a place where related features are nicely listed (and accepted as the answer). Users of PlantUML will appreciate `norank` in the context of this question. – fkleedorfer May 15 '20 at 07:11
21

If anyone wants to know a more specific, put probably much more useless answer, here is what I did in the end.

    order -down- publisher
    publisher -[hidden]up- order

so for some reason adding the duplicated command both ways solves it.

aSamWow
  • 861
  • 1
  • 7
  • 9
  • > for some reason: I guess the reason is that every edge adds weight. In Graphviz one can specify weight of edges, but I have not found a way to do it in PlantUML. – Uwe Geuder May 26 '21 at 00:57
3

All these good answers are compiled and referenced in the semi-official Hitchhiker’s Guide to PlantUML. See the Layout section.

Not sure how it was 3 years ago, but it's probably now a better starting point for PlantUML tweaks than SO.

Digital Stoic
  • 1,229
  • 11
  • 20