initial commit
This commit is contained in:
commit
3751b8ddb0
23 changed files with 2048 additions and 0 deletions
32
src/ManhattanConnectionModule.ts
Normal file
32
src/ManhattanConnectionModule.ts
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
|
||||
import { connectPoints } from 'diagram-js/lib/layout/ManhattanLayout';
|
||||
|
||||
function ManhattanLayoutPlugin(eventBus, modeling) {
|
||||
eventBus.on('connection.changed', (event) => {
|
||||
var connection = event.element;
|
||||
|
||||
if (connection.source && connection.target) {
|
||||
const x0 = connection.source.x + connection.source.width / 2;
|
||||
const x1 = connection.target.x + connection.target.width / 2;
|
||||
const y0 = connection.source.y + connection.source.height / 2;
|
||||
const y1 = connection.target.y + connection.target.height / 2;
|
||||
const x2 = (Math.abs(x0-x1) < 5) ? x0 : x1;
|
||||
const y2 = (Math.abs(y0-y1) < 5) ? y0 : y1;
|
||||
const waypoints = connectPoints(
|
||||
{ x: x0, y: y0 },
|
||||
{ x: x2, y: y2 });
|
||||
|
||||
const hasChanged = JSON.stringify(connection.waypoints) != JSON.stringify(waypoints);
|
||||
|
||||
if (hasChanged) {
|
||||
modeling.updateWaypoints(connection, waypoints)
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// export as module
|
||||
export default {
|
||||
__init__: [ 'manhattanLayoutPlugin' ],
|
||||
manhattanLayoutPlugin: [ 'type', ManhattanLayoutPlugin ]
|
||||
};
|
||||
Loading…
Reference in a new issue