d2-charts-api
Advanced tools
Comparing version 27.0.2 to 27.0.3
@@ -9,6 +9,10 @@ 'use strict'; | ||
exports.default = function (config) { | ||
exports.default = function (config, hideEmptyRowItems) { | ||
var emptySeriesIndexes = getEmptySeriesIndexes(config.series); | ||
return emptySeriesIndexes.length && config.xAxis && config.series ? Object.assign({}, config, getTrimmedXAxisObject(config.xAxis, emptySeriesIndexes), getTrimmedSeriesObject(config.series, emptySeriesIndexes)) : config; | ||
var _getFirstLastValueInd = getFirstLastValueIndexes(config.series), | ||
firstValueIndex = _getFirstLastValueInd.firstValueIndex, | ||
lastValueIndex = _getFirstLastValueInd.lastValueIndex; | ||
return emptySeriesIndexes.length && config.xAxis && config.series ? Object.assign({}, config, getTrimmedXAxisObject(config.xAxis, emptySeriesIndexes, firstValueIndex, lastValueIndex, hideEmptyRowItems), getTrimmedSeriesObject(config.series, emptySeriesIndexes, firstValueIndex, lastValueIndex, hideEmptyRowItems)) : config; | ||
}; | ||
@@ -27,11 +31,5 @@ | ||
function arrayCleanUndefined(array) { | ||
var results = []; | ||
array.forEach(function (item) { | ||
if (item !== undefined) { | ||
results.push(item); | ||
} | ||
return array.filter(function (item) { | ||
return item !== undefined; | ||
}); | ||
return results; | ||
} | ||
@@ -62,8 +60,62 @@ | ||
function getTrimmedXAxisObject(xAxis, emptySeriesIndexes) { | ||
function getFirstLastValueIndexes(series) { | ||
var firstValueIndex = undefined; | ||
var lastValueIndex = 0; | ||
var data = void 0; | ||
var i = void 0; | ||
series.forEach(function (seriesObj) { | ||
// make a copy of the array so we can reverse it | ||
// without affecting the original | ||
data = seriesObj.data.slice(); | ||
i = data.findIndex(function (value) { | ||
return value != undefined; | ||
}); | ||
if (i > -1) { | ||
firstValueIndex = firstValueIndex !== undefined ? Math.min(firstValueIndex, i) : i; | ||
} | ||
i = data.reverse().findIndex(function (value) { | ||
return value != undefined; | ||
}); | ||
if (i > -1) { | ||
lastValueIndex = Math.max(lastValueIndex, data.length - 1 - i); | ||
} | ||
}); | ||
return { firstValueIndex: firstValueIndex, lastValueIndex: lastValueIndex }; | ||
} | ||
function cleanData(data, emptySeriesIndexes, firstValueIndex, lastValueIndex, hideEmptyRowItems) { | ||
var cleanedData = void 0; | ||
switch (hideEmptyRowItems) { | ||
case 'ALL': | ||
cleanedData = arrayCleanUndefined(data.map(function (value, index) { | ||
return (0, _arrayContains2.default)(emptySeriesIndexes, index) ? undefined : value; | ||
})); | ||
break; | ||
case 'BEFORE_FIRST': | ||
cleanedData = data.slice(firstValueIndex); | ||
break; | ||
case 'AFTER_LAST': | ||
cleanedData = data.slice(0, lastValueIndex + 1); | ||
break; | ||
case 'BEFORE_FIRST_AFTER_LAST': | ||
cleanedData = data.slice(firstValueIndex, lastValueIndex + 1); | ||
break; | ||
default: | ||
cleanedData = data; | ||
} | ||
return cleanedData; | ||
} | ||
function getTrimmedXAxisObject(xAxis, emptySeriesIndexes, firstValueIndex, lastValueIndex, hideEmptyRowItems) { | ||
return { | ||
xAxis: _extends({}, xAxis, { | ||
categories: arrayCleanUndefined(xAxis.categories.map(function (category, index) { | ||
return (0, _arrayContains2.default)(emptySeriesIndexes, index) ? undefined : category; | ||
})) | ||
categories: cleanData(xAxis.categories, emptySeriesIndexes, firstValueIndex, lastValueIndex, hideEmptyRowItems) | ||
}) | ||
@@ -73,9 +125,7 @@ }; | ||
function getTrimmedSeriesObject(series, emptySeriesIndexes) { | ||
function getTrimmedSeriesObject(series, emptySeriesIndexes, firstValueIndex, lastValueIndex, hideEmptyRowItems) { | ||
return { | ||
series: series.map(function (seriesObj) { | ||
return _extends({}, seriesObj, { | ||
data: arrayCleanUndefined(seriesObj.data.map(function (value, index) { | ||
return (0, _arrayContains2.default)(emptySeriesIndexes, index) ? undefined : value; | ||
})) | ||
data: cleanData(seriesObj.data, emptySeriesIndexes, firstValueIndex, lastValueIndex, hideEmptyRowItems) | ||
}); | ||
@@ -82,0 +132,0 @@ }) |
@@ -58,4 +58,4 @@ 'use strict'; | ||
// hide empty categories | ||
if (layout.hideEmptyRows) { | ||
config = (0, _getTrimmedConfig2.default)(config); | ||
if (layout.hideEmptyRowItems !== 'NONE') { | ||
config = (0, _getTrimmedConfig2.default)(config, layout.hideEmptyRowItems); | ||
} | ||
@@ -62,0 +62,0 @@ |
@@ -83,3 +83,3 @@ 'use strict'; | ||
// in that case null is returned as value in the serie for highcharts | ||
dataItem.data.push(value === undefined ? null : parseFloat(value)); | ||
dataItem.data.push(value == undefined ? null : parseFloat(value)); | ||
}); | ||
@@ -86,0 +86,0 @@ |
{ | ||
"name": "d2-charts-api", | ||
"version": "27.0.2", | ||
"version": "27.0.3", | ||
"description": "DHIS2 charts api", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -5,11 +5,3 @@ import arrayContains from 'd2-utilizr/lib/arrayContains'; | ||
function arrayCleanUndefined(array) { | ||
var results = []; | ||
array.forEach(item => { | ||
if (item !== undefined) { | ||
results.push(item); | ||
} | ||
}); | ||
return results; | ||
return array.filter(item => item !== undefined); | ||
} | ||
@@ -40,7 +32,57 @@ | ||
function getTrimmedXAxisObject(xAxis, emptySeriesIndexes) { | ||
function getFirstLastValueIndexes(series) { | ||
let firstValueIndex = undefined; | ||
let lastValueIndex = 0; | ||
let data; | ||
let i; | ||
series.forEach(seriesObj => { | ||
// make a copy of the array so we can reverse it | ||
// without affecting the original | ||
data = seriesObj.data.slice(); | ||
i = data.findIndex(value => value != undefined); | ||
if (i > -1) { | ||
firstValueIndex = (firstValueIndex !== undefined) ? Math.min(firstValueIndex, i) : i; | ||
} | ||
i = data.reverse().findIndex(value => value != undefined); | ||
if (i > -1) { | ||
lastValueIndex = Math.max(lastValueIndex, (data.length - 1 - i)); | ||
} | ||
}); | ||
return { firstValueIndex, lastValueIndex }; | ||
} | ||
function cleanData(data, emptySeriesIndexes, firstValueIndex, lastValueIndex, hideEmptyRowItems) { | ||
let cleanedData; | ||
switch (hideEmptyRowItems) { | ||
case 'ALL': | ||
cleanedData = arrayCleanUndefined(data.map((value, index) => arrayContains(emptySeriesIndexes, index) ? undefined : value)); | ||
break; | ||
case 'BEFORE_FIRST': | ||
cleanedData = data.slice(firstValueIndex); | ||
break; | ||
case 'AFTER_LAST': | ||
cleanedData = data.slice(0, lastValueIndex + 1); | ||
break; | ||
case 'BEFORE_FIRST_AFTER_LAST': | ||
cleanedData = data.slice(firstValueIndex, lastValueIndex + 1); | ||
break; | ||
default: | ||
cleanedData = data; | ||
} | ||
return cleanedData; | ||
} | ||
function getTrimmedXAxisObject(xAxis, emptySeriesIndexes, firstValueIndex, lastValueIndex, hideEmptyRowItems) { | ||
return { | ||
xAxis: { | ||
...xAxis, | ||
categories: arrayCleanUndefined(xAxis.categories.map((category, index) => arrayContains(emptySeriesIndexes, index) ? undefined : category)) | ||
categories: cleanData(xAxis.categories, emptySeriesIndexes, firstValueIndex, lastValueIndex, hideEmptyRowItems) | ||
} | ||
@@ -50,7 +92,7 @@ }; | ||
function getTrimmedSeriesObject(series, emptySeriesIndexes) { | ||
function getTrimmedSeriesObject(series, emptySeriesIndexes, firstValueIndex, lastValueIndex, hideEmptyRowItems) { | ||
return { | ||
series: series.map(seriesObj => ({ | ||
...seriesObj, | ||
data: arrayCleanUndefined(seriesObj.data.map((value, index) => arrayContains(emptySeriesIndexes, index) ? undefined : value)) | ||
data: cleanData(seriesObj.data, emptySeriesIndexes, firstValueIndex, lastValueIndex, hideEmptyRowItems) | ||
})) | ||
@@ -60,7 +102,13 @@ }; | ||
export default function (config) { | ||
export default function (config, hideEmptyRowItems) { | ||
const emptySeriesIndexes = getEmptySeriesIndexes(config.series); | ||
const { firstValueIndex, lastValueIndex } = getFirstLastValueIndexes(config.series); | ||
return emptySeriesIndexes.length && config.xAxis && config.series ? | ||
Object.assign({}, config, getTrimmedXAxisObject(config.xAxis, emptySeriesIndexes), getTrimmedSeriesObject(config.series, emptySeriesIndexes)) : config; | ||
} | ||
Object.assign({}, | ||
config, | ||
getTrimmedXAxisObject(config.xAxis, emptySeriesIndexes, firstValueIndex, lastValueIndex, hideEmptyRowItems), | ||
getTrimmedSeriesObject(config.series, emptySeriesIndexes, firstValueIndex, lastValueIndex, hideEmptyRowItems) | ||
) : config; | ||
} |
@@ -63,4 +63,4 @@ import objectClean from 'd2-utilizr/lib/objectClean'; | ||
// hide empty categories | ||
if (layout.hideEmptyRows) { | ||
config = getTrimmedConfig(config); | ||
if (layout.hideEmptyRowItems !== 'NONE') { | ||
config = getTrimmedConfig(config, layout.hideEmptyRowItems); | ||
} | ||
@@ -67,0 +67,0 @@ |
@@ -50,3 +50,3 @@ const VALUE_ID = 'value'; | ||
// in that case null is returned as value in the serie for highcharts | ||
dataItem.data.push((value === undefined) ? null : parseFloat(value)); | ||
dataItem.data.push((value == undefined) ? null : parseFloat(value)); | ||
}); | ||
@@ -53,0 +53,0 @@ |
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
172135
2540