Skip to content

Commit

Permalink
dependency styles
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskn committed Oct 28, 2024
1 parent 0f05dea commit 25c464d
Show file tree
Hide file tree
Showing 35 changed files with 661 additions and 257 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import java.net.URL
internal const val AWS_ICON_URL = "https://raw.githubusercontent.com/awslabs/aws-icons-for-plantuml/v11.1/dist/"
internal const val AWS_ICON_COMMONS = "${AWS_ICON_URL}AWSCommon.puml"

// TODO sprites and image parsings

// TODO deprecate
/**
* Registry containing the available icons.
*
Expand All @@ -26,12 +25,13 @@ object IconRegistry {
/**
* Adds a new icon with the given name (case-insensitive) and URL to the registry.
*
* @throws IllegalArgumentException if url does not point to puml file
* @throws IllegalArgumentException if url does not point to puml file or name is blank
* @throws MalformedURLException if url is invalid
*/
fun addIcon(name: String, url: String) {
require(name.isNotBlank()) { "Icon name cannot be blank" }
require(url.endsWith(PUML_FILE_EXTENSION)) {
"Icon URL needs to point to .puml file"
"Icon URL needs to point to .puml file but was $url"
}
iconNameToIconUrl[name.lowercase()] = URI(url).toURL()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.github.chriskn.structurizrextension.api.view.style

// TODO doucment

enum class C4PUmlShape(val pUmlString: String) {
ROUNDED_BOX("RoundedBoxShape()"), EIGHT_SIDED("EightSidedShape()")
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package com.github.chriskn.structurizrextension.api.view.style

import com.github.chriskn.structurizrextension.api.view.style.styles.BoundaryStyle
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.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
import com.structurizr.view.clearPersonStyles

fun ViewSet.addElementStyle(elementStyle: ElementStyle) {
this.configuration.addProperty("$ELEMENT_STYLE_PROPERTY_NAME_PREFIX:${elementStyle.tag}", elementStyle.toJson())
Expand All @@ -21,6 +22,7 @@ fun ViewSet.getElementStyles(): List<ElementStyle> =
.filter { it.key.startsWith(ELEMENT_STYLE_PROPERTY_NAME_PREFIX) }
.map { elementStyleFromJson(it.value) }

// TODO remove?
internal fun ViewSet.clearElementStyles() {
this.configuration.clearElementStyles()
}
Expand All @@ -47,6 +49,14 @@ fun ViewSet.getPersonStyles(): List<PersonStyle> =
.filter { it.key.startsWith(PERSON_STYLE_PROPERTY_NAME_PREFIX) }
.map { personStyleFromJson(it.value) }

internal fun ViewSet.clearPersonStyles() {
this.configuration.clearPersonStyles()
fun ViewSet.addDependencyStyle(dependencyStyle: DependencyStyle) {
this.configuration.addProperty(
"$DEPENDENCY_STYLE_PROPERTY_NAME_PREFIX:${dependencyStyle.tag}",
dependencyStyle.toJson()
)
}

fun ViewSet.getDependencyStyles(): List<DependencyStyle> =
this.configuration.properties
.filter { it.key.startsWith(DEPENDENCY_STYLE_PROPERTY_NAME_PREFIX) }
.map { dependencyStyleFromJson(it.value) }
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.github.chriskn.structurizrextension.api.view.style

import com.github.chriskn.structurizrextension.api.view.style.styles.BoundaryStyle
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.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
Expand All @@ -12,6 +14,7 @@ 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"

fun View.addElementStyle(elementStyle: ElementStyle) {
this.addProperty("$ELEMENT_STYLE_PROPERTY_NAME_PREFIX:${elementStyle.tag}", elementStyle.toJson())
Expand Down Expand Up @@ -39,3 +42,12 @@ fun View.getPersonStyles(): List<PersonStyle> =
this.properties
.filter { it.key.startsWith(PERSON_STYLE_PROPERTY_NAME_PREFIX) }
.map { personStyleFromJson(it.value) }

fun View.addDependencyStyle(dependencyStyle: DependencyStyle) {
this.addProperty("$DEPENDENCY_STYLE_PROPERTY_NAME_PREFIX:${dependencyStyle.tag}", dependencyStyle.toJson())
}

fun View.getDependencyStyles(): List<DependencyStyle> =
this.properties
.filter { it.key.startsWith(DEPENDENCY_STYLE_PROPERTY_NAME_PREFIX) }
.map { dependencyStyleFromJson(it.value) }
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.github.chriskn.structurizrextension.api.icons.IconRegistry
import com.github.chriskn.structurizrextension.api.view.style.toValidColor
import java.net.MalformedURLException

data class PumlSprite(
data class PUmlSprite(
val name: String,
/**
* Url used for include statement
Expand All @@ -22,7 +22,6 @@ data class PumlSprite(
internal val validatedColor: String? = color?.let { toValidColor(color) }

init {
require(name.isNotBlank()) { "name cannot be blank" }
// TODO is the registry still needed?
IconRegistry.addIcon(name, includeUrl)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import com.fasterxml.jackson.annotation.JsonTypeInfo
value = [
Type(value = ImageSprite::class, name = "ImageSprite"),
Type(value = OpenIconicSprite::class, name = "OpenIconicSprite"),
Type(value = PumlSprite::class, name = "PumlSprite"),
Type(value = PUmlSprite::class, name = "PUmlSprite"),
]
)
abstract class Sprite(scale: Double?) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package com.github.chriskn.structurizrextension.api.view.style.styles

import com.github.chriskn.structurizrextension.api.view.style.C4Shape
import com.github.chriskn.structurizrextension.api.view.style.C4PUmlShape
import com.github.chriskn.structurizrextension.api.view.style.sprite.Sprite
import com.github.chriskn.structurizrextension.api.view.style.toValidColor
import com.structurizr.view.Border

// TODO doucment

Expand All @@ -12,26 +11,26 @@ class BoundaryStyle internal constructor(
override val tag: String,
override val backgroundColor: String?,
override val fontColor: String?,
override val border: Border?,
override val borderWith: Int?,
override val borderStyle: C4PUmlLineStyle?,
override val borderWidth: Int?,
override val borderColor: String?,
override val shadowing: Boolean,
override val c4Shape: C4Shape?,
override val c4Shape: C4PUmlShape?,
override val sprite: Sprite?,
override val legendText: String?,
override val legendSprite: Sprite?,
) : C4PumlStyle
) : ModelElementStyle

@Suppress("LongParameterList")
fun createBoundaryStyle(
tag: String,
backgroundColor: String? = null,
fontColor: String? = null,
border: Border? = null,
borderWith: Int? = null,
border: C4PUmlLineStyle? = null,
borderWidth: Int? = null,
borderColor: String? = null,
shadowing: Boolean = false,
c4Shape: C4Shape? = null,
c4Shape: C4PUmlShape? = null,
sprite: Sprite? = null,
legendText: String? = null,
legendSprite: Sprite? = null,
Expand All @@ -41,8 +40,8 @@ fun createBoundaryStyle(
tag = tag,
backgroundColor = toValidColor(backgroundColor),
fontColor = toValidColor(fontColor),
border = border,
borderWith = borderWith,
borderStyle = border,
borderWidth = borderWidth,
borderColor = toValidColor(borderColor),
shadowing = shadowing,
c4Shape = c4Shape,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.github.chriskn.structurizrextension.api.view.style.styles

enum class C4PUmlLineStyle(val pUmlString: String) {
DASHED("DashedLine()"),
DOTTED("DottedLine()"),
BOLD("BoldLine()"),
SOLID("SolidLine()"),
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.github.chriskn.structurizrextension.api.view.style.styles

import com.github.chriskn.structurizrextension.api.view.style.sprite.Sprite
import com.github.chriskn.structurizrextension.api.view.style.toValidColor

// TODO document

data class DependencyStyle internal constructor(
val tag: String,
val fontColor: String?,
val sprite: Sprite?,
val legendText: String?,
val legendSprite: Sprite?,
val technology: String?,
val lineColor: String?,
val lineStyle: C4PUmlLineStyle?,
val lineWidth: Int?,
)

@Suppress("LongParameterList")
fun createDependencyStyle(
tag: String,
fontColor: String? = null,
sprite: Sprite? = null,
legendText: String? = null,
legendSprite: Sprite? = null,
technology: String? = null,
lineColor: String? = null,
lineStyle: C4PUmlLineStyle? = null,
lineWidth: Int? = null,
): DependencyStyle {
require(tag.isNotBlank()) { "tag must not be blank" }
return DependencyStyle(
tag = tag,
fontColor = toValidColor(fontColor),
sprite = sprite,
legendText = legendText,
legendSprite = legendSprite,
technology = technology,
lineColor = toValidColor(lineColor),
lineStyle = lineStyle,
lineWidth = lineWidth,
)
}
Original file line number Diff line number Diff line change
@@ -1,37 +1,36 @@
package com.github.chriskn.structurizrextension.api.view.style.styles

import com.github.chriskn.structurizrextension.api.view.style.C4Shape
import com.github.chriskn.structurizrextension.api.view.style.C4PUmlShape
import com.github.chriskn.structurizrextension.api.view.style.sprite.Sprite
import com.github.chriskn.structurizrextension.api.view.style.toValidColor
import com.structurizr.view.Border

// TODO document

data class ElementStyle internal constructor(
override val tag: String,
override val backgroundColor: String?,
override val fontColor: String?,
override val border: Border?,
override val borderWith: Int?,
override val borderStyle: C4PUmlLineStyle?,
override val borderWidth: Int?,
override val borderColor: String?,
override val shadowing: Boolean,
override val c4Shape: C4Shape?,
override val c4Shape: C4PUmlShape?,
override val sprite: Sprite?,
override val legendText: String?,
override val legendSprite: Sprite?,
val technology: String?,
) : C4PumlStyle
) : ModelElementStyle

@Suppress("LongParameterList")
fun createElementStyle(
tag: String,
backgroundColor: String? = null,
fontColor: String? = null,
border: Border? = null,
borderWith: Int? = null,
borderStyle: C4PUmlLineStyle? = null,
borderWidth: Int? = null,
borderColor: String? = null,
shadowing: Boolean = false,
c4Shape: C4Shape? = null,
c4Shape: C4PUmlShape? = null,
sprite: Sprite? = null,
legendText: String? = null,
legendSprite: Sprite? = null,
Expand All @@ -42,8 +41,8 @@ fun createElementStyle(
tag = tag,
backgroundColor = toValidColor(backgroundColor),
fontColor = toValidColor(fontColor),
border = border,
borderWith = borderWith,
borderStyle = borderStyle,
borderWidth = borderWidth,
borderColor = toValidColor(borderColor),
shadowing = shadowing,
c4Shape = c4Shape,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
package com.github.chriskn.structurizrextension.api.view.style.styles

import com.github.chriskn.structurizrextension.api.view.style.C4Shape
import com.github.chriskn.structurizrextension.api.view.style.C4PUmlShape
import com.github.chriskn.structurizrextension.api.view.style.sprite.Sprite
import com.structurizr.view.Border

// TODO move to internal package
interface C4PumlStyle {
interface ModelElementStyle {
val tag: String
val backgroundColor: String?
val fontColor: String?
val border: Border?
val borderWith: Int?
val borderStyle: C4PUmlLineStyle?
val borderWidth: Int?
val borderColor: String?
val shadowing: Boolean
val c4Shape: C4Shape?
val c4Shape: C4PUmlShape?
val sprite: Sprite?
val legendText: String?
val legendSprite: Sprite?
Expand Down
Original file line number Diff line number Diff line change
@@ -1,36 +1,35 @@
package com.github.chriskn.structurizrextension.api.view.style.styles

import com.github.chriskn.structurizrextension.api.view.style.C4Shape
import com.github.chriskn.structurizrextension.api.view.style.C4PUmlShape
import com.github.chriskn.structurizrextension.api.view.style.sprite.Sprite
import com.github.chriskn.structurizrextension.api.view.style.toValidColor
import com.structurizr.view.Border

// TODO document

data class PersonStyle internal constructor(
override val tag: String,
override val backgroundColor: String?,
override val fontColor: String?,
override val border: Border?,
override val borderWith: Int?,
override val borderStyle: C4PUmlLineStyle?,
override val borderWidth: Int?,
override val borderColor: String?,
override val shadowing: Boolean,
override val c4Shape: C4Shape?,
override val c4Shape: C4PUmlShape?,
override val sprite: Sprite?,
override val legendText: String?,
override val legendSprite: Sprite?,
) : C4PumlStyle
) : ModelElementStyle

@Suppress("LongParameterList")
fun createPersonStyle(
tag: String,
backgroundColor: String? = null,
fontColor: String? = null,
border: Border? = null,
borderWith: Int? = null,
borderStyle: C4PUmlLineStyle? = null,
borderWidth: Int? = null,
borderColor: String? = null,
shadowing: Boolean = false,
c4Shape: C4Shape? = null,
c4Shape: C4PUmlShape? = null,
sprite: Sprite? = null,
legendText: String? = null,
legendSprite: Sprite? = null,
Expand All @@ -40,8 +39,8 @@ fun createPersonStyle(
tag = tag,
backgroundColor = toValidColor(backgroundColor),
fontColor = toValidColor(fontColor),
border = border,
borderWith = borderWith,
borderStyle = borderStyle,
borderWidth = borderWidth,
borderColor = toValidColor(borderColor),
shadowing = shadowing,
c4Shape = c4Shape,
Expand Down
Loading

0 comments on commit 25c464d

Please sign in to comment.