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
MIT License
6.33k stars 1.1k forks source link

add folder shape (container & component) #329

Closed mdreano closed 10 months ago

mdreano commented 10 months ago

Will be used by https://github.com/structurizr/export/pull/85

kirchsth commented 10 months ago

Hi @mdreano,

thank you for your suggestion, but I'm really not sure if we should add a new shape to the standard, because it would requires also 6 additional Element calls (SystemCollection, SystemCollection_Ext, ContainerCollection, ContainerCollection_Ext, ComponentCollection, ComponentCollection_Ext), a detailed discussion can found Support more shapes.

But you can add your own shapes based on following pattern (it is the updated version from #145, that it matches with the newest features too).

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

' ===========================

' define additional calls
!unquoted procedure UpdateHexagonStyleToo($tagStereo, $bgColor, $fontColor="", $borderColor="", $shadowing="", $shape="", $borderStyle="", $borderThickness="")
$elementTagSkinparams("hexagon", $tagStereo, $bgColor, $fontColor, $borderColor, $shadowing, "", $borderStyle, $borderThickness)
!endprocedure

!unquoted procedure ComponentHexagon($alias, $label, $techn="", $descr="", $sprite="", $tags="", $link="")
  $getElementLine("hexagon", "component", $alias, $label, $techn, $descr, $sprite, $tags, $link)
!endprocedure

!unquoted procedure ComponentHexagon_Ext($alias, $label, $techn="", $descr="", $sprite="", $tags="", $link="")
  $getElementLine("hexagon", "external_component", $alias, $label, $techn, $descr, $sprite, $tags, $link)
!endprocedure

!unquoted procedure ContainerHexagon($alias, $label, $techn="", $descr="", $sprite="", $tags="", $link="")
  $getElementLine("hexagon", "container", $alias, $label, $techn, $descr, $sprite, $tags, $link)
!endprocedure

!unquoted procedure ContainerHexagon_Ext($alias, $label, $techn="", $descr="", $sprite="", $tags="", $link="")
  $getElementLine("hexagon", "external_container", $alias, $label, $techn, $descr, $sprite, $tags, $link)
!endprocedure

!unquoted procedure SystemHexagon($alias, $label, $descr="", $sprite="", $tags="", $link="", $type="")
  ' $type reuses $techn definition of $tags
  $getElementLine("hexagon", "system", $alias, $label, $type, $descr, $sprite, $tags, $link)
!endprocedure

!unquoted procedure SystemHexagon_Ext($alias, $label, $descr="", $sprite="", $tags="", $link="", $type="")
  ' $type reuses $techn definition of $tags
  $getElementLine("hexagon", "external_system", $alias, $label, $type, $descr, $sprite, $tags, $link)
!endprocedure

' set default styles 
skinparam hexagon {
    StereotypeFontSize 12
    shadowing false
}

UpdateHexagonStyleToo("system", $SYSTEM_BG_COLOR, $ELEMENT_FONT_COLOR, $SYSTEM_BORDER_COLOR, false)
UpdateHexagonStyleToo("external_system", $EXTERNAL_SYSTEM_BG_COLOR, $ELEMENT_FONT_COLOR, $EXTERNAL_SYSTEM_BORDER_COLOR, false)
UpdateHexagonStyleToo("container", $CONTAINER_BG_COLOR, $ELEMENT_FONT_COLOR, $CONTAINER_BORDER_COLOR, false)
UpdateHexagonStyleToo("external_container", $EXTERNAL_CONTAINER_BG_COLOR, $ELEMENT_FONT_COLOR, $EXTERNAL_CONTAINER_BORDER_COLOR, false)
UpdateHexagonStyleToo("component", $COMPONENT_BG_COLOR, $COMPONENT_FONT_COLOR, $COMPONENT_BORDER_COLOR, false)
UpdateHexagonStyleToo("external_component", $EXTERNAL_COMPONENT_BG_COLOR, $COMPONENT_FONT_COLOR, $EXTERNAL_COMPONENT_BORDER_COLOR, false)

' =====================================================

' if custom styless are required call additional $UpdateHexagonStyleToo()
!$COLOR_A_5 = "#7f3bf7"
!$COLOR_A_1 = "#fe00f7"
!$COLOR_NEUTRAL = "#6633f7"
UpdateElementStyle("external_component", $EXTERNAL_COMPONENT_BG_COLOR, $COLOR_A_5, $COLOR_A_1, false)
UpdateHexagonStyleToo("external_component", $EXTERNAL_COMPONENT_BG_COLOR, $COLOR_A_5, $COLOR_A_1, false)

' if an additional cutom tag is required then call UpdateHexagonStyleToo() too
AddElementTag("special", $bgColor=$COLOR_NEUTRAL)
UpdateHexagonStyleToo("special", $bgColor=$COLOR_NEUTRAL)

ContainerHexagon(containerHex, "Special Container", "techn", "special version", $tags="special")

ComponentHexagon(compHex, "Componet", "techn", "Optional Description")
ComponentHexagon_Ext(compHexExt, "Component Ext", "techn")

SHOW_LEGEND("false")
@enduml

As an alternative you could use sprites or other images (like in e.g. #309) too

BR Helmut

MathieuDreano commented 10 months ago

Hello.

Thank you for taking the time to answer.

I have read the discussions but I am not so sure about the reason why you do not want more shapes. I feel like C4 more about levels rather than shapes used to represent them. We should be allowed use whatever shape fits our need to represent our components. So extending the set of shapes would be nice.

As for me, sprite will fit my needs, thanks !

And thanks again for all the work done so far.