File tree Expand file tree Collapse file tree 6 files changed +34
-6
lines changed
api/src/main/java/io/serverlessworkflow/api/interfaces
java/io/serverlessworkflow/diagram
resources/templates/plantuml Expand file tree Collapse file tree 6 files changed +34
-6
lines changed Original file line number Diff line number Diff line change @@ -254,7 +254,19 @@ String diagramSVG = workflowDiagram.getSvgDiagram();
254
254
` diagramSVG ` includes the diagram SVG source which you can then decide to save to a file,
255
255
print, or process further.
256
256
257
- Here are some generated diagrams from the specification examples:
257
+ By default the diagram legend is now shown. If you want to enable it you can do:
258
+
259
+ ``` java
260
+ Workflow workflow = Workflow . fromSource(source);
261
+
262
+ WorkflowDiagram workflowDiagram = new WorkflowDiagramImpl ();
263
+ workflowDiagram. setWorkflow(workflow)
264
+ .showLegend(true );
265
+
266
+ String diagramSVG = workflowDiagram. getSvgDiagram();
267
+ ```
268
+
269
+ Here are some generated diagrams from the specification examples (with legend enabled):
258
270
259
271
1 . [ Job Monitoring Example] ( https://github.com/serverlessworkflow/specification/blob/master/examples/examples.md#Monitor-Job-Example )
260
272
<p align =" center " >
Original file line number Diff line number Diff line change @@ -26,4 +26,6 @@ public interface WorkflowDiagram {
26
26
WorkflowDiagram setSource (String source );
27
27
28
28
String getSvgDiagram () throws Exception ;
29
+
30
+ WorkflowDiagram showLegend (boolean showLegend );
29
31
}
Original file line number Diff line number Diff line change @@ -34,6 +34,7 @@ public class WorkflowDiagramImpl implements WorkflowDiagram {
34
34
35
35
private String source ;
36
36
private Workflow workflow ;
37
+ private boolean showLegend = false ;
37
38
38
39
@ Override
39
40
public WorkflowDiagram setWorkflow (Workflow workflow ) {
@@ -46,7 +47,6 @@ public WorkflowDiagram setWorkflow(Workflow workflow) {
46
47
public WorkflowDiagram setSource (String source ) {
47
48
this .source = source ;
48
49
this .workflow = Workflow .fromSource (source );
49
-
50
50
return this ;
51
51
}
52
52
@@ -55,10 +55,16 @@ public String getSvgDiagram() throws Exception {
55
55
if (workflow == null ) {
56
56
throw new IllegalAccessException ("Unable to get diagram - no workflow set." );
57
57
}
58
- SourceStringReader reader = new SourceStringReader (WorkflowToPlantuml .convert (workflow ));
58
+ SourceStringReader reader = new SourceStringReader (WorkflowToPlantuml .convert (workflow , showLegend ));
59
59
final ByteArrayOutputStream os = new ByteArrayOutputStream ();
60
60
String desc = reader .generateImage (os , new FileFormatOption (FileFormat .SVG ));
61
61
os .close ();
62
62
return new String (os .toByteArray (), Charset .forName ("UTF-8" ));
63
63
}
64
+
65
+ @ Override
66
+ public WorkflowDiagram showLegend (boolean showLegend ) {
67
+ this .showLegend = showLegend ;
68
+ return this ;
69
+ }
64
70
}
Original file line number Diff line number Diff line change @@ -36,9 +36,11 @@ public class WorkflowDiagramModel {
36
36
private List <ModelStateDef > modelStateDefs = new ArrayList <>();
37
37
private List <ModelState > modelStates = new ArrayList <>();
38
38
private List <ModelConnection > modelConnections = new ArrayList <>();
39
+ private boolean showLegend ;
39
40
40
- public WorkflowDiagramModel (Workflow workflow ) {
41
+ public WorkflowDiagramModel (Workflow workflow , boolean showLegend ) {
41
42
this .workflow = workflow ;
43
+ this .showLegend = showLegend ;
42
44
inspect (workflow );
43
45
}
44
46
@@ -409,4 +411,8 @@ public List<ModelStateDef> getModelStateDefs() {
409
411
public void setModelStateDefs (List <ModelStateDef > modelStateDefs ) {
410
412
this .modelStateDefs = modelStateDefs ;
411
413
}
414
+
415
+ public boolean getShowLegend () {
416
+ return showLegend ;
417
+ }
412
418
}
Original file line number Diff line number Diff line change 23
23
import org .thymeleaf .context .Context ;
24
24
25
25
public class WorkflowToPlantuml {
26
- public static String convert (Workflow workflow ) {
26
+ public static String convert (Workflow workflow , boolean showLegend ) {
27
27
TemplateEngine plantUmlTemplateEngine = ThymeleafConfig .templateEngine ;
28
28
Context context = new Context ();
29
- context .setVariable ("diagram" , new WorkflowDiagramModel (workflow ));
29
+ context .setVariable ("diagram" , new WorkflowDiagramModel (workflow , showLegend ));
30
30
31
31
return plantUmlTemplateEngine .process ("workflow-template" , context );
32
32
}
Original file line number Diff line number Diff line change @@ -36,10 +36,12 @@ state "[(${diagram.title})]" as workflow << workflow >> {
36
36
37
37
}
38
38
39
+ [# th:if="${diagram.showLegend}" ]
39
40
legend center
40
41
State Types and Border Colors:
41
42
| Event | Operation | Switch | Delay | Parallel | SubFlow | Inject | ForEach | CallBack |
42
43
|<#7fe5f0>|<#bada55>|<#92a0f2>|<#b83b5e>|<#6a2c70>|<#87753c>|<#1e5f74>|<#931a25>|<#ffcb8e>|
43
44
endlegend
45
+ [/]
44
46
45
47
@enduml
You can’t perform that action at this time.
0 commit comments