Skip to content

Commit

Permalink
Set some default element style dimensions.
Browse files Browse the repository at this point in the history
  • Loading branch information
simonbrowndotje committed Mar 26, 2020
1 parent 10ac463 commit 5083ca2
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
22 changes: 22 additions & 0 deletions structurizr-core/src/com/structurizr/view/Styles.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@

public final class Styles {

private static final Integer DEFAULT_WIDTH_OF_ELEMENT = 450;
private static final Integer DEFAULT_HEIGHT_OF_ELEMENT = 300;

private static final Integer DEFAULT_WIDTH_OF_PERSON = 400;
private static final Integer DEFAULT_HEIGHT_OF_PERSON = 400;

private Collection<ElementStyle> elements = new LinkedList<>();
private Collection<RelationshipStyle> relationships = new LinkedList<>();

Expand Down Expand Up @@ -148,6 +154,22 @@ public ElementStyle findElementStyle(Element element) {
}
}

if (style.getWidth() == null) {
if (style.getShape() == Shape.Person) {
style.setWidth(DEFAULT_WIDTH_OF_PERSON);
} else {
style.setWidth(DEFAULT_WIDTH_OF_ELEMENT);
}
}

if (style.getHeight() == null) {
if (style.getShape() == Shape.Person) {
style.setHeight(DEFAULT_HEIGHT_OF_PERSON);
} else {
style.setHeight(DEFAULT_HEIGHT_OF_ELEMENT);
}
}

return style;
}

Expand Down
36 changes: 35 additions & 1 deletion structurizr-core/test/unit/com/structurizr/view/StyleTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public void test_findElementStyle_ReturnsTheDefaultStyle_WhenPassedNull() {
assertEquals("#dddddd", style.getBackground());
assertEquals("#000000", style.getColor());
assertEquals(Shape.Box, style.getShape());
assertEquals(new Integer(450), style.getWidth());
assertEquals(new Integer(300), style.getHeight());
}

@Test
Expand All @@ -28,6 +30,8 @@ public void test_findElementStyle_ReturnsTheDefaultStyle_WhenNoStylesAreDefined(
assertEquals("#dddddd", style.getBackground());
assertEquals("#000000", style.getColor());
assertEquals(Shape.Box, style.getShape());
assertEquals(new Integer(450), style.getWidth());
assertEquals(new Integer(300), style.getHeight());
}

@Test
Expand All @@ -36,13 +40,43 @@ public void test_findElementStyle_ReturnsTheCorrectStyle_WhenStylesAreDefined()
element.addTags("Some Tag");

styles.addElementStyle(Tags.SOFTWARE_SYSTEM).background("#ff0000").color("#ffffff");
styles.addElementStyle("Some Tag").color("#0000ff").stroke("#00ff00").shape(Shape.RoundedBox);
styles.addElementStyle("Some Tag").color("#0000ff").stroke("#00ff00").shape(Shape.RoundedBox).width(123).height(456);

ElementStyle style = styles.findElementStyle(element);
assertEquals("#ff0000", style.getBackground());
assertEquals("#0000ff", style.getColor());
assertEquals("#00ff00", style.getStroke());
assertEquals(Shape.RoundedBox, style.getShape());
assertEquals(new Integer(123), style.getWidth());
assertEquals(new Integer(456), style.getHeight());
}

@Test
public void test_findElementStyle_ReturnsTheDefaultElementSize_WhenTheShapeIsABox() {
SoftwareSystem element = model.addSoftwareSystem("Name", "Description");
element.addTags("Some Tag");

styles.addElementStyle(Tags.SOFTWARE_SYSTEM).background("#ff0000").color("#ffffff");
styles.addElementStyle("Some Tag").shape(Shape.Box);

ElementStyle style = styles.findElementStyle(element);
assertEquals(Shape.Box, style.getShape());
assertEquals(new Integer(450), style.getWidth());
assertEquals(new Integer(300), style.getHeight());
}

@Test
public void test_findElementStyle_ReturnsTheDefaultElementSize_WhenTheShapeIsAPerson() {
SoftwareSystem element = model.addSoftwareSystem("Name", "Description");
element.addTags("Some Tag");

styles.addElementStyle(Tags.SOFTWARE_SYSTEM).background("#ff0000").color("#ffffff");
styles.addElementStyle("Some Tag").shape(Shape.Person);

ElementStyle style = styles.findElementStyle(element);
assertEquals(Shape.Person, style.getShape());
assertEquals(new Integer(400), style.getWidth());
assertEquals(new Integer(400), style.getHeight());
}

@Test
Expand Down

0 comments on commit 5083ca2

Please sign in to comment.