Search code examples
plantuml

How can a PlantUML document specify its diagram type?


As far as I can tell, PlantUML auto-detects the diagram type for a given document (sequence diagram, usecase diagram, class diagram, activity diagram, etc.). This seems to work reasonably well, but I sometimes find that while editing a diagram I will make some seemingly minor change and suddenly my Activity diagram becomes a Class diagram (for example).

I would like some way to tell PlantUML what the diagram type is, and have compilation fail if the syntax isn't valid for that one chosen diagram type, but I haven't been able to find anything like this in the PlantUML documentation. Does such a diagram type identifier exist?


Solution

  • The simplest way is to start the diagram description with something that is specific to only one type of diagram.

    E.g. if I had just the following line

    A --> B
    
    • For a class diagram, I could add class A before it
    • For an activity diagram, I could change it to A -->[ ] B
    • For a sequence diagram, I could add participant A before it

    etc.

    In none of the cases is the visualization changed – I'm only adding what would be added automatically anyway.