From 80f0fb94e1e25b3b823cfbda5f029cfff909233f Mon Sep 17 00:00:00 2001 From: Alex Walter Date: Tue, 26 Jun 2018 21:48:43 -0700 Subject: [PATCH] add row numbers to the output boxes --- README.md | 6 ++++-- lib/index.js | 1 + lib/row.js | 6 ++++++ test/fixtures/four-squares-400.json | 12 ++++++++---- test/fixtures/four-squares.json | 12 ++++++++---- 5 files changed, 27 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 67671f2..8a5a3d0 100644 --- a/README.md +++ b/README.md @@ -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 }, ... ] diff --git a/lib/index.js b/lib/index.js index e912e09..b2f9f1e 100644 --- a/lib/index.js +++ b/lib/index.js @@ -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, diff --git a/lib/row.js b/lib/row.js index fdff562..e2621f1 100644 --- a/lib/row.js +++ b/lib/row.js @@ -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 @@ -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; @@ -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; diff --git a/test/fixtures/four-squares-400.json b/test/fixtures/four-squares-400.json index ad8ce0a..c07061a 100644 --- a/test/fixtures/four-squares-400.json +++ b/test/fixtures/four-squares-400.json @@ -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 } ] } \ No newline at end of file diff --git a/test/fixtures/four-squares.json b/test/fixtures/four-squares.json index c04d00d..d7c358a 100644 --- a/test/fixtures/four-squares.json +++ b/test/fixtures/four-squares.json @@ -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 } ] } \ No newline at end of file