Skip to content
This repository has been archived by the owner on Jan 10, 2024. It is now read-only.

C4PlantUML exporter: Stereotypes shown #29

Closed
dgutson opened this issue Nov 7, 2022 · 8 comments
Closed

C4PlantUML exporter: Stereotypes shown #29

dgutson opened this issue Nov 7, 2022 · 8 comments

Comments

@dgutson
Copy link

dgutson commented Nov 7, 2022

Given

workspace "Test Product Architecture" "Model of the Test Platform." {

    !identifiers hierarchical

    model {
        user1 = person "User1" "" "users"
        user2 = person "User2"
        frontend_user = person "FE user"
        webhooks_user = person "Webhooks User" "" "robot_user"
        EAS = softwaresystem "EAS" "Service1" {
            SP = container "Processor" "Process1" "Node.js"
            engine = container "Engine" "Processes2" "Go"

            SP -> engine "Sends data"
            engine -> SP "Send results"
        }

        backend = softwaresystem "Backend" "Backend1" "multi" {
            database = container "DB" "" "MongoDB" "DB"
            app = container "App" "Backend Server" "Node.js" {
                s1 = component "Service1"
                s2 = component "Service2"
                s1 -> s2
            }

            app -> database "Uses"
        }

        backend.app -> EAS.SP "Send data"
        backend.app -> EAS.engine "Sends data 2"
        EAS.SP -> backend.app "Send results"
    }

    views {
        properties {
            plantuml.includes https://raw.githubusercontent.com/plantuml/plantuml-stdlib/master/tupadr3/font-awesome-5/users.puml
            c4plantuml.tags true
            c4plantuml.legend false
            plantuml.sequenceDiagram true
        }

        systemlandscape TheSystemLandscape {
            include *
            autoLayout
        }

        component backend.app {
            include *
            autoLayout
        }

        theme default

        styles {
            element "DB" {
                shape Cylinder
            }

            element "dataset" {
                background #006400
            }

            element "robot_user" {
                properties {
                    c4plantuml.sprite robot
                }
            }

            element "users" {
                properties {
                    c4plantuml.sprite users
                }
            }

            element "multi" {
                properties {
                    c4plantuml.shadow true
                }    
            }
        }
    }
}

the stereotypes are shown:
image

image

Commenting out the include does not change the behavior.
I couldn't isolate exactly what causes the stereotypes to show up.
I had to call HIDE_STEREOTYPES() in an external puml include in order to workaround this.

@dgutson
Copy link
Author

dgutson commented Nov 7, 2022

Removing the whole styles {} block also preserves the behavior.

@dgutson
Copy link
Author

dgutson commented Nov 7, 2022

I think I spotted it:

        properties {
            #plantuml.includes https://raw.githubusercontent.com/plantuml/plantuml-stdlib/master/tupadr3/font-awesome-5/users.puml
            #c4plantuml.tags true
            #c4plantuml.legend false
            plantuml.sequenceDiagram true
        }

Commenting and uncommenting c4plantuml.legend false makes the difference between showing or not the stereotype.

@simonbrowndotje
Copy link
Contributor

It's the call to SHOW_LEGEND() in the PlantUML that's causing the stereotypes to appear or not. These two examples both render differently:

@startuml
!include https://raw.githubusercontent.com/plantuml-stdlib/C4-PlantUML/master/C4.puml
!include https://raw.githubusercontent.com/plantuml-stdlib/C4-PlantUML/master/C4_Context.puml

System(SoftwareSystem, "Software System")

SHOW_LEGEND()
@enduml
@startuml
!include https://raw.githubusercontent.com/plantuml-stdlib/C4-PlantUML/master/C4.puml
!include https://raw.githubusercontent.com/plantuml-stdlib/C4-PlantUML/master/C4_Context.puml

System(SoftwareSystem, "Software System")

@enduml

You'll need to ask the C4-PlantUML team why this happens ... I suspect it's because you generally want the legend or the stereotypes, but not both, and not neither.

@dgutson
Copy link
Author

dgutson commented Nov 7, 2022

Why not adding HIDE_STEREOTYPES() when c4plantuml.legend is false then?

@dgutson
Copy link
Author

dgutson commented Nov 7, 2022

Anyways I can ask to confirm.

@dgutson
Copy link
Author

dgutson commented Nov 7, 2022

I found this plantuml-stdlib/C4-PlantUML#37 which could be related.

@dgutson
Copy link
Author

dgutson commented Nov 7, 2022

@simonbrowndotje they confirmed, I think structurizr should just add the HIDE_STEREOTYPES() call as I suggested above, since your hypothesis was correct.

@dgutson
Copy link
Author

dgutson commented Nov 7, 2022

Didn't test it yet but fix should look like:

--- a/src/main/java/com/structurizr/export/plantuml/C4PlantUMLExporter.java
+++ b/src/main/java/com/structurizr/export/plantuml/C4PlantUMLExporter.java
@@ -165,10 +165,13 @@ public class C4PlantUMLExporter extends AbstractPlantUMLExporter {

     @Override
     protected void writeFooter(View view, IndentingWriter writer) {
+        writer.writeLine();
         if (includeLegend(view)) {
-            writer.writeLine();
             writer.writeLine("SHOW_LEGEND()");
         }
+        else {
+            writer.writeLine("HIDE_STEREOTYPE()");
+        }

         super.writeFooter(view, writer);
     }

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants