Skip to content

Linebreak in $label breaks font relationship styling #255

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Potherca opened this issue Nov 4, 2022 · 6 comments
Closed

Linebreak in $label breaks font relationship styling #255

Potherca opened this issue Nov 4, 2022 · 6 comments
Labels
bug Something isn't working
Milestone

Comments

@Potherca
Copy link
Member

Potherca commented Nov 4, 2022

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

@kirchsth
Copy link
Member

kirchsth commented Nov 4, 2022

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

@dgutson
Copy link

dgutson commented Nov 4, 2022

Also CC @simonbrowndotje here.

kirchsth added a commit to kirchsth/C4-PlantUML that referenced this issue Nov 10, 2022
@kirchsth
Copy link
Member

@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.

@kirchsth kirchsth mentioned this issue Nov 12, 2022
7 tasks
@Potherca
Copy link
Member Author

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...

@kirchsth
Copy link
Member

Ok, I created the PR

@kirchsth kirchsth moved this from Todo to Review in All Projects Nov 14, 2022
Repository owner moved this from Review to Done in All Projects Nov 15, 2022
@dgutson
Copy link

dgutson commented Nov 15, 2022

@kirchsth 🥇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Done
Development

No branches or pull requests

3 participants