Skip to content

Commit

Permalink
person and boundary styles
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskn committed Oct 6, 2024
1 parent c3e04c7 commit aecce42
Show file tree
Hide file tree
Showing 42 changed files with 1,493 additions and 507 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package com.github.chriskn.structurizrextension.api.view.style

import com.structurizr.view.Color

fun toValidColor(color: String): String =
if (Color.isHexColorCode(color)) {
fun toValidColor(color: String?): String? =
if (color == null) {
null
} else if (Color.isHexColorCode(color)) {
color.lowercase()
} else {
val hexColorCode = Color.fromColorNameToHexColorCode(color)
Expand Down

This file was deleted.

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

import com.structurizr.view.ElementStyle
import com.github.chriskn.structurizrextension.api.view.style.styles.BoundaryStyle
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.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.styles.add(elementStyle)
this.configuration.addProperty("$ELEMENT_STYLE_PROPERTY_NAME_PREFIX:${elementStyle.tag}", elementStyle.toJson())
}

fun ViewSet.getElementStyles(): List<ElementStyle> =
this.configuration.styles.elements.toList()
this.configuration.properties
.filter { it.key.startsWith(ELEMENT_STYLE_PROPERTY_NAME_PREFIX) }
.map { elementStyleFromJson(it.value) }

internal fun ViewSet.clearElementStyles() {
this.configuration.styles.elements.clear()
this.configuration.clearElementStyles()
}

fun ViewSet.addBoundaryStyle(boundaryStyle: BoundaryStyle) {
this.configuration.addProperty("$BOUNDARY_STYLE_PROPERTY_NAME_PREFIX:${boundaryStyle.tag}", boundaryStyle.toJson())
}

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()
}

fun ViewSet.addPersonStyle(personStyle: PersonStyle) {
this.configuration.addProperty("$PERSON_STYLE_PROPERTY_NAME_PREFIX:${personStyle.tag}", personStyle.toJson())
}

fun ViewSet.getPersonStyles(): List<PersonStyle> =
this.configuration.properties
.filter { it.key.startsWith(PERSON_STYLE_PROPERTY_NAME_PREFIX) }
.map { personStyleFromJson(it.value) }

internal fun ViewSet.clearPersonStyles() {
this.configuration.clearPersonStyles()
}
Original file line number Diff line number Diff line change
@@ -1,11 +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.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.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.ElementStyle
import com.structurizr.view.View

private const val ELEMENT_STYLE_PROPERTY_NAME_PREFIX = "c4:elementStyle"
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"

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

fun View.addBoundaryStyle(boundaryStyle: BoundaryStyle) {
this.addProperty("$BOUNDARY_STYLE_PROPERTY_NAME_PREFIX:${boundaryStyle.tag}", boundaryStyle.toJson())
}

fun View.getBoundaryStyles(): List<BoundaryStyle> =
this.properties
.filter { it.key.startsWith(BOUNDARY_STYLE_PROPERTY_NAME_PREFIX) }
.map { boundaryStyleFromJson(it.value) }

fun View.addPersonStyle(personStyle: PersonStyle) {
this.addProperty("$PERSON_STYLE_PROPERTY_NAME_PREFIX:${personStyle.tag}", personStyle.toJson())
}

fun View.getPersonStyles(): List<PersonStyle> =
this.properties
.filter { it.key.startsWith(PERSON_STYLE_PROPERTY_NAME_PREFIX) }
.map { personStyleFromJson(it.value) }
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
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.sprite.Sprite
import com.github.chriskn.structurizrextension.api.view.style.toValidColor
import com.structurizr.view.Border

// TODO doucment

class BoundaryStyle : C4PumlStyle {

override val tag: String
override val backgroundColor: String?
override val fontColor: String?
override val border: Border?
override val borderWith: Int?
override val borderColor: String?
override val shadowing: Boolean
override val c4Shape: C4Shape?
override val sprite: Sprite?
override val legendText: String?
override val legendSprite: Sprite?

@Suppress("LongParameterList")
constructor(
tag: String,
backgroundColor: String? = null,
fontColor: String? = null,
border: Border? = null,
borderWith: Int? = null,
borderColor: String? = null,
shadowing: Boolean = false,
c4Shape: C4Shape? = null,
sprite: Sprite? = null,
legendText: String? = null,
legendSprite: Sprite? = null
) {
require(tag.isNotBlank()) { "tag cannot be blank" }
this.tag = tag
this.backgroundColor = toValidColor(backgroundColor)
this.fontColor = toValidColor(fontColor)
this.border = border
this.borderWith = borderWith
this.borderColor = toValidColor(borderColor)
this.shadowing = shadowing
this.c4Shape = c4Shape
this.sprite = sprite
this.legendText = legendText
this.legendSprite = legendSprite
}

override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false

other as BoundaryStyle

if (tag != other.tag) return false
if (backgroundColor != other.backgroundColor) return false
if (fontColor != other.fontColor) return false
if (border != other.border) return false
if (borderWith != other.borderWith) return false
if (borderColor != other.borderColor) return false
if (shadowing != other.shadowing) return false
if (c4Shape != other.c4Shape) return false
if (sprite != other.sprite) return false
if (legendText != other.legendText) return false
if (legendSprite != other.legendSprite) return false

return true
}

override fun hashCode(): Int {
var result = tag.hashCode()
result = 31 * result + (backgroundColor?.hashCode() ?: 0)
result = 31 * result + (fontColor?.hashCode() ?: 0)
result = 31 * result + (border?.hashCode() ?: 0)
result = 31 * result + (borderWith ?: 0)
result = 31 * result + (borderColor?.hashCode() ?: 0)
result = 31 * result + shadowing.hashCode()
result = 31 * result + (c4Shape?.hashCode() ?: 0)
result = 31 * result + (sprite?.hashCode() ?: 0)
result = 31 * result + (legendText?.hashCode() ?: 0)
result = 31 * result + (legendSprite?.hashCode() ?: 0)
return result
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
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.sprite.Sprite
import com.structurizr.view.Border

// TODO move to internal package
interface C4PumlStyle {
val tag: String
val backgroundColor: String?
val fontColor: String?
val border: Border?
val borderWith: Int?
val borderColor: String?
val shadowing: Boolean
val c4Shape: C4Shape?
val sprite: Sprite?
val legendText: String?
val legendSprite: Sprite?
}
Loading

0 comments on commit aecce42

Please sign in to comment.