Skip to content

Commit

Permalink
refactor!: rename values in ShapeBpmnMarkerKind (#3147)
Browse files Browse the repository at this point in the history
The previous values related to "multi instance" included spaces which is
not consistent with values in other enums.
They now follow the kebab-case convention and their values are shorter.

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, use the enum
directly, in particular for:
  - MULTI_INSTANCE_PARALLEL
  - MULTI_INSTANCE_SEQUENTIAL
  • Loading branch information
tbouffard authored Aug 21, 2024
1 parent 7a9f2b4 commit e3f48eb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 20 deletions.
29 changes: 11 additions & 18 deletions src/component/mxgraph/shape/activity-shapes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ShapeBpmnMarkerKind, (paintParameter: PaintParameter) => void>([
[ShapeBpmnMarkerKind.EXPAND, (paintParameter: PaintParameter) => this.iconPainter.paintExpandIcon(paintParameter)],
[ShapeBpmnMarkerKind.LOOP, (paintParameter: PaintParameter) => this.iconPainter.paintLoopIcon(paintParameter)],
[ShapeBpmnMarkerKind.MULTI_INSTANCE_PARALLEL, (paintParameter: PaintParameter) => this.iconPainter.paintParallelMultiInstanceIcon(paintParameter)],
[ShapeBpmnMarkerKind.MULTI_INSTANCE_SEQUENTIAL, (paintParameter: PaintParameter) => this.iconPainter.paintSequentialMultiInstanceIcon(paintParameter)],
]);

constructor() {
super(undefined, undefined, undefined); // the configuration is passed with the styles at runtime
}
Expand All @@ -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();
}
Expand Down
4 changes: 2 additions & 2 deletions src/model/bpmn/internal/shape/kinds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}

/**
Expand Down

0 comments on commit e3f48eb

Please sign in to comment.