Skip to content

Instantly share code, notes, and snippets.

@KevinGutowski
Created October 13, 2021 21:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KevinGutowski/9471bdc0c7e784c03b7b8ea5b0e4770d to your computer and use it in GitHub Desktop.
Save KevinGutowski/9471bdc0c7e784c03b7b8ea5b0e4770d to your computer and use it in GitHub Desktop.
Resize widths of progress bars - Figma
let selection = figma.currentPage.selection[0]
let paddingWidth = selection.paddingLeft + selection.paddingRight
let insetWidth = selection.width - paddingWidth
let times = [60*10+10,60*10+22,60*12+42,60*13+59]
// Remove extra children
selection.children.forEach((e,i)=>{
if (i>0) {
e.remove()
}
})
let widthForParts = insetWidth - ((times.length - 1) * selection.itemSpacing)
let scaleFactor = widthForParts/(times[times.length-1]-times[0])
let widths = []
for (let i=0;i<times.length-1;i++) {
let partWidths = times[i+1]-times[i]
widths.push(partWidths*scaleFactor)
}
widths.forEach(width=>{
let newPart = selection.children[0].clone()
newPart.resize(width,newPart.height)
selection.appendChild(newPart)
})
selection.children[0].remove()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment