From 41b3a20f09d3cfc3408a458cd3ec4d2e55331afe Mon Sep 17 00:00:00 2001 From: KIRCHSTH Date: Sat, 22 May 2021 22:02:16 +0200 Subject: [PATCH 1/3] #149: LegendColor considers brightness --- C4.puml | 80 +++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 58 insertions(+), 22 deletions(-) diff --git a/C4.puml b/C4.puml index 290603c..05fbc6b 100644 --- a/C4.puml +++ b/C4.puml @@ -12,8 +12,9 @@ !global $LEGEND_FONT_COLOR = "#FFFFFF" !global $LEGEND_TITLE_COLOR = "#000000" -!global $LEGEND_UNDEFINED_BG_COLOR = "#D5CFEE" -!global $LEGEND_UNDEFINED_FONT_COLOR = "#8B77E4" +' %darken(darkkhaki,50), #khaki +!global $LEGEND_DARK_COLOR = "#66622E" +!global $LEGEND_LIGHT_COLOR = "#khaki" ' Labels ' ################################## @@ -202,7 +203,7 @@ $tagSkin !endprocedure ' arrow colors cannot start with # (legend background has to start with #) -!function ColorNoHash($c) +!function $colorWithoutHash($c) !if (%substr($c, 0, 1) == "#") !$c = %substr($c,1) !endif @@ -213,39 +214,74 @@ $tagSkin !$elementSkin = "skinparam arrow<<" + $tagStereo + ">> {" + %newline() !$elementSkin = $elementSkin + " Color " !if ($lineColor!="") - !$elementSkin = $elementSkin + ColorNoHash($lineColor) + !$elementSkin = $elementSkin + $colorWithoutHash($lineColor) !endif !if ($textColor!="") - !$elementSkin = $elementSkin + ";text:" + ColorNoHash($textColor) + !$elementSkin = $elementSkin + ";text:" + $colorWithoutHash($textColor) !endif !$elementSkin = $elementSkin + %newline() !$elementSkin = $elementSkin + "}" + %newline() $elementSkin !endprocedure -!function $tagLegendEntry($tagStereo, $bgColor, $fontColor, $borderColor, $shadowing, $shape) - !$tagEntry = "|" - !if ($bgColor!="") - !$bg = $bgColor +!unquoted function $contrastColor($color) + !if (%is_dark($color)) + !$value = $LEGEND_LIGHT_COLOR !else - !$bg = $LEGEND_UNDEFINED_BG_COLOR - !endif - ' named colors have to start with # too - !if (%substr($bg, 0, 1) != "#") - !$bg = "#" + $bg + !$value = $LEGEND_DARK_COLOR !endif - !$tagEntry = $tagEntry + "<" + $bg +">" - ' ..white rectangle - !if ($borderColor!="") - !$tagEntry = $tagEntry + " " + !return $value +!endfunction + +!unquoted function $flatColor($color) + !if (%is_dark($color)) + !$value = $LEGEND_DARK_COLOR !else - !$tagEntry = $tagEntry + " " + !$value = $LEGEND_LIGHT_COLOR !endif - !if ($fontColor!="") - !$tagEntry = $tagEntry + "" + !return $value +!endfunction + +' legend background has to start with # +!function $colorWithHash($c) + !if (%substr($c, 0, 1) != "#") + !$c = "#" + $c + !endif + !return $c +!endfunction + +!function $tagLegendEntry($tagStereo, $bgColor, $fontColor, $borderColor, $shadowing, $shape) + !$bg = $bgColor + !$fo = $fontColor + !$bo = $borderColor + + !if ($fo == "") + !if ($bg != "") + !$fo = $contrastColor($bg) + !else + !if ($bo == "") + !$fo = $LEGEND_DARK_COLOR + !$bg = $LEGEND_LIGHT_COLOR + !else + !$fo = $flatColor($bo) + !$bg = $contrastColor($bo) + !endif + !endif !else - !$tagEntry = $tagEntry + "" + !if ($bg == "") + !$bg = $contrastColor($fo) + !endif + !endif + + !if ($bo == "") + !$bo = $bg !endif + + !$tagEntry = "|" + !$tagEntry = $tagEntry + "<" + $colorWithHash($bg) +">" + ' ..white rectangle + !$tagEntry = $tagEntry + " " + !$tagEntry = $tagEntry + "" !$tagEntry = $tagEntry + " " + $tagStereo + " " !if ($shadowing == "true") !$tagEntry = $tagEntry + $LEGEND_SHADOW_TEXT From bbbda8c6e85524f9f29bab04b6e2ea1f3e5b26c6 Mon Sep 17 00:00:00 2001 From: KIRCHSTH Date: Sun, 23 May 2021 09:50:59 +0200 Subject: [PATCH 2/3] #149: LegendColor considers brightness (2 - relations too) --- C4.puml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/C4.puml b/C4.puml index 05fbc6b..f298cf3 100644 --- a/C4.puml +++ b/C4.puml @@ -224,7 +224,7 @@ $tagSkin $elementSkin !endprocedure -!unquoted function $contrastColor($color) +!unquoted function $contrastLegend($color) !if (%is_dark($color)) !$value = $LEGEND_LIGHT_COLOR !else @@ -233,7 +233,7 @@ $elementSkin !return $value !endfunction -!unquoted function $flatColor($color) +!unquoted function $flatLegend($color) !if (%is_dark($color)) !$value = $LEGEND_DARK_COLOR !else @@ -257,19 +257,19 @@ $elementSkin !if ($fo == "") !if ($bg != "") - !$fo = $contrastColor($bg) + !$fo = $contrastLegend($bg) !else !if ($bo == "") !$fo = $LEGEND_DARK_COLOR !$bg = $LEGEND_LIGHT_COLOR !else - !$fo = $flatColor($bo) - !$bg = $contrastColor($bo) + !$fo = $flatLegend($bo) + !$bg = $contrastLegend($bo) !endif !endif !else !if ($bg == "") - !$bg = $contrastColor($fo) + !$bg = $contrastLegend($fo) !endif !endif @@ -316,12 +316,12 @@ $elementSkin !if ($lineColor!="") !$tagEntry = $tagEntry + " " !else - !$tagEntry = $tagEntry + " " + !$tagEntry = $tagEntry + " " !endif !if ($textColor!="") !$tagEntry = $tagEntry + "" !else - !$tagEntry = $tagEntry + "" + !$tagEntry = $tagEntry + "" !endif !$tagEntry = $tagEntry + " " + $tagStereo + " " !if ($textColor == "") From 35bd190742e51ad92b0ea306c0cbbd9d633b7275 Mon Sep 17 00:00:00 2001 From: KIRCHSTH Date: Mon, 24 May 2021 15:07:35 +0200 Subject: [PATCH 3/3] #149: LegendColor considers brightness (3 - add old PlantUML version workaround) --- C4.puml | 51 +++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 41 insertions(+), 10 deletions(-) diff --git a/C4.puml b/C4.puml index f298cf3..ac98102 100644 --- a/C4.puml +++ b/C4.puml @@ -224,6 +224,14 @@ $tagSkin $elementSkin !endprocedure +' %is_dark() requires PlantUML version >=1.2021.6 +!if (%function_exists("%is_dark")) + !$PlantUMLSupportsDynamicLegendColor = %true() +!else + !$PlantUMLSupportsDynamicLegendColor = %false() + !log "dynamic undefined legend colors" requires PlantUML version >= 1.2021.6, therefore only static assigned colors are used +!endif + !unquoted function $contrastLegend($color) !if (%is_dark($color)) !$value = $LEGEND_LIGHT_COLOR @@ -257,19 +265,32 @@ $elementSkin !if ($fo == "") !if ($bg != "") +!if ($PlantUMLSupportsDynamicLegendColor) !$fo = $contrastLegend($bg) +!else + !$fo = $LEGEND_DARK_COLOR +!endif !else !if ($bo == "") !$fo = $LEGEND_DARK_COLOR !$bg = $LEGEND_LIGHT_COLOR !else +!if ($PlantUMLSupportsDynamicLegendColor) !$fo = $flatLegend($bo) !$bg = $contrastLegend($bo) +!else + !$fo = $LEGEND_DARK_COLOR + !$bg = $LEGEND_LIGHT_COLOR +!endif !endif !endif !else !if ($bg == "") +!if ($PlantUMLSupportsDynamicLegendColor) !$bg = $contrastLegend($fo) +!else + !$bg = $LEGEND_LIGHT_COLOR +!endif !endif !endif @@ -311,18 +332,28 @@ $elementSkin !endfunction !function $tagRelLegendEntry($tagStereo, $textColor, $lineColor) - !$tagEntry = "|" - ' ..white line - !if ($lineColor!="") - !$tagEntry = $tagEntry + " " - !else - !$tagEntry = $tagEntry + " " + !$tc = $textColor + !$lc = $lineColor + + !if ($tc=="") +!if ($PlantUMLSupportsDynamicLegendColor) + !$tc = $flatLegend($ARROW_COLOR) +!else + !$tc = $LEGEND_DARK_COLOR +!endif !endif - !if ($textColor!="") - !$tagEntry = $tagEntry + "" - !else - !$tagEntry = $tagEntry + "" + !if ($lc=="") +!if ($PlantUMLSupportsDynamicLegendColor) + !$lc = $flatLegend($ARROW_COLOR) +!else + !$lc = $LEGEND_DARK_COLOR +!endif !endif + + !$tagEntry = "|" + ' ..white line + !$tagEntry = $tagEntry + " " + !$tagEntry = $tagEntry + "" !$tagEntry = $tagEntry + " " + $tagStereo + " " !if ($textColor == "") !$tagEntry = $tagEntry + $LEGEND_NO_FONT_TEXT