@steelbreeze/landscape
Advanced tools
Comparing version 3.6.4 to 3.7.0
@@ -1,1 +0,1 @@ | ||
window.searchData = {"kinds":{"64":"Function","256":"Interface","1024":"Property"},"rows":[{"id":0,"kind":64,"name":"setMode","url":"index.html#setmode","classes":"tsd-kind-function"},{"id":1,"kind":64,"name":"table","url":"index.html#table","classes":"tsd-kind-function tsd-has-type-parameter"},{"id":2,"kind":256,"name":"Element","url":"interfaces/element.html","classes":"tsd-kind-interface"},{"id":3,"kind":1024,"name":"style","url":"interfaces/element.html#style","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"Element"},{"id":4,"kind":1024,"name":"text","url":"interfaces/element.html#text","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"Element"},{"id":5,"kind":256,"name":"Cell","url":"interfaces/cell.html","classes":"tsd-kind-interface"},{"id":6,"kind":1024,"name":"rows","url":"interfaces/cell.html#rows","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"Cell"},{"id":7,"kind":1024,"name":"cols","url":"interfaces/cell.html#cols","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"Cell"},{"id":8,"kind":1024,"name":"style","url":"interfaces/cell.html#style","classes":"tsd-kind-property tsd-parent-kind-interface tsd-is-inherited","parent":"Cell"},{"id":9,"kind":1024,"name":"text","url":"interfaces/cell.html#text","classes":"tsd-kind-property tsd-parent-kind-interface tsd-is-inherited","parent":"Cell"},{"id":10,"kind":64,"name":"merge","url":"index.html#merge","classes":"tsd-kind-function"}],"index":{"version":"2.3.9","fields":["name","parent"],"fieldVectors":[["name/0",[0,20.794]],["parent/0",[]],["name/1",[1,20.794]],["parent/1",[]],["name/2",[2,12.321]],["parent/2",[]],["name/3",[3,15.686]],["parent/3",[2,0.919]],["name/4",[4,15.686]],["parent/4",[2,0.919]],["name/5",[5,7.802]],["parent/5",[]],["name/6",[6,20.794]],["parent/6",[5,0.582]],["name/7",[7,20.794]],["parent/7",[5,0.582]],["name/8",[3,15.686]],["parent/8",[5,0.582]],["name/9",[4,15.686]],["parent/9",[5,0.582]],["name/10",[8,20.794]],["parent/10",[]]],"invertedIndex":[["cell",{"_index":5,"name":{"5":{}},"parent":{"6":{},"7":{},"8":{},"9":{}}}],["cols",{"_index":7,"name":{"7":{}},"parent":{}}],["element",{"_index":2,"name":{"2":{}},"parent":{"3":{},"4":{}}}],["merge",{"_index":8,"name":{"10":{}},"parent":{}}],["rows",{"_index":6,"name":{"6":{}},"parent":{}}],["setmode",{"_index":0,"name":{"0":{}},"parent":{}}],["style",{"_index":3,"name":{"3":{},"8":{}},"parent":{}}],["table",{"_index":1,"name":{"1":{}},"parent":{}}],["text",{"_index":4,"name":{"4":{},"9":{}},"parent":{}}]],"pipeline":[]}} | ||
window.searchData = {"kinds":{"64":"Function","256":"Interface","1024":"Property"},"rows":[{"id":0,"kind":256,"name":"Element","url":"interfaces/element.html","classes":"tsd-kind-interface"},{"id":1,"kind":1024,"name":"style","url":"interfaces/element.html#style","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"Element"},{"id":2,"kind":1024,"name":"text","url":"interfaces/element.html#text","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"Element"},{"id":3,"kind":256,"name":"Cell","url":"interfaces/cell.html","classes":"tsd-kind-interface"},{"id":4,"kind":1024,"name":"rows","url":"interfaces/cell.html#rows","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"Cell"},{"id":5,"kind":1024,"name":"cols","url":"interfaces/cell.html#cols","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"Cell"},{"id":6,"kind":1024,"name":"style","url":"interfaces/cell.html#style","classes":"tsd-kind-property tsd-parent-kind-interface tsd-is-inherited","parent":"Cell"},{"id":7,"kind":1024,"name":"text","url":"interfaces/cell.html#text","classes":"tsd-kind-property tsd-parent-kind-interface tsd-is-inherited","parent":"Cell"},{"id":8,"kind":64,"name":"table","url":"index.html#table","classes":"tsd-kind-function tsd-has-type-parameter"},{"id":9,"kind":64,"name":"merge","url":"index.html#merge","classes":"tsd-kind-function"}],"index":{"version":"2.3.9","fields":["name","parent"],"fieldVectors":[["name/0",[0,11.451]],["parent/0",[]],["name/1",[1,14.816]],["parent/1",[0,0.9]],["name/2",[2,14.816]],["parent/2",[0,0.9]],["name/3",[3,6.931]],["parent/3",[]],["name/4",[4,19.924]],["parent/4",[3,0.545]],["name/5",[5,19.924]],["parent/5",[3,0.545]],["name/6",[1,14.816]],["parent/6",[3,0.545]],["name/7",[2,14.816]],["parent/7",[3,0.545]],["name/8",[6,19.924]],["parent/8",[]],["name/9",[7,19.924]],["parent/9",[]]],"invertedIndex":[["cell",{"_index":3,"name":{"3":{}},"parent":{"4":{},"5":{},"6":{},"7":{}}}],["cols",{"_index":5,"name":{"5":{}},"parent":{}}],["element",{"_index":0,"name":{"0":{}},"parent":{"1":{},"2":{}}}],["merge",{"_index":7,"name":{"9":{}},"parent":{}}],["rows",{"_index":4,"name":{"4":{}},"parent":{}}],["style",{"_index":1,"name":{"1":{},"6":{}},"parent":{}}],["table",{"_index":6,"name":{"8":{}},"parent":{}}],["text",{"_index":2,"name":{"2":{},"7":{}},"parent":{}}]],"pipeline":[]}} |
@@ -1,1 +0,1 @@ | ||
var landscape;(()=>{"use strict";var e={};(()=>{var t=e;Object.defineProperty(t,"__esModule",{value:!0}),t.leastCommonMultiple=t.merge=t.table=t.setMode=void 0;let o=Math.max;t.setMode=function(e){o=e},t.table=function(e,t,o,a){return function(e,t,o){const a=t.x.map(((t,l)=>o?s(e,(e=>e[l].length)):1)),n=e.map((e=>o?1:s(e,(e=>e.length))));return l(e,n,((e,o,s,n)=>l(e,a,((e,t,l)=>({...e[Math.floor(e.length*(s+l)/(t*o))]})),t.y[n].map((e=>u(c(`axis y ${e.key}`,e.value)))))),t.x[0].map(((e,o)=>l(t.x,a,(e=>u(c(`axis x ${e[o].key}`,e[o].value))),t.y[0].map((()=>u(c("axis xy"))))))))}(e.map((e=>e.map((e=>e.length?function(e,t){const o=[];for(const s of e){const e=t(s);o.some((t=>r(t,e)))||o.push(u(e))}return o}(e,o):[u(c("empty"))])))),t,a)},t.merge=(e,t,o)=>{let s;a(e,((l,n)=>{a(l,((a,c)=>{o&&n&&(s=e[n-1][c])&&r(s,a)&&s.cols===a.cols?(s.rows+=a.rows,l.splice(c,1)):t&&c&&(s=l[c-1])&&r(s,a)&&s.rows===a.rows&&(s.cols+=a.cols,l.splice(c,1))}))}))};const s=(e,t)=>o(...e.map((e=>t(e)||1)));function l(e,t,o,s){return e.forEach(((e,l)=>{const a=t[l];for(let t=0;t<a;++t)s.push(o(e,a,t,l))})),s}const a=(e,t)=>{for(let o=e.length;o--;)t(e[o],o)};t.leastCommonMultiple=(...e)=>e.reduce(((e,t)=>e*t/n(e,t)));const n=(e,t)=>t?n(t,e%t):e,r=(e,t)=>e.key===t.key&&e.value===t.value&&e.style===t.style,c=(e,t="",o="")=>({key:o,value:t,style:e}),u=e=>({...e,rows:1,cols:1})})(),landscape=e})(); | ||
var landscape;(()=>{"use strict";var e={};(()=>{var s=e;Object.defineProperty(s,"__esModule",{value:!0}),s.merge=s.table=void 0,s.table=(e,s,t,r,c=Math.max)=>a(e.map((e=>e.map((e=>e.length?o(e,t):[l("empty")])))),s,r,c);const a=(e,s,a,o)=>{const r=s.x.map(((s,l)=>a?o(...e.map((e=>e[l].length))):1)),c=e.map((e=>a?1:o(...e.map((e=>e.length)))));return t(e,c,((e,a,o,c)=>t(e,r,((e,s,l)=>({...e[Math.floor(e.length*(o+l)/(s*a))]})),s.y[c].map((e=>l(`axis y ${e.key}`,e.value))))),s.x[0].map(((e,a)=>t(s.x,r,(e=>l(`axis x ${e[a].key}`,e[a].value)),s.y[0].map((()=>l("axis xy")))))))};s.merge=(e,s,a)=>{let l;r(e,((o,t)=>{r(o,((r,p)=>{a&&t&&(l=e[t-1][p])&&c(l,r)&&l.cols===r.cols?(l.rows+=r.rows,o.splice(p,1)):s&&p&&(l=o[p-1])&&c(l,r)&&l.rows===r.rows&&(l.cols+=r.cols,o.splice(p,1))}))}))};const l=(e,s="",a="")=>({key:a,value:s,style:e,rows:1,cols:1}),o=(e,s)=>{const a=[];for(const l of e){const e=s(l);a.some((s=>c(s,e)))||a.push({...e,rows:1,cols:1})}return a},t=(e,s,a,l)=>(e.forEach(((e,o)=>{for(let t=s[o],r=0;r<t;++r)l.push(a(e,t,r,o))})),l),r=(e,s)=>{for(let a=e.length;a--;)s(e[a],a)},c=(e,s)=>e.value===s.value&&e.style===s.style})(),landscape=e})(); |
@@ -1,2 +0,2 @@ | ||
import { Function, Pair } from '@steelbreeze/types'; | ||
import { Function, FunctionVA, Pair } from '@steelbreeze/types'; | ||
import { Axes, Cube } from '@steelbreeze/pivot'; | ||
@@ -7,3 +7,3 @@ /** The final text and class name to use when rendering cells in a table. */ | ||
style: string; | ||
/** Optional text to display in place of Pair.value (which is used to de-dup) */ | ||
/** Optional text to display in place of Pair.value (which is used to de-dup); this should have a single value for any given Pair.value. */ | ||
text?: string; | ||
@@ -18,3 +18,2 @@ } | ||
} | ||
export declare function setMode(value: (...values: Array<number>) => number): void; | ||
/** | ||
@@ -26,5 +25,5 @@ * Generates a table from a cube and it's axis. | ||
* @param onX A flag to indicate if cells in cube containing multiple values should be split on the x axis (if not, the y axis will be used). | ||
* @param precise A flag to control the method that cells are split; set to true to yeild an even number of splits for rows/columns. | ||
* @param method A function used to calculate how many rows or columns to split a row/column into based on the number of entries in each cell of that row/column. Defaults to Math.max, but other methods such as Least Common Multiple can be used for more precise table rendering. | ||
*/ | ||
export declare function table<TRow>(cube: Cube<TRow>, axes: Axes<TRow>, getElement: Function<TRow, Element>, onX: boolean): Array<Array<Cell>>; | ||
export declare const table: <TRow>(cube: Cube<TRow>, axes: Axes<TRow>, getElement: Function<TRow, Element>, onX: boolean, method?: FunctionVA<number, number>) => Array<Array<Cell>>; | ||
/** | ||
@@ -37,6 +36,1 @@ * Merge adjacent cells in a split table on the y and/or x axes. | ||
export declare const merge: (cells: Array<Array<Cell>>, onX: boolean, onY: boolean) => void; | ||
/** | ||
* Returns the least common multiple of a set of integers generated from an object. | ||
* @hidden | ||
*/ | ||
export declare const leastCommonMultiple: (...counts: Array<number>) => number; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.leastCommonMultiple = exports.merge = exports.table = exports.setMode = void 0; | ||
exports.merge = exports.table = void 0; | ||
/** | ||
* The formula used to calculate the number of cells to split a row or column into. | ||
* @hidden | ||
*/ | ||
let mode = Math.max; | ||
function setMode(value) { | ||
mode = value; | ||
} | ||
exports.setMode = setMode; | ||
/** | ||
* Generates a table from a cube and it's axis. | ||
@@ -19,8 +10,7 @@ * @param cube The source cube. | ||
* @param onX A flag to indicate if cells in cube containing multiple values should be split on the x axis (if not, the y axis will be used). | ||
* @param precise A flag to control the method that cells are split; set to true to yeild an even number of splits for rows/columns. | ||
* @param method A function used to calculate how many rows or columns to split a row/column into based on the number of entries in each cell of that row/column. Defaults to Math.max, but other methods such as Least Common Multiple can be used for more precise table rendering. | ||
*/ | ||
function table(cube, axes, getElement, onX) { | ||
// convert the source data to cells and remove resulting duplicates; create the resultant table | ||
return expand(cube.map(row => row.map(table => table.length ? cells(table, getElement) : [cell(element('empty'))])), axes, onX); | ||
} | ||
const table = (cube, axes, getElement, onX, method = Math.max) => | ||
// convert the source data to cells and remove resulting duplicates; create the resultant table | ||
expand(cube.map(row => row.map(table => table.length ? cells(table, getElement) : [cell('empty')])), axes, onX, method); | ||
exports.table = table; | ||
@@ -31,6 +21,6 @@ /** | ||
*/ | ||
function expand(cells, axes, onX) { | ||
const expand = (cells, axes, onX, method) => { | ||
// calcuate the x and y splits required | ||
const xSplits = axes.x.map((_, iX) => onX ? split(cells, row => row[iX].length) : 1); | ||
const ySplits = cells.map(row => onX ? 1 : split(row, table => table.length)); | ||
const xSplits = axes.x.map((_, iX) => onX ? method(...cells.map(row => row[iX].length)) : 1); | ||
const ySplits = cells.map(row => onX ? 1 : method(...row.map(table => table.length))); | ||
// iterate and expand the y axis based on the split data | ||
@@ -43,3 +33,3 @@ return reduce(cells, ySplits, (row, ySplit, ysi, iY) => | ||
// generate the y axis row header cells | ||
axes.y[iY].map(criterion => cell(element(`axis y ${criterion.key}`, criterion.value)))), | ||
axes.y[iY].map(criterion => cell(`axis y ${criterion.key}`, criterion.value))), | ||
// generate the x axis column header rows | ||
@@ -50,6 +40,6 @@ axes.x[0].map((_, iC) => | ||
// generate the x axis cells | ||
cell(element(`axis x ${x[iC].key}`, x[iC].value)), | ||
cell(`axis x ${x[iC].key}`, x[iC].value), | ||
// generate the x/y header | ||
axes.y[0].map(() => cell(element('axis xy')))))); | ||
} | ||
axes.y[0].map(() => cell('axis xy'))))); | ||
}; | ||
/** | ||
@@ -78,6 +68,11 @@ * Merge adjacent cells in a split table on the y and/or x axes. | ||
/** | ||
* Creates a cell within a table. | ||
* @hidden | ||
*/ | ||
const cell = (style, value = '', key = '') => ({ key, value, style, rows: 1, cols: 1 }); | ||
/** | ||
* Convert a table of rows into a table of cells. | ||
* @hidden | ||
*/ | ||
function cells(table, getElement) { | ||
const cells = (table, getElement) => { | ||
const result = []; | ||
@@ -87,20 +82,14 @@ for (const row of table) { | ||
if (!result.some(cell => equals(cell, element))) { | ||
result.push(cell(element)); | ||
result.push({ ...element, rows: 1, cols: 1 }); | ||
} | ||
} | ||
return result; | ||
} | ||
}; | ||
/** | ||
* Calculate the number of splits required for a given cell | ||
* @hidden | ||
*/ | ||
const split = (source, callbackfn) => mode(...source.map(item => callbackfn(item) || 1)); | ||
/** | ||
* Expands an array using, splitting values into multiple based on a set of corresponding splits then maps the data to a desired structure. | ||
* @hidden | ||
*/ | ||
function reduce(values, splits, callbackfn, seed) { | ||
const reduce = (values, splits, callbackfn, seed) => { | ||
values.forEach((value, iValue) => { | ||
const split = splits[iValue]; | ||
for (let iSplit = 0; iSplit < split; ++iSplit) { | ||
for (let split = splits[iValue], iSplit = 0; iSplit < split; ++iSplit) { | ||
seed.push(callbackfn(value, split, iSplit, iValue)); | ||
@@ -110,3 +99,3 @@ } | ||
return seed; | ||
} | ||
}; | ||
/** | ||
@@ -122,26 +111,5 @@ * A reverse for loop | ||
/** | ||
* Returns the least common multiple of a set of integers generated from an object. | ||
* @hidden | ||
*/ | ||
const leastCommonMultiple = (...counts) => counts.reduce((a, b) => (a * b) / greatestCommonFactor(a, b)); | ||
exports.leastCommonMultiple = leastCommonMultiple; | ||
/** | ||
* Returns the greatest common factor of two numbers | ||
* @hidden | ||
*/ | ||
const greatestCommonFactor = (a, b) => b ? greatestCommonFactor(b, a % b) : a; | ||
/** | ||
* Compare two Elements for equality | ||
* @hidden | ||
*/ | ||
const equals = (a, b) => a.key === b.key && a.value === b.value && a.style === b.style; | ||
/** | ||
* Creates a Element. | ||
* @hidden | ||
*/ | ||
const element = (style, value = '', key = '') => ({ key, value, style }); | ||
/** | ||
* Creates a cell within a table. | ||
* @hidden | ||
*/ | ||
const cell = (key) => ({ ...key, rows: 1, cols: 1 }); | ||
const equals = (a, b) => a.value === b.value && a.style === b.style; |
@@ -1,1 +0,1 @@ | ||
var landscape;(()=>{"use strict";var e={};(()=>{var t=e;Object.defineProperty(t,"__esModule",{value:!0}),t.leastCommonMultiple=t.merge=t.table=t.setMode=void 0;let o=Math.max;t.setMode=function(e){o=e},t.table=function(e,t,o,a){return function(e,t,o){const a=t.x.map(((t,l)=>o?s(e,(e=>e[l].length)):1)),n=e.map((e=>o?1:s(e,(e=>e.length))));return l(e,n,((e,o,s,n)=>l(e,a,((e,t,l)=>({...e[Math.floor(e.length*(s+l)/(t*o))]})),t.y[n].map((e=>u(c(`axis y ${e.key}`,e.value)))))),t.x[0].map(((e,o)=>l(t.x,a,(e=>u(c(`axis x ${e[o].key}`,e[o].value))),t.y[0].map((()=>u(c("axis xy"))))))))}(e.map((e=>e.map((e=>e.length?function(e,t){const o=[];for(const s of e){const e=t(s);o.some((t=>r(t,e)))||o.push(u(e))}return o}(e,o):[u(c("empty"))])))),t,a)},t.merge=(e,t,o)=>{let s;a(e,((l,n)=>{a(l,((a,c)=>{o&&n&&(s=e[n-1][c])&&r(s,a)&&s.cols===a.cols?(s.rows+=a.rows,l.splice(c,1)):t&&c&&(s=l[c-1])&&r(s,a)&&s.rows===a.rows&&(s.cols+=a.cols,l.splice(c,1))}))}))};const s=(e,t)=>o(...e.map((e=>t(e)||1)));function l(e,t,o,s){return e.forEach(((e,l)=>{const a=t[l];for(let t=0;t<a;++t)s.push(o(e,a,t,l))})),s}const a=(e,t)=>{for(let o=e.length;o--;)t(e[o],o)};t.leastCommonMultiple=(...e)=>e.reduce(((e,t)=>e*t/n(e,t)));const n=(e,t)=>t?n(t,e%t):e,r=(e,t)=>e.key===t.key&&e.value===t.value&&e.style===t.style,c=(e,t="",o="")=>({key:o,value:t,style:e}),u=e=>({...e,rows:1,cols:1})})(),landscape=e})(); | ||
var landscape;(()=>{"use strict";var e={};(()=>{var s=e;Object.defineProperty(s,"__esModule",{value:!0}),s.merge=s.table=void 0,s.table=(e,s,t,r,c=Math.max)=>a(e.map((e=>e.map((e=>e.length?o(e,t):[l("empty")])))),s,r,c);const a=(e,s,a,o)=>{const r=s.x.map(((s,l)=>a?o(...e.map((e=>e[l].length))):1)),c=e.map((e=>a?1:o(...e.map((e=>e.length)))));return t(e,c,((e,a,o,c)=>t(e,r,((e,s,l)=>({...e[Math.floor(e.length*(o+l)/(s*a))]})),s.y[c].map((e=>l(`axis y ${e.key}`,e.value))))),s.x[0].map(((e,a)=>t(s.x,r,(e=>l(`axis x ${e[a].key}`,e[a].value)),s.y[0].map((()=>l("axis xy")))))))};s.merge=(e,s,a)=>{let l;r(e,((o,t)=>{r(o,((r,p)=>{a&&t&&(l=e[t-1][p])&&c(l,r)&&l.cols===r.cols?(l.rows+=r.rows,o.splice(p,1)):s&&p&&(l=o[p-1])&&c(l,r)&&l.rows===r.rows&&(l.cols+=r.cols,o.splice(p,1))}))}))};const l=(e,s="",a="")=>({key:a,value:s,style:e,rows:1,cols:1}),o=(e,s)=>{const a=[];for(const l of e){const e=s(l);a.some((s=>c(s,e)))||a.push({...e,rows:1,cols:1})}return a},t=(e,s,a,l)=>(e.forEach(((e,o)=>{for(let t=s[o],r=0;r<t;++r)l.push(a(e,t,r,o))})),l),r=(e,s)=>{for(let a=e.length;a--;)s(e[a],a)},c=(e,s)=>e.value===s.value&&e.style===s.style})(),landscape=e})(); |
{ | ||
"name": "@steelbreeze/landscape", | ||
"version": "3.6.4", | ||
"version": "3.7.0", | ||
"description": "Landscape map viewpoint visualisation", | ||
@@ -18,3 +18,3 @@ "main": "lib/node/index.js", | ||
"devDependencies": { | ||
"@steelbreeze/types": "^1.0.0-rc.2", | ||
"@steelbreeze/types": "^1.0.0-rc.5", | ||
"typedoc": "^0.20.36", | ||
@@ -21,0 +21,0 @@ "typescript": "^4.2.4", |
@@ -68,2 +68,2 @@ # landscape | ||
Copyright (c) 2020-21 David Mesquita-Morris. | ||
Copyright (c) 2020-22 David Mesquita-Morris. |
@@ -1,2 +0,2 @@ | ||
import { Function, Pair } from '@steelbreeze/types'; | ||
import { Function, FunctionVA, Pair } from '@steelbreeze/types'; | ||
import { Axes, Cube } from '@steelbreeze/pivot'; | ||
@@ -9,3 +9,3 @@ | ||
/** Optional text to display in place of Pair.value (which is used to de-dup) */ | ||
/** Optional text to display in place of Pair.value (which is used to de-dup); this should have a single value for any given Pair.value. */ | ||
text?: string; | ||
@@ -24,12 +24,2 @@ } | ||
/** | ||
* The formula used to calculate the number of cells to split a row or column into. | ||
* @hidden | ||
*/ | ||
let mode: (...values: Array<number>) => number = Math.max; | ||
export function setMode(value: (...values: Array<number>) => number): void { | ||
mode = value; | ||
} | ||
/** | ||
* Generates a table from a cube and it's axis. | ||
@@ -40,8 +30,7 @@ * @param cube The source cube. | ||
* @param onX A flag to indicate if cells in cube containing multiple values should be split on the x axis (if not, the y axis will be used). | ||
* @param precise A flag to control the method that cells are split; set to true to yeild an even number of splits for rows/columns. | ||
* @param method A function used to calculate how many rows or columns to split a row/column into based on the number of entries in each cell of that row/column. Defaults to Math.max, but other methods such as Least Common Multiple can be used for more precise table rendering. | ||
*/ | ||
export function table<TRow>(cube: Cube<TRow>, axes: Axes<TRow>, getElement: Function<TRow, Element>, onX: boolean): Array<Array<Cell>> { | ||
export const table = <TRow>(cube: Cube<TRow>, axes: Axes<TRow>, getElement: Function<TRow, Element>, onX: boolean, method: FunctionVA<number, number> = Math.max): Array<Array<Cell>> => | ||
// convert the source data to cells and remove resulting duplicates; create the resultant table | ||
return expand(cube.map(row => row.map(table => table.length ? cells(table, getElement) : <Cell[]>[cell(element('empty'))])), axes, onX); | ||
} | ||
expand(cube.map(row => row.map(table => table.length ? cells(table, getElement) : [cell('empty')])), axes, onX, method); | ||
@@ -52,6 +41,6 @@ /** | ||
*/ | ||
function expand<TRow>(cells: Cube<Cell>, axes: Axes<TRow>, onX: boolean): Array<Array<Cell>> { | ||
const expand = <TRow>(cells: Cube<Cell>, axes: Axes<TRow>, onX: boolean, method: FunctionVA<number, number>): Array<Array<Cell>> => { | ||
// calcuate the x and y splits required | ||
const xSplits = axes.x.map((_, iX) => onX ? split(cells, row => row[iX].length) : 1); | ||
const ySplits = cells.map(row => onX ? 1 : split(row, table => table.length)); | ||
const xSplits = axes.x.map((_, iX) => onX ? method(...cells.map(row => row[iX].length)) : 1); | ||
const ySplits = cells.map(row => onX ? 1 : method(...row.map(table => table.length))); | ||
@@ -68,3 +57,3 @@ // iterate and expand the y axis based on the split data | ||
// generate the y axis row header cells | ||
axes.y[iY].map(criterion => cell(element(`axis y ${criterion.key}`, criterion.value)))), | ||
axes.y[iY].map(criterion => cell(`axis y ${criterion.key}`, criterion.value))), | ||
@@ -78,6 +67,6 @@ // generate the x axis column header rows | ||
// generate the x axis cells | ||
cell(element(`axis x ${x[iC].key}`, x[iC].value)), | ||
cell(`axis x ${x[iC].key}`, x[iC].value), | ||
// generate the x/y header | ||
axes.y[0].map(() => cell(element('axis xy')))) | ||
axes.y[0].map(() => cell('axis xy'))) | ||
)); | ||
@@ -97,3 +86,2 @@ } | ||
forEachRev(row, (cell, iX) => { | ||
if (onY && iY && (next = cells[iY - 1][iX]) && equals(next, cell) && next.cols === cell.cols) { | ||
@@ -110,7 +98,14 @@ next.rows += cell.rows; | ||
/** | ||
* Creates a cell within a table. | ||
* @hidden | ||
*/ | ||
const cell = (style: string, value: string = '', key = ''): Cell => ({ key, value, style, rows: 1, cols: 1 }); | ||
/** | ||
* Convert a table of rows into a table of cells. | ||
* @hidden | ||
*/ | ||
function cells<TRow>(table: Array<TRow>, getElement: Function<TRow, Element>): Array<Cell> { | ||
const cells = <TRow>(table: Array<TRow>, getElement: Function<TRow, Element>): Array<Cell> => { | ||
const result: Array<Cell> = []; | ||
@@ -122,3 +117,3 @@ | ||
if (!result.some(cell => equals(cell, element))) { | ||
result.push(cell(element)); | ||
result.push({...element, rows: 1, cols: 1}); | ||
} | ||
@@ -131,16 +126,8 @@ } | ||
/** | ||
* Calculate the number of splits required for a given cell | ||
* @hidden | ||
*/ | ||
const split = <T>(source: Array<T>, callbackfn: Function<T, number>) => mode(...source.map(item => callbackfn(item) || 1)) | ||
/** | ||
* Expands an array using, splitting values into multiple based on a set of corresponding splits then maps the data to a desired structure. | ||
* @hidden | ||
*/ | ||
function reduce<TSource, TResult>(values: TSource[], splits: number[], callbackfn: (value: TSource, split: number, iSplit: number, iValue: number) => TResult, seed: TResult[]): TResult[] { | ||
const reduce = <TSource, TResult>(values: TSource[], splits: number[], callbackfn: (value: TSource, split: number, iSplit: number, iValue: number) => TResult, seed: TResult[]): TResult[] => { | ||
values.forEach((value, iValue) => { | ||
const split = splits[iValue]; | ||
for (let iSplit = 0; iSplit < split; ++iSplit) { | ||
for (let split = splits[iValue], iSplit = 0; iSplit < split; ++iSplit) { | ||
seed.push(callbackfn(value, split, iSplit, iValue)); | ||
@@ -164,29 +151,5 @@ } | ||
/** | ||
* Returns the least common multiple of a set of integers generated from an object. | ||
* @hidden | ||
*/ | ||
export const leastCommonMultiple = (...counts: Array<number>): number => counts.reduce((a, b) => (a * b) / greatestCommonFactor(a, b)); | ||
/** | ||
* Returns the greatest common factor of two numbers | ||
* @hidden | ||
*/ | ||
const greatestCommonFactor = (a: number, b: number): number => b ? greatestCommonFactor(b, a % b) : a; | ||
/** | ||
* Compare two Elements for equality | ||
* @hidden | ||
*/ | ||
const equals = (a: Element, b: Element): boolean => a.key === b.key && a.value === b.value && a.style === b.style; | ||
/** | ||
* Creates a Element. | ||
* @hidden | ||
*/ | ||
const element = (style: string, value: string = '', key = ''): Element => ({ key, value, style }); | ||
/** | ||
* Creates a cell within a table. | ||
* @hidden | ||
*/ | ||
const cell = (key: Element): Cell => ({ ...key, rows: 1, cols: 1 }); | ||
const equals = (a: Element, b: Element): boolean => a.value === b.value && a.style === b.style; |
@@ -6,3 +6,4 @@ const path = require('path'); | ||
landscape: [ './lib/node/index.js' ], | ||
render: ['./lib/node/render.js'] | ||
render: ['./lib/node/render.js'], | ||
math: ['./lib/node/math.js'] | ||
}, | ||
@@ -9,0 +10,0 @@ mode: 'production', |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
47
500913
3748