Skip to content

Commit

Permalink
Use reverse func to calculate cell value
Browse files Browse the repository at this point in the history
  • Loading branch information
David Mesquita-Morris committed May 27, 2022
1 parent 40694aa commit c0a87d2
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion docs/dist/landscape.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions lib/node/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,20 @@ exports.table = table;
* @param onY A flag to indicate that cells should be merged on the y axis.
*/
const merge = (cells, onX, onY) => {
reverse(cells, (iY, row) => reverse(row, iX => onY && iY && mergeCells(cells[iY - 1][iX], 'cols', 'rows', row, iX) || onX && iX && mergeCells(row[iX - 1], 'rows', 'cols', row, iX)));
reverse(cells, (iY, row) => reverse(row, (iX, cell) => onY && iY && mergeCells(cells[iY - 1][iX], cell, 'cols', 'rows', row, iX) || onX && iX && mergeCells(row[iX - 1], cell, 'rows', 'cols', row, iX)));
};
exports.merge = merge;
/**
* Merge two adjacent cells if they are equivalent
* @hidden
*/
const mergeCells = (next, compareKey, mergeKey, row, iX) => {
let result = equals(next, row[iX], compareKey);
if (result) {
next[mergeKey] += row[iX][mergeKey];
const mergeCells = (next, cell, compareKey, mergeKey, row, iX) => {
if (equals(next, cell, compareKey)) {
next[mergeKey] += cell[mergeKey];
row.splice(iX, 1);
return true;
}
return result;
return false;
};
/**
* Transform an array of rows into an array of cells.
Expand Down
2 changes: 1 addition & 1 deletion lib/web/landscape.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@steelbreeze/landscape",
"version": "3.8.7",
"version": "3.8.8",
"description": "Landscape map viewpoint visualisation",
"main": "lib/node/index.js",
"module": "lib/node/index.js",
Expand Down
10 changes: 5 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ export const table = <TRow>(cube: Cube<TRow>, axes: Axes<TRow>, getElement: Call
*/
export const merge = (cells: Array<Array<Cell>>, onX: boolean, onY: boolean): void => {
reverse(cells, (iY, row) =>
reverse(row, iX =>
onY && iY && mergeCells(cells[iY - 1][iX], 'cols', 'rows', row, iX) || onX && iX && mergeCells(row[iX - 1], 'rows', 'cols', row, iX)
reverse(row, (iX, cell) =>
onY && iY && mergeCells(cells[iY - 1][iX], cell, 'cols', 'rows', row, iX) || onX && iX && mergeCells(row[iX - 1], cell, 'rows', 'cols', row, iX)
)
);
}
Expand All @@ -79,9 +79,9 @@ export const merge = (cells: Array<Array<Cell>>, onX: boolean, onY: boolean): vo
* Merge two adjacent cells if they are equivalent
* @hidden
*/
const mergeCells = (next: Cell, compareKey: keyof Layout, mergeKey: keyof Layout, row: Array<Cell>, iX: number): boolean => {
if (equals(next, row[iX], compareKey)) {
next[mergeKey] += row[iX][mergeKey];
const mergeCells = (next: Cell, cell: Cell, compareKey: keyof Layout, mergeKey: keyof Layout, row: Array<Cell>, iX: number): boolean => {
if (equals(next, cell, compareKey)) {
next[mergeKey] += cell[mergeKey];
row.splice(iX, 1);

return true;
Expand Down

0 comments on commit c0a87d2

Please sign in to comment.