From fb8d37548db75608d3fa0391f86bdaa1a3d09565 Mon Sep 17 00:00:00 2001 From: Gregory Bednov Date: Mon, 13 Jan 2025 18:57:22 +0300 Subject: [PATCH] now it updates only when moved or created, not when bending points are corrected --- src/ManhattanConnectionModule.ts | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/src/ManhattanConnectionModule.ts b/src/ManhattanConnectionModule.ts index 3e45ffe..3059fca 100644 --- a/src/ManhattanConnectionModule.ts +++ b/src/ManhattanConnectionModule.ts @@ -1,10 +1,7 @@ import { connectPoints } from 'diagram-js/lib/layout/ManhattanLayout'; -function ManhattanLayoutPlugin(eventBus, modeling) { - eventBus.on('connection.changed', (event) => { - var connection = event.element; - +export function updateWaypointsByManhattan (connection, modeling) { if (connection.source && connection.target) { const x0 = connection.source.x + connection.source.width / 2; const x1 = connection.target.x + connection.target.width / 2; @@ -22,11 +19,31 @@ function ManhattanLayoutPlugin(eventBus, modeling) { modeling.updateWaypoints(connection, waypoints) } } +} + +function ManhattanLayoutPlugin(eventBus, modeling) { + eventBus.on('connection.added', (event) => { + var connection = event.element; + updateWaypointsByManhattan(connection, modeling); + }); + + eventBus.on("shape.move.end", (event) => { + console.log(event.shape); + if (event.shape.incoming) { + event.shape.incoming.forEach(element => { + updateWaypointsByManhattan(element, modeling); + }); + } + + if (event.shape.outgoing) { + event.shape.outgoing.forEach(element => { + updateWaypointsByManhattan(element, modeling); + }); + } }); } -// export as module export default { __init__: [ 'manhattanLayoutPlugin' ], manhattanLayoutPlugin: [ 'type', ManhattanLayoutPlugin ] -}; \ No newline at end of file +};