Skip to content

Commit

Permalink
Roll all table generation into split function
Browse files Browse the repository at this point in the history
  • Loading branch information
David Mesquita-Morris committed Aug 13, 2021
1 parent f098bf5 commit 9c2948e
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 19 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.

9 changes: 1 addition & 8 deletions lib/node/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,9 @@ function split(cube, xAxis, yAxis, getKey, onX) {
const table = cube[yIndex][xIndex];
const index = Math.floor(table.length * (nyi + nxi) / (xSplit * ySplit));
return cell(table.length ? getKey(table[index]) : { text: '', className: 'empty' });
})], yAxis[yIndex].data.map(pair => cell({ className: `axis y ${pair.key}`, text: pair.value }))))], header(xAxis, yAxis, xSplits)); // NOTE: use the last [] as the header rows to avoud the [...[], ...[]] and same for xy headers
})], yAxis[yIndex].data.map(pair => cell({ className: `axis y ${pair.key}`, text: pair.value }))))], generate(xAxis[0].data.length, row => xAxis.reduce((res, measure, index) => [...res, ...generate(xSplits[index], () => cell({ className: `axis x ${measure.data[row].key}`, text: measure.data[row].value }))], yAxis[0].data.map(() => cell({ className: 'axis xy', text: '' })))));
}
exports.split = split;
/**
* Creates the x axis header (including the x/y header block)
* @hidden
*/
function header(xAxis, yAxis, xSplits) {
return generate(xAxis[0].data.length, row => [...yAxis[0].data.map(() => cell({ className: 'axis xy', text: '' })), ...xAxis.reduce((res, measure, index) => [...res, ...generate(xSplits[index], () => cell({ className: `axis x ${measure.data[row].key}`, text: measure.data[row].value }))], [])]);
}
/**
* Creates a cell within a table
* @hidden
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.

10 changes: 1 addition & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,7 @@ export function split<TRow extends Row>(cube: Cube<TRow>, xAxis: Dimension<TRow>
const table = cube[yIndex][xIndex];
const index = Math.floor(table.length * (nyi + nxi) / (xSplit * ySplit));
return cell(table.length ? getKey(table[index]) : { text: '', className: 'empty' });
})], yAxis[yIndex].data.map(pair => cell({ className: `axis y ${pair.key}`, text: pair.value }))))], header(xAxis, yAxis, xSplits)); // NOTE: use the last [] as the header rows to avoud the [...[], ...[]] and same for xy headers
}

/**
* Creates the x axis header (including the x/y header block)
* @hidden
*/
function header<TRow extends Row>(xAxis: Dimension<TRow>, yAxis: Dimension<TRow>, xSplits: number[]): Cell[][] {
return generate(xAxis[0].data.length, row => [...yAxis[0].data.map(() => cell({ className: 'axis xy', text: '' })), ...xAxis.reduce<Cell[]>((res, measure, index) => [...res, ...generate(xSplits[index], () => cell({ className: `axis x ${measure.data[row].key}`, text: measure.data[row].value }))], [])]);
})], yAxis[yIndex].data.map(pair => cell({ className: `axis y ${pair.key}`, text: pair.value }))))], generate(xAxis[0].data.length, row => xAxis.reduce<Cell[]>((res, measure, index) => [...res, ...generate(xSplits[index], () => cell({ className: `axis x ${measure.data[row].key}`, text: measure.data[row].value }))], yAxis[0].data.map(() => cell({ className: 'axis xy', text: '' })))));
}

/**
Expand Down

0 comments on commit 9c2948e

Please sign in to comment.