d2-analysis
Advanced tools
Comparing version 31.0.5 to 31.0.6
@@ -593,2 +593,6 @@ 'use strict'; | ||
Response.prototype.getDxIds = function () { | ||
return this.metaData.dimensions.dx; | ||
}; | ||
Response.prototype.getOrganisationUnitsIds = function () { | ||
@@ -623,4 +627,4 @@ return this.metaData.dimensions.ou; | ||
Response.prototype.getItemAggregationType = function (id) { | ||
return this.metaData.items[id].totalAggregationType; | ||
Response.prototype.getTotalAggregationType = function (id) { | ||
return (this.metaData.items[id] || {}).totalAggregationType; | ||
}; | ||
@@ -659,2 +663,10 @@ | ||
Response.prototype.getMultiplierHeader = function () { | ||
return this.getHeaderByName('multiplier'); | ||
}; | ||
Response.prototype.getDivisorHeader = function () { | ||
return this.getHeaderByName('divisor'); | ||
}; | ||
Response.prototype.hasIdByDimensionName = function (id, dimensionName) { | ||
@@ -664,2 +676,12 @@ return (0, _arrayContains2.default)(this.getIdsByDimensionName(dimensionName), id); | ||
Response.prototype.getTotalAggregationTypes = function () { | ||
var _this5 = this; | ||
return [].concat(_toConsumableArray(new Set((this.getDxIds() || []).map(function (id) { | ||
return _this5.getTotalAggregationType(id); | ||
}).filter(function (aggType) { | ||
return typeof aggType === 'string'; | ||
})))); | ||
}; | ||
// dep 2 | ||
@@ -723,3 +745,3 @@ Response.prototype.getValueHeaderIndex = function () { | ||
Response.prototype.getIdMap = function (layout, name) { | ||
var _this5 = this; | ||
var _this6 = this; | ||
@@ -739,5 +761,5 @@ var refs = this.getRefs(), | ||
headerIndexOrder.forEach(function (index) { | ||
header = _this5.getHeaderByIndex(index); | ||
header = _this6.getHeaderByIndex(index); | ||
rowValue = responseRow.getAt(index); | ||
key = header.isPrefix ? _this5.getPrefixedId(rowValue, header.name) : rowValue; | ||
key = header.isPrefix ? _this6.getPrefixedId(rowValue, header.name) : rowValue; | ||
@@ -748,3 +770,3 @@ idCombination.add(key); | ||
responseRow.setIdCombination(idCombination); | ||
idMap[idCombination.get()] = responseRow.getAt(_this5.getHeaderByName(name).getIndex()); | ||
idMap[idCombination.get()] = responseRow.getAt(_this6.getHeaderByName(name).getIndex()); | ||
}); | ||
@@ -756,3 +778,3 @@ | ||
Response.prototype.getAllIdMap = function (layout) { | ||
var _this6 = this; | ||
var _this7 = this; | ||
@@ -772,5 +794,5 @@ var refs = this.getRefs(), | ||
headerIndexOrder.forEach(function (index) { | ||
header = _this6.getHeaderByIndex(index); | ||
header = _this7.getHeaderByIndex(index); | ||
rowValue = responseRow.getAt(index); | ||
key = header.isPrefix ? _this6.getPrefixedId(rowValue, header.name) : rowValue; | ||
key = header.isPrefix ? _this7.getPrefixedId(rowValue, header.name) : rowValue; | ||
@@ -782,6 +804,6 @@ idCombination.add(key); | ||
idMap[idCombination.get()] = { | ||
'value': responseRow.getAt(_this6.getHeaderByName('value').getIndex()), | ||
'denominator': responseRow.getAt(_this6.getHeaderByName('denominator').getIndex()), | ||
'numerator': responseRow.getAt(_this6.getHeaderByName('numerator').getIndex()), | ||
'factor': responseRow.getAt(_this6.getHeaderByName('factor').getIndex()) | ||
'value': responseRow.getAt(_this7.getHeaderByName('value').getIndex()), | ||
'denominator': responseRow.getAt(_this7.getHeaderByName('denominator').getIndex()), | ||
'numerator': responseRow.getAt(_this7.getHeaderByName('numerator').getIndex()), | ||
'factor': responseRow.getAt(_this7.getHeaderByName('factor').getIndex()) | ||
}; | ||
@@ -815,8 +837,8 @@ }); | ||
Response.prototype.getValues = function (paramArray, layout) { | ||
var _this7 = this; | ||
var _this8 = this; | ||
return (0, _arrayFrom2.default)(paramArray).map(function (param) { | ||
return _this7.getValue(param, layout); | ||
return _this8.getValue(param, layout); | ||
}); | ||
}; | ||
//# sourceMappingURL=Response.js.map |
@@ -6,3 +6,3 @@ 'use strict'; | ||
}); | ||
exports.FilterCell = exports.RightPaddingCell = exports.LeftPaddingCell = exports.TopPaddingCell = exports.BottomPaddingCell = exports.PaddingCell = exports.DimensionLabelCell = exports.DimensionEmptyCell = exports.DimensionGrandTotalCell = exports.DimensionSubTotalCell = exports.ColumnAxisCell = exports.RowAxisCell = exports.TotalCell = exports.SubTotalCell = exports.PlainValueCell = exports.ValueCell = exports.TextCell = exports.NumberCell = exports.TableCell = undefined; | ||
exports.FilterCell = exports.RightPaddingCell = exports.LeftPaddingCell = exports.TopPaddingCell = exports.BottomPaddingCell = exports.PaddingCell = exports.DimensionLabelCell = exports.DimensionEmptyCell = exports.DimensionGrandTotalCell = exports.DimensionSubTotalCell = exports.ColumnAxisCell = exports.RowAxisCell = exports.TotalCell = exports.SubTotalCell = exports.PlainValueCell = exports.TextValueCell = exports.ValueCell = exports.TextCell = exports.NumberCell = exports.TableCell = undefined; | ||
@@ -27,2 +27,20 @@ var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
var cellClsMap = _defineProperty({}, _PivotTableConstants.TOTAL_CELL, { | ||
totalAggregationType: _defineProperty({}, _PivotTableConstants.NA_AGGREGATION_TOTAL, 'aggtype-na') | ||
}); | ||
var cellTitleMap = _defineProperty({}, _PivotTableConstants.TOTAL_CELL, { | ||
totalAggregationType: _defineProperty({}, _PivotTableConstants.NA_AGGREGATION_TOTAL, 'Irrelevant total - sum across aggregation types') | ||
}); | ||
var cellDisplayValueMap = _defineProperty({}, _PivotTableConstants.TOTAL_CELL, { | ||
totalAggregationType: _defineProperty({}, _PivotTableConstants.NA_AGGREGATION_TOTAL, '-') | ||
}); | ||
var getFromCellMap = function getFromCellMap(map, type, prop, value) { | ||
return type in map && prop in map[type] && value in map[type][prop] && map[type][prop][value]; | ||
}; | ||
var TableCell = exports.TableCell = function TableCell() { | ||
@@ -58,3 +76,3 @@ var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
} else if (typeof displayValue === 'number') { | ||
_this.displayValue = (0, _PivotTableUtils.getRoundedHtmlValue)(displayValue); | ||
_this.displayValue = (0, _PivotTableUtils.getDefaultNumberDisplayValue)(displayValue, config.skipRounding); | ||
} else { | ||
@@ -106,2 +124,17 @@ _this.displayValue = ' '; | ||
var TextValueCell = exports.TextValueCell = function (_ValueCell) { | ||
_inherits(TextValueCell, _ValueCell); | ||
function TextValueCell(value, displayValue, config) { | ||
_classCallCheck(this, TextValueCell); | ||
var _this4 = _possibleConstructorReturn(this, (TextValueCell.__proto__ || Object.getPrototypeOf(TextValueCell)).call(this, value, displayValue, config)); | ||
_this4.cls += ' align-left cursor-default'; | ||
return _this4; | ||
} | ||
return TextValueCell; | ||
}(ValueCell); | ||
var PlainValueCell = exports.PlainValueCell = function (_NumberCell2) { | ||
@@ -113,7 +146,7 @@ _inherits(PlainValueCell, _NumberCell2); | ||
var _this4 = _possibleConstructorReturn(this, (PlainValueCell.__proto__ || Object.getPrototypeOf(PlainValueCell)).call(this, value, displayValue, config)); | ||
var _this5 = _possibleConstructorReturn(this, (PlainValueCell.__proto__ || Object.getPrototypeOf(PlainValueCell)).call(this, value, displayValue, config)); | ||
_this4.type = _PivotTableConstants.VALUE_CELL; | ||
_this4.cls = 'pivot-value'; | ||
return _this4; | ||
_this5.type = _PivotTableConstants.VALUE_CELL; | ||
_this5.cls = 'pivot-value'; | ||
return _this5; | ||
} | ||
@@ -130,7 +163,7 @@ | ||
var _this5 = _possibleConstructorReturn(this, (SubTotalCell.__proto__ || Object.getPrototypeOf(SubTotalCell)).call(this, value, displayValue, config)); | ||
var _this6 = _possibleConstructorReturn(this, (SubTotalCell.__proto__ || Object.getPrototypeOf(SubTotalCell)).call(this, value, displayValue, config)); | ||
_this5.type = _PivotTableConstants.SUB_TOTAL_CELL; | ||
_this5.cls = 'pivot-value-subtotal'; | ||
return _this5; | ||
_this6.type = _PivotTableConstants.SUB_TOTAL_CELL; | ||
_this6.cls = 'pivot-value-subtotal'; | ||
return _this6; | ||
} | ||
@@ -149,7 +182,17 @@ | ||
var _this6 = _possibleConstructorReturn(this, (TotalCell.__proto__ || Object.getPrototypeOf(TotalCell)).call(this, value, displayValue, config)); | ||
var _this7 = _possibleConstructorReturn(this, (TotalCell.__proto__ || Object.getPrototypeOf(TotalCell)).call(this, value, displayValue, config)); | ||
_this6.type = _PivotTableConstants.TOTAL_CELL; | ||
_this6.cls = 'pivot-value-total-subgrandtotal'; | ||
return _this6; | ||
_this7.type = _PivotTableConstants.TOTAL_CELL; | ||
_this7.cls = 'pivot-value-total-subgrandtotal'; | ||
var aggTypeCls = getFromCellMap(cellClsMap, _this7.type, 'totalAggregationType', config.totalAggregationType); | ||
aggTypeCls && (_this7.cls += ' ' + aggTypeCls); | ||
var aggTypeTitle = getFromCellMap(cellTitleMap, _this7.type, 'totalAggregationType', config.totalAggregationType); | ||
aggTypeTitle && (_this7.title += ' (' + aggTypeTitle + ')'); | ||
var aggTypeDisplayValue = getFromCellMap(cellDisplayValueMap, _this7.type, 'totalAggregationType', config.totalAggregationType); | ||
aggTypeDisplayValue && (_this7.displayValue = aggTypeDisplayValue); | ||
return _this7; | ||
} | ||
@@ -168,13 +211,13 @@ | ||
var _this7 = _possibleConstructorReturn(this, (RowAxisCell.__proto__ || Object.getPrototypeOf(RowAxisCell)).call(this, displayValue, config)); | ||
var _this8 = _possibleConstructorReturn(this, (RowAxisCell.__proto__ || Object.getPrototypeOf(RowAxisCell)).call(this, displayValue, config)); | ||
_this7.type = _PivotTableConstants.DIMENSION_CELL; | ||
_this7.cls = 'pivot-dim pivot-row-dim td-nobreak'; | ||
_this7.axis = 'row'; | ||
_this8.type = _PivotTableConstants.DIMENSION_CELL; | ||
_this8.cls = 'pivot-dim pivot-row-dim td-nobreak'; | ||
_this8.axis = 'row'; | ||
if (_this7.showHierarchy) { | ||
_this7.csl += ' align-left'; | ||
if (_this8.showHierarchy) { | ||
_this8.csl += ' align-left'; | ||
} | ||
return _this7; | ||
return _this8; | ||
} | ||
@@ -191,13 +234,13 @@ | ||
var _this8 = _possibleConstructorReturn(this, (ColumnAxisCell.__proto__ || Object.getPrototypeOf(ColumnAxisCell)).call(this, displayValue, config)); | ||
var _this9 = _possibleConstructorReturn(this, (ColumnAxisCell.__proto__ || Object.getPrototypeOf(ColumnAxisCell)).call(this, displayValue, config)); | ||
_this8.type = _PivotTableConstants.DIMENSION_CELL; | ||
_this8.cls = 'pivot-dim pivot-col-dim'; | ||
_this8.axis = 'column'; | ||
_this9.type = _PivotTableConstants.DIMENSION_CELL; | ||
_this9.cls = 'pivot-dim pivot-col-dim'; | ||
_this9.axis = 'column'; | ||
if (_this8.sort) { | ||
_this8.cls += ' td-sortable'; | ||
if (_this9.sort) { | ||
_this9.cls += ' td-sortable'; | ||
} | ||
return _this8; | ||
return _this9; | ||
} | ||
@@ -214,7 +257,7 @@ | ||
var _this9 = _possibleConstructorReturn(this, (DimensionSubTotalCell.__proto__ || Object.getPrototypeOf(DimensionSubTotalCell)).call(this, displayValue, config)); | ||
var _this10 = _possibleConstructorReturn(this, (DimensionSubTotalCell.__proto__ || Object.getPrototypeOf(DimensionSubTotalCell)).call(this, displayValue, config)); | ||
_this9.type = _PivotTableConstants.DIMENSION_SUB_TOTAL_CELL; | ||
_this9.cls = 'pivot-dim-subtotal'; | ||
return _this9; | ||
_this10.type = _PivotTableConstants.DIMENSION_SUB_TOTAL_CELL; | ||
_this10.cls = 'pivot-dim-subtotal'; | ||
return _this10; | ||
} | ||
@@ -231,16 +274,16 @@ | ||
var _this10 = _possibleConstructorReturn(this, (DimensionGrandTotalCell.__proto__ || Object.getPrototypeOf(DimensionGrandTotalCell)).call(this, value, displayValue, config)); | ||
var _this11 = _possibleConstructorReturn(this, (DimensionGrandTotalCell.__proto__ || Object.getPrototypeOf(DimensionGrandTotalCell)).call(this, value, displayValue, config)); | ||
_this10.type = _PivotTableConstants.DIMENSION_TOTAL_CELL; | ||
_this10.cls = 'pivot-dim-total'; | ||
_this11.type = _PivotTableConstants.DIMENSION_TOTAL_CELL; | ||
_this11.cls = 'pivot-dim-total'; | ||
if (_this10.sort) { | ||
_this10.cls += ' td-sortable'; | ||
if (_this11.sort) { | ||
_this11.cls += ' td-sortable'; | ||
} | ||
if (_this10.generateUuid) { | ||
_this10.uuid = (0, _uuid2.default)(); | ||
if (_this11.generateUuid) { | ||
_this11.uuid = (0, _uuid2.default)(); | ||
} | ||
return _this10; | ||
return _this11; | ||
} | ||
@@ -257,7 +300,7 @@ | ||
var _this11 = _possibleConstructorReturn(this, (DimensionEmptyCell.__proto__ || Object.getPrototypeOf(DimensionEmptyCell)).call(this, ' ', config)); | ||
var _this12 = _possibleConstructorReturn(this, (DimensionEmptyCell.__proto__ || Object.getPrototypeOf(DimensionEmptyCell)).call(this, ' ', config)); | ||
_this11.type = _PivotTableConstants.EMPTY_CELL; | ||
_this11.cls = 'pivot-empty'; | ||
return _this11; | ||
_this12.type = _PivotTableConstants.EMPTY_CELL; | ||
_this12.cls = 'pivot-empty'; | ||
return _this12; | ||
} | ||
@@ -274,8 +317,8 @@ | ||
var _this12 = _possibleConstructorReturn(this, (DimensionLabelCell.__proto__ || Object.getPrototypeOf(DimensionLabelCell)).call(this, displayValue, config)); | ||
var _this13 = _possibleConstructorReturn(this, (DimensionLabelCell.__proto__ || Object.getPrototypeOf(DimensionLabelCell)).call(this, displayValue, config)); | ||
_this12.type = _PivotTableConstants.LABELED_CELL; | ||
_this12.cls = 'pivot-dim-label'; | ||
_this12.axis = 'row'; | ||
return _this12; | ||
_this13.type = _PivotTableConstants.LABELED_CELL; | ||
_this13.cls = 'pivot-dim-label'; | ||
_this13.axis = 'row'; | ||
return _this13; | ||
} | ||
@@ -292,7 +335,7 @@ | ||
var _this13 = _possibleConstructorReturn(this, (PaddingCell.__proto__ || Object.getPrototypeOf(PaddingCell)).call(this, config)); | ||
var _this14 = _possibleConstructorReturn(this, (PaddingCell.__proto__ || Object.getPrototypeOf(PaddingCell)).call(this, config)); | ||
_this13.type = _PivotTableConstants.PADDING_CELL; | ||
_this13.displayValue = ' '; | ||
return _this13; | ||
_this14.type = _PivotTableConstants.PADDING_CELL; | ||
_this14.displayValue = ' '; | ||
return _this14; | ||
} | ||
@@ -309,10 +352,10 @@ | ||
var _this14 = _possibleConstructorReturn(this, (BottomPaddingCell.__proto__ || Object.getPrototypeOf(BottomPaddingCell)).call(this, config)); | ||
var _this15 = _possibleConstructorReturn(this, (BottomPaddingCell.__proto__ || Object.getPrototypeOf(BottomPaddingCell)).call(this, config)); | ||
_this14.cls = 'pivot-padding bottom-padding'; | ||
_this15.cls = 'pivot-padding bottom-padding'; | ||
_this14.hidden = heightInPixels <= 0; | ||
_this14.height = heightInPixels; | ||
return _this14; | ||
_this15.hidden = heightInPixels <= 0; | ||
_this15.height = heightInPixels; | ||
return _this15; | ||
} | ||
@@ -329,10 +372,10 @@ | ||
var _this15 = _possibleConstructorReturn(this, (TopPaddingCell.__proto__ || Object.getPrototypeOf(TopPaddingCell)).call(this, config)); | ||
var _this16 = _possibleConstructorReturn(this, (TopPaddingCell.__proto__ || Object.getPrototypeOf(TopPaddingCell)).call(this, config)); | ||
_this15.cls = 'pivot-padding top-padding'; | ||
_this16.cls = 'pivot-padding top-padding'; | ||
_this15.hidden = heightInPixels <= 0; | ||
_this15.height = heightInPixels; | ||
return _this15; | ||
_this16.hidden = heightInPixels <= 0; | ||
_this16.height = heightInPixels; | ||
return _this16; | ||
} | ||
@@ -349,10 +392,10 @@ | ||
var _this16 = _possibleConstructorReturn(this, (LeftPaddingCell.__proto__ || Object.getPrototypeOf(LeftPaddingCell)).call(this, config)); | ||
var _this17 = _possibleConstructorReturn(this, (LeftPaddingCell.__proto__ || Object.getPrototypeOf(LeftPaddingCell)).call(this, config)); | ||
_this16.cls = 'pivot-padding left-padding'; | ||
_this17.cls = 'pivot-padding left-padding'; | ||
_this16.hidden = widthInPixels <= 0; | ||
_this16.width = widthInPixels; | ||
return _this16; | ||
_this17.hidden = widthInPixels <= 0; | ||
_this17.width = widthInPixels; | ||
return _this17; | ||
} | ||
@@ -369,10 +412,10 @@ | ||
var _this17 = _possibleConstructorReturn(this, (RightPaddingCell.__proto__ || Object.getPrototypeOf(RightPaddingCell)).call(this, config)); | ||
var _this18 = _possibleConstructorReturn(this, (RightPaddingCell.__proto__ || Object.getPrototypeOf(RightPaddingCell)).call(this, config)); | ||
_this17.cls = 'pivot-padding right-padding'; | ||
_this18.cls = 'pivot-padding right-padding'; | ||
_this17.hidden = widthInPixels <= 0; | ||
_this17.width = widthInPixels; | ||
return _this17; | ||
_this18.hidden = widthInPixels <= 0; | ||
_this18.width = widthInPixels; | ||
return _this18; | ||
} | ||
@@ -389,11 +432,11 @@ | ||
var _this18 = _possibleConstructorReturn(this, (FilterCell.__proto__ || Object.getPrototypeOf(FilterCell)).call(this, config)); | ||
var _this19 = _possibleConstructorReturn(this, (FilterCell.__proto__ || Object.getPrototypeOf(FilterCell)).call(this, config)); | ||
_this18.type = _PivotTableConstants.FILTER_CELL; | ||
_this18.cls = 'pivot-filter cursor-default'; | ||
_this19.type = _PivotTableConstants.FILTER_CELL; | ||
_this19.cls = 'pivot-filter cursor-default'; | ||
_this18.displayValue = displayValue; | ||
_this18.colSpan = colSpan; | ||
return _this18; | ||
_this19.displayValue = displayValue; | ||
_this19.colSpan = colSpan; | ||
return _this19; | ||
} | ||
@@ -400,0 +443,0 @@ |
@@ -34,4 +34,9 @@ 'use strict'; | ||
var AVERAGE_AGGREGATION_TOTAL = exports.AVERAGE_AGGREGATION_TOTAL = 'AVERAGE'; | ||
var SUM_AGGREGATION_TOTAL = exports.SUM_AGGREGATION_TOTAL = 'TOTAL'; | ||
var SUM_AGGREGATION_TOTAL = exports.SUM_AGGREGATION_TOTAL = 'SUM'; | ||
var NA_AGGREGATION_TOTAL = exports.NA_AGGREGATION_TOTAL = 'N/A'; | ||
var DEFAULT_NUMBER_DECIMALS = exports.DEFAULT_NUMBER_DECIMALS = 1; | ||
var SMALL_NUMBER_DECIMALS = exports.SMALL_NUMBER_DECIMALS = 2; | ||
var SKIP_ROUNDING_NUMBER_DECIMALS = exports.SKIP_ROUNDING_NUMBER_DECIMALS = 10; | ||
var PIVOT_TABLE_CELLS = exports.PIVOT_TABLE_CELLS = { | ||
@@ -38,0 +43,0 @@ VALUE_CELL: VALUE_CELL, |
@@ -6,3 +6,3 @@ 'use strict'; | ||
}); | ||
exports.assert = exports.defaultProxyGenerator = exports.addMerge = exports.roundIf = exports.getPercentageHtml = exports.getRoundedHtmlValue = exports.getNumberOfDecimals = undefined; | ||
exports.assert = exports.defaultProxyGenerator = exports.addMergeValueObject = exports.addMerge = exports.roundAndStrip = exports.roundIf = exports.getPercentageHtml = exports.getRoundedHtmlValue = exports.getNumberOfDecimals = exports.getDefaultNumberDisplayValue = undefined; | ||
@@ -17,6 +17,16 @@ var _numberToFixed = require('d2-utilizr/lib/numberToFixed'); | ||
var _isNumeric = require('d2-utilizr/lib/isNumeric'); | ||
var _isNumeric2 = _interopRequireDefault(_isNumeric); | ||
var _PivotTableConstants = require('./PivotTableConstants'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var getDefaultNumberDisplayValue = exports.getDefaultNumberDisplayValue = function getDefaultNumberDisplayValue(value, skipRounding) { | ||
return skipRounding ? getRoundedHtmlValue(value, _PivotTableConstants.SKIP_ROUNDING_NUMBER_DECIMALS) : getRoundedHtmlValue(value, value < 1 && value > -1 ? _PivotTableConstants.SMALL_NUMBER_DECIMALS : _PivotTableConstants.DEFAULT_NUMBER_DECIMALS); | ||
}; | ||
/** @description returns the number of decumal of given float | ||
* @param {number} number | ||
* @param {number} number | ||
* @returns {number} | ||
@@ -31,15 +41,15 @@ * @deprecated should switch to use function located in d2-utilizr | ||
/** @description returns the rounded value of the given float. | ||
* @param {number} value | ||
* @param {number} [dec=2] | ||
* @param {number} value | ||
* @param {number} [dec=NUMBER_OF_DECIMALS] | ||
* @returns {number} | ||
*/ | ||
var getRoundedHtmlValue = exports.getRoundedHtmlValue = function getRoundedHtmlValue(value) { | ||
var dec = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 2; | ||
var dec = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _PivotTableConstants.DEFAULT_NUMBER_DECIMALS; | ||
return parseFloat(roundIf(value, 2)).toString(); | ||
return parseFloat(roundAndStrip(value, dec)).toString(); | ||
}; | ||
/** @description get percentage representation of value. | ||
* @param {number} value | ||
* @param {number} total | ||
* @param {number} value | ||
* @param {number} total | ||
* @returns {string} | ||
@@ -52,4 +62,4 @@ */ | ||
/** @description round number if needed. | ||
* @param {number} number | ||
* @param {number} precision | ||
* @param {number} number | ||
* @param {number} precision | ||
* @returns {number} | ||
@@ -69,2 +79,21 @@ */ | ||
/** @description round number if needed. | ||
* @param {number} number | ||
* @param {number} precision | ||
* @returns {number} | ||
*/ | ||
var roundAndStrip = exports.roundAndStrip = function roundAndStrip(number, precision) { | ||
var n = parseFloat(number); | ||
if (!((0, _isNumeric2.default)(number) && (0, _isNumber2.default)(n))) { | ||
return number; | ||
} | ||
if (!(0, _isNumeric2.default)(precision)) { | ||
return n; | ||
} | ||
return n.toFixed(precision); | ||
}; | ||
var addMerge = exports.addMerge = function addMerge(a, b) { | ||
@@ -78,2 +107,15 @@ Object.keys(a).forEach(function (key) { | ||
var addMergeValueObject = exports.addMergeValueObject = function addMergeValueObject(a, b) { | ||
Object.keys(a).forEach(function (key) { | ||
if (Boolean(b[key])) { | ||
if (typeof a[key] === 'number') { | ||
a[key] += b[key]; | ||
return; | ||
} else if (key === 'totalAggregationType') { | ||
a[key] = !a[key] ? b[key] : a[key] !== b[key] ? _PivotTableConstants.NA_AGGREGATION_TOTAL : a[key]; | ||
} | ||
} | ||
}); | ||
}; | ||
var defaultProxyGenerator = exports.defaultProxyGenerator = function defaultProxyGenerator(defaultReturnValue) { | ||
@@ -80,0 +122,0 @@ return new Proxy({}, { get: function get(target, name) { |
{ | ||
"name": "d2-analysis", | ||
"version": "31.0.5", | ||
"version": "31.0.6", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -506,2 +506,6 @@ import arrayClean from 'd2-utilizr/lib/arrayClean'; | ||
Response.prototype.getDxIds = function() { | ||
return this.metaData.dimensions.dx; | ||
}; | ||
Response.prototype.getOrganisationUnitsIds = function() { | ||
@@ -529,4 +533,4 @@ return this.metaData.dimensions.ou; | ||
Response.prototype.getItemAggregationType = function(id) { | ||
return this.metaData.items[id].totalAggregationType; | ||
Response.prototype.getTotalAggregationType = function(id) { | ||
return (this.metaData.items[id] || {}).totalAggregationType; | ||
}; | ||
@@ -560,2 +564,10 @@ | ||
Response.prototype.getMultiplierHeader = function() { | ||
return this.getHeaderByName('multiplier'); | ||
} | ||
Response.prototype.getDivisorHeader = function() { | ||
return this.getHeaderByName('divisor'); | ||
} | ||
Response.prototype.hasIdByDimensionName = function(id, dimensionName) { | ||
@@ -565,2 +577,9 @@ return arrayContains(this.getIdsByDimensionName(dimensionName), id); | ||
Response.prototype.getTotalAggregationTypes = function() { | ||
return [...new Set((this.getDxIds() || []) | ||
.map(id => this.getTotalAggregationType(id)) | ||
.filter(aggType => typeof aggType === 'string')) | ||
]; | ||
}; | ||
// dep 2 | ||
@@ -567,0 +586,0 @@ Response.prototype.getValueHeaderIndex = function() { |
@@ -30,3 +30,3 @@ import isArray from 'd2-utilizr/lib/isArray'; | ||
} | ||
this.spanType = spanTypes[type]; | ||
@@ -60,3 +60,3 @@ this.size = 1; | ||
this.type = type; | ||
let aAccFloorWidth = []; | ||
@@ -92,3 +92,3 @@ | ||
}); | ||
let aaAllFloorObjects = new Array(this.dims); | ||
@@ -153,7 +153,7 @@ | ||
let nSpan = this.dims > 1 ? arraySort(this.span.slice())[1] : this.size; | ||
let aAllFloorObjectsLast = aaAllFloorObjects[aaAllFloorObjects.length - 1]; | ||
for (let positionIndex = 0, leaf, parentUuids, obj, leafUuids = []; positionIndex < aAllFloorObjectsLast.length; positionIndex++) { | ||
leaf = aAllFloorObjectsLast[positionIndex]; | ||
@@ -186,3 +186,3 @@ leafUuids.push(leaf.uuid); | ||
this.dims = this.dims ? this.dims : 1; | ||
this.xItems = { | ||
@@ -248,7 +248,7 @@ unique: aaUniqueFloorIds, | ||
PivotTableAxis.prototype.getAxisLabel = function(positionIndex) { | ||
if (this.dims) { | ||
return this.response.getNameById(this.dimensionNames[positionIndex]); | ||
} | ||
return null; | ||
@@ -258,5 +258,5 @@ } | ||
PivotTableAxis.prototype.getDimensionSpan = function(positionIndex, dimensionIndex) { | ||
return this.span[dimensionIndex] - | ||
return this.span[dimensionIndex] - | ||
this.getNumberOfHiddenPreceding(positionIndex, dimensionIndex) - | ||
this.getNumberOfHiddenProceeding(positionIndex, dimensionIndex) - | ||
this.getNumberOfHiddenProceeding(positionIndex, dimensionIndex) - | ||
this.getDistanceFromLastPositionDimensionUnitActual(positionIndex, dimensionIndex); | ||
@@ -266,3 +266,3 @@ }; | ||
PivotTableAxis.prototype.getNumberOfHiddenPreceding = function(positionIndex, dimensionIndex) { | ||
return this.getDistanceFromLastPositionDimensionUnitOffset(positionIndex, dimensionIndex) - | ||
return this.getDistanceFromLastPositionDimensionUnitOffset(positionIndex, dimensionIndex) - | ||
this.getDistanceFromLastPositionDimensionUnitActual(positionIndex, dimensionIndex); | ||
@@ -274,3 +274,3 @@ }; | ||
let normalized = this.getPositionIndexWithoutTotals(actualPositionIndex); | ||
return normalized % this.span[dimensionIndex]; | ||
@@ -280,6 +280,6 @@ }; | ||
PivotTableAxis.prototype.getDistanceFromLastPositionDimensionUnitActual = function(positionIndex, dimensionIndex) { | ||
let actualPositionIndex = this.getPositionIndexOffsetHidden(positionIndex); | ||
let normalized = this.getPositionIndexWithoutTotals(actualPositionIndex); | ||
return this.normalizePositionIndexOffset(positionIndex) - | ||
@@ -291,3 +291,3 @@ ((this.sumAxisSpanUpToIndex(normalized, dimensionIndex) - | ||
PivotTableAxis.prototype.getNumberOfHiddenProceeding = function(positionIndex, dimensionIndex) { | ||
return this.getDistanceToNextPositionDimensionUnitOffset(positionIndex, dimensionIndex) - | ||
return this.getDistanceToNextPositionDimensionUnitOffset(positionIndex, dimensionIndex) - | ||
this.getDistanceToNextPositionDimensionUnitActual(positionIndex, dimensionIndex); | ||
@@ -297,6 +297,6 @@ }; | ||
PivotTableAxis.prototype.getDistanceToNextPositionDimensionUnitOffset = function(positionIndex, dimensionIndex) { | ||
let actualPositionIndex = this.getPositionIndexOffsetHidden(positionIndex); | ||
let normalized = this.getPositionIndexWithoutTotals(actualPositionIndex); | ||
return this.span[dimensionIndex] - (normalized % this.span[dimensionIndex]); | ||
@@ -306,7 +306,7 @@ }; | ||
PivotTableAxis.prototype.getDistanceToNextPositionDimensionUnitActual = function(positionIndex, dimensionIndex) { | ||
let actualPositionIndex = this.getPositionIndexOffsetHidden(positionIndex); | ||
let normalized = this.getPositionIndexWithoutTotals(actualPositionIndex); | ||
return this.getAxisSpan(normalized, dimensionIndex) - | ||
return this.getAxisSpan(normalized, dimensionIndex) - | ||
(this.normalizePositionIndexOffset(positionIndex) - | ||
@@ -322,3 +322,3 @@ ((this.sumAxisSpanUpToIndex(normalized, dimensionIndex) - | ||
} | ||
return positionIndex; | ||
@@ -328,7 +328,7 @@ }; | ||
PivotTableAxis.prototype.getPositionIndexWithoutTotals = function(positionIndex) { | ||
if (this.doSubTotals) { | ||
return Math.max(0, positionIndex - Math.floor(positionIndex / (this.uniqueFactor + 1))); | ||
return Math.max(0, positionIndex - Math.floor(positionIndex / (this.uniqueFactor + 1))); | ||
} | ||
return positionIndex; | ||
@@ -338,3 +338,3 @@ }; | ||
PivotTableAxis.prototype.normalizePositionIndexOffset = function(positionIndex) { | ||
if (this.doSubTotals) { | ||
@@ -344,3 +344,3 @@ let actualPositionIndex = this.getPositionIndexOffsetHidden(positionIndex); | ||
} | ||
return positionIndex; | ||
@@ -354,7 +354,7 @@ }; | ||
PivotTableAxis.prototype.createRenderMap = function() { | ||
let map = []; | ||
for (let positionIndex = 0; positionIndex < this.actualSize; positionIndex++) { | ||
if (!this.isPositionEmpty(positionIndex) || !this.doHideEmpty) { | ||
@@ -377,9 +377,9 @@ map.push(positionIndex); | ||
PivotTableAxis.prototype.sumAxisSpanUpToIndex = function(positionIndex, dimensionIndex) { | ||
let sum = 0; | ||
for (let i = 0; i < Math.floor(positionIndex / this.span[dimensionIndex]) + 1; i++) { | ||
sum += this.spanMap[dimensionIndex][i]; | ||
} | ||
return sum; | ||
@@ -408,7 +408,7 @@ }; | ||
} | ||
if (this.doTotals) { | ||
size += 1; | ||
size += 1; | ||
} | ||
return size; | ||
@@ -418,9 +418,9 @@ }; | ||
PivotTableAxis.prototype.getUniqueFactor = function() { | ||
if (this.xItems && this.xItems.unique) { | ||
return this.xItems.unique.length < 2 ? | ||
return this.xItems.unique.length < 2 ? | ||
1 : (this.size / this.xItems.unique[0].length); | ||
} | ||
return null; | ||
}; |
@@ -1,2 +0,2 @@ | ||
import { getRoundedHtmlValue } from './PivotTableUtils'; | ||
import { getDefaultNumberDisplayValue } from './PivotTableUtils'; | ||
import uuid from 'd2-utilizr/lib/uuid'; | ||
@@ -13,4 +13,36 @@ | ||
PADDING_CELL, | ||
FILTER_CELL } from '../table/PivotTableConstants'; | ||
FILTER_CELL, | ||
NA_AGGREGATION_TOTAL} from '../table/PivotTableConstants'; | ||
const cellClsMap = { | ||
[TOTAL_CELL]: { | ||
totalAggregationType: { | ||
[NA_AGGREGATION_TOTAL]: 'aggtype-na', | ||
}, | ||
}, | ||
}; | ||
const cellTitleMap = { | ||
[TOTAL_CELL]: { | ||
totalAggregationType: { | ||
[NA_AGGREGATION_TOTAL]: 'Irrelevant total - sum across aggregation types', | ||
}, | ||
}, | ||
}; | ||
const cellDisplayValueMap = { | ||
[TOTAL_CELL]: { | ||
totalAggregationType: { | ||
[NA_AGGREGATION_TOTAL]: '-', | ||
} | ||
} | ||
} | ||
const getFromCellMap = function(map, type, prop, value) { | ||
return (type in map) && | ||
(prop in map[type]) && | ||
(value in map[type][prop]) && | ||
map[type][prop][value]; | ||
}; | ||
export class TableCell { | ||
@@ -26,3 +58,3 @@ | ||
style = ''; | ||
constructor(config={}) { | ||
@@ -42,7 +74,5 @@ Object.assign(this, config); | ||
} | ||
else if (typeof displayValue === 'number') { | ||
this.displayValue = getRoundedHtmlValue(displayValue); | ||
this.displayValue = getDefaultNumberDisplayValue(displayValue, config.skipRounding); | ||
} | ||
else { | ||
@@ -60,3 +90,3 @@ this.displayValue = ' '; | ||
this.displayValue = typeof displayValue !== 'string' && typeof displayValue !== 'number' ? | ||
this.displayValue = typeof displayValue !== 'string' && typeof displayValue !== 'number' ? | ||
' ' : displayValue; | ||
@@ -71,3 +101,3 @@ this.title = this.displayValue; | ||
cls = 'pivot-value'; | ||
constructor(value, displayValue, config) { | ||
@@ -80,2 +110,11 @@ super(value, displayValue, config); | ||
export class TextValueCell extends ValueCell { | ||
constructor(value, displayValue, config) { | ||
super(value, displayValue, config); | ||
this.cls += ' align-left cursor-default'; | ||
} | ||
} | ||
export class PlainValueCell extends NumberCell { | ||
@@ -85,3 +124,3 @@ | ||
cls = 'pivot-value'; | ||
constructor(value, displayValue, config) { | ||
@@ -93,3 +132,3 @@ super(value, displayValue, config); | ||
export class SubTotalCell extends NumberCell { | ||
type = SUB_TOTAL_CELL; | ||
@@ -104,3 +143,3 @@ cls = 'pivot-value-subtotal'; | ||
export class TotalCell extends NumberCell { | ||
type = TOTAL_CELL; | ||
@@ -111,2 +150,11 @@ cls = 'pivot-value-total-subgrandtotal'; | ||
super(value, displayValue, config); | ||
const aggTypeCls = getFromCellMap(cellClsMap, this.type, 'totalAggregationType', config.totalAggregationType); | ||
aggTypeCls && (this.cls += (' ' + aggTypeCls)); | ||
const aggTypeTitle = getFromCellMap(cellTitleMap, this.type, 'totalAggregationType', config.totalAggregationType); | ||
aggTypeTitle && (this.title += (' (' + aggTypeTitle + ')')); | ||
const aggTypeDisplayValue = getFromCellMap(cellDisplayValueMap, this.type, 'totalAggregationType', config.totalAggregationType); | ||
aggTypeDisplayValue && (this.displayValue = aggTypeDisplayValue); | ||
} | ||
@@ -207,3 +255,3 @@ }; | ||
cls = 'pivot-padding bottom-padding'; | ||
constructor(heightInPixels, config) { | ||
@@ -210,0 +258,0 @@ super(config); |
@@ -29,4 +29,9 @@ export const VALUE_CELL = 'value'; | ||
export const AVERAGE_AGGREGATION_TOTAL = 'AVERAGE'; | ||
export const SUM_AGGREGATION_TOTAL = 'TOTAL'; | ||
export const SUM_AGGREGATION_TOTAL = 'SUM'; | ||
export const NA_AGGREGATION_TOTAL = 'N/A'; | ||
export const DEFAULT_NUMBER_DECIMALS = 1; | ||
export const SMALL_NUMBER_DECIMALS = 2; | ||
export const SKIP_ROUNDING_NUMBER_DECIMALS = 10; | ||
export const PIVOT_TABLE_CELLS = { | ||
@@ -33,0 +38,0 @@ VALUE_CELL, |
import numberToFixed from 'd2-utilizr/lib/numberToFixed'; | ||
import isNumber from 'd2-utilizr/lib/isNumber'; | ||
import isNumeric from 'd2-utilizr/lib/isNumeric'; | ||
import { NA_AGGREGATION_TOTAL, DEFAULT_NUMBER_DECIMALS, SKIP_ROUNDING_NUMBER_DECIMALS, SMALL_NUMBER_DECIMALS } from './PivotTableConstants'; | ||
export const getDefaultNumberDisplayValue = (value, skipRounding) => | ||
skipRounding ? | ||
getRoundedHtmlValue(value, SKIP_ROUNDING_NUMBER_DECIMALS) : | ||
getRoundedHtmlValue(value, value < 1 && value > -1 ? SMALL_NUMBER_DECIMALS : DEFAULT_NUMBER_DECIMALS); | ||
/** @description returns the number of decumal of given float | ||
* @param {number} number | ||
* @param {number} number | ||
* @returns {number} | ||
@@ -15,13 +22,13 @@ * @deprecated should switch to use function located in d2-utilizr | ||
/** @description returns the rounded value of the given float. | ||
* @param {number} value | ||
* @param {number} [dec=2] | ||
* @param {number} value | ||
* @param {number} [dec=NUMBER_OF_DECIMALS] | ||
* @returns {number} | ||
*/ | ||
export const getRoundedHtmlValue = (value, dec=2) => { | ||
return parseFloat(roundIf(value, 2)).toString(); | ||
export const getRoundedHtmlValue = (value, dec = DEFAULT_NUMBER_DECIMALS) => { | ||
return parseFloat(roundAndStrip(value, dec)).toString(); | ||
}; | ||
/** @description get percentage representation of value. | ||
* @param {number} value | ||
* @param {number} total | ||
* @param {number} value | ||
* @param {number} total | ||
* @returns {string} | ||
@@ -34,4 +41,4 @@ */ | ||
/** @description round number if needed. | ||
* @param {number} number | ||
* @param {number} precision | ||
* @param {number} number | ||
* @param {number} precision | ||
* @returns {number} | ||
@@ -51,2 +58,21 @@ */ | ||
/** @description round number if needed. | ||
* @param {number} number | ||
* @param {number} precision | ||
* @returns {number} | ||
*/ | ||
export const roundAndStrip = (number, precision) => { | ||
var n = parseFloat(number); | ||
if (!(isNumeric(number) && isNumber(n))) { | ||
return number; | ||
} | ||
if (!isNumeric(precision)) { | ||
return n; | ||
} | ||
return n.toFixed(precision); | ||
}; | ||
export const addMerge = (a, b) => { | ||
@@ -60,5 +86,19 @@ Object.keys(a).forEach(key => { | ||
export const addMergeValueObject = (a, b) => { | ||
Object.keys(a).forEach(key => { | ||
if (Boolean(b[key])) { | ||
if (typeof a[key] === 'number') { | ||
a[key] += b[key]; | ||
return; | ||
} | ||
else if (key === 'totalAggregationType') { | ||
a[key] = !a[key] ? b[key] : (a[key] !== b[key]) ? NA_AGGREGATION_TOTAL : a[key]; | ||
} | ||
} | ||
}); | ||
}; | ||
export const defaultProxyGenerator = defaultReturnValue => { | ||
return new Proxy( | ||
{}, | ||
{}, | ||
{ get: (target, name) => name in target ? target[name] : defaultReturnValue } | ||
@@ -65,0 +105,0 @@ ); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
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
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
4002173
53993