metafizzy / isotope

:revolving_hearts: Filter & sort magical layouts
https://isotope.metafizzy.co
11.05k stars 1.41k forks source link

Packery layout mode is working not as expected #1581

Closed SabathMedia closed 1 year ago

SabathMedia commented 3 years ago

Packery layout mode is working not as expected.

Test case: https://codepen.io/sabath-media/pen/dyOZLdE

thesublimeobject commented 3 years ago

@SabathMedia —

Okay, so I'm not sure this is actually wrong, but @desandro, you might need to confirm my intuition here.

The reason this isn't incorrect is because it loops through the remaining fit-able pieces from left to right, and in order, downward. Therefore, by the time it gets to the second row, the first two pieces have fit correctly in the first row, and then it fills in the next two pieces in the second row, since they can both fit. Once that has happened, there are only two pieces left, and neither of them can fit in the last remaining space in row #2, therefore they both get relegated to rows #3/4. If, for example, you added another box element at the bottom, it would indeed place itself into row #2 with the remaining space.

I understand why you think this might be wrong, but realistically, I imagine that this layout mode was not exactly intended for such a small number of elements, since you could, of course, pretty easily arrange this # of elements without a library. To be clear, I'm speaking for @desandro here, and I could definitely be wrong. Nonetheless, if you had this same layout with say 100 of these elements, the packing algorithm would have many more future elements to fill in the gaps, and this issue with just a few elements wouldn't exist. So, I think in the end, it's just that your expectations of what packery should do with so few elements is slightly off, though I can understand why you would think that.

Let me know if this makes sense and if you have any other questions.