javascripthtmlalgorithmbin-packing

Bin Packing Algorithm for Fitting HTML elements on the Screen


I recently built a web extension that can scrape HTML elements from a page and open a new tab with those elements. I came across a problem that I've been working on for hours but I'm not coming up with a good solution. Basically I want to fit these elements on the screen by arranging them somehow, while also being able to scale them. I plan to implement this algorithm in Javascript so I can use it with my web extension.

Goals:

Constraints:

Here's an example of what my extension outputted in a new tab (was trying to make a cheat sheet):

https://imgur.com/yNzIp2w

I've done a decent amount of searching into bin packing algorithms (although that's pretty new for me) and similar topics but haven't found any that include the ability to scale the rectangles.

Any help here would be much appreciated!


Solution

  • You can experiment with the 80% and 10% to get some values that work well with your bin packing algorithm.