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

add row numbers to the output boxes #45

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,16 @@ Into this:
"top": 10,
"width": 170,
"height": 340,
"left": 10
"left": 10,
"row": 0
},
{
"aspectRatio": 1.5,
"top": 10,
"width": 510,
"height": 340,
"left": 190
"left": 190,
"row": 0
},
...
]
Expand Down
1 change: 1 addition & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ function createNewRow(layoutConfig, layoutData) {
}

return new Row({
number: layoutData._rows.length,
top: layoutData._containerHeight,
left: layoutConfig.containerPadding.left,
width: layoutConfig.containerWidth - layoutConfig.containerPadding.left - layoutConfig.containerPadding.right,
Expand Down
6 changes: 6 additions & 0 deletions lib/row.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ var merge = require('merge');
*
* @param {Object} layoutConfig - The same as that passed
* @param {Object} Initialization parameters. The following are all required:
* @param params.number {Number} The index of this row
* @param params.top {Number} Top of row, relative to container
* @param params.left {Number} Left side of row relative to container (equal to container left padding)
* @param params.width {Number} Width of row, not including container padding
Expand All @@ -28,6 +29,9 @@ var merge = require('merge');

var Row = module.exports = function (params) {

// The index of this row
this.number = params.number;

// Top of row, relative to container
this.top = params.top;

Expand Down Expand Up @@ -240,6 +244,8 @@ Row.prototype = {
// item.left = this.width - itemWidthSum - item.width;
item.left = itemWidthSum;

item.row = this.number;

// Increment width.
itemWidthSum += item.width + this.spacing;

Expand Down
12 changes: 8 additions & 4 deletions test/fixtures/four-squares-400.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,32 @@
"top": 10,
"width": 380,
"height": 380,
"left": 10
"left": 10,
"row": 0
},
{
"aspectRatio": 1,
"height": 380,
"left": 10,
"top": 400,
"width": 380
"width": 380,
"row": 1
},
{
"aspectRatio": 1,
"height": 380,
"left": 10,
"top": 790,
"width": 380
"width": 380,
"row": 2
},
{
"aspectRatio": 1,
"top": 1180,
"width": 380,
"height": 380,
"left": 10
"left": 10,
"row": 3
}
]
}
12 changes: 8 additions & 4 deletions test/fixtures/four-squares.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,32 @@
"top": 10,
"width": 340,
"height": 340,
"left": 10
"left": 10,
"row": 0
},
{
"aspectRatio": 1,
"top": 10,
"width": 340,
"height": 340,
"left": 360
"left": 360,
"row": 0
},
{
"aspectRatio": 1,
"top": 10,
"width": 340,
"height": 340,
"left": 710
"left": 710,
"row": 0
},
{
"aspectRatio": 1,
"top": 360,
"width": 340,
"height": 340,
"left": 10
"left": 10,
"row": 1
}
]
}