Skip to content

Instantly share code, notes, and snippets.

@robkamp
Last active December 28, 2023 20:12
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robkamp/fac2b2d80ee44e7085c70738de544341 to your computer and use it in GitHub Desktop.
Save robkamp/fac2b2d80ee44e7085c70738de544341 to your computer and use it in GitHub Desktop.
#jArchi AlignHorizontally
// Author: Rob Kamp
// Requires: jArchi - https://www.archimatetool.com/blog/2018/07/02/jarchi/
// Purpose: Align to lowest, spread the selected elements horizontally, and resize to be equal size
// Date: 2019-11-20
// Version 1.0
// Change: Initial version
console.log("Start: Spread and Align horizontally");
minY = null;
minX = null;
maxWidth = 0;
maxHeight = 0;
// Determine the width, height, and
$(selection).each(function(element) {
minY = Math.min(element.bounds.y,minY==null?element.bounds.y:minY);
minX = Math.min(element.bounds.x,minX==null?element.bounds.x:minX);
maxWidth = Math.max(element.bounds.width,maxWidth);
maxHeight = Math.max(element.bounds.height,maxHeight);
});
// Sort the selection so the order stays the same
$(selection).sort(function (left,right) {
return left.bounds.x-right.bounds.x;
});
// Walk throught the sorted selection
$(selection).each(function (element) {
// Set the new bounds
element.bounds = {x: minX, y: minY, width: maxWidth, height: maxHeight};
// Set the spacing for the next element
minX = minX + maxWidth + 20;
});
console.log("End: Spread and Align horizontally");
@michaelljackson101
Copy link

Very helpful. Thank you.

@vnevzorov
Copy link

Thank you, very helpful.

@phoforjob
Copy link

It's working well.
Thank you.

@AlexisHFr
Copy link

Thanks ! very handy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment