Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Any way to define specific element column within 'greedy' algorithm? #13

Open
Jackky90 opened this issue Nov 8, 2023 · 1 comment
Open

Comments

@Jackky90
Copy link

Jackky90 commented Nov 8, 2023

Dobar dan!🤗
Your solution of representing masonry layout is very close to meet my needs, it's very clever.
But I'm little stuck: in my grid I have first element unique, that should always be in the first column, on the top. But with greedy algorithm it mostly appears in the second column. chronological algorithm doesn't make sense, since grid becomes look ugly. Do you have any solution of it?

@Jackky90
Copy link
Author

Jackky90 commented Nov 8, 2023

My dirty workarounds result:

.forEach( item =>
{
	let min = sums.reduce( ( min, sum, index ) => sums[ min ] <= sum ? min : index, 0 )

	if ( undefined !== item.item.dataset.preserve )
		min = 0

	sums[ min ] += item.value
	item._subset = min
} )

Hardcoded this logic in Greedy class algorithm. That's all I need for now: set specific element strictly first. TO DO: make this memorize it's markup position and preserve some elements directly on that place. Will come back, if I'll have any considerations, and, maybe, a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant