From 44d197dbc66a595fa1bdbe6ebafc6debf2a2fd3e Mon Sep 17 00:00:00 2001 From: Simon Brown Date: Sun, 28 Mar 2021 14:08:49 +0100 Subject: [PATCH] Better mirror how the Structurizr web renderer deals with element styling. --- .../unit/com/structurizr/view/ThemeUtilsTests.java | 2 +- .../src/com/structurizr/view/Styles.java | 14 +++++++++++++- .../unit/com/structurizr/view/StylesTests.java | 4 ++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/structurizr-client/test/unit/com/structurizr/view/ThemeUtilsTests.java b/structurizr-client/test/unit/com/structurizr/view/ThemeUtilsTests.java index cb730df8..143c8ce1 100644 --- a/structurizr-client/test/unit/com/structurizr/view/ThemeUtilsTests.java +++ b/structurizr-client/test/unit/com/structurizr/view/ThemeUtilsTests.java @@ -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()); diff --git a/structurizr-core/src/com/structurizr/view/Styles.java b/structurizr-core/src/com/structurizr/view/Styles.java index 411a27f0..944efc2f 100644 --- a/structurizr-core/src/com/structurizr/view/Styles.java +++ b/structurizr-core/src/com/structurizr/view/Styles.java @@ -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; @@ -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()) { @@ -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; } diff --git a/structurizr-core/test/unit/com/structurizr/view/StylesTests.java b/structurizr-core/test/unit/com/structurizr/view/StylesTests.java index 8a8fb884..758eee9f 100644 --- a/structurizr-core/test/unit/com/structurizr/view/StylesTests.java +++ b/structurizr-core/test/unit/com/structurizr/view/StylesTests.java @@ -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()); @@ -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());