-
Notifications
You must be signed in to change notification settings - Fork 36
feat: add support for 'BPMN in Color' #2614
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
Changes from 26 commits
c958950
44563ff
94db78b
3a8f874
aa7080d
7606577
7b03ac6
00eb1ea
5d965d0
8e98dd8
e0660fe
0f255fa
04afe69
3902d44
b832d6d
3513199
80aacb8
921ce1c
f838422
57af8c9
7f1407e
f5ec16f
f9bd177
d957d43
04052da
be6e750
4d2cc3d
4ee509e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -22,11 +22,10 @@ import { Edge, Waypoint } from '../../../../model/bpmn/internal/edge/edge'; | |||||||||||
| import type { Shapes } from '../../../../model/bpmn/internal/BpmnModel'; | ||||||||||||
| import type BpmnModel from '../../../../model/bpmn/internal/BpmnModel'; | ||||||||||||
| import Label, { Font } from '../../../../model/bpmn/internal/Label'; | ||||||||||||
| import { MessageVisibleKind } from '../../../../model/bpmn/internal/edge/kinds'; | ||||||||||||
| import { MessageVisibleKind, ShapeBpmnCallActivityKind, ShapeBpmnMarkerKind, ShapeUtil } from '../../../../model/bpmn/internal'; | ||||||||||||
| import type { BPMNDiagram, BPMNEdge, BPMNLabel, BPMNLabelStyle, BPMNShape } from '../../../../model/bpmn/json/BPMNDI'; | ||||||||||||
| import type { Point } from '../../../../model/bpmn/json/DC'; | ||||||||||||
| import type { ConvertedElements } from './utils'; | ||||||||||||
| import { ShapeBpmnCallActivityKind, ShapeBpmnMarkerKind, ShapeUtil } from '../../../../model/bpmn/internal'; | ||||||||||||
| import { ensureIsArray } from '../../../helpers/array-utils'; | ||||||||||||
| import type { ParsingMessageCollector } from '../../parsing-messages'; | ||||||||||||
| import { EdgeUnknownBpmnElementWarning, LabelStyleMissingFontWarning, ShapeUnknownBpmnElementWarning } from '../warnings'; | ||||||||||||
|
|
@@ -104,26 +103,44 @@ export default class DiagramConverter { | |||||||||||
| return false; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| private deserializeShape(shape: BPMNShape, findShapeElement: (bpmnElement: string) => ShapeBpmnElement): Shape | undefined { | ||||||||||||
| const bpmnElement = findShapeElement(shape.bpmnElement); | ||||||||||||
| private deserializeShape(bpmnShape: BPMNShape, findShapeElement: (bpmnElement: string) => ShapeBpmnElement): Shape | undefined { | ||||||||||||
| const bpmnElement = findShapeElement(bpmnShape.bpmnElement); | ||||||||||||
| if (bpmnElement) { | ||||||||||||
| const bounds = DiagramConverter.deserializeBounds(shape); | ||||||||||||
| const bounds = DiagramConverter.deserializeBounds(bpmnShape); | ||||||||||||
|
|
||||||||||||
| if ( | ||||||||||||
| (bpmnElement instanceof ShapeBpmnSubProcess || | ||||||||||||
| (bpmnElement instanceof ShapeBpmnCallActivity && bpmnElement.callActivityKind === ShapeBpmnCallActivityKind.CALLING_PROCESS)) && | ||||||||||||
| !shape.isExpanded | ||||||||||||
| !bpmnShape.isExpanded | ||||||||||||
| ) { | ||||||||||||
| bpmnElement.markers.push(ShapeBpmnMarkerKind.EXPAND); | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| let isHorizontal; | ||||||||||||
| if (ShapeUtil.isPoolOrLane(bpmnElement.kind)) { | ||||||||||||
| isHorizontal = shape.isHorizontal ?? true; | ||||||||||||
| isHorizontal = bpmnShape.isHorizontal ?? true; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| const label = this.deserializeLabel(shape.BPMNLabel, shape.id); | ||||||||||||
| return new Shape(shape.id, bpmnElement, bounds, label, isHorizontal); | ||||||||||||
| const bpmnLabel = bpmnShape.BPMNLabel; | ||||||||||||
| const label = this.deserializeLabel(bpmnLabel, bpmnShape.id); | ||||||||||||
| const shape = new Shape(bpmnShape.id, bpmnElement, bounds, label, isHorizontal); | ||||||||||||
| DiagramConverter.setColorExtensionsOnShape(shape, bpmnShape); | ||||||||||||
|
|
||||||||||||
| return shape; | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| // 'BPMN in Color' extensions with fallback to bpmn.io colors | ||||||||||||
| private static setColorExtensionsOnShape(shape: Shape, bpmnShape: BPMNShape): void { | ||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: I think we don't need to check if
Suggested change
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 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']; |
||||||||||||
| if ('background-color' in bpmnShape) { | ||||||||||||
| shape.extensions.fillColor = <string>bpmnShape['background-color']; | ||||||||||||
| } else if ('fill' in bpmnShape) { | ||||||||||||
| shape.extensions.fillColor = <string>bpmnShape['fill']; | ||||||||||||
| } | ||||||||||||
| if ('border-color' in bpmnShape) { | ||||||||||||
| shape.extensions.strokeColor = <string>bpmnShape['border-color']; | ||||||||||||
| } else if ('stroke' in bpmnShape) { | ||||||||||||
| shape.extensions.strokeColor = <string>bpmnShape['stroke']; | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
|
|
@@ -136,26 +153,37 @@ export default class DiagramConverter { | |||||||||||
|
|
||||||||||||
| private deserializeEdges(edges: BPMNEdge | BPMNEdge[]): Edge[] { | ||||||||||||
| return ensureIsArray(edges) | ||||||||||||
| .map(edge => { | ||||||||||||
| .map(bpmnEdge => { | ||||||||||||
| const flow = | ||||||||||||
| this.convertedElements.findSequenceFlow(edge.bpmnElement) || | ||||||||||||
| this.convertedElements.findMessageFlow(edge.bpmnElement) || | ||||||||||||
| this.convertedElements.findAssociationFlow(edge.bpmnElement); | ||||||||||||
| this.convertedElements.findSequenceFlow(bpmnEdge.bpmnElement) || | ||||||||||||
| this.convertedElements.findMessageFlow(bpmnEdge.bpmnElement) || | ||||||||||||
| this.convertedElements.findAssociationFlow(bpmnEdge.bpmnElement); | ||||||||||||
|
|
||||||||||||
| if (!flow) { | ||||||||||||
| this.parsingMessageCollector.warning(new EdgeUnknownBpmnElementWarning(edge.bpmnElement)); | ||||||||||||
| this.parsingMessageCollector.warning(new EdgeUnknownBpmnElementWarning(bpmnEdge.bpmnElement)); | ||||||||||||
| return; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| const waypoints = this.deserializeWaypoints(edge.waypoint); | ||||||||||||
| const label = this.deserializeLabel(edge.BPMNLabel, edge.id); | ||||||||||||
| const messageVisibleKind = edge.messageVisibleKind ? (edge.messageVisibleKind as unknown as MessageVisibleKind) : MessageVisibleKind.NONE; | ||||||||||||
| const waypoints = this.deserializeWaypoints(bpmnEdge.waypoint); | ||||||||||||
| const label = this.deserializeLabel(bpmnEdge.BPMNLabel, bpmnEdge.id); | ||||||||||||
| const messageVisibleKind = bpmnEdge.messageVisibleKind ? (bpmnEdge.messageVisibleKind as unknown as MessageVisibleKind) : MessageVisibleKind.NONE; | ||||||||||||
|
|
||||||||||||
| return new Edge(edge.id, flow, waypoints, label, messageVisibleKind); | ||||||||||||
| const edge = new Edge(bpmnEdge.id, flow, waypoints, label, messageVisibleKind); | ||||||||||||
| DiagramConverter.setColorExtensionsOnEdge(edge, bpmnEdge); | ||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. question: |
||||||||||||
| return edge; | ||||||||||||
| }) | ||||||||||||
| .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) { | ||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion:
Suggested change
|
||||||||||||
| edge.extensions.strokeColor = <string>bpmnEdge['border-color']; | ||||||||||||
| } else if ('stroke' in bpmnEdge) { | ||||||||||||
| edge.extensions.strokeColor = <string>bpmnEdge['stroke']; | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| private deserializeWaypoints(waypoints: Point[]): Waypoint[] { | ||||||||||||
| return ensureIsArray(waypoints).map(waypoint => new Waypoint(waypoint.x, waypoint.y)); | ||||||||||||
| } | ||||||||||||
|
|
@@ -164,9 +192,13 @@ export default class DiagramConverter { | |||||||||||
| if (bpmnLabel && typeof bpmnLabel === 'object') { | ||||||||||||
| const font = this.findFont(bpmnLabel.labelStyle, id); | ||||||||||||
| const bounds = DiagramConverter.deserializeBounds(bpmnLabel); | ||||||||||||
|
|
||||||||||||
| const label = new Label(font, bounds); | ||||||||||||
| if ('color' in bpmnLabel) { | ||||||||||||
| label.extensions.color = <string>bpmnLabel.color; | ||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. question: Same as for
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here this would change the behavior. |
||||||||||||
| return label; | ||||||||||||
| } | ||||||||||||
| if (font || bounds) { | ||||||||||||
| return new Label(font, bounds); | ||||||||||||
| return label; | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
Uh oh!
There was an error while loading. Please reload this page.