Skip to content
This repository was archived by the owner on Jan 10, 2024. It is now read-only.

Commit 7cdec9a

Browse files
Mermaid exporter now correctly styles software system/container boundaries in the same way the Structurizr renderer and PlantUML exporters do.
1 parent 45dfe34 commit 7cdec9a

File tree

7 files changed

+13
-29
lines changed

7 files changed

+13
-29
lines changed

src/main/java/com/structurizr/export/mermaid/MermaidDiagramExporter.java

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,8 @@ protected void endGroupBoundary(ModelView view, IndentingWriter writer) {
133133

134134
@Override
135135
protected void startSoftwareSystemBoundary(ModelView view, SoftwareSystem softwareSystem, IndentingWriter writer) {
136-
String color;
137-
if (softwareSystem.equals(view.getSoftwareSystem())) {
138-
color = "#444444";
139-
} else {
140-
color = "#cccccc";
141-
}
136+
ElementStyle elementStyle = view.getViewSet().getConfiguration().getStyles().findElementStyle(softwareSystem);
137+
String color = elementStyle.getStroke();
142138

143139
writer.writeLine(String.format("subgraph %s [%s]", softwareSystem.getId(), softwareSystem.getName()));
144140
writer.indent();
@@ -155,20 +151,8 @@ protected void endSoftwareSystemBoundary(ModelView view, IndentingWriter writer)
155151

156152
@Override
157153
protected void startContainerBoundary(ModelView view, Container container, IndentingWriter writer) {
158-
String color = "#444444";
159-
if (view instanceof ComponentView) {
160-
if (container.equals(((ComponentView)view).getContainer())) {
161-
color = "#444444";
162-
} else {
163-
color = "#cccccc";
164-
}
165-
} else if (view instanceof DynamicView) {
166-
if (container.equals(((DynamicView)view).getElement())) {
167-
color = "#444444";
168-
} else {
169-
color = "#cccccc";
170-
}
171-
}
154+
ElementStyle elementStyle = view.getViewSet().getConfiguration().getStyles().findElementStyle(container);
155+
String color = elementStyle.getStroke();
172156

173157
writer.writeLine(String.format("subgraph %s [%s]", container.getId(), container.getName()));
174158
writer.indent();

src/test/java/com/structurizr/export/mermaid/36141-Components.mmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ graph TB
1616
style 21 fill:#438dd5,stroke:#2e6295,color:#ffffff
1717

1818
subgraph 20 [API Application]
19-
style 20 fill:#ffffff,stroke:#444444,color:#444444
19+
style 20 fill:#ffffff,stroke:#2e6295,color:#2e6295
2020

2121
29["<div style='font-weight: bold'>Sign In Controller</div><div style='font-size: 70%; margin-top: 0px'>[Component: Spring MVC Rest Controller]</div><div style='font-size: 80%; margin-top:10px'>Allows users to sign in to<br />the Internet Banking System.</div>"]
2222
style 29 fill:#85bbf0,stroke:#5d82a8,color:#000000

src/test/java/com/structurizr/export/mermaid/36141-Containers.mmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ graph TB
1212
style 6 fill:#999999,stroke:#6b6b6b,color:#ffffff
1313

1414
subgraph 2 [Internet Banking System]
15-
style 2 fill:#ffffff,stroke:#444444,color:#444444
15+
style 2 fill:#ffffff,stroke:#0b4884,color:#0b4884
1616

1717
17["<div style='font-weight: bold'>Single-Page Application</div><div style='font-size: 70%; margin-top: 0px'>[Container: JavaScript and Angular]</div><div style='font-size: 80%; margin-top:10px'>Provides all of the Internet<br />banking functionality to<br />customers via their web<br />browser.</div>"]
1818
style 17 fill:#438dd5,stroke:#2e6295,color:#ffffff

src/test/java/com/structurizr/export/mermaid/36141-SignIn.mmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ graph TB
55
style diagram fill:#ffffff,stroke:#ffffff
66

77
subgraph 20 [API Application]
8-
style 20 fill:#ffffff,stroke:#444444,color:#444444
8+
style 20 fill:#ffffff,stroke:#2e6295,color:#2e6295
99

1010
29["<div style='font-weight: bold'>Sign In Controller</div><div style='font-size: 70%; margin-top: 0px'>[Component: Spring MVC Rest Controller]</div><div style='font-size: 80%; margin-top:10px'>Allows users to sign in to<br />the Internet Banking System.</div>"]
1111
style 29 fill:#85bbf0,stroke:#5d82a8,color:#000000

src/test/java/com/structurizr/export/mermaid/MermaidDiagramExporterTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,14 @@ public void test_renderContainerDiagramWithExternalContainers() {
149149
" style diagram fill:#ffffff,stroke:#ffffff\n" +
150150
"\n" +
151151
" subgraph 1 [Software System 1]\n" +
152-
" style 1 fill:#ffffff,stroke:#444444,color:#444444\n" +
152+
" style 1 fill:#ffffff,stroke:#9a9a9a,color:#9a9a9a\n" +
153153
"\n" +
154154
" 2[\"<div style='font-weight: bold'>Container 1</div><div style='font-size: 70%; margin-top: 0px'>[Container]</div>\"]\n" +
155155
" style 2 fill:#dddddd,stroke:#9a9a9a,color:#000000\n" +
156156
" end\n" +
157157
"\n" +
158158
" subgraph 3 [Software System 2]\n" +
159-
" style 3 fill:#ffffff,stroke:#cccccc,color:#cccccc\n" +
159+
" style 3 fill:#ffffff,stroke:#9a9a9a,color:#9a9a9a\n" +
160160
"\n" +
161161
" 4[\"<div style='font-weight: bold'>Container 2</div><div style='font-size: 70%; margin-top: 0px'>[Container]</div>\"]\n" +
162162
" style 4 fill:#dddddd,stroke:#9a9a9a,color:#000000\n" +
@@ -190,14 +190,14 @@ public void test_renderComponentDiagramWithExternalComponents() {
190190
" style diagram fill:#ffffff,stroke:#ffffff\n" +
191191
"\n" +
192192
" subgraph 2 [Container 1]\n" +
193-
" style 2 fill:#ffffff,stroke:#444444,color:#444444\n" +
193+
" style 2 fill:#ffffff,stroke:#9a9a9a,color:#9a9a9a\n" +
194194
"\n" +
195195
" 3[\"<div style='font-weight: bold'>Component 1</div><div style='font-size: 70%; margin-top: 0px'>[Component]</div>\"]\n" +
196196
" style 3 fill:#dddddd,stroke:#9a9a9a,color:#000000\n" +
197197
" end\n" +
198198
"\n" +
199199
" subgraph 5 [Container 2]\n" +
200-
" style 5 fill:#ffffff,stroke:#cccccc,color:#cccccc\n" +
200+
" style 5 fill:#ffffff,stroke:#9a9a9a,color:#9a9a9a\n" +
201201
"\n" +
202202
" 6[\"<div style='font-weight: bold'>Component 2</div><div style='font-size: 70%; margin-top: 0px'>[Component]</div>\"]\n" +
203203
" style 6 fill:#dddddd,stroke:#9a9a9a,color:#000000\n" +

src/test/java/com/structurizr/export/mermaid/groups-Components.mmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ graph TB
88
style 3 fill:#dddddd,stroke:#9a9a9a,color:#000000
99

1010
subgraph 6 [F]
11-
style 6 fill:#ffffff,stroke:#444444,color:#444444
11+
style 6 fill:#ffffff,stroke:#9a9a9a,color:#9a9a9a
1212

1313
subgraph group1 [Group 4]
1414
style group1 fill:#ffffff,stroke:#cccccc,color:#cccccc

src/test/java/com/structurizr/export/mermaid/groups-Containers.mmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ graph TB
88
style 3 fill:#dddddd,stroke:#9a9a9a,color:#000000
99

1010
subgraph 4 [D]
11-
style 4 fill:#ffffff,stroke:#444444,color:#444444
11+
style 4 fill:#ffffff,stroke:#9a9a9a,color:#9a9a9a
1212

1313
subgraph group1 [Group 3]
1414
style group1 fill:#ffffff,stroke:#cccccc,color:#cccccc

0 commit comments

Comments
 (0)