plantuml-stdlib / C4-PlantUML

C4-PlantUML combines the benefits of PlantUML and the C4 model for providing a simple way of describing and communicate software architectures

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

System() etc. with sprites, but no label

mtnpke opened this issue · comments

Hi!

I think a nice feature to have would be to be able to declare systems, containers etc. that only contain a sprite and no label. This is useful for including a logo sprite that already has text in it, so having it as label text would be repetitive. Right now, if you write for example System_Ext(Test, "", $sprite="img:test.png"), you will get an extra blank line in the rectangle after the image, which is visually unpleasing.

I can understand the issue regarding superfluous whitespace. I can really mess with the harmony of an image.

Current Fixed

A quick dig in the code leads me to believe this shouldn't be too hard to resolve, although I would have to check before committing myself to anything.

As far as I can see, this behaviour comes from the $getComponent, $getContainer, $getPerson and $getSystem, and $getNode functions, respectively.

For getSystem and getPerson it would be neccesary to add an extr if to check for the label.
The current code reads:

C4-PlantUML/C4_Context.puml

Lines 342 to 344 in e374b34

!if ($descr == "") && ($sprite != "")
!return $getSprite($sprite)+'\n== '+$breakLabel($label)
!endif

That would have to be changed to:

!if ($descr == "") && ($sprite != "")
  !if ($label == "") 
    !return $getSprite($sprite)
  !else
    !return $getSprite($sprite)+'\n== '+$breakLabel($label)
  !endif
!endif

For getComponent, getContainer, and getNode* the code is:

!$component = $component + '== ' + $breakLabel($label)

!$container = $container + '== ' + $breakLabel($label)

!$nodeText = $nodeText + '== ' + $breakText($label, "\n== ")

!$nodeText = $nodeText + '== ' + $breakText($label, "\l== ")

!$nodeText = $nodeText + '== ' + $breakText($label, "\r== ")

which would need to be changed to:

  !if ($label != "")
    ...
  !endif

@kirchsth Can I ask you for feedback and/or to tell me what I am missing? 😁

@Potherca: Thank you for the implementation.

I think it is complete I only would

  • add the check to the $getRel() call too - here we can have sprites with text too
  !if ($link != "")
    !$usedNewLine = ']]**\n**[[' + $link + ' '
    !$rel = $rel + '**[[' + $link + ' ' + $breakText($label, $usedNewLine) + ']]**'
  !else
    !$usedNewLine = '**\n**'
    !$rel = $rel + '**' + $breakText($label, $usedNewLine) + '**'
  !endif
  • and maybe introduce a common $getElementBase() base call too (maybe with a better name instead of Base)
!function $getElementBase($label, $techn, $descr, $sprite)
  !$element = ""                                                       
  !if ($sprite != "")
    !$element = $element + $getSprite($sprite) + '\n'
  !endif
  !if ($label != "")                                                       -----------------
    !$element = $element + '== ' + $breakLabel($label)
  !endif                                                                   ----------------- 
  !if ($techn != "")
    !$element = $element + '\n//<size:' + $TECHN_FONT_SIZE + '>[' + $breakTechn($techn, '-1') + ']</size>//'
  !endif
  !if ($descr != "")
    !$element = $element + '\n\n' + $descr
  !endif
  !return $element
!endfunction

!function $getComponent($label, $techn, $descr, $sprite)
  $getElementBase($label, $techn, $descr, $sprite)
!endfunction

!function $getContainer($label, $techn, $descr, $sprite)
  $getElementBase($label, $techn, $descr, $sprite)
!endfunction

!function $getPerson($label, $descr, $sprite)
  !if ($sprite == "") && ($defaultPersonSprite != "")
    !$sprite = $defaultPersonSprite
  !endif
  $getElementBase(.., $techn="", ...)
!endfunction

!function $getSystem($label, $descr, $sprite)
   $getElementBase(.., $techn="", ...)
!endfunction
  • and update $getNode(), $getNode_L(), $getNode_R() with a common $getNodeBase() implementation (but with very low priority)

Please be aware that I didn't check anything.

And I think we should at least test if all arguments are empty that it is not "crashing".

Thank you and best regards
Helmut

Hi @mtnpke,
I implemented it in #285.
Can you please check it?
Thank you and BR
Helmut

@kirchsth Yeah, it's working great :)
@Potherca Thanks, much obliged!