Last active
June 13, 2023 14:52
-
-
Save xmayeur/55aff576bc8b16f50e59e016f8765cd4 to your computer and use it in GitHub Desktop.
#jarchi - This script modifies a visual relationship to create an orthogonal L-shape
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Author X. Mayeur | |
* | |
* Requires jArchi - https://www.archimatetool.com/blog/2018/07/02/jarchi/ | |
* | |
* This script takes a selection of visual objects as input, filter it to keep only relationships | |
* and create L-shape ortho connector | |
*/ | |
console.show() | |
console.clear() | |
for each (var o in $(selection).filter("relationship")) { | |
var view = o.view; | |
var rel = o.concept; | |
var source = o.source; | |
var target = o.target; | |
sb = source.bounds | |
tb = target.bounds | |
// calculate the source and target element absolute (x,y) coordinate | |
var pp = $(source).parents() | |
for each (p in pp) { | |
try { | |
sb.x += p.bounds.x | |
sb.y += p.bounds.y | |
} catch(e){} | |
} | |
var pp = $(target).parents() | |
for each (p in pp) { | |
try { | |
tb.x += p.bounds.x | |
tb.y += p.bounds.y | |
} catch(e){} | |
} | |
dx = tb.x - sb.x | |
dy = tb.y - sb.y | |
try { | |
o.deleteAllBendpoints() | |
} catch(e) {} | |
// New bendpoint 1 | |
// target object is left below source | |
if (tb.x+tb.width < sb.x & tb.y - tb.height > sb.y) { | |
var bp1 = { | |
startX: 0, | |
startY: dy, | |
endX: -dx, | |
endY: 0 | |
} | |
} | |
// target object is left above source | |
if (tb.x+tb.width < sb.x & tb.y + tb.height < sb.y) { | |
var bp1 = { | |
startX: dx, | |
startY: 0, | |
endX: 0, | |
endY: -dy | |
} | |
} | |
// target is right above source | |
if (tb.x > sb.x + sb.width & tb.y + tb.height < sb.y) { | |
var bp1 = { | |
startX: -dx, | |
startY: 0, | |
endX: 0, | |
endY: dy | |
} | |
} | |
// target is right below source | |
if (sb.x+sb.width < tb.x & tb.y - tb.height > sb.y) { | |
var bp1 = { | |
startX: 0, | |
startY: -dy, | |
endX: dx, | |
endY: 0 | |
} | |
} | |
// Add bendpoints at index positions | |
try { | |
o.addRelativeBendpoint(bp1, 0); | |
} catch(e) {} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you, very helpful. I have been thinking about such script, but could not figure out how to implement it.