From f1605555500264986eeb08cf3acaeabbbfb96eeb Mon Sep 17 00:00:00 2001 From: Thomas Bouffard <27200110+tbouffard@users.noreply.github.com> Date: Tue, 5 Mar 2024 17:09:36 +0100 Subject: [PATCH] refactor: use map instead of switch to manage the marker painters (as to handle event icons) --- .../mxgraph/shape/activity-shapes.ts | 68 ++++++++----------- 1 file changed, 28 insertions(+), 40 deletions(-) diff --git a/src/component/mxgraph/shape/activity-shapes.ts b/src/component/mxgraph/shape/activity-shapes.ts index e8cb7746fc..c5200fb4ea 100644 --- a/src/component/mxgraph/shape/activity-shapes.ts +++ b/src/component/mxgraph/shape/activity-shapes.ts @@ -48,6 +48,29 @@ export abstract class BaseActivityShape extends mxRectangleShape { // The actual value is injected at runtime by BpmnCellRenderer protected iconPainter: IconPainter = undefined; + private iconPainters = new Map void>([ + [ShapeBpmnMarkerKind.ADHOC, (paintParameter: PaintParameter) => this.iconPainter.paintAdHocIcon(paintParameter)], + [ + ShapeBpmnMarkerKind.COMPENSATION, + (paintParameter: PaintParameter) => + this.iconPainter.paintDoubleLeftArrowheadsIcon({ + ...paintParameter, + iconWidth: 16, + // ratioFromParent: 0.3, + // iconStyleConfig: { + // ...paintParameter.iconStyleConfig, + // strokeWidth: 1.5, + // // no impact, still filled + // isFilled: false, + // }, + }), + ], + [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 } @@ -73,46 +96,11 @@ 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; - } - case ShapeBpmnMarkerKind.ADHOC: { - this.iconPainter.paintAdHocIcon(paintParameter); - break; - } - case ShapeBpmnMarkerKind.COMPENSATION: { - // this.iconPainter.paintExpandIcon(paintParameter); - // TODO don't work, the icon dimensions are too large --> must ensure icon size + when used with loop marker, the marker is filled - // this.iconPainter.paintDoubleLeftArrowheadsIcon(paintParameter); - // this.iconPainter.paintAsteriskIcon({ - this.iconPainter.paintDoubleLeftArrowheadsIcon({ - ...paintParameter, - iconWidth: 16, - // ratioFromParent: 0.3, - // iconStyleConfig: { - // ...paintParameter.iconStyleConfig, - // strokeWidth: 1.5, - // // no impact, still filled - // isFilled: false, - // }, - }); - break; - } - } + + // inspired from event-shapes that could be updated to not used "IconPainter.emptyIcon" and not called the function if it is not defined + const markerPainter = this.iconPainters.get(marker as ShapeBpmnMarkerKind); + markerPainter?.(paintParameter); + // Restore original configuration to avoid side effects if the iconPainter changed the canvas configuration (colors, ....) paintParameter.canvas.restore(); }