public ElementStyle findElementStyle(Element element) { ElementStyle style = new ElementStyle("").background("#dddddd").color("#000000").shape(Shape.Box); if (element != null) { for (String tag : element.getTagsAsSet()) { ElementStyle elementStyle = findElementStyle(tag); if (elementStyle != null) { if (elementStyle.getBackground() != null && elementStyle.getBackground().trim().length() > 0) { style.setBackground(elementStyle.getBackground()); } if (elementStyle.getColor() != null && elementStyle.getColor().trim().length() > 0) { style.setColor(elementStyle.getColor()); } if (elementStyle.getShape() != null) { style.setShape(elementStyle.getShape()); } } } } return style; }
@Test public void test_opacity() { ElementStyle style = new ElementStyle(); assertNull(style.getOpacity()); style.opacity(-1); assertEquals(0, style.getOpacity().intValue()); style.opacity(0); assertEquals(0, style.getOpacity().intValue()); style.opacity(50); assertEquals(50, style.getOpacity().intValue()); style.opacity(100); assertEquals(100, style.getOpacity().intValue()); style.opacity(101); assertEquals(100, style.getOpacity().intValue()); }
public ElementStyle(String tag, Integer width, Integer height, String background, String color, Integer fontSize, Shape shape) { this.tag = tag; this.width = width; this.height = height; setBackground(background); setColor(color); this.fontSize = fontSize; this.shape = shape; }
public ElementStyle addElementStyle(String tag) { ElementStyle elementStyle = null; if (tag != null) { elementStyle = new ElementStyle(); elementStyle.setTag(tag); add(elementStyle); } return elementStyle; }
public static void main(String[] args) throws Exception { Workspace workspace = new Workspace("Getting Started", "This is a model of my software system."); Model model = workspace.getModel(); Person user = model.addPerson("User", "A user of my software system."); SoftwareSystem softwareSystem = model.addSoftwareSystem("Software System", "My software system."); user.uses(softwareSystem, "Uses"); ViewSet views = workspace.getViews(); SystemContextView contextView = views.createSystemContextView(softwareSystem, "SystemContext", "An example of a System Context diagram."); contextView.addAllSoftwareSystems(); contextView.addAllPeople(); Styles styles = views.getConfiguration().getStyles(); styles.addElementStyle(Tags.SOFTWARE_SYSTEM).background("#1168bd").color("#ffffff"); styles.addElementStyle(Tags.PERSON).background("#08427b").color("#ffffff").shape(Shape.Person); PlantUMLWriter plantUMLWriter = new PlantUMLWriter(); // if you're using dark background colours, you might need to explicitly set the foreground colour using skin params // e.g. rectangleFontColor, rectangleFontColor<<Software System>>, etc plantUMLWriter.addSkinParam("rectangleFontColor", "#ffffff"); plantUMLWriter.addSkinParam("rectangleStereotypeFontColor", "#ffffff"); // write to a specific writer StringWriter stringWriter = new StringWriter(); plantUMLWriter.write(workspace, stringWriter); System.out.println(stringWriter.toString()); // or just output directly to stdout // plantUMLWriter.toStdOut(workspace); }
@Test public void test_findElementStyle_ReturnsTheCorrectStyle_WhenStylesAreDefined() { SoftwareSystem element = model.addSoftwareSystem("Name", "Description"); element.addTags("Some Tag"); styles.addElementStyle(Tags.SOFTWARE_SYSTEM).background("#ff0000").color("#ffffff"); styles.addElementStyle("Some Tag").color("#0000ff").shape(Shape.RoundedBox); ElementStyle style = styles.findElementStyle(element); assertEquals("#ff0000", style.getBackground()); assertEquals("#0000ff", style.getColor()); assertEquals(Shape.RoundedBox, style.getShape()); }
styles.addElementStyle("Spring PetClinic").background("#6CB33E").color("#ffffff"); styles.addElementStyle(Tags.PERSON).background("#519823").color("#ffffff").shape(Shape.Person); styles.addElementStyle(Tags.CONTAINER).background("#91D366").color("#ffffff"); styles.addElementStyle("Database").shape(Shape.Cylinder); styles.addElementStyle("Spring MVC Controller").background("#D4F3C0").color("#000000"); styles.addElementStyle("Spring Service").background("#6CB33E").color("#000000"); styles.addElementStyle("Spring Repository").background("#95D46C").color("#000000"); styles.addElementStyle("Failover").opacity(25); styles.addRelationshipStyle("Failover").opacity(25).position(70);
financialRiskSystem.addTags("Risk System"); styles.addElementStyle(Tags.ELEMENT).color("#ffffff").fontSize(34); styles.addElementStyle("Risk System").background("#550000").color("#ffffff"); styles.addElementStyle(Tags.SOFTWARE_SYSTEM).width(650).height(400).background("#801515").shape(Shape.RoundedBox); styles.addElementStyle(Tags.PERSON).width(550).background("#d46a6a").shape(Shape.Person); styles.addRelationshipStyle(TAG_ALERT).color("#ff0000"); styles.addElementStyle("Future State").opacity(30).border(Border.Dashed); styles.addRelationshipStyle("Future State").opacity(30).dashed(true);
styles.addElementStyle(Tags.ELEMENT).color("#ffffff").background("#438dd5").fontSize(34).width(650).height(400); styles.addElementStyle("Box").shape(Shape.Box); styles.addElementStyle("RoundedBox").shape(Shape.RoundedBox); styles.addElementStyle("Ellipse").shape(Shape.Ellipse); styles.addElementStyle("Circle").shape(Shape.Circle); styles.addElementStyle("Cylinder").shape(Shape.Cylinder); styles.addElementStyle("Web Browser").shape(Shape.WebBrowser); styles.addElementStyle("Mobile Device Portrait").shape(Shape.MobileDevicePortrait).width(400).height(650); styles.addElementStyle("Mobile Device Landscape").shape(Shape.MobileDeviceLandscape); styles.addElementStyle("Pipe").shape(Shape.Pipe); styles.addElementStyle("Folder").shape(Shape.Folder); styles.addElementStyle("Hexagon").shape(Shape.Hexagon); styles.addElementStyle("Robot").shape(Shape.Robot).width(550); styles.addElementStyle("Person").shape(Shape.Person).width(550);
template.addContextSection(fulfilmentSystem, Format.Markdown, "This is the context section for the Fulfilment System... ![](embed:FulfilmentSystemContext)"); styles.addElementStyle(Tags.SOFTWARE_SYSTEM).shape(Shape.RoundedBox); styles.addElementStyle(Tags.PERSON).shape(Shape.Person); styles.addElementStyle(Tags.ELEMENT).color("#ffffff"); styles.addElementStyle(EXTERNAL_TAG).background("#EC5381").border(Border.Dashed); styles.addElementStyle(INTERNAL_TAG).background("#B60037");
styles.addElementStyle(Tags.ELEMENT).color("#000000"); styles.addElementStyle(Tags.PERSON).background("#ffbf00").shape(Shape.Person); styles.addElementStyle(Tags.CONTAINER).background("#facc2E"); styles.addElementStyle(MESSAGE_BUS_TAG).width(1600).shape(Shape.Pipe); styles.addElementStyle(MICROSERVICE_TAG).shape(Shape.Hexagon); styles.addElementStyle(DATASTORE_TAG).background("#f5da81").shape(Shape.Cylinder); styles.addRelationshipStyle(Tags.RELATIONSHIP).routing(Routing.Orthogonal);
@Test public void test_findElementStyle_ReturnsTheDefaultStyle_WhenPassedNull() { ElementStyle style = styles.findElementStyle(null); assertEquals("#dddddd", style.getBackground()); assertEquals("#000000", style.getColor()); assertEquals(Shape.Box, style.getShape()); }
@Test public void test_setIcon_WithAUrlThatHasATrailingSpaceCharacter() { ElementStyle style = new ElementStyle(); style.setIcon("https://structurizr.com/static/img/structurizr-logo.png "); assertEquals("https://structurizr.com/static/img/structurizr-logo.png", style.getIcon()); }
@Test public void test_background_SetsTheBackgroundProperty_WhenAValidHexColorCodeIsSpecified() { ElementStyle style = new ElementStyle(); style.background("#ffffff"); assertEquals("#ffffff", style.getBackground()); style.background("#FFFFFF"); assertEquals("#ffffff", style.getBackground()); style.background("#123456"); assertEquals("#123456", style.getBackground()); }
styles.addElementStyle(Tags.PERSON).shape(Shape.Person);
@Test public void test_color_SetsTheColorProperty_WhenAValidHexColorCodeIsSpecified() { ElementStyle style = new ElementStyle(); style.color("#ffffff"); assertEquals("#ffffff", style.getColor()); style.color("#FFFFFF"); assertEquals("#ffffff", style.getColor()); style.color("#123456"); assertEquals("#123456", style.getColor()); }
@Test public void test_setBackground_SetsTheBackgroundProperty_WhenAValidHexColorCodeIsSpecified() { ElementStyle style = new ElementStyle(); style.setBackground("#ffffff"); assertEquals("#ffffff", style.getBackground()); style.setBackground("#FFFFFF"); assertEquals("#ffffff", style.getBackground()); style.setBackground("#123456"); assertEquals("#123456", style.getBackground()); }
public static void main(String[] args) throws Exception { Workspace workspace = new Workspace("HTTP-based health checks example", "An example of how to use the HTTP-based health checks feature"); Model model = workspace.getModel(); ViewSet views = workspace.getViews(); SoftwareSystem structurizr = model.addSoftwareSystem("Structurizr", "A publishing platform for software architecture diagrams and documentation based upon the C4 model."); Container webApplication = structurizr.addContainer("structurizr.com", "Provides all of the server-side functionality of Structurizr, serving static and dynamic content to users.", "Java and Spring MVC"); Container database = structurizr.addContainer("Database", "Stores information about users, workspaces, etc.", "Relational Database Schema"); database.addTags(DATABASE_TAG); webApplication.uses(database, "Reads from and writes to", "JDBC"); DeploymentNode amazonWebServices = model.addDeploymentNode("Amazon Web Services", "", "us-east-1"); DeploymentNode pivotalWebServices = amazonWebServices.addDeploymentNode("Pivotal Web Services", "Platform as a Service provider.", "Cloud Foundry"); ContainerInstance liveWebApplication = pivotalWebServices.addDeploymentNode("www.structurizr.com", "An open source Java EE web server.", "Apache Tomcat") .add(webApplication); ContainerInstance liveDatabaseInstance = amazonWebServices.addDeploymentNode("Amazon RDS", "Database as a Service provider.", "MySQL") .add(database); // add health checks to the container instances, which return a simple HTTP 200 to say everything is okay liveWebApplication.addHealthCheck("Web Application is running", "https://www.structurizr.com/health"); liveDatabaseInstance.addHealthCheck("Database is accessible from Web Application", "https://www.structurizr.com/health/database"); // the pass/fail status from the health checks is used to supplement any deployment views that include the container instances that have health checks defined DeploymentView deploymentView = views.createDeploymentView(structurizr, "Deployment", "A deployment diagram showing the live environment."); deploymentView.setEnvironment("Live"); deploymentView.addAllDeploymentNodes(); views.getConfiguration().getStyles().addElementStyle(Tags.ELEMENT).color("#ffffff"); views.getConfiguration().getStyles().addElementStyle(DATABASE_TAG).shape(Shape.Cylinder); StructurizrClient structurizrClient = new StructurizrClient(API_KEY, API_SECRET); structurizrClient.putWorkspace(WORKSPACE_ID, workspace); }
@Test(expected = IllegalArgumentException.class) public void test_background_ThrowsAnException_WhenAnInvalidHexColorCodeIsSpecified() { ElementStyle style = new ElementStyle(); style.background("white"); }
@Test public void test_setColor_SetsTheColorProperty_WhenAValidHexColorCodeIsSpecified() { ElementStyle style = new ElementStyle(); style.setColor("#ffffff"); assertEquals("#ffffff", style.getColor()); style.setColor("#FFFFFF"); assertEquals("#ffffff", style.getColor()); style.setColor("#123456"); assertEquals("#123456", style.getColor()); }