From a910f20324f3641cc1afc2c358313d29d2758a16 Mon Sep 17 00:00:00 2001 From: Thomas Bouffard <27200110+tbouffard@users.noreply.github.com> Date: Wed, 6 Mar 2024 11:21:09 +0100 Subject: [PATCH] getMarkerIconOriginFunction: simplify algo + add comments to explain what has been done in the POC --- src/component/mxgraph/shape/activity-shapes.ts | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/component/mxgraph/shape/activity-shapes.ts b/src/component/mxgraph/shape/activity-shapes.ts index c5200fb4ea..266ae3e99a 100644 --- a/src/component/mxgraph/shape/activity-shapes.ts +++ b/src/component/mxgraph/shape/activity-shapes.ts @@ -26,17 +26,22 @@ import { buildPaintParameter } from './render/icon-painter'; import { orderActivityMarkers } from './render/utils'; function getMarkerIconOriginFunction(numberOfMarkers: number, markerPosition: number): (canvas: BpmnCanvas) => void { - // work for 1, 2, 3 and 4 markers + // Tested with 1, 2, 3 and 4 markers - // middle marker - if (markerPosition == (numberOfMarkers + 1) / 2) { - return (canvas: BpmnCanvas) => canvas.setIconOriginForIconBottomCentered(); - } + // Middle marker - the following code is not needed, the general algorithm works for this case (the computed translation is then 0 on both x and y) + // if (markerPosition == (numberOfMarkers + 1) / 2) { + // return (canvas: BpmnCanvas) => canvas.setIconOriginForIconBottomCentered(); + // } + // General algorithm + // it includes the fix for 2 markers + // The previous implementation was adding too much spacing: it added SHAPE_ACTIVITY_MARKER_ICON_SIZE instead of SHAPE_ACTIVITY_MARKER_ICON_SIZE / 2 return (canvas: BpmnCanvas) => { canvas.setIconOriginForIconBottomCentered(); const xTranslation = ((2 * markerPosition - (numberOfMarkers + 1)) * (StyleDefault.SHAPE_ACTIVITY_MARKER_ICON_SIZE + StyleDefault.SHAPE_ACTIVITY_MARKER_ICON_MARGIN)) / 2; - // must call a function that doesn't apply scaling to the translation as we are using absolute values here + // Here, we must call a function that doesn't apply scaling to the translation as we are passing an absolute translation value. + // The "translateIconOriginWithoutScaling" method had been added for the POC. An alternative could be to add a parameter to the existing "translateIconOrigin" method to indicate if the translation must be done. + // For example: translateIconOrigin(dx: number, dy: number, useScaling = true): void canvas.translateIconOriginWithoutScaling(xTranslation, 0); }; }