naturalatlas / image-layout Goto Github PK
View Code? Open in Web Editor NEWA collection of deterministic image layout algorithms written in pure javascript.
License: Apache License 2.0
A collection of deterministic image layout algorithms written in pure javascript.
License: Apache License 2.0
Sometimes images are 2x higher than the idealElementHeight
.
I don't really like the fact, because some images are really too big and pixelated.
I've been looking into the source and found the calculation for the number of needed rows.
https://github.com/naturalatlas/image-layout/blob/master/layouts/fixed-partition.js#L43
I've played with the calculation by changing it to:
var rowsNeeded = Math.round(summedWidth / containerWidth * 0.75)
Images can't now be that big anymore and they can be a little smaller, but that's perfect.
It could be an addition to the option object that defaults to 1.
I'm just not sure how to name it, weight seems to broad.
Thanks.
With the following set up, the algorithm yield the results display below:
import layout from 'image-layout/layouts/fixed-partition'
const elements = [
{"width":800,"height":536},
{"width":708,"height":800},
{"width":800,"height":536}
]
const result = layout(elements, {
containerWidth: 1200,
idealElementHeight: 280,
spacing: 40
})
{
"width": 1200,
"height": 310,
"positions": [
{
"y": 0,
"x": 0,
"width": 432,
"height": 310
},
{
"y": 0,
"x": 472,
"width": 256,
"height": 310
},
{
"y": 0,
"x": 768,
"width": 432,
"height": 310
}
]
}
Given the aspect ratio of the images, I'd expect the row to have a height of 290px
instead of 310px
. When spacing is set to 0
I get results that respect the aspect ratio. Do I miss something?
Hi,
What I basically want to achieve, is make it horizontally scrollable, using fixed-partition layout.
How would I go about adding maximum rows to display, or "cut" it up to different segments?
I've tried filtering and sorting the images into multiple layout "instances", to render separate, based on maximum X/Y, but no luck so far.
Any help would be much appreciated, thanks in regards.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.