How can I tag classes then show only classes bearing given tags in a class diagram?

+1 vote
asked Mar 1, 2018 in Closed feature request by matthewadams12 (240 points)

I'm using the following strategy for my domain model.

  • One file per class, interface, enum, or annotation.  Each class in a file only contains basic attributes (string, datetime, integer, decimal, etc).
  • One file storing all relations, including inheritance, interface implementation, association, aggregation, and composition.
  • Separate class diagram files (each representing a bounded context, AKA a subset of the larger domain model) with @startuml & @enduml directives that !include class/interface/enum/annotation files and the relations file.

The result of this strategy is that I have a high number of hide statements in all class diagram files so that only the classes that I intend to show on the diagram are visible.  This gets tedious.  Worse, if I add a new relation to the relations file, I have to go check all of the other class diagram files to ensure that I didn't just inadvertently add artifacts to the other class diagram files that include the same relations file.

In what way can I add one or more tags to classes/interfaces/enums/annotations, then, in the class diagram file, say something like show only myFirstTag myOtherTag to only show those classes with tags myFirstTag or myOtherTag so that I don't have to have so many hide statements?

This would be a really useful feature.

1 Answer

0 votes
answered Mar 2, 2018 by plantuml (294,960 points)
selected Mar 21, 2018 by Anthony-Gaudino
 
Best answer

We could extends the syntax of the hide/show syntax to hide by default all created classes/interface/enum/annotations.

This is not implemented yet, but imagine a new "hide everything" feature that would by default hide every classes/interface/enum/annotations created.
You would have to declare classes you want to show (in your !include file of each classes).

So something like:

@startuml
hide everything
class foo1
show foo1
class foo2
show foo2
' foo3 and foo4 are not explicitely shown, so they would be hidden.
foo3 --> foo4
@enduml

would only show foo1 and foo2.

Would this suit your needs ?

commented Mar 6, 2018 by plantuml (294,960 points)
Good question...
We could exclude notes from all this show/hide mechanism..
Probably the best solution is to allow tags on note.
So yet another beta http://beta.plantuml.net/plantuml.jar (version 1.2018.02beta20) that supports:
@startuml
class Foo $a
Foo -- Goo
class Bar $z
note "A note" as N1 $z
N1 .. Bar
hide *
show $z
@enduml
What do you think about it ? Does it sound logical to you ?
commented Mar 7, 2018 by matthewadams12 (240 points)
I like that.  It allows me to put notes anywhere.  I'm ok with it, provided that I can add tags to every form of the note syntax (there are many).  From what I can tell, it looks like tags could be appended to the "as" clause in most forms.  Please ensure that _all_ forms of notes can be tagged in the syntax change.

While you're at it, are there any other primitives that could tagged and later hidden/shown?  I've only made these suggestions in the context of class diagrams.  I'd welcome input regarding tags on other artifact types that are in other kinds of diagrams, too!  :)

Great work!

PS: I would find it helpful if y'all were doing this work on a remote branch in a public git repo rather than privately in subversion.  I could've seen the changes you've been making, more easily learned your codebase, played around with things, tried different things out, and, most importantly, saved you some work!  :)
commented Mar 7, 2018 by matthewadams12 (240 points)
edited Mar 7, 2018 by matthewadams12
I just noticed one more thing about hiding elements.  It appears, although I'm not 100% sure, that the hidden elements still take up screen space.  I think it would be preferable, when hiding something, for it to never be included in the diagram at all, so that it never has the ability to take up any space.
commented Mar 7, 2018 by plantuml (294,960 points)
> Please ensure that _all_ forms of notes can be tagged in the syntax change.
> While you're at it, are there any other primitives that could tagged and later hidden/shown?
> I've only made these suggestions in the context of class diagrams.
> I'd welcome input regarding tags on other artifact types that are in other kinds of diagrams, too!  :)
>
Yes, we also would like to extends those tags to every diagrams.
Because of the way we parse texts, it's difficult to garantee that _all_ forms of notes are supported.
It should sound very strange to you, but the quickest way for us to proceed is to wait for users to report bugs...

About hide/show, you're 100% right. This is not something we can change because it has been implemented that way for some users.
The good news is that we've added remove/restore in last beta http://beta.plantuml.net/plantuml.jar that really remove elements. You'll see that it can be an issue, because the layout may be highly impacted by element removals.

So you can have:
@startuml
class Foo $a
Foo -- Goo
class Bar $z
note "A note" as N1 $z
N1 .. Bar
remove *
restore $z
@enduml

About code change, I am aware that using a private subversion is not very open, and that a public git repo would be far better. All this will be released in the incoming days/weeks so that you will be able to see how it works.

Thanks for your tests-to-be about remove/restore :-)
commented Nov 20, 2023 by The-Lu (63,920 points)

Hi PlantUML team,

It seems that the last example is broken...

@startuml
class Foo $a
Foo -- Goo
class Bar $z
note "A note" as N1 $z
N1 .. Bar
remove *
restore $z
@enduml

  • Could you have a look?

See also, same remark here:

Regards,
Th.

...