-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
nested state grouping works improperly #3700
Comments
I came across the same issue. It looks like if you add an edge inside a subgraph, both of the connected nodes are added/inserted into the subgraph, even if the node itself was declared outside of the subgraph. Here is a simple example of the issue;
|
This is a minimal state diagram that shows the problem: stateDiagram-v2
[*] --> A
A --> b1
state B {
b1 --> C
}
C --> [*]
Link to the above in Mermaid Live online editor Interestingly, adding a note to C changes the layout. Here is a diagram with 3 examples. Example #2 is the same as Example #1 except it has a note attached. stateDiagram-v2
A : Example 1
A --> b1
note right of B1
C is first encountered \nwithin state B1\nand so is assumed\n to be within it.
end note
B1 : Composite B #1
state B1{
b1 --> C
}
C --> D
note right of D
The relationship 'C --> D'\nis outside (after) state B1\n so D is interprested as outside of B.
end note
A2 : Example 2\n(note attached)
A2 --> b1_2
B2 : Composite B #2\n(same as B1)
state B2 {
b1_2--> C2
}
C2 --> D2
note left of C2
This is the same as\nExample 1 except\nC2 has a note attached.\nThis changes how C2\nis interpreted.\nHere is causes C2 to \nbe placed outside of\n Composite B #2!
end note
A3 : Example 3\nrelationship after\nComposite B #3 ends
A3 --> b1_3
B3 : Composite B #3
state B3 {
b1_3
}
b1_3 --> C3
C3 --> D3
note left of C3
This works\nwhen the relationship\nfrom b1_3 to C3\nis put after the close\nof Composite B #3
end note
|
I can work on this. |
@SpacyRicochet Your example is for a flowchart. Although the error is happening in both, the code is different (there is no reason you would necessarily know that). |
With reference to this example, I wondered what would happen if the whole lot was enclosed in another outer state, so tried this.... stateDiagram-v2
A : Example 1
[*] --> Outer
state Outer {
A --> b1
note right of B1
C is first encountered \nwithin state B1\nand so is assumed\n to be within it.
end note
B1 : Composite B #1
state B1{
b1 --> C
}
C --> D
note right of D
The relationship 'C --> D'\nis outside (after) state B1\n so D is interprested as outside of B.
end note
A2 : Example 2\n(note attached)
A2 --> b1_2
B2 : Composite B #2\n(same as B1)
state B2 {
b1_2--> C2
}
C2 --> D2
note left of C2
This is the same as\nExample 1 except\nC2 has a note attached.\nThis changes how C2\nis interpreted.\nHere is causes C2 to \nbe placed outside of\n Composite B #2!
end note
A3 : Example 3\nrelationship after\nComposite B #3 ends
A3 --> b1_3
B3 : Composite B #3
state B3 {
b1_3
}
b1_3 --> C3
C3 --> D3
note left of C3
This works\nwhen the relationship\nfrom b1_3 to C3\nis put after the close\nof Composite B #3
end note
}
But, on the live editor (and here, it would seem!), no diagram is shown - the error is displayed here so it might be that there is just something wrong (as I'm new to Mermaid), but I'm at a bit of a loss as to why just wrapping all that in another outer state would totally break it. Moving the closing brace of state Outer to just above the stateDiagram-v2
A : Example 1
[*] --> Outer
state Outer {
A --> b1
note right of B1
C is first encountered \nwithin state B1\nand so is assumed\n to be within it.
end note
B1 : Composite B #1
state B1{
b1 --> C
}
C --> D
note right of D
The relationship 'C --> D'\nis outside (after) state B1\n so D is interprested as outside of B.
end note
A2 : Example 2\n(note attached)
A2 --> b1_2
B2 : Composite B #2\n(same as B1)
state B2 {
b1_2--> C2
}
C2 --> D2
note left of C2
This is the same as\nExample 1 except\nC2 has a note attached.\nThis changes how C2\nis interpreted.\nHere is causes C2 to \nbe placed outside of\n Composite B #2!
end note
A3 : Example 3\nrelationship after\nComposite B #3 ends
A3 --> b1_3
B3 : Composite B #3
state B3 {
b1_3
}
}
b1_3 --> C3
C3 --> D3
note left of C3
This works\nwhen the relationship\nfrom b1_3 to C3\nis put after the close\nof Composite B #3
end note
This is the sort of thing I've tried; it's a slightly more complex state diagram, but.. stateDiagram-v2
[*] --> A
state A {
[*] --> B
state check <<choice>>
B --> check : B Result
check --> C : success
check --> D : failure
C --> E : Ev1
state F {
[*] --> G
G --> I : Ev2
I --> G : Ev3
G --> H : Ev4
H --> G
I --> J : success
J --> H : Ev4
G --> E : Ev1
}
}
Basically, state stateDiagram-v2
[*] --> A
state A {
[*] --> B
state check <<choice>>
B --> check : B Result
check --> C : success
check --> D : failure
C --> E : Ev1
state F {
[*] --> G
G --> I : Ev2
I --> G : Ev3
G --> H : Ev4
H --> G
I --> J : success
J --> H : Ev4
}
G --> E : Ev1
}
Maybe I'm doing something wrong, but... |
The grouping here seems all off.
Idle
andFault
should both be in the outer context.The text was updated successfully, but these errors were encountered: