Why does an arrow make a duplicate component?

0 votes
asked Mar 3, 2021 in Question / help by scott_sauyet (120 points)

I'm very new to PlantUML, so this is likely something basic.

Sometimes when I add a arrow from one rectangle to another, the original component is not linked.  Instead, a new component is created and linked.  What am I doing wrong?

In my example, I have this fairly simple diagram:

@startuml
database "DB" {
  frame Rules {
    rectangle "Item 1"
    rectangle "Item 2"
  }
}

rectangle "App Server" {
  rectangle "My UI"
}

rectangle "System" {
  rectangle "Foo"
}

[My UI] --> [Item 1] : create and edit
[System] --> [Item 1] : extract
@enduml

And this is generated:

Resulting Diagram


Note that the arrow from System to Item 1 is for a new component and not the existing "System" element.

What am I doing wrong?

1 Answer

0 votes
answered Mar 3, 2021 by plantuml (295,000 points)
selected Mar 3, 2021 by scott_sauyet
 
Best answer

You should use this instead :

@startuml
database "DB" {
  frame Rules {
    rectangle "Item 1"
    rectangle "Item 2"
  }
}

rectangle "App Server" {
  rectangle "My UI"
}

rectangle "System" {
  rectangle "Foo"
}

[My UI] --> [Item 1] : create and edit
System --> [Item 1] : extract
@enduml

http://www.plantuml.com/plantuml/uml/ROyn3u9038Nt-nKljpFew63G61C65uaJOQXSDIOSa5un4iD_5s4XwDZtldvfuw0aslhIE5AwKc3OmzxYRO2Ra6USsvB3E0F2XL9rBmSeKVPOsR_n-XltfZTcrkoQ1YdBasMopwfJXqjY5tpQ1MN_mnxhUYIpSIb756sHJSVasA0G9cLGvS3keMQoB2b-gL2X9kRA3Rz_0000

I agree that the syntax is not very convenient in that case. 

commented Mar 3, 2021 by scott_sauyet (120 points)
Thank you very much.

So it looks as though the brackets can be used when -- and only when -- the name contains a space.  I guess that makes sense.
commented Mar 3, 2021 by Martin (8,360 points)
edited Mar 4, 2021 by Martin

No, it seems to be more to do with whether the thing you are referencing is a container or not.  So System contains Foo, and so can't be referenced using the [System] notation.  

Therefore I suspect there is no way of referencing the "App Server" container without giving it an alias, because of the space in the name.

As far as I understand, [x] is supposed to represent "the component* called x".  And referring to it will automatically create a component* called x if x doesn't already exist.  The two oddities to me are that it ignores containers (even component* ones), and that it doesn't mind if x already exists as something other than a component*.

* I'm referring to the 'component' shape (the rectangle with the little icon in the top right).

...