Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for 'BPMN in Color' #2614

Merged
merged 28 commits into from
May 25, 2023
Merged

feat: add support for 'BPMN in Color' #2614

merged 28 commits into from
May 25, 2023

Conversation

tbouffard
Copy link
Member

@tbouffard tbouffard commented Apr 9, 2023

Support the 'BPMN in Color' and use bpmn.io colors as fallback.
The BPMN parser always extract the colors, but by default, they are ignored by the Renderer. It is possible to enable the support in the Renderer by setting an options at the library initialization.

This introduces internal management of BPMN extensions for BPMNShape, BPMNEdge and BPMNLabel.

The parsing tests are using diagrams taken from the 'BPMN in Color' specification sample (this ensure that the implementation is compliant with the specification) and from the original issue requesting support for modeling colors as an example of bpmn.io colors.

closes #2588

Tasks

  • e2e tests thresholds
  • disable by default
  • add new tests to handle the new option: StyleComputer and e2e tests
  • DiagramConverter.deserializeShape: "Refactor this function to reduce its Cognitive Complexity from 16 to the 15 allowed." (feedback from SonarCloud)
  • update the Internal Model schema
  • update the documentation: create a dedicated section (after the BPMN theme paragraph for instance) mentioning that it supports the spec (including links to the spec) + fallback bpmn.io.
  • update JSDoc of the types of the "Update Style" API parameters: warn about resetting using "default". This overrides the initial colors value set in the BPMN model.
  • introduce a ignoreBpmnColors option to enable/disable the rendering support

Decision about support by default of "BPMN in Color"

Decision with @csouchet on 2023-04-12

  • BPMN in Color support is disabled by default. We want to support it but we want to keep execution highlight easy to see. Adding colors to non highlighted elements defeat this purpose (as colors highlight the elements). See C.1.1 that has a lot of colors and that we used in several examples.
  • to enable it, pass an option to the a lib at initialization
  • the option will be ignoreBpmnColors which is true by default. The new option involves the "BPMN renderer", so it must be consistent with the new options we plan to introduce in the future. See [FEAT] Define the options that will be used to configure the Renderer #2659.

Screenshots

sample from the "BPMN in Color" Specification

Available in https://github.com/bpmn-miwg/bpmn-in-color, also stored for use in XML parsing unit tests

sample_from_spec

adapted from the diagram provided in #2588

Also used in XML parsing unit tests

xml-parsing_test_issue-2588-both-bpmn-in-color-and-bpmnio_infor-modeler bpmn

e2e test diagram, including message flow icons that are also colored

e2e_02_msg_flow_icon_ok

Files from miwg-test-suite

File without color with color
A.2.1 A 2 1 A 2 1
A.4.1 A 4 1 A 4 1
C.1.0 C 1 0 C 1 0
C.1.1 C 1 1 C 1 1
C.3.0 C 3 0 C 3 0
C.8.0 C 8 0 C 8 0

Support the 'BPMN in Color' and use bpmn.io colors as fallback.

This introduces internal management of BPMN extensions for BPMNShape, BPMNEdge and BPMNLabel.

The parsing tests are using diagrams taken from the 'BPMN in Color' specification sample and from the original issue
requesting support for modeling colors (#2588) as an example of bpmn.io colors.
@tbouffard tbouffard added enhancement New feature or request WIP 🚧 Pull request in progress and/or not ready for review. Used in addition to marking it as draft BPMN diagram styling Change the standard rendering: stroke color, thickness labels Apr 9, 2023
@github-actions
Copy link

github-actions bot commented Apr 9, 2023

♻️ PR Preview 4ee509e has been successfully destroyed since this PR has been closed.

🤖 By surge-preview

@github-actions
Copy link

github-actions bot commented Apr 9, 2023

♻️ PR Preview 4ee509e has been successfully destroyed since this PR has been closed.

🤖 By surge-preview

@tbouffard tbouffard added BPMN rendering Something about the way the lib is rendering BPMN elements BPMN diagram styling Change the standard rendering: stroke color, thickness and removed BPMN diagram styling Change the standard rendering: stroke color, thickness BPMN rendering Something about the way the lib is rendering BPMN elements labels Apr 9, 2023
@tbouffard tbouffard added BPMN support Something about the BPMN specification that the lib is already supporting or will support and removed BPMN diagram styling Change the standard rendering: stroke color, thickness labels Apr 25, 2023
@tbouffard tbouffard added the decision record Track project and architectural decisions label May 11, 2023
@tbouffard tbouffard marked this pull request as ready for review May 16, 2023 05:36
@tbouffard tbouffard removed the WIP 🚧 Pull request in progress and/or not ready for review. Used in addition to marking it as draft label May 16, 2023
@tbouffard tbouffard requested a review from csouchet May 16, 2023 05:36
src/model/bpmn/internal/types.ts Show resolved Hide resolved
src/component/parser/json/converter/DiagramConverter.ts Outdated Show resolved Hide resolved
src/model/bpmn/internal/types.ts Outdated Show resolved Hide resolved
# Conflicts:
#	src/component/BpmnVisualization.ts
#	src/component/options.ts
#	test/unit/component/mxgraph/renderer/StyleComputer.test.ts
@tbouffard tbouffard requested a review from csouchet May 25, 2023 12:30
src/component/mxgraph/renderer/StyleComputer.ts Outdated Show resolved Hide resolved
src/component/mxgraph/renderer/StyleComputer.ts Outdated Show resolved Hide resolved
}

