Skip to content

Commit

Permalink
Adds support for icons to the Ilograph exporter (#332).
Browse files Browse the repository at this point in the history
  • Loading branch information
simonbrowndotje committed Sep 1, 2024
1 parent 2a8602d commit a6e531f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
public class IlographExporter extends AbstractWorkspaceExporter {

public static final String ILOGRAPH_ICON = "ilograph.icon";

public WorkspaceExport export(Workspace workspace) {
IndentingWriter writer = new IndentingWriter();
writer.writeLine("resources:");
Expand Down Expand Up @@ -216,6 +218,15 @@ private void writeElement(IndentingWriter writer, Workspace workspace, Element e
writer.writeLine(String.format("backgroundColor: \"%s\"", elementStyle.getBackground()));
}
writer.writeLine(String.format("color: \"%s\"", elementStyle.getColor()));

String icon = elementStyle.getProperties().get(ILOGRAPH_ICON);
if (StringUtils.isNullOrEmpty(icon)) {
icon = elementStyle.getIcon();
}
if (!StringUtils.isNullOrEmpty(icon)) {
writer.writeLine(String.format("icon: \"%s\"", icon));
}

writer.writeLine();
writer.outdent();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,31 @@ resources:
subtitle: "[Deployment Node]"
backgroundColor: "#ffffff"
color: "#232f3e"
icon: "https://static.structurizr.com/themes/amazon-web-services-2020.04.30/[email protected]"

children:
- id: "6"
name: "US-East-1"
subtitle: "[Deployment Node]"
backgroundColor: "#ffffff"
color: "#147eba"
icon: "https://static.structurizr.com/themes/amazon-web-services-2020.04.30/[email protected]"

children:
- id: "12"
name: "Amazon RDS"
subtitle: "[Deployment Node]"
backgroundColor: "#ffffff"
color: "#3b48cc"
icon: "https://static.structurizr.com/themes/amazon-web-services-2020.04.30/[email protected]"

children:
- id: "13"
name: "MySQL"
subtitle: "[Deployment Node]"
backgroundColor: "#ffffff"
color: "#3b48cc"
icon: "https://static.structurizr.com/themes/amazon-web-services-2020.04.30/[email protected]"

children:
- id: "14"
Expand All @@ -62,13 +66,15 @@ resources:
subtitle: "[Deployment Node]"
backgroundColor: "#ffffff"
color: "#cc2264"
icon: "https://static.structurizr.com/themes/amazon-web-services-2020.04.30/[email protected]"

children:
- id: "10"
name: "Amazon EC2"
subtitle: "[Deployment Node]"
backgroundColor: "#ffffff"
color: "#d86613"
icon: "https://static.structurizr.com/themes/amazon-web-services-2020.04.30/[email protected]"

children:
- id: "11"
Expand All @@ -84,13 +90,15 @@ resources:
description: "Highly available and scalable cloud DNS service."
backgroundColor: "#ffffff"
color: "#693cc5"
icon: "AWS/Networking/Route-53.svg"

- id: "8"
name: "Elastic Load Balancer"
subtitle: "[Infrastructure Node]"
description: "Automatically distributes incoming application traffic."
backgroundColor: "#ffffff"
color: "#693cc5"
icon: "https://static.structurizr.com/themes/amazon-web-services-2020.04.30/[email protected]"

perspectives:
- name: Static Structure
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,18 @@

import com.structurizr.Workspace;
import com.structurizr.export.AbstractExporterTests;
import com.structurizr.export.Diagram;
import com.structurizr.export.WorkspaceExport;
import com.structurizr.export.dot.DOTExporter;
import com.structurizr.model.CustomElement;
import com.structurizr.model.Model;
import com.structurizr.util.WorkspaceUtils;
import com.structurizr.view.CustomView;
import com.structurizr.view.ThemeUtils;
import org.junit.jupiter.api.Test;

import java.io.File;

import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertEquals;

public class IlographWriterTests extends AbstractExporterTests {
public class IlographExporterTests extends AbstractExporterTests {

@Test
public void test_BigBankPlcExample() throws Exception {
Expand All @@ -31,6 +28,8 @@ public void test_BigBankPlcExample() throws Exception {
@Test
public void test_AmazonWebServicesExample() throws Exception {
Workspace workspace = WorkspaceUtils.loadWorkspaceFromJson(new File("./src/test/resources/structurizr-54915-workspace.json"));
workspace.getViews().getConfiguration().getStyles().addElementStyle("Amazon Web Services - Route 53").addProperty(IlographExporter.ILOGRAPH_ICON, "AWS/Networking/Route-53.svg");

ThemeUtils.loadThemes(workspace);
IlographExporter ilographExporter = new IlographExporter();
WorkspaceExport export = ilographExporter.export(workspace);
Expand Down

0 comments on commit a6e531f

Please sign in to comment.