Skip to content

Commit

Permalink
reimplement async dependencies using styles
Browse files Browse the repository at this point in the history
add kdoc
  • Loading branch information
chriskn committed Nov 3, 2024
1 parent 25c464d commit d1e5d40
Show file tree
Hide file tree
Showing 56 changed files with 630 additions and 429 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,45 @@ import com.structurizr.view.SystemLandscapeView

private const val SHOW_BOUNDARY_PROPERTY = "SHOW_BOUNDARY"

/**
* If set to true, higher model elements (systems or containers) will be shown as boundaries. default false
*/
var DynamicView.showExternalBoundaries: Boolean
get() = this.properties[SHOW_BOUNDARY_PROPERTY].toBoolean()
set(value) {
this.addProperty(SHOW_BOUNDARY_PROPERTY, value.toString())
}

/**
* If set to true, software systems will be shown as boundaries. default false
*/
var ContainerView.showExternalSoftwareSystemBoundaries: Boolean
get() = this.properties[SHOW_BOUNDARY_PROPERTY].toBoolean()
set(value) {
this.addProperty(SHOW_BOUNDARY_PROPERTY, value.toString())
}

/**
* If set to true, container will be shown as boundaries. default false
*/
var ComponentView.showExternalContainerBoundaries: Boolean
get() = this.properties[SHOW_BOUNDARY_PROPERTY].toBoolean()
set(value) {
this.addProperty(SHOW_BOUNDARY_PROPERTY, value.toString())
}

/**
* If set to true, enterprise boundary will be shown. default false
*/
var SystemLandscapeView.showEnterpriseBoundary: Boolean
get() = this.properties[SHOW_BOUNDARY_PROPERTY].toBoolean()
set(value) {
this.addProperty(SHOW_BOUNDARY_PROPERTY, value.toString())
}

