Skip to content
This repository was archived by the owner on Mar 28, 2026. It is now read-only.

Commit aaaeacd

Browse files
Some minor changes to support building a diagram legend with the PlantUML exporter.
1 parent e9a340c commit aaaeacd

4 files changed

Lines changed: 54 additions & 21 deletions

File tree

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ subprojects { proj ->
88

99
description = 'Structurizr'
1010
group = 'com.structurizr'
11-
version = '1.15.0'
11+
version = '1.15.1'
1212

1313
repositories {
1414
mavenCentral()

structurizr-core/src/com/structurizr/model/ModelItem.java

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.fasterxml.jackson.annotation.JsonIgnore;
44
import com.structurizr.PropertyHolder;
55
import com.structurizr.util.StringUtils;
6+
import com.structurizr.util.TagUtils;
67
import com.structurizr.util.Url;
78

89
import java.util.*;
@@ -45,20 +46,7 @@ void setId(String id) {
4546
* or an empty string if there are no tags
4647
*/
4748
public String getTags() {
48-
Set<String> setOfTags = getTagsAsSet();
49-
50-
if (setOfTags.isEmpty()) {
51-
return "";
52-
}
53-
54-
StringBuilder buf = new StringBuilder();
55-
for (String tag : setOfTags) {
56-
buf.append(tag);
57-
buf.append(",");
58-
}
59-
60-
String tagsAsString = buf.toString();
61-
return tagsAsString.substring(0, tagsAsString.length()-1);
49+
return TagUtils.toString(getTagsAsSet());
6250
}
6351

6452
@JsonIgnore
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.structurizr.util;
2+
3+
import java.util.Collection;
4+
5+
public class TagUtils {
6+
7+
public static String toString(Collection<String> tags) {
8+
if (tags.isEmpty()) {
9+
return "";
10+
}
11+
12+
StringBuilder buf = new StringBuilder();
13+
for (String tag : tags) {
14+
buf.append(tag);
15+
buf.append(",");
16+
}
17+
18+
String tagsAsString = buf.toString();
19+
return tagsAsString.substring(0, tagsAsString.length()-1);
20+
}
21+
22+
}

structurizr-core/src/com/structurizr/view/Styles.java

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.structurizr.model.*;
44
import com.structurizr.util.StringUtils;
5+
import com.structurizr.util.TagUtils;
56

67
import java.util.*;
78

@@ -88,13 +89,14 @@ public RelationshipStyle addRelationshipStyle(String tag) {
8889
*
8990
*
9091
* @param tag the tag (a String)
91-
* @return an ElementStyle instance
92+
* @return an ElementStyle instance, or null if there is no style for the given tag
9293
*/
9394
public ElementStyle findElementStyle(String tag) {
9495
if (tag == null) {
9596
return null;
9697
}
9798

99+
boolean elementStyleExists = false;
98100
tag = tag.trim();
99101
ElementStyle style = new ElementStyle(tag);
100102

@@ -106,11 +108,16 @@ public ElementStyle findElementStyle(String tag) {
106108

107109
for (ElementStyle elementStyle : elementStyles) {
108110
if (elementStyle != null && elementStyle.getTag().equals(tag)) {
111+
elementStyleExists = true;
109112
style.copyFrom(elementStyle);
110113
}
111114
}
112115

113-
return style;
116+
if (elementStyleExists) {
117+
return style;
118+
} else {
119+
return null;
120+
}
114121
}
115122

116123
/**
@@ -119,13 +126,14 @@ public ElementStyle findElementStyle(String tag) {
119126
*
120127
*
121128
* @param tag the tag (a String)
122-
* @return a RelationshipStyle instance
129+
* @return a RelationshipStyle instance, or null if there is no style for the given tag
123130
*/
124131
public RelationshipStyle findRelationshipStyle(String tag) {
125132
if (tag == null) {
126133
return null;
127134
}
128135

136+
boolean relationshipStyleExists = false;
129137
tag = tag.trim();
130138
RelationshipStyle style = new RelationshipStyle(tag);
131139

@@ -138,10 +146,15 @@ public RelationshipStyle findRelationshipStyle(String tag) {
138146
for (RelationshipStyle relationshipStyle : relationshipStyles) {
139147
if (relationshipStyle != null && relationshipStyle.getTag().equals(tag)) {
140148
style.copyFrom(relationshipStyle);
149+
relationshipStyleExists = true;
141150
}
142151
}
143152

144-
return style;
153+
if (relationshipStyleExists) {
154+
return style;
155+
} else {
156+
return null;
157+
}
145158
}
146159

147160
/**
@@ -155,7 +168,7 @@ public RelationshipStyle findRelationshipStyle(String tag) {
155168
* @return an ElementStyle object
156169
*/
157170
public ElementStyle findElementStyle(Element element) {
158-
ElementStyle style = new ElementStyle("").background("#dddddd").color("#000000").shape(Shape.Box).fontSize(24).border(Border.Solid).opacity(100).metadata(true).description(true);
171+
ElementStyle style = new ElementStyle(Tags.ELEMENT).background("#dddddd").color("#000000").shape(Shape.Box).fontSize(24).border(Border.Solid).opacity(100).metadata(true).description(true);
159172

160173
if (element instanceof DeploymentNode) {
161174
style.setBackground("#ffffff");
@@ -164,6 +177,8 @@ public ElementStyle findElementStyle(Element element) {
164177
}
165178

166179
if (element != null) {
180+
Set<String> tagsUsedToComposeStyle = new LinkedHashSet<>();
181+
tagsUsedToComposeStyle.add(Tags.ELEMENT);
167182
String tags = element.getTags();
168183

169184
if (element instanceof SoftwareSystemInstance) {
@@ -179,9 +194,12 @@ public ElementStyle findElementStyle(Element element) {
179194
ElementStyle elementStyle = findElementStyle(tag);
180195
if (elementStyle != null) {
181196
style.copyFrom(elementStyle);
197+
tagsUsedToComposeStyle.add(elementStyle.getTag());
182198
}
183199
}
184200
}
201+
202+
style.setTag(TagUtils.toString(tagsUsedToComposeStyle));
185203
}
186204

187205
if (style.getWidth() == null) {
@@ -219,9 +237,11 @@ public ElementStyle findElementStyle(Element element) {
219237
* @return a RelationshipStyle object
220238
*/
221239
public RelationshipStyle findRelationshipStyle(Relationship relationship) {
222-
RelationshipStyle style = new RelationshipStyle("").thickness(2).color("#707070").dashed(true).routing(Routing.Direct).fontSize(24).width(200).position(50).opacity(100);
240+
RelationshipStyle style = new RelationshipStyle(Tags.RELATIONSHIP).thickness(2).color("#707070").dashed(true).routing(Routing.Direct).fontSize(24).width(200).position(50).opacity(100);
223241

224242
if (relationship != null) {
243+
Set<String> tagsUsedToComposeStyle = new LinkedHashSet<>();
244+
tagsUsedToComposeStyle.add(Tags.RELATIONSHIP);
225245
String tags = relationship.getTags();
226246
String linkedRelationshipId = relationship.getLinkedRelationshipId();
227247

@@ -239,9 +259,12 @@ public RelationshipStyle findRelationshipStyle(Relationship relationship) {
239259
RelationshipStyle relationshipStyle = findRelationshipStyle(tag);
240260
if (relationshipStyle != null) {
241261
style.copyFrom(relationshipStyle);
262+
tagsUsedToComposeStyle.add(relationshipStyle.getTag());
242263
}
243264
}
244265
}
266+
267+
style.setTag(TagUtils.toString(tagsUsedToComposeStyle));
245268
}
246269

247270
return style;

0 commit comments

Comments
 (0)