process-analytics / bpmn-visualization-js

A TypeScript library for visualizing process execution data on BPMN diagrams
https://process-analytics.github.io/bpmn-visualization-js/
Apache License 2.0
224 stars 31 forks source link

[FEAT] Add text color CSS styling to elements #1964

Closed DumitruCorini closed 2 years ago

DumitruCorini commented 2 years ago

Is your feature request related to a problem? Please describe. Currently, we can style the background of elements (fill css property) and border of elements (stroke css property). I would like to also be able to style each element text color (textColor css property? or any other name 😃).

Describe the solution you'd like I would like for something like this to make the text inside the rectangle blue :

.myElement rect {
    textColor: blue;
}

Describe alternatives you've considered I have tried setting the css color property, but that doesn't seem to do anything.

Additional context I can provide any if requested.

tbouffard commented 2 years ago

@DumitruCorini this is already possible but not with the way you describe here. Also remember that the styling/theming feature is experimental and subject to changes.

Labels are currently displayed using foreignObject including HTML node (see #320) and they can be identified by using the bpmn-label CSS selector. We don't have dedicated examples for label CSS styling, but we have a unreleased demo that shows how to style labels: see https://github.com/process-analytics/bpmn-visualization-examples/blob/v0.23.2/demo/predictions/css/demo.css#L38-L44

Here is the common syntax

.bpmn-label > g div {
    color: orange !important;
    font-weight: bold;
}

We are currently working on the global theming strategy #45 and we plan to have more examples in the future (https://github.com/process-analytics/bpmn-visualization-examples/issues/115 and https://github.com/process-analytics/bpmn-visualization-examples/issues/268). So things should improve later this year.

tbouffard commented 2 years ago

@DumitruCorini We have just introduced a TypeScript live example running at CodeSandbox that includes the usage of CSS label styling. ⏩ https://codesandbox.io/s/bpmn-visualization-ts-sandbox-erkrbc?file=/src/styles.css

DumitruCorini commented 2 years ago

That looks great. 😲

I had a question about the DOM. Why all the labels and the rectangles sharing the same parent in the DOM? You have something like this:

parent -> rectangle1 - label1 - rectangle2 - label2

I would have expected something like this:

parent1 -> rectangle1 - label1
parent2 -> rectangle2 - label2

This would make styling of specific elements easier, since they will have different parents, instead of all of them being under a single parent. For example:

Or the label might be under the rectangle, like so :

parent -> 
- rectangle1 -> label1
- rectangle2 -> label2 

If it's easier to implement.

tbouffard commented 2 years ago

I understand that the DOM is messy, but today, we have no solution for that

As mxGraph is discontinued, we will try to make its successor maxGraph work better by suggesting or providing improvements. In the past, we also investigated using alternative libs. We faced integration issue with the only one we found and matched our needs #970. So for now, we will live with the current limitations of mxGraph.

DumitruCorini commented 2 years ago

Ok, thank you for the detailed information. The CodeSandbox improvements that you provided will probably be enough for now.

tbouffard commented 2 years ago

OK fine, so I am closing this issue now. I will work on adding new examples about CSS theming later (https://github.com/process-analytics/bpmn-visualization-examples/issues/115).