How can I defined an automatic table background color?

0 votes
asked May 9, 2021 in Question / help by kirchsth (4,880 points)

I found the automatic text color based on the background color (of a table cell).

@startuml
legend
|<#white><color:#automatic> white area |
|<#red><color:#automatic> red area |
|<#blue><color:#automatic> blue area |

'crash if activated
' |<#automatic><color:#blue> blue text |
' |<#automatic><color:#white> white text |
' |<#automatic><color:#red> red text |
endlegend
@enduml

 

Is it possible to define an automatic background color based on the text color in a table cell too?
All my current tests crashes

@startuml
legend
|<#white><color:#automatic> white area |
|<#red><color:#automatic> red area |
|<#blue><color:#automatic> blue area |

'crash if activated
|<#automatic><color:#blue> blue text |
|<#automatic><color:#white> white text |
|<#automatic><color:#red> red text |
endlegend
@enduml

Thank you
Helmut

commented May 9, 2021 by The-Lu (63,920 points)

Hello K.,

But automatic is only black or white...

See documentation on §Automatic font color from color page:

If that can help,
Regards,
Th.

commented May 10, 2021 by kirchsth (4,880 points)
Hello Th.

not black or white is the problem. My problem is that I want a legend of tags and

a) one set of tags use a specific background color (e.g. "white area", "red area" and "blue area") but without a specific font color.  PlantUML offers the font color "automatic" that the cell text is still visible (black or white)  -> this is working

b) another set of tags uses a specific font color. For that I require that the cell color itself is automatically calculated based on the font color (e.g. "white text", ...). But this I cannot get working.

Regards
Helmut

1 Answer

0 votes
answered May 16, 2021 by The-Lu (63,920 points)
selected May 16, 2021 by kirchsth
 
Best answer

Hello K.,

According to the new color builtin functions (%darken, %lighten, %is_dark, %is_light) [on V1.2021.6], we can now use on user color functions...

And for example replace '#automatic' by  a tone_on_tone_color user function, as:

@startuml
!unquoted function $tone_on_tone_color($color)
  !if %is_dark($color)
    !$value = %lighten($color, 80)
  !else
    !$value = %darken($color, 80)
  !endif
  !return $value
!endfunction

legend
|<#white><color:#automatic> white area |
|<#red><color:#automatic> red area |
|<#blue><color:#automatic> blue area |

|<$tone_on_tone_color(#blue)><color:#blue> blue text |
|<$tone_on_tone_color(#white)><color:#white> white text |
|<$tone_on_tone_color(#red)><color:#red> red text |
endlegend
@enduml

And you can observe an expected result wink

Awaiting another builtin function for reverse, complementary or opposite color... (I can ask on a next wanted feature... cheeky)

If that can help,
Regards,
Th.

commented May 16, 2021 by kirchsth (4,880 points)
Super, thank you. Now I can have multiple color options.
Helmut
...