@dhis2/analytics 26.12.1 → 26.12.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cjs/visualizations/config/adapters/dhis_highcharts/__tests__/getCumulativeData.spec.js +54 -0
- package/build/cjs/visualizations/config/adapters/dhis_highcharts/getCumulativeData.js +32 -24
- package/build/es/visualizations/config/adapters/dhis_highcharts/__tests__/getCumulativeData.spec.js +51 -0
- package/build/es/visualizations/config/adapters/dhis_highcharts/getCumulativeData.js +32 -24
- package/package.json +1 -1
package/build/cjs/visualizations/config/adapters/dhis_highcharts/__tests__/getCumulativeData.spec.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _visTypes = require("../../../../../modules/visTypes.js");
|
|
4
|
+
var _getCumulativeData = _interopRequireDefault(require("../getCumulativeData.js"));
|
|
5
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
6
|
+
const testData = [{
|
|
7
|
+
data: [1, 1, 1],
|
|
8
|
+
accData: [1, 2, 3]
|
|
9
|
+
}, {
|
|
10
|
+
data: [1.5, 2.5, 3.5],
|
|
11
|
+
accData: [1.5, 4, 7.5]
|
|
12
|
+
}, {
|
|
13
|
+
data: [-1, -1, -1],
|
|
14
|
+
accData: [-1, -2, -3]
|
|
15
|
+
}, {
|
|
16
|
+
data: [null, 1],
|
|
17
|
+
accData: [null, 1]
|
|
18
|
+
}, {
|
|
19
|
+
data: [1, null],
|
|
20
|
+
accData: [1, null]
|
|
21
|
+
}, {
|
|
22
|
+
data: [null, null],
|
|
23
|
+
accData: [null, null]
|
|
24
|
+
}, {
|
|
25
|
+
data: [1, null, 2],
|
|
26
|
+
accData: [1, null, 3]
|
|
27
|
+
}];
|
|
28
|
+
describe('getDefaultCumulativeData', () => {
|
|
29
|
+
const getDefaultSeries = (test, prop) => [{
|
|
30
|
+
data: test[prop]
|
|
31
|
+
}];
|
|
32
|
+
test('series get correct cumulative values', () => {
|
|
33
|
+
testData.forEach(test => {
|
|
34
|
+
expect((0, _getCumulativeData.default)(getDefaultSeries(test, 'data'), {})).toEqual(getDefaultSeries(test, 'accData'));
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
describe('getTwoCategoryCumulativeData', () => {
|
|
39
|
+
const getTwoCategorySeries = (test, prop) => [{
|
|
40
|
+
data: test[prop].map((value, index) => [index, value]),
|
|
41
|
+
custom: {
|
|
42
|
+
data: [test[prop]]
|
|
43
|
+
}
|
|
44
|
+
}];
|
|
45
|
+
const layout = {
|
|
46
|
+
type: _visTypes.VIS_TYPE_COLUMN,
|
|
47
|
+
rows: [{}, {}]
|
|
48
|
+
};
|
|
49
|
+
test('series get correct cumulative values', () => {
|
|
50
|
+
testData.forEach(test => {
|
|
51
|
+
expect((0, _getCumulativeData.default)(getTwoCategorySeries(test, 'data'), layout)).toEqual(getTwoCategorySeries(test, 'accData'));
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
});
|
|
@@ -9,50 +9,58 @@ var _visTypes = require("../../../../modules/visTypes.js");
|
|
|
9
9
|
var _getTwoCategorySplitSerieData = _interopRequireDefault(require("./getTwoCategorySplitSerieData.js"));
|
|
10
10
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
11
|
function getDefaultCumulativeData(series) {
|
|
12
|
-
let decimals
|
|
13
|
-
let
|
|
12
|
+
let decimals;
|
|
13
|
+
let accValue;
|
|
14
|
+
let accData;
|
|
14
15
|
series.forEach(seriesObj => {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
decimals = 0;
|
|
17
|
+
accValue = null;
|
|
18
|
+
accData = seriesObj.data.reduce((accSeriesData, value) => {
|
|
19
|
+
if (value === null) {
|
|
20
|
+
accSeriesData.push(value);
|
|
21
|
+
} else {
|
|
22
|
+
decimals = Math.max(decimals, (0, _numberDecimals.default)(value));
|
|
23
|
+
accValue += value;
|
|
24
|
+
accSeriesData.push(accValue);
|
|
19
25
|
}
|
|
20
|
-
|
|
21
|
-
return accumulator;
|
|
26
|
+
return accSeriesData;
|
|
22
27
|
}, []);
|
|
23
28
|
|
|
24
29
|
// round values to the largest number of decimals found in the serie
|
|
25
30
|
// this is to avoid the floating-point problems in JavaScript
|
|
26
31
|
// the condition in the return statement is because sometimes value can be null
|
|
27
|
-
seriesObj.data =
|
|
28
|
-
return value ? parseFloat(value.toFixed(decimals)) : value;
|
|
29
|
-
});
|
|
30
|
-
decimals = 0;
|
|
32
|
+
seriesObj.data = accData.map(value => value ? parseFloat(value.toFixed(decimals)) : value);
|
|
31
33
|
});
|
|
32
34
|
return series;
|
|
33
35
|
}
|
|
34
36
|
function getTwoCategoryCumulativeData(series) {
|
|
35
|
-
let decimals
|
|
37
|
+
let decimals;
|
|
38
|
+
let accValue;
|
|
39
|
+
let accSeriesData;
|
|
40
|
+
let accSeriesDataByCategory;
|
|
36
41
|
series.filter(seriesObj => !seriesObj.custom.isTwoCategoryFakeSerie).forEach(seriesObj => {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
decimals = 0;
|
|
43
|
+
accSeriesData = [];
|
|
44
|
+
seriesObj.custom.data.forEach(seriesDataByCategory => {
|
|
45
|
+
accValue = null;
|
|
46
|
+
accSeriesDataByCategory = [];
|
|
47
|
+
seriesDataByCategory.forEach(value => {
|
|
48
|
+
if (value === null) {
|
|
49
|
+
accSeriesDataByCategory.push(value);
|
|
50
|
+
} else {
|
|
51
|
+
decimals = Math.max(decimals, (0, _numberDecimals.default)(value));
|
|
52
|
+
accValue += value;
|
|
53
|
+
accSeriesDataByCategory.push(accValue);
|
|
44
54
|
}
|
|
45
|
-
cumulativeGroupValues.push(value);
|
|
46
55
|
});
|
|
47
|
-
|
|
56
|
+
accSeriesData.push(accSeriesDataByCategory);
|
|
48
57
|
});
|
|
49
58
|
|
|
50
59
|
// round values to the largest number of decimals found in the serie
|
|
51
60
|
// this is to avoid the floating-point problems in JavaScript
|
|
52
61
|
// the condition in the return statement is because sometimes value can be null
|
|
53
|
-
seriesObj.custom.data =
|
|
62
|
+
seriesObj.custom.data = accSeriesData.map(seriesDataByCategory => seriesDataByCategory.map(value => value ? parseFloat(value.toFixed(decimals)) : value));
|
|
54
63
|
seriesObj.data = (0, _getTwoCategorySplitSerieData.default)(seriesObj.custom.data);
|
|
55
|
-
decimals = 0;
|
|
56
64
|
});
|
|
57
65
|
return series;
|
|
58
66
|
}
|
package/build/es/visualizations/config/adapters/dhis_highcharts/__tests__/getCumulativeData.spec.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { VIS_TYPE_COLUMN } from '../../../../../modules/visTypes.js';
|
|
2
|
+
import getCumulativeData from '../getCumulativeData.js';
|
|
3
|
+
const testData = [{
|
|
4
|
+
data: [1, 1, 1],
|
|
5
|
+
accData: [1, 2, 3]
|
|
6
|
+
}, {
|
|
7
|
+
data: [1.5, 2.5, 3.5],
|
|
8
|
+
accData: [1.5, 4, 7.5]
|
|
9
|
+
}, {
|
|
10
|
+
data: [-1, -1, -1],
|
|
11
|
+
accData: [-1, -2, -3]
|
|
12
|
+
}, {
|
|
13
|
+
data: [null, 1],
|
|
14
|
+
accData: [null, 1]
|
|
15
|
+
}, {
|
|
16
|
+
data: [1, null],
|
|
17
|
+
accData: [1, null]
|
|
18
|
+
}, {
|
|
19
|
+
data: [null, null],
|
|
20
|
+
accData: [null, null]
|
|
21
|
+
}, {
|
|
22
|
+
data: [1, null, 2],
|
|
23
|
+
accData: [1, null, 3]
|
|
24
|
+
}];
|
|
25
|
+
describe('getDefaultCumulativeData', () => {
|
|
26
|
+
const getDefaultSeries = (test, prop) => [{
|
|
27
|
+
data: test[prop]
|
|
28
|
+
}];
|
|
29
|
+
test('series get correct cumulative values', () => {
|
|
30
|
+
testData.forEach(test => {
|
|
31
|
+
expect(getCumulativeData(getDefaultSeries(test, 'data'), {})).toEqual(getDefaultSeries(test, 'accData'));
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
describe('getTwoCategoryCumulativeData', () => {
|
|
36
|
+
const getTwoCategorySeries = (test, prop) => [{
|
|
37
|
+
data: test[prop].map((value, index) => [index, value]),
|
|
38
|
+
custom: {
|
|
39
|
+
data: [test[prop]]
|
|
40
|
+
}
|
|
41
|
+
}];
|
|
42
|
+
const layout = {
|
|
43
|
+
type: VIS_TYPE_COLUMN,
|
|
44
|
+
rows: [{}, {}]
|
|
45
|
+
};
|
|
46
|
+
test('series get correct cumulative values', () => {
|
|
47
|
+
testData.forEach(test => {
|
|
48
|
+
expect(getCumulativeData(getTwoCategorySeries(test, 'data'), layout)).toEqual(getTwoCategorySeries(test, 'accData'));
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
});
|
|
@@ -2,50 +2,58 @@ import numberDecimals from 'd2-utilizr/lib/numberDecimals';
|
|
|
2
2
|
import { isTwoCategoryChartType } from '../../../../modules/visTypes.js';
|
|
3
3
|
import getTwoCategorySplitSerieData from './getTwoCategorySplitSerieData.js';
|
|
4
4
|
function getDefaultCumulativeData(series) {
|
|
5
|
-
let decimals
|
|
6
|
-
let
|
|
5
|
+
let decimals;
|
|
6
|
+
let accValue;
|
|
7
|
+
let accData;
|
|
7
8
|
series.forEach(seriesObj => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
decimals = 0;
|
|
10
|
+
accValue = null;
|
|
11
|
+
accData = seriesObj.data.reduce((accSeriesData, value) => {
|
|
12
|
+
if (value === null) {
|
|
13
|
+
accSeriesData.push(value);
|
|
14
|
+
} else {
|
|
15
|
+
decimals = Math.max(decimals, numberDecimals(value));
|
|
16
|
+
accValue += value;
|
|
17
|
+
accSeriesData.push(accValue);
|
|
12
18
|
}
|
|
13
|
-
|
|
14
|
-
return accumulator;
|
|
19
|
+
return accSeriesData;
|
|
15
20
|
}, []);
|
|
16
21
|
|
|
17
22
|
// round values to the largest number of decimals found in the serie
|
|
18
23
|
// this is to avoid the floating-point problems in JavaScript
|
|
19
24
|
// the condition in the return statement is because sometimes value can be null
|
|
20
|
-
seriesObj.data =
|
|
21
|
-
return value ? parseFloat(value.toFixed(decimals)) : value;
|
|
22
|
-
});
|
|
23
|
-
decimals = 0;
|
|
25
|
+
seriesObj.data = accData.map(value => value ? parseFloat(value.toFixed(decimals)) : value);
|
|
24
26
|
});
|
|
25
27
|
return series;
|
|
26
28
|
}
|
|
27
29
|
function getTwoCategoryCumulativeData(series) {
|
|
28
|
-
let decimals
|
|
30
|
+
let decimals;
|
|
31
|
+
let accValue;
|
|
32
|
+
let accSeriesData;
|
|
33
|
+
let accSeriesDataByCategory;
|
|
29
34
|
series.filter(seriesObj => !seriesObj.custom.isTwoCategoryFakeSerie).forEach(seriesObj => {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
decimals = 0;
|
|
36
|
+
accSeriesData = [];
|
|
37
|
+
seriesObj.custom.data.forEach(seriesDataByCategory => {
|
|
38
|
+
accValue = null;
|
|
39
|
+
accSeriesDataByCategory = [];
|
|
40
|
+
seriesDataByCategory.forEach(value => {
|
|
41
|
+
if (value === null) {
|
|
42
|
+
accSeriesDataByCategory.push(value);
|
|
43
|
+
} else {
|
|
44
|
+
decimals = Math.max(decimals, numberDecimals(value));
|
|
45
|
+
accValue += value;
|
|
46
|
+
accSeriesDataByCategory.push(accValue);
|
|
37
47
|
}
|
|
38
|
-
cumulativeGroupValues.push(value);
|
|
39
48
|
});
|
|
40
|
-
|
|
49
|
+
accSeriesData.push(accSeriesDataByCategory);
|
|
41
50
|
});
|
|
42
51
|
|
|
43
52
|
// round values to the largest number of decimals found in the serie
|
|
44
53
|
// this is to avoid the floating-point problems in JavaScript
|
|
45
54
|
// the condition in the return statement is because sometimes value can be null
|
|
46
|
-
seriesObj.custom.data =
|
|
55
|
+
seriesObj.custom.data = accSeriesData.map(seriesDataByCategory => seriesDataByCategory.map(value => value ? parseFloat(value.toFixed(decimals)) : value));
|
|
47
56
|
seriesObj.data = getTwoCategorySplitSerieData(seriesObj.custom.data);
|
|
48
|
-
decimals = 0;
|
|
49
57
|
});
|
|
50
58
|
return series;
|
|
51
59
|
}
|