Last active
September 17, 2021 10:24
-
-
Save trischbeck/ae82886485f41b015bd1e8a08c91a9ba to your computer and use it in GitHub Desktop.
Sorts selected visual elements within a view, based on https://gist.github.com/robkamp/fac2b2d80ee44e7085c70738de544341 #archi
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
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * | |
Script Name: alignVertically | |
Purpose: Sorts selected visual elements within a view by ID (alphabetically) and stacks them in a vertical layout | |
Builds on the AlignSpreadHorizontally script by Rob Kamp (https://gist.github.com/robkamp/fac2b2d80ee44e7085c70738de544341) | |
Thomas Rischbeck, rischbeck@itmc.ch, (C) ITMC 2021 | |
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */// Author: Rob Kamp | |
console.log("Start: Spread and Align vertically"); | |
minY = null; | |
minX = null; | |
maxWidth = 0; | |
maxHeight = 0; | |
distance = 5; | |
// 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; | |
minY = minY + maxHeight + distance; | |
}); | |
console.log("End: Spread and Align vertically"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment