-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4f6fc93
commit ea69215
Showing
8 changed files
with
208 additions
and
61 deletions.
There are no files selected for viewing
Binary file renamed
BIN
+11.9 KB
...923358f7fe31a0e073b92765141e67fcb5579.idx → ...964a1e325ed338ecd63a990839efa6ecdd023.idx
Binary file not shown.
Binary file renamed
BIN
+148 KB
...23358f7fe31a0e073b92765141e67fcb5579.pack → ...64a1e325ed338ecd63a990839efa6ecdd023.pack
Binary file not shown.
Binary file renamed
BIN
+1.61 KB
...923358f7fe31a0e073b92765141e67fcb5579.rev → ...964a1e325ed338ecd63a990839efa6ecdd023.rev
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,69 @@ | ||
const minHorizontalGapPercentage = 0.3; | ||
const verticalGapPercentage = 0.3; | ||
|
||
const bestHorizontalFit = (windowWidth, objectWidth) => { | ||
let columns = 1; | ||
let percentage = | ||
(windowWidth - columns * objectWidth) / (objectWidth * (1 + columns)); | ||
let prevPercentage = percentage; | ||
|
||
while (percentage >= minHorizontalGapPercentage) { | ||
prevPercentage = percentage; | ||
columns += 1; | ||
percentage = | ||
(windowWidth - columns * objectWidth) / (objectWidth * (1 + columns)); | ||
} | ||
|
||
return [columns - 1, prevPercentage]; | ||
}; | ||
|
||
export function listView(collection) { | ||
const width = window.innerWidth; | ||
const length = collection.length; | ||
|
||
const gap = 1; | ||
const objWidth = collection[0].width; | ||
const objHorizontalGap = gap * objWidth; | ||
const objHeight = collection[0].height; | ||
const objVerticalGap = gap * objHeight; | ||
const objVerticalGap = parseInt(verticalGapPercentage * objHeight); | ||
const objWidth = collection[0].width; | ||
const [cols, horizontalGapPercentage] = bestHorizontalFit(width, objWidth); | ||
const objHorizontalGap = parseInt(horizontalGapPercentage * objWidth); | ||
|
||
const cols = Math.ceil(width / (objWidth + objHorizontalGap)); | ||
const rows = Math.ceil(collection.length / cols); | ||
const rows = Math.ceil(length / cols); | ||
|
||
const height = rows * (objHeight + objVerticalGap / 2) + objVerticalGap / 2; | ||
const height = rows * (objHeight + objVerticalGap) + objVerticalGap; | ||
const finalHeight = height > window.innerHeight ? height : window.innerHeight; | ||
|
||
for (let i = 0; i < collection.length; i++) { | ||
const x = (i % cols) * objWidth + (((i % cols) + 1) * objHorizontalGap) / 2; | ||
const y = | ||
Math.floor(i / cols) * objHeight + | ||
((Math.floor(i / cols) + 1) * objVerticalGap) / 2; | ||
|
||
collection[i].x = x; | ||
collection[i].y = y; | ||
const allX = []; | ||
for (let i = 1; i <= cols; i++) { | ||
allX.push(i * objHorizontalGap + (i - 1) * objWidth); | ||
} | ||
|
||
const maxLength = rows * cols; | ||
const halfCols = Math.ceil(cols / 2); | ||
|
||
collection.forEach((object, index) => { | ||
const numElement = index + 1; | ||
|
||
const objRow = Math.ceil(numElement / cols); | ||
let objCol; | ||
const res = numElement % cols; | ||
if (res === 0) { | ||
objCol = cols; | ||
} else { | ||
objCol = res; | ||
} | ||
|
||
const rowLength = | ||
maxLength - numElement >= cols ? cols : length - cols * (rows - 1); | ||
const halfCol = Math.ceil(rowLength / 2); | ||
|
||
const allXIndex = halfCols - (halfCol - objCol); | ||
|
||
const x = allX[allXIndex - 1]; | ||
const y = objRow * objVerticalGap + (objRow - 1) * objHeight; | ||
|
||
object.x = x; | ||
object.y = y; | ||
}); | ||
|
||
return [width, finalHeight]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters