From 711ccec47f8b50f278930ab7bfa1c192f5d133de Mon Sep 17 00:00:00 2001 From: Thomas Bouffard <27200110+tbouffard@users.noreply.github.com> Date: Fri, 16 Aug 2024 18:13:28 +0200 Subject: [PATCH 1/2] refactor!: rename values of multi instance in `ShapeBpmnMarkerKind` The previous values included spaces which is not consistent with values in other enums. Use a kebab case and shorten the values. Refactor also the way markers are painted in `BaseActivityShape`: remove the use of the switch in favor of the use of a Map. This makes the implementation consistent with `EventShape`. BREAKING CHANGES: some values in `ShapeBpmnMarkerKind` have changed. Values are not supposed to be used directly, so this change should not have any impact. For applications using such values, replace the value by the of the enum, in particular for: - MULTI_INSTANCE_PARALLEL - MULTI_INSTANCE_SEQUENTIAL --- .../mxgraph/shape/activity-shapes.ts | 29 +++++++------------ src/model/bpmn/internal/shape/kinds.ts | 4 +-- 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/src/component/mxgraph/shape/activity-shapes.ts b/src/component/mxgraph/shape/activity-shapes.ts index f38824c396..7fe7f3f5d6 100644 --- a/src/component/mxgraph/shape/activity-shapes.ts +++ b/src/component/mxgraph/shape/activity-shapes.ts @@ -44,6 +44,13 @@ export abstract class BaseActivityShape extends mxRectangleShape { // The actual value is injected at runtime by BpmnCellRenderer protected iconPainter: IconPainter = undefined; + private markerPainterFunctions = new Map void>([ + [ShapeBpmnMarkerKind.EXPAND, (paintParameter: PaintParameter) => this.iconPainter.paintExpandIcon(paintParameter)], + [ShapeBpmnMarkerKind.LOOP, (paintParameter: PaintParameter) => this.iconPainter.paintLoopIcon(paintParameter)], + [ShapeBpmnMarkerKind.MULTI_INSTANCE_SEQUENTIAL, (paintParameter: PaintParameter) => this.iconPainter.paintSequentialMultiInstanceIcon(paintParameter)], + [ShapeBpmnMarkerKind.MULTI_INSTANCE_PARALLEL, (paintParameter: PaintParameter) => this.iconPainter.paintParallelMultiInstanceIcon(paintParameter)], + ]); + constructor() { super(undefined, undefined, undefined); // the configuration is passed with the styles at runtime } @@ -64,24 +71,10 @@ export abstract class BaseActivityShape extends mxRectangleShape { setIconOriginFunct: getMarkerIconOriginFunction(orderedMarkers.length, index + 1), }; paintParameter.canvas.save(); // ensure we can later restore the configuration - switch (marker) { - case ShapeBpmnMarkerKind.LOOP: { - this.iconPainter.paintLoopIcon(paintParameter); - break; - } - case ShapeBpmnMarkerKind.MULTI_INSTANCE_SEQUENTIAL: { - this.iconPainter.paintSequentialMultiInstanceIcon(paintParameter); - break; - } - case ShapeBpmnMarkerKind.MULTI_INSTANCE_PARALLEL: { - this.iconPainter.paintParallelMultiInstanceIcon(paintParameter); - break; - } - case ShapeBpmnMarkerKind.EXPAND: { - this.iconPainter.paintExpandIcon(paintParameter); - break; - } - } + + // Paint the marker + this.markerPainterFunctions.get(marker as ShapeBpmnMarkerKind)?.(paintParameter); + // Restore original configuration to avoid side effects if the iconPainter changed the canvas configuration (colors, ....) paintParameter.canvas.restore(); } diff --git a/src/model/bpmn/internal/shape/kinds.ts b/src/model/bpmn/internal/shape/kinds.ts index a53374017a..bd1bd26ead 100644 --- a/src/model/bpmn/internal/shape/kinds.ts +++ b/src/model/bpmn/internal/shape/kinds.ts @@ -124,8 +124,8 @@ export enum ShapeBpmnMarkerKind { COMPENSATION = 'compensation', EXPAND = 'expand', LOOP = 'loop', - MULTI_INSTANCE_PARALLEL = 'parallel multi instance', - MULTI_INSTANCE_SEQUENTIAL = 'sequential multi instance', + MULTI_INSTANCE_PARALLEL = 'multi-parallel', + MULTI_INSTANCE_SEQUENTIAL = 'multi-sequential', } /** From f1befc723866eb1465dcde5308d6d9deb7a3901f Mon Sep 17 00:00:00 2001 From: Thomas Bouffard <27200110+tbouffard@users.noreply.github.com> Date: Wed, 21 Aug 2024 14:06:22 +0200 Subject: [PATCH 2/2] activity-shapes.ts: order markerPainterFunctions in alphabetic order for consistency --- src/component/mxgraph/shape/activity-shapes.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/component/mxgraph/shape/activity-shapes.ts b/src/component/mxgraph/shape/activity-shapes.ts index 7fe7f3f5d6..f1be83f59b 100644 --- a/src/component/mxgraph/shape/activity-shapes.ts +++ b/src/component/mxgraph/shape/activity-shapes.ts @@ -47,8 +47,8 @@ export abstract class BaseActivityShape extends mxRectangleShape { private markerPainterFunctions = new Map void>([ [ShapeBpmnMarkerKind.EXPAND, (paintParameter: PaintParameter) => this.iconPainter.paintExpandIcon(paintParameter)], [ShapeBpmnMarkerKind.LOOP, (paintParameter: PaintParameter) => this.iconPainter.paintLoopIcon(paintParameter)], - [ShapeBpmnMarkerKind.MULTI_INSTANCE_SEQUENTIAL, (paintParameter: PaintParameter) => this.iconPainter.paintSequentialMultiInstanceIcon(paintParameter)], [ShapeBpmnMarkerKind.MULTI_INSTANCE_PARALLEL, (paintParameter: PaintParameter) => this.iconPainter.paintParallelMultiInstanceIcon(paintParameter)], + [ShapeBpmnMarkerKind.MULTI_INSTANCE_SEQUENTIAL, (paintParameter: PaintParameter) => this.iconPainter.paintSequentialMultiInstanceIcon(paintParameter)], ]); constructor() {