/**
* If set to true, enterprise boundary will be shown. default false
*/
var SystemContextView.showEnterpriseBoundary: Boolean
get() = this.properties[SHOW_BOUNDARY_PROPERTY].toBoolean()
set(value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fun ViewSet.systemLandscapeView(
* @param softwareSystem the SoftwareSystem object representing the scope of the view
* @param key the key for the view (must be unique)
* @param description a description of the view
* @param layout [C4PlantUmlLayout]
* @param layout [C4PlantUmlLayout]
* @return a SystemContextView object
* @throws IllegalArgumentException if the software system is null or the key is not unique
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.github.chriskn.structurizrextension.api.view.style

/**
* Enum representing the available element shapes in C4 PlantUml
*/
enum class C4PUmlElementShape(internal val pUmlString: String) {
ROUNDED_BOX("RoundedBoxShape()"),
EIGHT_SIDED("EightSidedShape()")
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,58 +4,91 @@ import com.github.chriskn.structurizrextension.api.view.style.styles.BoundarySty
import com.github.chriskn.structurizrextension.api.view.style.styles.DependencyStyle
import com.github.chriskn.structurizrextension.api.view.style.styles.ElementStyle
import com.github.chriskn.structurizrextension.api.view.style.styles.PersonStyle
import com.github.chriskn.structurizrextension.internal.export.view.style.BOUNDARY_STYLE_PROPERTY_NAME_PREFIX
import com.github.chriskn.structurizrextension.internal.export.view.style.DEPENDENCY_STYLE_PROPERTY_NAME_PREFIX
import com.github.chriskn.structurizrextension.internal.export.view.style.ELEMENT_STYLE_PROPERTY_NAME_PREFIX
import com.github.chriskn.structurizrextension.internal.export.view.style.PERSON_STYLE_PROPERTY_NAME_PREFIX
import com.github.chriskn.structurizrextension.internal.export.view.style.boundaryStyleFromJson
import com.github.chriskn.structurizrextension.internal.export.view.style.dependencyStyleFromJson
import com.github.chriskn.structurizrextension.internal.export.view.style.elementStyleFromJson
import com.github.chriskn.structurizrextension.internal.export.view.style.personStyleFromJson
import com.github.chriskn.structurizrextension.internal.export.view.style.toJson
import com.structurizr.view.ViewSet
import com.structurizr.view.clearBoundaryStyles
import com.structurizr.view.clearElementStyles

/**
* Add element style to all views
*
* @param elementStyle the element style to add
*/
fun ViewSet.addElementStyle(elementStyle: ElementStyle) {
this.configuration.addProperty("$ELEMENT_STYLE_PROPERTY_NAME_PREFIX:${elementStyle.tag}", elementStyle.toJson())
}

/**
* Get element styles
*
* @return the list of element styles assigned to the ViewSet
*/
fun ViewSet.getElementStyles(): List<ElementStyle> =
this.configuration.properties
.filter { it.key.startsWith(ELEMENT_STYLE_PROPERTY_NAME_PREFIX) }
.map { elementStyleFromJson(it.value) }

// TODO remove?
internal fun ViewSet.clearElementStyles() {
this.configuration.clearElementStyles()
}

/**
* Add boundary style to all views
*
* @param boundaryStyle the boundary style to add
*/
fun ViewSet.addBoundaryStyle(boundaryStyle: BoundaryStyle) {
this.configuration.addProperty("$BOUNDARY_STYLE_PROPERTY_NAME_PREFIX:${boundaryStyle.tag}", boundaryStyle.toJson())
}

/**
* Get boundary styles
*
* @return the list of boundary styles assigned to the ViewSet
*/
fun ViewSet.getBoundaryStyles(): List<BoundaryStyle> =
this.configuration.properties
.filter { it.key.startsWith(BOUNDARY_STYLE_PROPERTY_NAME_PREFIX) }
.map { boundaryStyleFromJson(it.value) }

internal fun ViewSet.clearBoundaryStyles() {
this.configuration.clearBoundaryStyles()
}

/**
* Add person style to all views
*
* @param personStyle the person style to add
*/
fun ViewSet.addPersonStyle(personStyle: PersonStyle) {
this.configuration.addProperty("$PERSON_STYLE_PROPERTY_NAME_PREFIX:${personStyle.tag}", personStyle.toJson())
}

/**
* Get person styles
*
* @return the list of person styles assigned to the ViewSet
*/
fun ViewSet.getPersonStyles(): List<PersonStyle> =
this.configuration.properties
.filter { it.key.startsWith(PERSON_STYLE_PROPERTY_NAME_PREFIX) }
.map { personStyleFromJson(it.value) }

/**
* Add dependency style to all views
*
* @param dependencyStyle the dependency style to add
*/
fun ViewSet.addDependencyStyle(dependencyStyle: DependencyStyle) {
this.configuration.addProperty(
"$DEPENDENCY_STYLE_PROPERTY_NAME_PREFIX:${dependencyStyle.tag}",
dependencyStyle.toJson()
)
}

/**
* Get dependency styles
*
* @return the list of dependency styles assigned to the ViewSet
*/
fun ViewSet.getDependencyStyles(): List<DependencyStyle> =
this.configuration.properties
.filter { it.key.startsWith(DEPENDENCY_STYLE_PROPERTY_NAME_PREFIX) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,49 +4,89 @@ import com.github.chriskn.structurizrextension.api.view.style.styles.BoundarySty
import com.github.chriskn.structurizrextension.api.view.style.styles.DependencyStyle
import com.github.chriskn.structurizrextension.api.view.style.styles.ElementStyle
import com.github.chriskn.structurizrextension.api.view.style.styles.PersonStyle
import com.github.chriskn.structurizrextension.internal.export.view.style.BOUNDARY_STYLE_PROPERTY_NAME_PREFIX
import com.github.chriskn.structurizrextension.internal.export.view.style.DEPENDENCY_STYLE_PROPERTY_NAME_PREFIX
import com.github.chriskn.structurizrextension.internal.export.view.style.ELEMENT_STYLE_PROPERTY_NAME_PREFIX
import com.github.chriskn.structurizrextension.internal.export.view.style.PERSON_STYLE_PROPERTY_NAME_PREFIX
import com.github.chriskn.structurizrextension.internal.export.view.style.boundaryStyleFromJson
import com.github.chriskn.structurizrextension.internal.export.view.style.dependencyStyleFromJson
import com.github.chriskn.structurizrextension.internal.export.view.style.elementStyleFromJson
import com.github.chriskn.structurizrextension.internal.export.view.style.personStyleFromJson
import com.github.chriskn.structurizrextension.internal.export.view.style.propertyName
import com.github.chriskn.structurizrextension.internal.export.view.style.toJson
import com.structurizr.view.View

internal const val ELEMENT_STYLE_PROPERTY_NAME_PREFIX = "c4:elementStyle"
internal const val BOUNDARY_STYLE_PROPERTY_NAME_PREFIX = "c4:boundaryStyle"
internal const val PERSON_STYLE_PROPERTY_NAME_PREFIX = "c4:personStyle"
internal const val DEPENDENCY_STYLE_PROPERTY_NAME_PREFIX = "c4:dependencyStyle"

/**
* Add element style to this view
*
* @param elementStyle the element style to add
*/
fun View.addElementStyle(elementStyle: ElementStyle) {
this.addProperty("$ELEMENT_STYLE_PROPERTY_NAME_PREFIX:${elementStyle.tag}", elementStyle.toJson())
this.addProperty(elementStyle.propertyName(), elementStyle.toJson())
}

/**
* Get element styles
*
* @return all element style for this view
*/
fun View.getElementStyles(): List<ElementStyle> =
this.properties
.filter { it.key.startsWith(ELEMENT_STYLE_PROPERTY_NAME_PREFIX) }
.map { elementStyleFromJson(it.value) }

/**
* Add boundary style to this view
*
* @param boundaryStyle the boundary style to add
*/
fun View.addBoundaryStyle(boundaryStyle: BoundaryStyle) {
this.addProperty("$BOUNDARY_STYLE_PROPERTY_NAME_PREFIX:${boundaryStyle.tag}", boundaryStyle.toJson())
this.addProperty(boundaryStyle.propertyName(), boundaryStyle.toJson())
}

/**
* Get boundary styles
*
* @return all boundary styles for this view
*/
fun View.getBoundaryStyles(): List<BoundaryStyle> =
this.properties
.filter { it.key.startsWith(BOUNDARY_STYLE_PROPERTY_NAME_PREFIX) }
.map { boundaryStyleFromJson(it.value) }

/**
* Add person style to this view
*
* @param personStyle the person style to add
*/
fun View.addPersonStyle(personStyle: PersonStyle) {
this.addProperty("$PERSON_STYLE_PROPERTY_NAME_PREFIX:${personStyle.tag}", personStyle.toJson())
this.addProperty(personStyle.propertyName(), personStyle.toJson())
}

/**
* Get person styles
*
* @return all person styles for this view
*/
fun View.getPersonStyles(): List<PersonStyle> =
this.properties
.filter { it.key.startsWith(PERSON_STYLE_PROPERTY_NAME_PREFIX) }
.map { personStyleFromJson(it.value) }

/**
* Add dependency style to this view
*
* @param dependencyStyle the dependency style to add
*/
fun View.addDependencyStyle(dependencyStyle: DependencyStyle) {
this.addProperty("$DEPENDENCY_STYLE_PROPERTY_NAME_PREFIX:${dependencyStyle.tag}", dependencyStyle.toJson())
this.addProperty(dependencyStyle.propertyName(), dependencyStyle.toJson())
}

/**
* Get dependency styles
*
* @return all dependency styles for this view
*/
fun View.getDependencyStyles(): List<DependencyStyle> =
this.properties
.filter { it.key.startsWith(DEPENDENCY_STYLE_PROPERTY_NAME_PREFIX) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ import java.net.URI

private val fileInUriRegex = "[^/\\\\&?]+\\.\\w{3,4}(?=([?&].*\$|\$))".toRegex()

/**
* Image sprite
*
* Can be used to include images via an image url.
*
* @property url the image url. Must use "img:" scheme and point to a file. img:{File or Url}
* @property scale the image scale. Must be greater zero. 1.0 is default
* @constructor Create Image sprite
*/
data class ImageSprite(
val url: String,
val scale: Double? = null,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
package com.github.chriskn.structurizrextension.api.view.style.sprite

import com.fasterxml.jackson.annotation.JsonIgnore
import com.github.chriskn.structurizrextension.api.view.style.toValidColor
import com.github.chriskn.structurizrextension.internal.view.style.toValidColor

/**
* Open iconic sprite
*
* Can be used to include open iconic icons.
* See [Open Iconic](https://github.com/iconic/open-iconic)
*
* @property name the name of the icon
* @property color the color of the icon. Must be a valid hex code or a named color (e.g. "green")
* @property scale the scale of the icon
* @constructor Create Open iconic sprite
*/
data class OpenIconicSprite(
val name: String,
val color: String? = null,
val scale: Double? = null,
) : Sprite(scale) {

@get:JsonIgnore
internal val validatedColor: String? = color?.let { toValidColor(color) }
internal val colorValidated: String? = color?.let { toValidColor(color) }
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,20 @@ package com.github.chriskn.structurizrextension.api.view.style.sprite

import com.fasterxml.jackson.annotation.JsonIgnore
import com.github.chriskn.structurizrextension.api.icons.IconRegistry
import com.github.chriskn.structurizrextension.api.view.style.toValidColor
import com.github.chriskn.structurizrextension.internal.view.style.toValidColor
import java.net.MalformedURLException

/**
* Plant UML sprite
*
* Can be used to include plantuml icons.
*
* @property name the name of the icon
* @property url url pointing to a .puml file
* @property color the color of the icon. Must be a valid hex code or a named color (e.g. "green")
* @property scale the scale of the icon
* @constructor Create Plant UML sprite
*/
data class PUmlSprite(
val name: String,
/**
Expand All @@ -13,16 +24,16 @@ data class PUmlSprite(
* @throws IllegalArgumentException if url does not point to puml file
* @throws MalformedURLException if url is invalid
*/
val includeUrl: String,
val url: String,
val color: String? = null,
val scale: Double? = null,
) : Sprite(scale) {

@get:JsonIgnore
internal val validatedColor: String? = color?.let { toValidColor(color) }
internal val colorValidated: String? = color?.let { toValidColor(color) }

init {
// TODO is the registry still needed?
IconRegistry.addIcon(name, includeUrl)
IconRegistry.addIcon(name, url)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ import com.fasterxml.jackson.annotation.JsonTypeInfo
Type(value = PUmlSprite::class, name = "PUmlSprite"),
]
)
/**
* Base class for Sprites
*/
abstract class Sprite(scale: Double?) {

init {
Expand Down
Loading

0 comments on commit d1e5d40

Please sign in to comment.