Functional subdiagrams

0 votes
asked Dec 17, 2020 in Question / help by agf1997 (140 points)

Sorry for the basic question.  I'm new to plantuml.  Is it possible to create functional subdiagrams that can be used multiple times?

I'm thinking something like this?

@startuml
left to right direction

function myGroup {
  object Foo
  object Bar
  object Baz
  object Qux
  object Quux
  object Quuz
  object Corge
  Foo --> Bar
  Foo --> Baz
  Bar --> Qux
  Bar --> Quux
  Baz --> Quuz
  Baz --> Corge
}

object Top
object myGroup() as myGroup1
object mygroup() as myGroup2

Top --> myGroup1
Top --> myGroup2
@enduml

1 Answer

+1 vote
answered Dec 18, 2020 by The-Lu (12,780 points)
selected 5 days ago by agf1997
 
Best answer

Hello A.,

You can see on processing procedure:

With procedure ('procedure') and sub-diagram ('{{' and '}}'), in order to be as close as possible to your proposal, you can use:

@startuml
!unquoted procedure myGroup($as)
  rectangle $as [
  {{
    object Foo
    object Bar
    object Baz
    object Qux
    object Quux
    object Quuz
    object Corge
    Foo --> Bar
    Foo --> Baz
    Bar --> Qux
    Bar --> Quux
    Baz --> Quuz
    Baz --> Corge
  }}
  ]
!end procedure

object Top
myGroup(myGroup1)
myGroup(myGroup2)

Top --> myGroup1
Top --> myGroup2
@enduml

And here is the result:


[See on PlantUML server]

If that can help,
Regards,
Th.

commented Dec 18, 2020 by agf1997 (140 points)

Thanks TH ... is there a way to

  • Make Top go directly into Foo?
  • remove the box around myGroup?
The goal is to avoid repetitive code but not to call out items in myGroup as being distinct from the rest of the diagram.
Thanks
commented Dec 18, 2020 by agf1997 (140 points)

I suspect I'm close

@startuml
!procedure $myGroup($root)
      {{
      object Foo
      object Bar
      object Baz
      $root --> Foo
      Foo --> Bar
      Foo --> Baz
      }}
!endprocedure

object Top

$myGroup("Top")
$myGroup("Top")
@enduml

commented Dec 18, 2020 by The-Lu (12,780 points)

Hello A.,

In this case don't use sub-diagram, but incremental object (increment alias (with '$i') of object with the same name) as:

@startuml
!procedure myGroup($i)
  object  "Foo"   as Foo##$i
  object  "Bar"   as Bar##$i
  object  "Baz"   as Baz##$i
  object  "Qux"   as Qux##$i
  object  "Quux"  as Quux##$i
  object  "Quuz"  as Quuz##$i
  object  "Corge" as Corge##$i
  Foo##$i --> Bar##$i
  Foo##$i --> Baz##$i
  Bar##$i --> Qux##$i
  Bar##$i --> Quux##$i
  Baz##$i --> Quuz##$i
  Baz##$i --> Corge##$i
!end procedure

object Top
myGroup(1)
myGroup(2)

Top --> Foo1
Top --> Foo2
@enduml

We observe the expected result:


[See on..]

See also on the documentation:

If that can help,
Regards,
Th.

commented Dec 19, 2020 by Martin

It's the same thing really; but instead of indexing the element names, you can simulate Namespaces:

@startuml
!unquoted procedure myGroup($as)
    object "Foo" as $as.Foo
    object "Bar" as $as.Bar
    object "Baz" as $as.Baz
    object "Qux" as $as.Qux
    object "Quux" as $as.Quux
    object "Quuz" as $as.Quuz
    object "Corge" as $as.Corge
    $as.Foo --> $as.Bar
    $as.Foo --> $as.Baz
    $as.Bar --> $as.Qux
    $as.Bar --> $as.Quux
    $as.Baz --> $as.Quuz
    $as.Baz --> $as.Corge
!end procedure

object Top
myGroup(myGroup1)
myGroup(myGroup2)

Top --> myGroup1.Foo
Top --> myGroup2.Foo
@enduml

As an aside: I know the OP says they don't want the boxes around the groups, but with a bit of effort I got Objects to work with real Namespaces.  I'm not sure if it is working by design or by accident as it was quite picky about the syntax.

PS

An additional tweak could be to add the "together" function into the group.  Particularly useful if you have floating objects.  E.g. if you disconnect "Corge" from "Baz".

Compare:

With:

...