// 'BPMN in Color' extensions with fallback to bpmn.io colors
private static setColorExtensionsOnShape(shape: Shape, bpmnShape: BPMNShape): void {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion:

I think we don't need to check if background-color, fill, border-color and stroke are in bpmnShape, because even if there are undefined, with this implementation or the suggested implementation, the attributes of shape.extensions will be undefined.

Suggested change
private static setColorExtensionsOnShape(shape: Shape, bpmnShape: BPMNShape): void {
private static setColorExtensionsOnShape(shape: Shape, bpmnShape: BPMNShape): void {
shape.extensions.fillColor = <string>bpmnShape['background-color'] ?? <string>bpmnShape['fill'];
shape.extensions.strokeColor = <string>bpmnShape['border-color'] ?? <string>bpmnShape['stroke'];
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The usage of the color extensions is very rare, so the idea was to not have properties with undefined values but to have no property in this case.
The model is not stored internally, so I will give it a try to your proposal to simplify the code here and for Edge.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@csouchet the proposal cannot be implemented out of the box

const backgroundColor = bpmnShape['background-color'];

generates a TS error TS7053: Element implicitly has an 'any' type because expression of type '"background-color"' can't be used to index type 'BPMNShape'.   Property 'background-color' does not exist on type 'BPMNShape'.

I can ignore the error but the resulting code is less lisible and ignoring error is misleading

    // eslint-disable-next-line @typescript-eslint/ban-ts-comment -- explain why!
    // @ts-ignore
    shape.extensions.fillColor = <string>bpmnShape['background-color'] ?? <string>bpmnShape['fill'];
    // eslint-disable-next-line @typescript-eslint/ban-ts-comment -- explain why!
    // @ts-ignore
    shape.extensions.strokeColor = <string>bpmnShape['border-color'] ?? <string>bpmnShape['stroke'];


return new Edge(edge.id, flow, waypoints, label, messageVisibleKind);
const edge = new Edge(bpmnEdge.id, flow, waypoints, label, messageVisibleKind);
DiagramConverter.setColorExtensionsOnEdge(edge, bpmnEdge);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question:
Same as for Shape

})
.filter(Boolean);
}

// 'BPMN in Color' extensions with fallback to bpmn.io colors
private static setColorExtensionsOnEdge(edge: Edge, bpmnEdge: BPMNEdge): void {
if ('border-color' in bpmnEdge) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion:

Suggested change
if ('border-color' in bpmnEdge) {
edge.extensions.strokeColor = <string>bpmnEdge['border-color'] ?? <string>bpmnEdge['stroke'];
}


const label = new Label(font, bounds);
if ('color' in bpmnLabel) {
label.extensions.color = <string>bpmnLabel.color;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question:

Same as for Shape & Edge

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here this would change the behavior.
We return a Label instance only if properties are set (previously only font and bounds.
If I change the implementation as for shape and edge, we will always have an instance even when the label color is undefined.
So, I prefer not to change it.

@sonarcloud
Copy link

sonarcloud bot commented May 25, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

100.0% 100.0% Coverage
0.0% 0.0% Duplication

@tbouffard tbouffard merged commit d340bae into master May 25, 2023
@tbouffard tbouffard deleted the feat/bpmn-in-color branch May 25, 2023 15:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BPMN support Something about the BPMN specification that the lib is already supporting or will support decision record Track project and architectural decisions enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEAT] Add fill and stroke attributes in xml to draw colors per bpmn element
2 participants