[Style] Regression on document background-color style

0 votes
asked Apr 12 in Bug by The-Lu (22,220 points)

Hello PlantUML team,

It seems that occurs some regression about document style;
Here is an example:

CodePNGSVG
@startwbs
<style>
document {
  BackGroundColor pink
}
wbsDiagram {
  BackGroundColor palegreen
}
</style>
+ r
++ aa
+++ aaa
++ bb
+++ bbb
@endwbs

Why document style is not managed?

Is always this order:

  • document (only first level, without heritage), then root (with heritage), then diagram (with heritage), then node/object...?

Regards,
Th.

1 Answer

0 votes
answered Apr 13 by plantuml (252,860 points)
selected Apr 13 by The-Lu
 
Best answer

First, sorry about those implementation changes: style are still under development...
It's indeed a regression, but due to the fact that the logic was not properly implemented in previous releases :-)

To fix your issue, you have to use:

<style>
wbsDiagram {
  BackGroundColor palegreen
}
document {
  BackGroundColor pink
}
</style>

or

<style>
document {
  BackGroundColor pink
}
wbsDiagram {
  element {
    BackGroundColor palegreen
  }
}
</style>

Why is it so ?

You have to know that order in <style> declaration is very important.
The background of the diagram is specified by "root.wbsDiagram.document.BackgroundColor". Note that the order in keys here is not important. That is we could also say that the background is specified by "root.document.wbsDiagram.BackgroundColor"
The background of all elements is specified by "root.wbsDiagram.element.node.BackgroundColor" or "root.element.wbsDiagram.BackgroundColor"

So if we take your original example:

<style>
document {
  BackGroundColor pink
}
wbsDiagram {
  BackGroundColor palegreen
}
</style>

The first directive "BackGroundColor pink" means "Every backcolor of any document are pink".
The second directive "BackGroundColor palegreen" means "Every backcolor (so including document and element) are palegreen". That's why you have a full "palegreen" result.

Just changing the order of directive change the result:
Everything in "wbsDiagram" is background palegreen but all "document" (so including wbsDiagram and all other diagrams BTW) are pink.

I understand that this may be quite confusing, but once you get the logic, you can achieve really a great flexibility.

It gives the possibility to change a setting (for example default font size, color, name...) for all diagrams without to have to set a setting for Sequence, then one for Class, then one for Activity...
And at the same time, it gives the possibility to change a setting for a specific diagrams type (only Sequence for example).

As exercise, you can study this or this

Hope it helps, we are really open to feedback !

commented Apr 13 by The-Lu (22,220 points)

Hello PlantUML,

Your answer is perfectly clear, thank you very much.
I will now pay attention to the orderred in the style

Let's wait for the continuation to explicitly mention this in the documentation. 

Regards,
Th.

...