@dhis2/analytics 21.8.2 → 21.9.1
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/CHANGELOG.md +14 -0
- package/build/cjs/components/PeriodDimension/PeriodDimension.js +32 -1
- package/build/cjs/components/PeriodDimension/PeriodTransfer.js +20 -6
- package/build/cjs/components/PeriodDimension/__tests__/PeriodDimension.spec.js +13 -0
- package/build/cjs/components/PeriodDimension/__tests__/__snapshots__/PeriodDimension.spec.js.snap +6 -0
- package/build/cjs/components/PeriodDimension/utils/fixedPeriods.js +206 -478
- package/build/cjs/locales/en/translations.json +0 -14
- package/build/cjs/modules/pivotTable/PivotTableEngine.js +9 -28
- package/build/cjs/modules/pivotTable/__tests__/addToTotalIfNumber.js +72 -0
- package/build/cjs/modules/pivotTable/addToTotalIfNumber.js +10 -0
- package/build/es/components/PeriodDimension/PeriodDimension.js +30 -1
- package/build/es/components/PeriodDimension/PeriodTransfer.js +19 -6
- package/build/es/components/PeriodDimension/__tests__/PeriodDimension.spec.js +13 -0
- package/build/es/components/PeriodDimension/__tests__/__snapshots__/PeriodDimension.spec.js.snap +6 -0
- package/build/es/components/PeriodDimension/utils/fixedPeriods.js +204 -477
- package/build/es/locales/en/translations.json +0 -14
- package/build/es/modules/pivotTable/PivotTableEngine.js +8 -28
- package/build/es/modules/pivotTable/__tests__/addToTotalIfNumber.js +69 -0
- package/build/es/modules/pivotTable/addToTotalIfNumber.js +1 -0
- package/package.json +2 -1
|
@@ -147,20 +147,6 @@
|
|
|
147
147
|
"Fixed periods": "Fixed periods",
|
|
148
148
|
"Selected Periods": "Selected Periods",
|
|
149
149
|
"No periods selected": "No periods selected",
|
|
150
|
-
"January": "January",
|
|
151
|
-
"February": "February",
|
|
152
|
-
"March": "March",
|
|
153
|
-
"April": "April",
|
|
154
|
-
"May": "May",
|
|
155
|
-
"June": "June",
|
|
156
|
-
"July": "July",
|
|
157
|
-
"August": "August",
|
|
158
|
-
"September": "September",
|
|
159
|
-
"October": "October",
|
|
160
|
-
"November": "November",
|
|
161
|
-
"December": "December",
|
|
162
|
-
"Week {{weekNumber}}": "Week {{weekNumber}}",
|
|
163
|
-
"Bi-Week {{biWeekNumber}}": "Bi-Week {{biWeekNumber}}",
|
|
164
150
|
"Daily": "Daily",
|
|
165
151
|
"Weekly": "Weekly",
|
|
166
152
|
"Weekly (Start Wednesday)": "Weekly (Start Wednesday)",
|
|
@@ -3,6 +3,7 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
|
3
3
|
import times from 'lodash/times';
|
|
4
4
|
import { DIMENSION_ID_ORGUNIT } from '../predefinedDimensions.js';
|
|
5
5
|
import { AdaptiveClippingController } from './AdaptiveClippingController.js';
|
|
6
|
+
import { addToTotalIfNumber } from './addToTotalIfNumber.js';
|
|
6
7
|
import { parseValue } from './parseValue.js';
|
|
7
8
|
import { AGGREGATE_TYPE_NA, AGGREGATE_TYPE_AVERAGE, AGGREGATE_TYPE_SUM, CELL_TYPE_VALUE, CELL_TYPE_TOTAL, CELL_TYPE_SUBTOTAL, SORT_ORDER_ASCENDING, SORT_ORDER_DESCENDING, DISPLAY_DENSITY_PADDING_COMPACT, DISPLAY_DENSITY_PADDING_COMFORTABLE, DISPLAY_DENSITY_OPTION_COMFORTABLE, DISPLAY_DENSITY_OPTION_COMPACT, DISPLAY_DENSITY_OPTION_NORMAL, DISPLAY_DENSITY_PADDING_NORMAL, FONT_SIZE_OPTION_SMALL, FONT_SIZE_SMALL, FONT_SIZE_OPTION_LARGE, FONT_SIZE_LARGE, FONT_SIZE_OPTION_NORMAL, FONT_SIZE_NORMAL, VALUE_TYPE_NUMBER, NUMBER_TYPE_COLUMN_PERCENTAGE, NUMBER_TYPE_ROW_PERCENTAGE, DIMENSION_TYPE_DATA, DIMENSION_TYPE_DATA_ELEMENT_GROUP_SET, DIMENSION_TYPE_ORGUNIT, DIMENSION_TYPE_PERIOD, VALUE_TYPE_TEXT, NUMBER_TYPE_VALUE } from './pivotTableConstants.js';
|
|
8
9
|
import { renderValue } from './renderValue.js';
|
|
@@ -596,10 +597,7 @@ export class PivotTableEngine {
|
|
|
596
597
|
dataFields.forEach(field => {
|
|
597
598
|
const headerIndex = this.dimensionLookup.dataHeaders[field];
|
|
598
599
|
const value = parseValue(dataRow[headerIndex]);
|
|
599
|
-
|
|
600
|
-
if (value && !isNaN(value)) {
|
|
601
|
-
totalCell[field] = (totalCell[field] || 0) + value;
|
|
602
|
-
}
|
|
600
|
+
totalCell[field] = addToTotalIfNumber(value, totalCell[field]);
|
|
603
601
|
});
|
|
604
602
|
}
|
|
605
603
|
|
|
@@ -618,10 +616,7 @@ export class PivotTableEngine {
|
|
|
618
616
|
dataFields.forEach(field => {
|
|
619
617
|
const headerIndex = this.dimensionLookup.dataHeaders[field];
|
|
620
618
|
const value = parseValue(dataRow[headerIndex]);
|
|
621
|
-
|
|
622
|
-
if (value && !isNaN(value)) {
|
|
623
|
-
percentageTotal[field] = (percentageTotal[field] || 0) + value;
|
|
624
|
-
}
|
|
619
|
+
percentageTotal[field] = addToTotalIfNumber(value, percentageTotal[field]);
|
|
625
620
|
});
|
|
626
621
|
|
|
627
622
|
if (totals.columnSubtotal) {
|
|
@@ -636,10 +631,7 @@ export class PivotTableEngine {
|
|
|
636
631
|
dataFields.forEach(field => {
|
|
637
632
|
const headerIndex = this.dimensionLookup.dataHeaders[field];
|
|
638
633
|
const value = parseValue(dataRow[headerIndex]);
|
|
639
|
-
|
|
640
|
-
if (value && !isNaN(value)) {
|
|
641
|
-
percentageTotal[field] = (percentageTotal[field] || 0) + value;
|
|
642
|
-
}
|
|
634
|
+
percentageTotal[field] = addToTotalIfNumber(value, percentageTotal[field]);
|
|
643
635
|
});
|
|
644
636
|
}
|
|
645
637
|
|
|
@@ -655,10 +647,7 @@ export class PivotTableEngine {
|
|
|
655
647
|
dataFields.forEach(field => {
|
|
656
648
|
const headerIndex = this.dimensionLookup.dataHeaders[field];
|
|
657
649
|
const value = parseValue(dataRow[headerIndex]);
|
|
658
|
-
|
|
659
|
-
if (value && !isNaN(value)) {
|
|
660
|
-
percentageTotal[field] = (percentageTotal[field] || 0) + value;
|
|
661
|
-
}
|
|
650
|
+
percentageTotal[field] = addToTotalIfNumber(value, percentageTotal[field]);
|
|
662
651
|
});
|
|
663
652
|
}
|
|
664
653
|
}
|
|
@@ -675,10 +664,7 @@ export class PivotTableEngine {
|
|
|
675
664
|
dataFields.forEach(field => {
|
|
676
665
|
const headerIndex = this.dimensionLookup.dataHeaders[field];
|
|
677
666
|
const value = parseValue(dataRow[headerIndex]);
|
|
678
|
-
|
|
679
|
-
if (value && !isNaN(value)) {
|
|
680
|
-
percentageTotal[field] = (percentageTotal[field] || 0) + value;
|
|
681
|
-
}
|
|
667
|
+
percentageTotal[field] = addToTotalIfNumber(value, percentageTotal[field]);
|
|
682
668
|
});
|
|
683
669
|
|
|
684
670
|
if (totals.rowSubtotal) {
|
|
@@ -693,10 +679,7 @@ export class PivotTableEngine {
|
|
|
693
679
|
dataFields.forEach(field => {
|
|
694
680
|
const headerIndex = this.dimensionLookup.dataHeaders[field];
|
|
695
681
|
const value = parseValue(dataRow[headerIndex]);
|
|
696
|
-
|
|
697
|
-
if (value && !isNaN(value)) {
|
|
698
|
-
percentageTotal[field] = (percentageTotal[field] || 0) + value;
|
|
699
|
-
}
|
|
682
|
+
percentageTotal[field] = addToTotalIfNumber(value, percentageTotal[field]);
|
|
700
683
|
});
|
|
701
684
|
}
|
|
702
685
|
|
|
@@ -712,10 +695,7 @@ export class PivotTableEngine {
|
|
|
712
695
|
dataFields.forEach(field => {
|
|
713
696
|
const headerIndex = this.dimensionLookup.dataHeaders[field];
|
|
714
697
|
const value = parseValue(dataRow[headerIndex]);
|
|
715
|
-
|
|
716
|
-
if (value && !isNaN(value)) {
|
|
717
|
-
percentageTotal[field] = (percentageTotal[field] || 0) + value;
|
|
718
|
-
}
|
|
698
|
+
percentageTotal[field] = addToTotalIfNumber(value, percentageTotal[field]);
|
|
719
699
|
});
|
|
720
700
|
}
|
|
721
701
|
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { addToTotalIfNumber } from '../addToTotalIfNumber.js';
|
|
2
|
+
const tests = [{
|
|
3
|
+
testName: 'negative value',
|
|
4
|
+
value: -1,
|
|
5
|
+
total: undefined,
|
|
6
|
+
expected: -1
|
|
7
|
+
}, {
|
|
8
|
+
testName: 'zero value',
|
|
9
|
+
value: 0,
|
|
10
|
+
total: undefined,
|
|
11
|
+
expected: 0
|
|
12
|
+
}, {
|
|
13
|
+
testName: 'positive value',
|
|
14
|
+
value: 1,
|
|
15
|
+
total: undefined,
|
|
16
|
+
expected: 1
|
|
17
|
+
}, {
|
|
18
|
+
testName: 'null value',
|
|
19
|
+
value: null,
|
|
20
|
+
total: undefined,
|
|
21
|
+
expected: undefined
|
|
22
|
+
}, {
|
|
23
|
+
testName: 'undefined value',
|
|
24
|
+
value: undefined,
|
|
25
|
+
total: undefined,
|
|
26
|
+
expected: undefined
|
|
27
|
+
}, {
|
|
28
|
+
testName: 'string value',
|
|
29
|
+
value: 'string',
|
|
30
|
+
total: undefined,
|
|
31
|
+
expected: undefined
|
|
32
|
+
}, {
|
|
33
|
+
testName: 'negative value with existing total',
|
|
34
|
+
value: -1,
|
|
35
|
+
total: 100,
|
|
36
|
+
expected: 99
|
|
37
|
+
}, {
|
|
38
|
+
testName: 'zero value with existing total',
|
|
39
|
+
value: 0,
|
|
40
|
+
total: 100,
|
|
41
|
+
expected: 100
|
|
42
|
+
}, {
|
|
43
|
+
testName: 'positive value with existing total',
|
|
44
|
+
value: 1,
|
|
45
|
+
total: 100,
|
|
46
|
+
expected: 101
|
|
47
|
+
}, {
|
|
48
|
+
testName: 'null value with existing total',
|
|
49
|
+
value: null,
|
|
50
|
+
total: 100,
|
|
51
|
+
expected: 100
|
|
52
|
+
}, {
|
|
53
|
+
testName: 'undefined value with existing total',
|
|
54
|
+
value: undefined,
|
|
55
|
+
total: 100,
|
|
56
|
+
expected: 100
|
|
57
|
+
}, {
|
|
58
|
+
testName: 'string value with existing total',
|
|
59
|
+
value: 'string',
|
|
60
|
+
total: 100,
|
|
61
|
+
expected: 100
|
|
62
|
+
}];
|
|
63
|
+
describe('addToTotalIfNumber', () => {
|
|
64
|
+
tests.forEach(t => {
|
|
65
|
+
it(t.testName, () => {
|
|
66
|
+
expect(addToTotalIfNumber(t.value, t.total)).toEqual(t.expected);
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const addToTotalIfNumber = (value, total) => typeof value === 'number' && Number.isFinite(value) ? (total !== null && total !== void 0 ? total : 0) + value : total;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dhis2/analytics",
|
|
3
|
-
"version": "21.
|
|
3
|
+
"version": "21.9.1",
|
|
4
4
|
"main": "./build/cjs/index.js",
|
|
5
5
|
"module": "./build/es/index.js",
|
|
6
6
|
"exports": {
|
|
@@ -59,6 +59,7 @@
|
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
61
|
"@dhis2/d2-ui-translation-dialog": "^7.3.1",
|
|
62
|
+
"@dhis2/multi-calendar-dates": "1.0.0",
|
|
62
63
|
"classnames": "^2.3.1",
|
|
63
64
|
"d2-utilizr": "^0.2.16",
|
|
64
65
|
"d3-color": "^1.2.3",
|