Last active
November 24, 2019 09:25
-
-
Save xmayeur/331c59177fc75d974f02e40381c607f3 to your computer and use it in GitHub Desktop.
#jarchi - this script transforms a visual relationship as a orthogonal U-shape one
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 U-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) {} | |
if (sb.y < tb.y) { | |
var bp1 = { | |
startX: 0, | |
startY: 0, | |
endX: -dx, | |
endY: tb.y+dy+tb.height | |
} | |
var bp2 = { | |
startX: dx, | |
startY: tb.y+tb.height, | |
endX: 0, | |
endY: 0 | |
} | |
} else { | |
var bp1 = { | |
startX: 0, | |
startY: 3*tb.height, | |
endX: -dx, | |
endY: tb.y+tb.height | |
} | |
var bp2 = { | |
startX: dx, | |
startY: tb.y+tb.height-dy, | |
endX: 0, | |
endY:3*tb.height | |
} | |
} | |
// Add bendpoints at index positions | |
try { | |
o.addRelativeBendpoint(bp1, 0); | |
o.addRelativeBendpoint(bp2, 1); | |
} catch (e) {console.log(e)} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment