plantuml-stdlib/C4-PlantUML

Linebreak in $label breaks font relationship styling

Potherca opened this issue · 6 comments

When a newline/linebreak is present in the $label of a relationship, the styling breaks.

@startuml
!include https://raw.githubusercontent.com/plantuml-stdlib/C4-PlantUML/v2.4.0/C4_Container.puml

Container(a, "A")
Container(b, "B")
Container(c, "C")
Container(d, "D")

Rel(a, b, "Relation1 Relation2")
Rel(c, d, "Relation1\nRelation2")
@enduml

The user can remedie this by adding the "closing" and "opening" creole markers themselves before and after the newline **\n**:

@startuml
!include https://raw.githubusercontent.com/plantuml-stdlib/C4-PlantUML/v2.4.0/C4_Container.puml

Container(a, "A")
Container(b, "B")

Rel(a, b, "Relation1**\n**Relation2")
@enduml

But to me, this feels like a hack.

To fix this, we could parse the label to replace \n with **\n**, but that might be more work than its worth.
Alternatively, we could use HTML instead of Creole syntax, or employ a stereotype:

@startuml
(A) -> (B) : <b>Relation1\nRelation2

skinparam ArrowFontStyle<<bold>> bold

(C) -> (D)<<bold>> : Relation1\nRelation2
@enduml

For $techn and $descr we have already a function like $breakDescr($descr, $REL_DESCR_MAX_CHAR_WIDTH) which supports explicit \n too.

@startuml
!include https://raw.githubusercontent.com/plantuml-stdlib/C4-PlantUML/v2.4.0/C4_Container.puml

Container(a, "A")
Container(b, "B")
Container(c, "C")
Container(d, "D")

Rel(c, d, "Relation1\nRelation2", "LONG\nTECHN", "LONG\nDescription")
@enduml

We could add similar for labels too
BR Helmut
PS: I wouldn't see it as a bug, its more a feature request

Also CC @simonbrowndotje here.

@Potherca: I have extended it that all $labels and missing $techn args supports line breaks too (I think now we cover all with \n).

It can be tested with my extended branch

@startuml
' convert it with additional command line argument -DRELATIVE_INCLUDE="./.." to use locally
!if %variable_exists("RELATIVE_INCLUDE")
  !include %get_variable_value("RELATIVE_INCLUDE")/C4_Component.puml
  !include %get_variable_value("RELATIVE_INCLUDE")/C4_Deployment.puml
!else
  !include https://raw.githubusercontent.com/kirchsth/C4-PlantUML/extended/C4_Component.puml
  !include https://raw.githubusercontent.com/kirchsth/C4-PlantUML/extended/C4_Deployment.puml
!endif

Enterprise_Boundary(eb, "Enterprise\nBoundary") {
  Person(p1, "Normal\nUser\nLabel", "Description\nLine\nBreak")
  Container(c1, "Container\nLabel", "container techn\nwith line break", "Description\nLine\nBreak")
  Component(c2, "Component\nLabel", component techn\nwith line break", "Description\nLine\nBreak")
}

System_Ext(s1, "System Label\nWith\nLineBreak", "Description\nLine\nBreak")

Rel_(p1, c1, "A relation\nwith custom direction", "o-DOWN->>")
Rel_(p1, c2, "A relation\nwith custom direction", "and technology\nwith LBs", "o-RIGHT-o")

Rel(c1, c2, "A label\nwith\nline breaks", "and technology\nwith LBs")
Rel(c1, s1, "A linked label\nwith\nline breaks", "and technology\nwith LBs", $link = "http://www.plantuml.com")

Node(n1, "A node label\nwith\nline breaks", "type with\nline break", "description\nwith line break")
Node(n2, "A node label", "PlantUML packages have no automatic line breaks, line breaks are automatically inserted into type", "PlantUML packages have no automatic line breaks, line breaks are automatically inserted into description") {
  Container(cInNode, "A container in node")
}

!if %variable_exists("RELATIVE_INCLUDE")
  !include %get_variable_value("RELATIVE_INCLUDE")/C4_Dynamic.puml
!else
  !include https://raw.githubusercontent.com/kirchsth/C4-PlantUML/extended/C4_Dynamic.puml
!endif

Component(from, "From component")
Component(to, "To component")

Rel_("pre1", from, to, "A custom dynamic relation\nwith custom direction", "o-DOWN->>")
Rel_("pre2", from, to, "A custom dynamic relation\nwith custom direction", "and technology\nwith LBs", "+--+")
Rel(from, to, "A dynamic relation\nwith line break")
@enduml

If you like it I can push my local branch and create a PR.

Best regards
Helmut

PS.: But I'm still not sure if we should support \n in labels at all. E.g. label is typically a component, class name or (logical) function ... names which have no line breaks at all. I think the only valid reason for a line break in a label is that C4-Stdlib is used as drawing tool and not as modelling tool.

I have extended it that all $labels and missing $techn args supports line breaks too (I think now we cover all with \n).

Great! This makes things more consistent and predictable, I think. Good stuff!

If you like it I can push my local branch and create a PR.

I like! Push that PR! 👍

I'm still not sure if we should support \n in labels at all. [..] I think the only valid reason for a line break in a label is that C4-Stdlib is used as drawing tool and not as modelling tool.

I think this breaks down into either telling the user how to use the tool or listing to the user how the tool is used.
For the sake of consistency, I think for this scenario we should use the "listen to the user" approach. Although I do very much appreciate the critical note. We do need to stay sharp regarding feature changes and expantions...

Ok, I created the PR