Skip to content

Commit

Permalink
feat: add global diagram settings + update arrow colors + update unit…
Browse files Browse the repository at this point in the history
… tests resources accordingly
  • Loading branch information
Pascal Dal Farra committed Jul 11, 2024
1 parent 961f5ce commit 59df160
Show file tree
Hide file tree
Showing 35 changed files with 234 additions and 192 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,10 @@ public String toPlantUml(
historyStatesToHistoryId = StateMachineHelper.collectHistoryStates(stateMachine);
historyTransitions = new ArrayList<>();

StringBuilder sb = new StringBuilder();
sb.append("""
@startuml
'https://plantuml.com/state-diagram
'hide description area for state without description
hide empty description
""");
StringBuilder sb = new StringBuilder("@startuml\n")
.append(PlantUmlWriterParameters.getStateDiagramSettings(plantUmlWriterParameters))
.append("\n");


// 2nd pass: processing statemachine AND collecting history transitions in 'historyTransitions
processRegion(stateMachine, stateContext, plantUmlWriterParameters, sb, "", null);
Expand Down Expand Up @@ -651,7 +646,7 @@ private void processPseudoStatesTransition(
S target = targetState.getId();
sb.append("""
%s%s
%s%s -%s[%s]-> %s %s
%s%s -%s%s-> %s %s
"""
.formatted(
indent,
Expand Down Expand Up @@ -746,7 +741,7 @@ private void addTransition(
Transition<S, E> transition
) {
sb.append("""
%s%s -%s[%s]-> %s %s
%s%s -%s%s-> %s %s
"""
.formatted(
indent,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package org.springframework.statemachine.plantuml;

import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Value;
import lombok.*;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.lang.Nullable;
Expand All @@ -21,7 +18,48 @@ public class PlantUmlWriterParameters<S> {

private static final Log log = LogFactory.getLog(PlantUmlWriterParameters.class);

// TODO add hidden arrows 'S1 -[hidden]-> S2'
public static final String DEFAULT_STATE_DIAGRAM_SETTINGS = """
'https://plantuml.com/state-diagram
'hide description area for state without description
hide empty description
'https://plantuml.com/fr/skinparam
'https://plantuml-documentation.readthedocs.io/en/latest/formatting/all-skin-params.html
'https://plantuml.com/fr/color
skinparam BackgroundColor white
skinparam DefaultFontColor black
'skinparam DefaultFontName Impact
skinparam DefaultFontSize 14
skinparam DefaultFontStyle Normal
skinparam NoteBackgroundColor #FEFFDD
skinparam NoteBorderColor black
skinparam state {
ArrowColor black
BackgroundColor #F1F1F1
BorderColor #181818
FontColor black
' FontName Impact
FontSize 14
FontStyle Normal
}
""";

@Setter
private String stateDiagramSettings = DEFAULT_STATE_DIAGRAM_SETTINGS;

public static String getStateDiagramSettings(@Nullable PlantUmlWriterParameters<?> plantUmlWriterParameters) {
return plantUmlWriterParameters == null
? DEFAULT_STATE_DIAGRAM_SETTINGS
: plantUmlWriterParameters.getStateDiagramSettings();
}

private String getStateDiagramSettings() {
return stateDiagramSettings == null
? ""
: stateDiagramSettings;
}

/**
* Direction of an arrow connecting 2 States
Expand Down Expand Up @@ -206,7 +244,7 @@ public String getStateColor(S state, @Nullable S currentState) {
}

public String getArrowColor(boolean isCurrentTransaction) {
return isCurrentTransaction ? "#FF0000" : "#000000";
return isCurrentTransaction ? "[#FF0000]" : "";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,15 @@ void plantUmlTest(String resourcePath, PlantUmlWriterParameters<String> plantUml
// make umlStateMachineModelFactory aware of beans available in BeansForUmlFiles.class
umlStateMachineModelFactory.setBeanFactory(context);

if (plantUmlWriterParameters == null) {
plantUmlWriterParameters = new PlantUmlWriterParameters<>();
}// setting some PlantUml parameters
plantUmlWriterParameters.setStateDiagramSettings("""
'https://plantuml.com/state-diagram
'hide description area for state without description
hide empty description
""");
// Dumping statemachine to PlantUml diagram
String stateMachineAsPlantUML = new PlantUmlWriter<String, String>()
.toPlantUml(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ state S5
state S6


[*] -[#000000]-> S1
S1 -down[#000000]-> CHOICE1 : E1\n/ s1ToChoice
CHOICE1 -down[#000000]-> CHOICE2 : [choice2Guard]\n/ choice1ToChoice2
CHOICE2 -down[#000000]-> S6 : / choiceToS6
CHOICE2 -down[#000000]-> S5 : [s5Guard]\n/ choiceToS5
CHOICE1 -down[#000000]-> S4 : / choiceToS4
CHOICE1 -down[#000000]-> S3 : [s3Guard]
CHOICE1 -down[#000000]-> S2 : [s2Guard]\n/ choiceToS2
[*] --> S1
CHOICE1 -down-> CHOICE2 : [choice2Guard]\n/ choice1ToChoice2
CHOICE1 -down-> S2 : [s2Guard]\n/ choiceToS2
CHOICE1 -down-> S3 : [s3Guard]
CHOICE1 -down-> S4 : / choiceToS4
CHOICE2 -down-> S5 : [s5Guard]\n/ choiceToS5
CHOICE2 -down-> S6 : / choiceToS6
S1 -down-> CHOICE1 : E1\n/ s1ToChoice

@enduml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ state S5
state S6


[*] -[#000000]-> S1
S1 -down[#000000]-> JUNCTION1 : E1\n/ s1ToChoice
JUNCTION1 -down[#000000]-> JUNCTION2 : [choice2Guard]\n/ choice1ToChoice2
JUNCTION2 -down[#000000]-> S6 : / choiceToS6
JUNCTION2 -down[#000000]-> S5 : [s5Guard]\n/ choiceToS5
JUNCTION1 -down[#000000]-> S4 : / choiceToS4
JUNCTION1 -down[#000000]-> S3 : [s3Guard]
JUNCTION1 -down[#000000]-> S2 : [s2Guard]\n/ choiceToS2
[*] --> S1
JUNCTION1 -down-> JUNCTION2 : [choice2Guard]\n/ choice1ToChoice2
JUNCTION1 -down-> S2 : [s2Guard]\n/ choiceToS2
JUNCTION1 -down-> S3 : [s3Guard]
JUNCTION1 -down-> S4 : / choiceToS4
JUNCTION2 -down-> S5 : [s5Guard]\n/ choiceToS5
JUNCTION2 -down-> S6 : / choiceToS6
S1 -down-> JUNCTION1 : E1\n/ s1ToChoice

@enduml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ state S1
state S2


[*] -[#000000]-> S1
S1 -down[#000000]-> S2
[*] --> S1
S1 -down-> S2

@enduml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ state S1
state S2


[*] -[#000000]-> S1 : / initialAction
S1 -down[#000000]-> S2 : E1
[*] --> S1 : / initialAction
S1 -down-> S2 : E1

@enduml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ state choice1 <<choice>>
note left of choice1 : choice1


[*] -[#000000]-> S1
S1 -down[#000000]-> choice1 : E1
choice1 -down[#000000]-> S2 : [s2Guard]
choice1 -down[#000000]-> S3 : [s3Guard]
choice1 -down[#000000]-> S4
[*] --> S1
S1 -down-> choice1 : E1
choice1 -down-> S2 : [s2Guard]
choice1 -down-> S3 : [s3Guard]
choice1 -down-> S4

@enduml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ state S2 {
state S21


[*] -[#000000]-> S20
[*] --> S20
state S30
state S31


[*] -[#000000]-> S30
[*] --> S30
}
'S3 <<JOIN>>
state S3 <<join>>
Expand All @@ -29,17 +29,17 @@ note left of SF : SF
state SI


S1 -down[#000000]-> S20
S1 -down-> S20

S1 -down[#000000]-> S30
S1 -down-> S30

[*] -[#000000]-> SI
S20 -down[#000000]-> S21 : E2
S30 -down[#000000]-> S31 : E3
SI -down[#000000]-> S1 : E1
S31 -down[#000000]-> S3
S21 -down[#000000]-> S3
S3 -down[#000000]-> S4 : [extendedState.variables.isEmpty()]
S3 -down[#000000]-> SF : [!extendedState.variables.isEmpty()]
[*] --> SI
S20 -down-> S21 : E2
S21 -down-> S3
S30 -down-> S31 : E3
S31 -down-> S3
S3 -down-> S4 : [extendedState.variables.isEmpty()]
S3 -down-> SF : [!extendedState.variables.isEmpty()]
SI -down-> S1 : E1

@enduml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ state S1 {
state S12


[*] -[#000000]-> S11
[*] --> S11
}


[*] -[#000000]-> S1
S11 -down[#000000]-> CHOICE
CHOICE -down[#000000]-> S12
[*] --> S1
CHOICE -down-> S12
S11 -down-> CHOICE

@enduml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ state S1 {
state S12


[*] -[#000000]-> S11
[*] --> S11
}


[*] -[#000000]-> S1
S11 -down[#000000]-> CHOICE
CHOICE -down[#000000]-> S12
[*] --> S1
CHOICE -down-> S12
S11 -down-> CHOICE

@enduml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ S2 : /entry s2Entry
S2 : /do extendedState.variables.put('hellos2do','hellos2dovalue')


[*] -[#000000]-> S1
S1 -down[#000000]-> S2 : E1\n/ e1Action
[*] --> S1
S1 -down-> S2 : E1\n/ e1Action

@enduml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ state S3
state S4


[*] -[#000000]-> S1
S1 -down[#000000]-> CHOICE : E1
CHOICE -down[#000000]-> S4
CHOICE -down[#000000]-> S3 : [s3Guard]
CHOICE -down[#000000]-> S2 : [s2Guard]
[*] --> S1
CHOICE -down-> S2 : [s2Guard]
CHOICE -down-> S3 : [s3Guard]
CHOICE -down-> S4
S1 -down-> CHOICE : E1

@enduml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@startuml
note "!!! NOT WORKING !!!\n!!! Missing 'EXIT -down[#000000]-> S4' transition !!!\n It seems ConnectionPointRef is not supported by Spring Statemachine" as NOT_WORKING
note "!!! NOT WORKING !!!\n!!! Missing 'EXIT -down-> S4' transition !!!\n It seems ConnectionPointRef is not supported by Spring Statemachine" as NOT_WORKING
'https://plantuml.com/state-diagram

'hide description area for state without description
Expand All @@ -11,20 +11,20 @@ state S2 {
state S22


[*] -[#000000]-> S21
[*] --> S21
state ENTRY <<entryPoint>>
state EXIT <<exitPoint>>
}
state S3
state S4


[*] -[#000000]-> S1
S1 -down[#000000]-> S2 : E1
ENTRY -down[#000000]-> S22
S22 -down[#000000]-> EXIT : E4
S1 -down[#000000]-> ENTRY : E3
S2 -down[#000000]-> S3 : E2
EXIT -down[#000000]-> S4
[*] --> S1
S1 -down-> S2 : E1
ENTRY -down-> S22
S22 -down-> EXIT : E4
S1 -down-> ENTRY : E3
S2 -down-> S3 : E2
EXIT -down-> S4

@enduml
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ state S2 {
state S22


[*] -[#000000]-> S21
[*] --> S21
state ENTRY <<entryPoint>>
state EXIT <<exitPoint>>
}
state S3
state S4


[*] -[#000000]-> S1
ENTRY -down[#000000]-> S22
S22 -down[#000000]-> EXIT : E4
S1 -down[#000000]-> ENTRY : E3
EXIT -down[#000000]-> S4
S1 -down[#000000]-> S2 : E1
S2 -down[#000000]-> S3 : E2
[*] --> S1
ENTRY -down-> S22
EXIT -down-> S4
S1 -down-> ENTRY : E3
S1 -down-> S2 : E1
S22 -down-> EXIT : E4
S2 -down-> S3 : E2

@enduml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ state S2
state S3


[*] -[#000000]-> S1
S1 -down[#000000]-> S2 : E1
S2 -down[#000000]-> S3 : E2
[*] --> S1
S1 -down-> S2 : E1
S2 -down-> S3 : E2

@enduml
Loading

0 comments on commit 59df160

Please sign in to comment.