Confusing behavior with nested elements

0 votes
asked Aug 23 in Bug by dnoland (120 points)

Hello, sorry if this has been asked before (I didn't find it when I searched).

I think I have found a bug in the rendering of component diagrams.

This diagram behaves as expected.

@startuml
' Behaves as expected
rectangle food {
  rectangle vegetable {
  }
}
rectangle food {
  rectangle fruit {
  }
}
rectangle "not a food" {
}
@enduml

While this diagram has some very confusing behavior. 

@startuml
rectangle food {
  rectangle vegetable {
  }
}
rectangle food {
  rectangle fruit {
  }
}
rectangle fruit {
}
' The "not a food" rectangle is included in the food rectangle?
rectangle "not a food"
@enduml

Specifically, the "not a food" rectangle is included in the food rectangle where the diagram definition does not seem to include it.

I assume this is not the intended behavior for plantuml.

Am I simply abusing plantuml by declaring food twice?

I have found it very useful to be able to inject elements into the layout hierarchy independent of the location of their initial declaration (it is a handy trick when using the preprocessor to build complex diagrams).

This behavior is obviously reproducible with the plantuml webserver but I also verified it using the following plantuml version (packaged with ArchLinux).
 

PlantUML version 1.2020.15 (Sun Jun 28 05:39:45 MDT 2020)
(GPL source distribution)
Java Runtime: OpenJDK Runtime Environment
JVM: OpenJDK 64-Bit Server VM
Default Encoding: UTF-8
Language: en
Country: US
 
PLANTUML_LIMIT_SIZE: 4096

Dot version: dot - graphviz version 2.44.1 (0)
Installation seems OK. File generation OK 

Thanks in advance for any help :)

commented Aug 24 by albert (2,900 points)

I think the confusing comes from the double usage of the label fruit and also implicitly of the ID fruit on different levels.

When using:

@startuml
rectangle food {
  rectangle vegetable {
  }
}
rectangle food {
  rectangle fruit {
  }
}
rectangle fruit as F2 {
}
' The "not a food" rectangle is included in the food rectangle?
rectangle "not a food"
@enduml

i.e. explicitly specifying the ID for  the second fruit (for clarity it would probably be better to have all fruits to have a label) I think the problem is gone.

Did I overlook something?

commented Aug 24 by dnoland (120 points)
I guess my bigger question is why the behavior in my second diagram happens in the first place.

I can work around the issue as you point out but I still feel that the context of the fruit rectangle leaking into another scope is a bug.

Is there some reason why that would be the desired behavior?

Also, I am unclear if declaring food twice in the way I have here is supported behavior.

Is it a bug that any of that renders at all?
commented Aug 25 by albert (2,900 points)

I don't know the internals either but I guess that the ID of the rectangle fruit in booth cases is fruit and that the scope is not stored otherwise the scope of the first case should be something like food.fruit and in the second case just fruit.

Furthermore it is strange that rectangle "not a food" is also place inside the rectangle food, this look clearly like a bug to me.

I think @plantuml should shine a light on this problem.

commented Aug 26 by dnoland (120 points)
I agree.  I can't see how this could be the desired behavior.

Thanks for taking a look at it :)

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:

[Antispam2 Feature: please please wait 1 or 2 minutes (this message will disappear) before pressing the button otherwise it will fail](--------)
To avoid this verification in future, please log in or register.
...