-
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.
incorporate suggested changes for tree views and list views
- Loading branch information
1 parent
4ba0b9b
commit cbbfc6c
Showing
2 changed files
with
113 additions
and
32 deletions.
There are no files selected for viewing
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,60 @@ | ||
const horizontalGapPercentage = 0.4; | ||
const verticalGapPercentage = 0.3; | ||
|
||
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 objHorizontalGap = parseInt(horizontalGapPercentage * objWidth); | ||
const objHeight = collection[0].height; | ||
const objVerticalGap = gap * objHeight; | ||
const objVerticalGap = parseInt(verticalGapPercentage * objHeight); | ||
|
||
const cols = Math.ceil(width / (objWidth + objHorizontalGap)); | ||
const rows = Math.ceil(collection.length / cols); | ||
let cols = (width - objHorizontalGap) / (objWidth + objHorizontalGap); | ||
const decimal = cols % 1; | ||
|
||
const height = rows * (objHeight + objVerticalGap / 2) + objVerticalGap / 2; | ||
const finalHeight = height > window.innerHeight ? height : window.innerHeight; | ||
if (decimal >= 0.5) { | ||
cols = cols + 1; | ||
} | ||
cols = Math.floor(cols); | ||
|
||
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; | ||
const rows = Math.ceil(length / cols); | ||
|
||
collection[i].x = x; | ||
collection[i].y = y; | ||
const height = rows * (objHeight + objVerticalGap) + objVerticalGap; | ||
const finalHeight = height > window.innerHeight ? height : window.innerHeight; | ||
|
||
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