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

Commit 4015cf7

Browse files
Adds support for element style stroke widths (re: https://github.com/structurizr/structurizr/issues/124).
1 parent 4a37a4e commit 4015cf7

5 files changed

Lines changed: 77 additions & 2 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.3'
11+
version = '1.16.0'
1212

1313
repositories {
1414
mavenCentral()

docs/changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 1.16.0 (unreleased to Maven Central)
4+
5+
- Adds support for element style stroke widths.
6+
37
## 1.15.3 (11th October 2022)
48

59
- Updates some transitive dependencies.

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ public final class ElementStyle extends AbstractStyle {
2626
@JsonInclude(value = JsonInclude.Include.NON_NULL)
2727
private String stroke;
2828

29+
@JsonInclude(value = JsonInclude.Include.NON_NULL)
30+
private Integer strokeWidth;
31+
2932
@JsonInclude(value = JsonInclude.Include.NON_NULL)
3033
private String color;
3134

@@ -164,6 +167,30 @@ public ElementStyle stroke(String color) {
164167
return this;
165168
}
166169

170+
/**
171+
* Gets the stroke width, in pixels, between 1 and 10.
172+
*
173+
* @return the stroke width
174+
*/
175+
public Integer getStrokeWidth() {
176+
return strokeWidth;
177+
}
178+
179+
public void setStrokeWidth(Integer strokeWidth) {
180+
if (strokeWidth == null) {
181+
this.strokeWidth = null;
182+
} else if (strokeWidth < 1) {
183+
this.strokeWidth = 1;
184+
} else {
185+
this.strokeWidth = Math.min(10, strokeWidth);
186+
}
187+
}
188+
189+
public ElementStyle strokeWidth(Integer strokeWidth) {
190+
setStrokeWidth(strokeWidth);
191+
return this;
192+
}
193+
167194
/**
168195
* Gets the foreground (text) colour of the element, as a HTML RGB hex string (e.g. #123456).
169196
*
@@ -352,6 +379,10 @@ void copyFrom(ElementStyle elementStyle) {
352379
this.setStroke(elementStyle.getStroke());
353380
}
354381

382+
if (elementStyle.getStrokeWidth() != null) {
383+
this.setStrokeWidth(elementStyle.getStrokeWidth());
384+
}
385+
355386
if (!StringUtils.isNullOrEmpty(elementStyle.getColor())) {
356387
this.setColor(elementStyle.getColor());
357388
}

structurizr-core/test/unit/com/structurizr/view/ElementStyleTests.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,4 +294,40 @@ void setProperties_SetsTheProperties_WhenANonEmptyMapIsSpecified() {
294294
assertEquals("value", style.getProperties().get("name"));
295295
}
296296

297+
@Test
298+
void setStrokeWidth_WhenNullIsSpecified() {
299+
ElementStyle style = new ElementStyle();
300+
style.setStrokeWidth(10);
301+
style.setStrokeWidth(null);
302+
assertNull(style.getStrokeWidth());
303+
}
304+
305+
@Test
306+
void setStrokeWidth_WhenANegativeIntegerIsSpecified() {
307+
ElementStyle style = new ElementStyle();
308+
style.setStrokeWidth(-1);
309+
assertEquals(1, style.getStrokeWidth());
310+
}
311+
312+
@Test
313+
void setStrokeWidth_WhenZeroIsSpecified() {
314+
ElementStyle style = new ElementStyle();
315+
style.setStrokeWidth(0);
316+
assertEquals(1, style.getStrokeWidth());
317+
}
318+
319+
@Test
320+
void setStrokeWidth_WhenAPositiveIntegerIsSpecified() {
321+
ElementStyle style = new ElementStyle();
322+
style.setStrokeWidth(10);
323+
assertEquals(10, style.getStrokeWidth());
324+
}
325+
326+
@Test
327+
void setStrokeWidth_WhenAPositiveIntegerOver10IsSpecified() {
328+
ElementStyle style = new ElementStyle();
329+
style.setStrokeWidth(20);
330+
assertEquals(10, style.getStrokeWidth());
331+
}
332+
297333
}

structurizr-core/test/unit/com/structurizr/view/StylesTests.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ void findElementStyle_ReturnsTheDefaultStyle_WhenPassedNull() {
2222
assertNull(style.getIcon());
2323
assertEquals(Border.Solid, style.getBorder());
2424
assertEquals("#9a9a9a", style.getStroke());
25+
assertNull(style.getStrokeWidth());
2526
assertEquals(Integer.valueOf(100), style.getOpacity());
2627
assertEquals(true, style.getMetadata());
2728
assertEquals(true, style.getDescription());
@@ -40,6 +41,7 @@ void findElementStyle_ReturnsTheDefaultStyle_WhenNoStylesAreDefined() {
4041
assertNull(style.getIcon());
4142
assertEquals(Border.Solid, style.getBorder());
4243
assertEquals("#9a9a9a", style.getStroke());
44+
assertNull(style.getStrokeWidth());
4345
assertEquals(Integer.valueOf(100), style.getOpacity());
4446
assertEquals(true, style.getMetadata());
4547
assertEquals(true, style.getDescription());
@@ -51,7 +53,7 @@ void findElementStyle_ReturnsTheCorrectStyle_WhenStylesAreDefined() {
5153
element.addTags("Some Tag");
5254

5355
styles.addElementStyle(Tags.SOFTWARE_SYSTEM).background("#ff0000").color("#ffffff");
54-
styles.addElementStyle("Some Tag").color("#0000ff").stroke("#00ff00").shape(Shape.RoundedBox).width(123).height(456);
56+
styles.addElementStyle("Some Tag").color("#0000ff").stroke("#00ff00").strokeWidth(2).shape(Shape.RoundedBox).width(123).height(456);
5557

5658
ElementStyle style = styles.findElementStyle(element);
5759
assertEquals(Integer.valueOf(123), style.getWidth());
@@ -63,6 +65,7 @@ void findElementStyle_ReturnsTheCorrectStyle_WhenStylesAreDefined() {
6365
assertNull(style.getIcon());
6466
assertEquals(Border.Solid, style.getBorder());
6567
assertEquals("#00ff00", style.getStroke());
68+
assertEquals(2, style.getStrokeWidth());
6669
assertEquals(Integer.valueOf(100), style.getOpacity());
6770
assertEquals(true, style.getMetadata());
6871
assertEquals(true, style.getDescription());
@@ -89,6 +92,7 @@ void findElementStyle_ReturnsTheCorrectStyleForAnElementInstance_WhenStylesAreDe
8992
assertNull(style.getIcon());
9093
assertEquals(Border.Solid, style.getBorder());
9194
assertEquals("#00ff00", style.getStroke());
95+
assertNull(style.getStrokeWidth());
9296
assertEquals(Integer.valueOf(100), style.getOpacity());
9397
assertEquals(true, style.getMetadata());
9498
assertEquals(true, style.getDescription());

0 commit comments

Comments
 (0)