Skip to content

Commit

Permalink
Better mirror how the Structurizr web renderer deals with element sty…
Browse files Browse the repository at this point in the history
…ling.
  • Loading branch information
simonbrowndotje committed Mar 28, 2021
1 parent c79d3a8 commit 44d197d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public void test_findElementStyle_WithThemes() {
assertEquals(Shape.RoundedBox, style.getShape()); // from workspace
assertNull(style.getIcon());
assertEquals(Border.Solid, style.getBorder());
assertEquals("#dddddd", style.getStroke());
assertEquals("#b20000", style.getStroke());
assertEquals(new Integer(100), style.getOpacity());
assertEquals(true, style.getMetadata());
assertEquals(true, style.getDescription());
Expand Down
14 changes: 13 additions & 1 deletion structurizr-core/src/com/structurizr/view/Styles.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.structurizr.view;

import com.structurizr.Workspace;
import com.structurizr.model.DeploymentNode;
import com.structurizr.model.Element;
import com.structurizr.model.Relationship;
import com.structurizr.model.Tags;
Expand Down Expand Up @@ -141,7 +142,13 @@ private RelationshipStyle findRelationshipStyle(String tag) {
}

public ElementStyle findElementStyle(Element element) {
ElementStyle style = new ElementStyle("").background("#dddddd").stroke("#dddddd").color("#000000").shape(Shape.Box).fontSize(24).border(Border.Solid).opacity(100).metadata(true).description(true);
ElementStyle style = new ElementStyle("").background("#dddddd").color("#000000").shape(Shape.Box).fontSize(24).border(Border.Solid).opacity(100).metadata(true).description(true);

if (element instanceof DeploymentNode) {
style.setBackground("#ffffff");
style.setColor("#000000");
style.setStroke("#888888");
}

if (element != null) {
for (String tag : element.getTagsAsSet()) {
Expand All @@ -168,6 +175,11 @@ public ElementStyle findElementStyle(Element element) {
}
}

if (style.getStroke() == null) {
java.awt.Color color = java.awt.Color.decode(style.getBackground());
style.setStroke(String.format("#%06X", (0xFFFFFF & color.darker().getRGB())));
}

return style;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public void test_findElementStyle_ReturnsTheDefaultStyle_WhenPassedNull() {
assertEquals(Shape.Box, style.getShape());
assertNull(style.getIcon());
assertEquals(Border.Solid, style.getBorder());
assertEquals("#dddddd", style.getStroke());
assertEquals("#9a9a9a", style.getStroke());
assertEquals(new Integer(100), style.getOpacity());
assertEquals(true, style.getMetadata());
assertEquals(true, style.getDescription());
Expand All @@ -39,7 +39,7 @@ public void test_findElementStyle_ReturnsTheDefaultStyle_WhenNoStylesAreDefined(
assertEquals(Shape.Box, style.getShape());
assertNull(style.getIcon());
assertEquals(Border.Solid, style.getBorder());
assertEquals("#dddddd", style.getStroke());
assertEquals("#9a9a9a", style.getStroke());
assertEquals(new Integer(100), style.getOpacity());
assertEquals(true, style.getMetadata());
assertEquals(true, style.getDescription());
Expand Down

0 comments on commit 44d197d

Please sign in to comment.