mirror of
https://github.com/qlik-oss/nebula.js.git
synced 2025-12-19 17:58:43 -05:00
42 lines
854 B
JavaScript
42 lines
854 B
JavaScript
const noop = () => {};
|
|
|
|
function fallback(x, value) {
|
|
if (typeof x === 'undefined') {
|
|
return () => value;
|
|
}
|
|
return () => x;
|
|
}
|
|
|
|
function defFn(def = {}) {
|
|
return {
|
|
min: typeof def.min === 'function' ? def.min : fallback(def.min, 0),
|
|
max: typeof def.max === 'function' ? def.max : fallback(def.max, 1000),
|
|
add: def.add || noop,
|
|
description: def.description || noop,
|
|
move: def.move || noop,
|
|
remove: def.remove || noop,
|
|
replace: def.replace || noop,
|
|
};
|
|
}
|
|
|
|
function target(def) {
|
|
return {
|
|
path: def.path || '/qHyperCubeDef',
|
|
dimensions: defFn(def.dimensions),
|
|
measures: defFn(def.measures),
|
|
};
|
|
}
|
|
|
|
export default function qae(def = {}) {
|
|
const q = {
|
|
properties: {
|
|
...def.properties,
|
|
},
|
|
data: {
|
|
targets: ((def.data || {}).targets || []).map(target),
|
|
},
|
|
};
|
|
|
|
return q;
|
|
}
|