@steelbreeze/landscape
Advanced tools
Comparing version 3.8.2 to 3.8.3
@@ -1,1 +0,1 @@ | ||
var landscape;(()=>{"use strict";var e={};(()=>{var a=e;Object.defineProperty(a,"__esModule",{value:!0}),a.merge=a.table=void 0,a.table=(e,a,s,r,o=Math.max)=>{const p=e.map((e=>e.map((e=>e.length?e.map(((a,l)=>({...s(a,l,e),rows:1,cols:1}))):[t("empty")])))),m=a.x.map(((e,a)=>r?o(...p.map((e=>e[a].length))):1));return l(p,p.map((e=>r?1:o(...e.map((e=>e.length))))),a.x[0].map(((e,s)=>l(a.x,m,a.y[0].map((()=>t("axis xy"))),(e=>t(`axis x ${e[s].key}`,e[s].value))))),((e,s,r,o)=>l(e,m,a.y[o].map((e=>t(`axis y ${e.key}`,e.value))),((e,a,l)=>({...e[Math.floor(e.length*(r+l)/(a*s))]})))))},a.merge=(e,a,l)=>s(e,((t,o)=>s(o,((s,p)=>l&&t&&r(e[t-1][s],"cols","rows",o,s,p)||a&&s&&r(o[s-1],"rows","cols",o,s,p)))));const l=(e,a,l,t)=>{for(let s=e.length,r=0;r<s;++r)for(let s=a[r],o=0;o<s;++o)l.push(t(e[r],s,o,r));return l},t=(e,a="",l="")=>({key:l,value:a,style:e,rows:1,cols:1}),s=(e,a)=>{for(let l=e.length;l--;)a(l,e[l])},r=(e,a,l,t,s,r)=>e.value===r.value&&e.style===r.style&&e[a]===r[a]&&(e[l]+=r[l],t.splice(s,1),!0)})(),landscape=e})(); | ||
var landscape;(()=>{"use strict";var e={};(()=>{var l=e;Object.defineProperty(l,"__esModule",{value:!0}),l.merge=l.table=void 0,l.table=(e,l,a,r,o=Math.max)=>{const p=e.map((e=>e.map((e=>e.length?e.map((e=>({...a(e),rows:1,cols:1}))):[s("empty")])))),m=l.x.map(((e,l)=>r?o(...p.map((e=>e[l].length))):1));return t(p,p.map((e=>r?1:o(...e.map((e=>e.length))))),l.x[0].map(((e,a)=>t(l.x,m,l.y[0].map((()=>s("axis xy"))),(e=>s(`axis x ${e[a].key}`,e[a].value))))),((e,a,r,o)=>t(e,m,l.y[o].map((e=>s(`axis y ${e.key}`,e.value))),((e,l,s)=>({...e[Math.floor(e.length*(r+s)/(l*a))]})))))},l.merge=(e,l,s)=>{let t;r(e,((o,p)=>{r(p,((r,m)=>{s&&o&&a(t=e[o-1][r],m,"cols")?(t.rows+=m.rows,p.splice(r,1)):l&&r&&a(t=p[r-1],m,"rows")&&(t.cols+=m.cols,p.splice(r,1))}))}))};const a=(e,l,a)=>e?.value===l?.value&&e.style===l.style&&e[a]===l[a],s=(e,l="",a="")=>({key:a,value:l,style:e,rows:1,cols:1}),t=(e,l,a,s)=>{for(let t=e.length,r=0;r<t;++r)for(let t=l[r],o=0;o<t;++o)a.push(s(e[r],t,o,r));return a},r=(e,l)=>{for(let a=e.length;a--;)l(a,e[a])}})(),landscape=e})(); |
import { Callback, FunctionVA, Pair } from '@steelbreeze/types'; | ||
import { Axes, Cube } from '@steelbreeze/pivot'; | ||
/** Information required for styling an element when rendering. */ | ||
/** The styling to add to a key value pair when rendering. */ | ||
export interface Style { | ||
/** The class name to use in the final table rendering. */ | ||
style: string; | ||
/** 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. */ | ||
/** Optional alternative 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; | ||
} | ||
/** Layout information catering for merged adjacent cells. */ | ||
/** The layout information used to determine how many rows and columns a cell needs to occupy. */ | ||
export interface Layout { | ||
@@ -17,5 +17,5 @@ /** The number of rows to occupy. */ | ||
} | ||
/** The final text and class name to use when rendering cells in a table. */ | ||
/** An element derived from a row of data. */ | ||
export declare type Element = Pair & Style; | ||
/** An extension of Element, adding the layout information the Cell will occupy in the final table rendering. */ | ||
/** An element ready for rendering as a table cell. */ | ||
export declare type Cell = Element & Layout; | ||
@@ -22,0 +22,0 @@ /** |
@@ -14,3 +14,3 @@ "use strict"; | ||
// transform the cube of rows into a cube of cells | ||
const cells = cube.map(slice => slice.map(table => table.length ? table.map((row, index) => ({ ...getElement(row, index, table), rows: 1, cols: 1 })) : [cell('empty')])); | ||
const cells = cube.map(slice => slice.map(table => table.length ? table.map(row => ({ ...getElement(row), rows: 1, cols: 1 })) : [cell('empty')])); | ||
// calcuate the x splits required (y splits inlined below) | ||
@@ -40,5 +40,29 @@ const xSplits = axes.x.map((_, iX) => onX ? method(...cells.map(row => row[iX].length)) : 1); | ||
*/ | ||
const merge = (cells, onX, onY) => reverse(cells, (iY, row) => reverse(row, (iX, cell) => onY && iY && mergeCells(cells[iY - 1][iX], 'cols', 'rows', row, iX, cell) || onX && iX && mergeCells(row[iX - 1], 'rows', 'cols', row, iX, cell))); | ||
const merge = (cells, onX, onY) => { | ||
let next; | ||
reverse(cells, (iY, row) => { | ||
reverse(row, (iX, cell) => { | ||
if (onY && iY && equals(next = cells[iY - 1][iX], cell, 'cols')) { | ||
next.rows += cell.rows; | ||
row.splice(iX, 1); | ||
} | ||
else if (onX && iX && equals(next = row[iX - 1], cell, 'rows')) { | ||
next.cols += cell.cols; | ||
row.splice(iX, 1); | ||
} | ||
}); | ||
}); | ||
}; | ||
exports.merge = merge; | ||
/** | ||
* Compare two Elements for equality, using value, style and optionally, one other property. | ||
* @hidden | ||
*/ | ||
const equals = (a, b, compareKey) => a?.value === b?.value && a.style === b.style && a[compareKey] === b[compareKey]; | ||
/** | ||
* Creates a cell within a table. | ||
* @hidden | ||
*/ | ||
const cell = (style, value = '', key = '') => ({ key, value, style, rows: 1, cols: 1 }); | ||
/** | ||
* Expands an array using, splitting values into multiple based on a set of corresponding splits then maps the data to a desired structure. | ||
@@ -56,26 +80,9 @@ * @hidden | ||
/** | ||
* Creates a cell within a table. | ||
* Reverse iterate an array | ||
* @hidden | ||
*/ | ||
const cell = (style, value = '', key = '') => ({ key, value, style, rows: 1, cols: 1 }); | ||
/** | ||
* Reverse iterate an array. | ||
* @hidden | ||
*/ | ||
const reverse = (source, callback) => { | ||
for (let i = source.length; i--;) { | ||
callback(i, source[i]); | ||
for (let index = source.length; index--;) { | ||
callback(index, source[index]); | ||
} | ||
}; | ||
/** | ||
* Merge two adjacent cells | ||
* @hidden | ||
*/ | ||
const mergeCells = (next, compareKey, mergeKey, row, iX, cell) => { | ||
if (next.value === cell.value && next.style === cell.style && next[compareKey] === cell[compareKey]) { | ||
next[mergeKey] += cell[mergeKey]; | ||
row.splice(iX, 1); | ||
return true; | ||
} | ||
return false; | ||
}; |
@@ -1,1 +0,1 @@ | ||
var landscape;(()=>{"use strict";var e={};(()=>{var a=e;Object.defineProperty(a,"__esModule",{value:!0}),a.merge=a.table=void 0,a.table=(e,a,s,r,o=Math.max)=>{const p=e.map((e=>e.map((e=>e.length?e.map(((a,l)=>({...s(a,l,e),rows:1,cols:1}))):[t("empty")])))),m=a.x.map(((e,a)=>r?o(...p.map((e=>e[a].length))):1));return l(p,p.map((e=>r?1:o(...e.map((e=>e.length))))),a.x[0].map(((e,s)=>l(a.x,m,a.y[0].map((()=>t("axis xy"))),(e=>t(`axis x ${e[s].key}`,e[s].value))))),((e,s,r,o)=>l(e,m,a.y[o].map((e=>t(`axis y ${e.key}`,e.value))),((e,a,l)=>({...e[Math.floor(e.length*(r+l)/(a*s))]})))))},a.merge=(e,a,l)=>s(e,((t,o)=>s(o,((s,p)=>l&&t&&r(e[t-1][s],"cols","rows",o,s,p)||a&&s&&r(o[s-1],"rows","cols",o,s,p)))));const l=(e,a,l,t)=>{for(let s=e.length,r=0;r<s;++r)for(let s=a[r],o=0;o<s;++o)l.push(t(e[r],s,o,r));return l},t=(e,a="",l="")=>({key:l,value:a,style:e,rows:1,cols:1}),s=(e,a)=>{for(let l=e.length;l--;)a(l,e[l])},r=(e,a,l,t,s,r)=>e.value===r.value&&e.style===r.style&&e[a]===r[a]&&(e[l]+=r[l],t.splice(s,1),!0)})(),landscape=e})(); | ||
var landscape;(()=>{"use strict";var e={};(()=>{var l=e;Object.defineProperty(l,"__esModule",{value:!0}),l.merge=l.table=void 0,l.table=(e,l,a,r,o=Math.max)=>{const p=e.map((e=>e.map((e=>e.length?e.map((e=>({...a(e),rows:1,cols:1}))):[s("empty")])))),m=l.x.map(((e,l)=>r?o(...p.map((e=>e[l].length))):1));return t(p,p.map((e=>r?1:o(...e.map((e=>e.length))))),l.x[0].map(((e,a)=>t(l.x,m,l.y[0].map((()=>s("axis xy"))),(e=>s(`axis x ${e[a].key}`,e[a].value))))),((e,a,r,o)=>t(e,m,l.y[o].map((e=>s(`axis y ${e.key}`,e.value))),((e,l,s)=>({...e[Math.floor(e.length*(r+s)/(l*a))]})))))},l.merge=(e,l,s)=>{let t;r(e,((o,p)=>{r(p,((r,m)=>{s&&o&&a(t=e[o-1][r],m,"cols")?(t.rows+=m.rows,p.splice(r,1)):l&&r&&a(t=p[r-1],m,"rows")&&(t.cols+=m.cols,p.splice(r,1))}))}))};const a=(e,l,a)=>e?.value===l?.value&&e.style===l.style&&e[a]===l[a],s=(e,l="",a="")=>({key:a,value:l,style:e,rows:1,cols:1}),t=(e,l,a,s)=>{for(let t=e.length,r=0;r<t;++r)for(let t=l[r],o=0;o<t;++o)a.push(s(e[r],t,o,r));return a},r=(e,l)=>{for(let a=e.length;a--;)l(a,e[a])}})(),landscape=e})(); |
{ | ||
"name": "@steelbreeze/landscape", | ||
"version": "3.8.2", | ||
"version": "3.8.3", | ||
"description": "Landscape map viewpoint visualisation", | ||
@@ -5,0 +5,0 @@ "main": "lib/node/index.js", |
import { Callback, FunctionVA, Pair } from '@steelbreeze/types'; | ||
import { Axes, Cube } from '@steelbreeze/pivot'; | ||
/** Information required for styling an element when rendering. */ | ||
/** The styling to add to a key value pair when rendering. */ | ||
export interface Style { | ||
@@ -9,7 +9,7 @@ /** The class name to use in the final table rendering. */ | ||
/** 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. */ | ||
/** Optional alternative 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; | ||
} | ||
/** Layout information catering for merged adjacent cells. */ | ||
/** The layout information used to determine how many rows and columns a cell needs to occupy. */ | ||
export interface Layout { | ||
@@ -23,7 +23,7 @@ /** The number of rows to occupy. */ | ||
/** The final text and class name to use when rendering cells in a table. */ | ||
/** An element derived from a row of data. */ | ||
export type Element = Pair & Style; | ||
/** An extension of Element, adding the layout information the Cell will occupy in the final table rendering. */ | ||
export type Cell = Element & Layout; | ||
/** An element ready for rendering as a table cell. */ | ||
export type Cell = Element & Layout | ||
@@ -40,3 +40,3 @@ /** | ||
// transform the cube of rows into a cube of cells | ||
const cells = cube.map(slice => slice.map(table => table.length ? table.map((row, index) => ({ ...getElement(row, index, table), rows: 1, cols: 1 })) : [cell('empty')])); | ||
const cells = cube.map(slice => slice.map(table => table.length ? table.map(row => ({ ...getElement(row), rows: 1, cols: 1 })) : [cell('empty')])); | ||
@@ -73,10 +73,32 @@ // calcuate the x splits required (y splits inlined below) | ||
*/ | ||
export const merge = (cells: Array<Array<Cell>>, onX: boolean, onY: boolean): void => | ||
reverse(cells, (iY, row) => | ||
reverse(row, (iX, cell) => | ||
onY && iY && mergeCells(cells[iY - 1][iX], 'cols', 'rows', row, iX, cell) || onX && iX && mergeCells(row[iX - 1], 'rows', 'cols', row, iX, cell) | ||
) | ||
); | ||
export const merge = (cells: Array<Array<Cell>>, onX: boolean, onY: boolean): void => { | ||
let next: Cell; | ||
reverse(cells, (iY, row) => { | ||
reverse(row, (iX, cell) => { | ||
if (onY && iY && equals(next = cells[iY - 1][iX], cell, 'cols')) { | ||
next.rows += cell.rows; | ||
row.splice(iX, 1); | ||
} else if (onX && iX && equals(next = row[iX - 1], cell, 'rows')) { | ||
next.cols += cell.cols; | ||
row.splice(iX, 1); | ||
} | ||
}); | ||
}); | ||
} | ||
/** | ||
* Compare two Elements for equality, using value, style and optionally, one other property. | ||
* @hidden | ||
*/ | ||
const equals = (a: Cell, b: Cell, compareKey: keyof Layout): boolean => | ||
a?.value === b?.value && a.style === b.style && a[compareKey] === b[compareKey]; | ||
/** | ||
* Creates a cell within a table. | ||
* @hidden | ||
*/ | ||
const cell = (style: string, value: string = '', key = ''): Cell => ({ key, value, style, rows: 1, cols: 1 }); | ||
/** | ||
* Expands an array using, splitting values into multiple based on a set of corresponding splits then maps the data to a desired structure. | ||
@@ -96,30 +118,9 @@ * @hidden | ||
/** | ||
* Creates a cell within a table. | ||
* Reverse iterate an array | ||
* @hidden | ||
*/ | ||
const cell = (style: string, value: string = '', key = ''): Cell => ({ key, value, style, rows: 1, cols: 1 }); | ||
/** | ||
* Reverse iterate an array. | ||
* @hidden | ||
*/ | ||
const reverse = <T>(source: Array<T>, callback: (i: number, value: T) => void): void => { | ||
for (let i = source.length; i--;) { | ||
callback(i, source[i]); | ||
const reverse = <TValue>(source: Array<TValue>, callback: (index: number, value: TValue) => void): void => { | ||
for (let index = source.length; index--;) { | ||
callback(index, source[index]); | ||
} | ||
} | ||
/** | ||
* Merge two adjacent cells | ||
* @hidden | ||
*/ | ||
const mergeCells = (next: Cell, compareKey: keyof Layout, mergeKey: keyof Layout, row: Cell[], iX: number, cell: Cell): boolean => { | ||
if (next.value === cell.value && next.style === cell.style && next[compareKey] === cell[compareKey]) { | ||
next[mergeKey] += cell[mergeKey]; | ||
row.splice(iX, 1); | ||
return true; | ||
} | ||
return false; | ||
} |
384531
3128