@dhis2/analytics 26.12.1 → 26.12.3

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.
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = exports.WithMenu = exports.SelectedDimension = exports.RecommendedDimension = exports.LockedDimension = exports.FixedDimensionsOnly = exports.FixedAndDynamicDimensions = exports.DynamicDimensionsOnly = exports.DisabledDimension = void 0;
6
+ exports.default = exports.WithMenu = exports.TextWrapping = exports.SelectedDimension = exports.RecommendedDimension = exports.LockedDimension = exports.FixedDimensionsOnly = exports.FixedAndDynamicDimensions = exports.DynamicDimensionsOnly = exports.DisabledDimension = void 0;
7
7
  var _react = _interopRequireDefault(require("react"));
8
8
  var _DimensionsPanel = _interopRequireDefault(require("../components/DimensionsPanel/DimensionsPanel.js"));
9
9
  var _predefinedDimensions = require("../modules/predefinedDimensions.js");
@@ -20,13 +20,16 @@ const fixedDimensions = [{
20
20
  }];
21
21
  const dynamicDimensions = [{
22
22
  id: '0000001',
23
- name: 'One'
23
+ name: 'Dietary diversity score based on variety of consumed food groups over a weekly period'
24
24
  }, {
25
25
  id: '0000002',
26
- name: 'Two'
26
+ name: 'Healthcare services access and utilization frequency including preventive check-ups and specialist care'
27
27
  }, {
28
28
  id: '0000003',
29
- name: 'Three'
29
+ name: 'Sleep quality index incorporating duration, time to sleep, frequency of awakenings, and restfulness'
30
+ }, {
31
+ id: '0000004',
32
+ name: 'Malaria incidence rate'
30
33
  }];
31
34
  const onDimensionClick = () => alert('click');
32
35
  var _default = exports.default = {
@@ -120,4 +123,26 @@ const WithMenu = () => {
120
123
  exports.WithMenu = WithMenu;
121
124
  WithMenu.story = {
122
125
  name: 'with menu'
126
+ };
127
+ const TextWrapping = () => {
128
+ return /*#__PURE__*/_react.default.createElement("div", {
129
+ style: {
130
+ width: '260px',
131
+ height: '400px',
132
+ borderInlineEnd: '1px dotted #CCC',
133
+ resize: 'both',
134
+ overflow: 'auto'
135
+ }
136
+ }, /*#__PURE__*/_react.default.createElement(_DimensionsPanel.default, {
137
+ dimensions: [...fixedDimensions, ...dynamicDimensions],
138
+ onDimensionClick: onDimensionClick,
139
+ onDimensionOptionsClick: () => alert('options click'),
140
+ recommendedDimension: dimension => dimension === '0000002',
141
+ lockedDimension: dimension => dimension === '0000003',
142
+ selectedIds: ['0000003', '0000002']
143
+ }));
144
+ };
145
+ exports.TextWrapping = TextWrapping;
146
+ TextWrapping.story = {
147
+ name: 'text wrapping'
123
148
  };
@@ -15,10 +15,10 @@ const OptionsButton = _ref => {
15
15
  } = _ref;
16
16
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("button", {
17
17
  onClick: onClick,
18
- className: "jsx-2728765288"
18
+ className: "jsx-2074438274"
19
19
  }, /*#__PURE__*/_react.default.createElement(_ui.IconMore16, null)), /*#__PURE__*/_react.default.createElement(_style.default, {
20
- id: "2728765288"
21
- }, ["button.jsx-2728765288{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;-webkit-box-pack:center;-webkit-justify-content:center;-ms-flex-pack:center;justify-content:center;height:20px;width:20px;padding:0;border:none;background:none;outline:none;cursor:pointer;border-top-right-radius:2px;border-bottom-left-radius:2px;}", "button.jsx-2728765288:hover{background-color:rgba(0,0,0,0.09);}"]));
20
+ id: "2074438274"
21
+ }, ["button.jsx-2074438274{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;-webkit-box-pack:center;-webkit-justify-content:center;-ms-flex-pack:center;justify-content:center;height:100%;width:20px;padding:0;border:none;background:none;outline:none;cursor:pointer;border-top-right-radius:2px;border-bottom-left-radius:2px;}", "button.jsx-2074438274:hover{background-color:rgba(33,41,52,0.08);}", "button.jsx-2074438274:active{background-color:rgba(33,41,52,0.13);}"]));
22
22
  };
23
23
  OptionsButton.propTypes = {
24
24
  onClick: _propTypes.default.func
@@ -5,6 +5,6 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
  var _ui = require("@dhis2/ui");
8
- const _defaultExport = [`.item.jsx-1684920521{color:${_ui.colors.grey900};background-color:transparent;fill:${_ui.colors.grey800};display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;outline:none;-webkit-box-pack:justify;-webkit-justify-content:space-between;-ms-flex-pack:justify;justify-content:space-between;padding:0 0 0 4px;margin:0;border-radius:2px;cursor:pointer;min-height:22px;border:1px solid transparent;}`, `.item.jsx-1684920521:not(.deactivated):not(.dragging):hover{background-color:${_ui.colors.grey100};border-color:${_ui.colors.grey400};}`, ".label.jsx-1684920521{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;}", ".labelWrapper.jsx-1684920521{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;}", ".labelText.jsx-1684920521{font-size:13px;line-height:15px;margin-top:1px;}", ".iconWrapper.jsx-1684920521{width:16px;height:16px;margin:2px 4px 0 0;-webkit-flex:0 0 auto;-ms-flex:0 0 auto;flex:0 0 auto;-webkit-align-self:flex-start;-ms-flex-item-align:start;align-self:flex-start;}", ".item.deactivated.jsx-1684920521{opacity:0.5;cursor:not-allowed;}", `.item.selected.jsx-1684920521{background-color:${_ui.colors.teal100};border:1px solid ${_ui.colors.teal200};color:${_ui.colors.teal900};fill:${_ui.colors.teal800};font-weight:400;}`, ".item.selected.jsx-1684920521:not(.deactivated):hover{background:#cdeae8;border-color:#93c4bf;box-shadow:0 1px 2px 0 rgb(0 0 0 / 0.05);}", ".optionsWrapper.jsx-1684920521{width:20px;height:20px;}", `.lockWrapper.jsx-1684920521 svg.jsx-1684920521 path.jsx-1684920521{fill:${_ui.colors.grey800};}`, `.lockWrapper.jsx-1684920521{background:${_ui.colors.grey300};height:20px;padding:0 2px 0 3px;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;-webkit-box-pack:center;-webkit-justify-content:center;-ms-flex-pack:center;justify-content:center;}`, ".item.selected.jsx-1684920521 .lockWrapper.jsx-1684920521{background:#cbe7e5;}", `.item.selected.jsx-1684920521 .lockWrapper.jsx-1684920521 svg.jsx-1684920521 path.jsx-1684920521{fill:${_ui.colors.teal900};}`];
9
- _defaultExport.__hash = "1684920521";
8
+ const _defaultExport = [`.item.jsx-3350116288{color:${_ui.colors.grey900};background-color:transparent;fill:${_ui.colors.grey800};display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;gap:4px;outline:none;-webkit-box-pack:justify;-webkit-justify-content:space-between;-ms-flex-pack:justify;justify-content:space-between;padding:0 0 0 4px;margin:0;border-radius:2px;cursor:pointer;min-height:22px;border:1px solid transparent;}`, `.item.jsx-3350116288:not(.deactivated):not(.dragging):hover{background-color:${_ui.colors.grey100};border-color:${_ui.colors.grey400};}`, ".label.jsx-3350116288{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;}", ".labelWrapper.jsx-3350116288{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;padding:2px 0;}", ".labelText.jsx-3350116288{font-size:13px;line-height:15px;margin-top:1px;-webkit-align-self:center;-ms-flex-item-align:center;align-self:center;}", ".iconWrapper.jsx-3350116288{width:16px;height:16px;margin:2px 4px 0 0;-webkit-flex:0 0 auto;-ms-flex:0 0 auto;flex:0 0 auto;-webkit-align-self:flex-start;-ms-flex-item-align:start;align-self:flex-start;}", ".item.deactivated.jsx-3350116288{opacity:0.5;cursor:not-allowed;}", `.item.selected.jsx-3350116288{background-color:${_ui.colors.teal100};border:1px solid ${_ui.colors.teal200};color:${_ui.colors.teal900};fill:${_ui.colors.teal800};font-weight:400;}`, ".item.selected.jsx-3350116288:not(.deactivated):hover{background:#cdeae8;border-color:#93c4bf;box-shadow:0 1px 2px 0 rgb(0 0 0 / 0.05);}", ".optionsWrapper.jsx-3350116288{width:20px;-webkit-flex-shrink:0;-ms-flex-negative:0;flex-shrink:0;-webkit-align-self:stretch;-ms-flex-item-align:stretch;align-self:stretch;}", `.lockWrapper.jsx-3350116288 svg.jsx-3350116288 path.jsx-3350116288{fill:${_ui.colors.grey800};}`, `.lockWrapper.jsx-3350116288{background:${_ui.colors.grey300};-webkit-align-self:stretch;-ms-flex-item-align:stretch;align-self:stretch;padding:0 2px 0 3px;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;-webkit-box-pack:center;-webkit-justify-content:center;-ms-flex-pack:center;justify-content:center;}`, ".item.selected.jsx-3350116288 .lockWrapper.jsx-3350116288{background:#cbe7e5;}", `.item.selected.jsx-3350116288 .lockWrapper.jsx-3350116288 svg.jsx-3350116288 path.jsx-3350116288{fill:${_ui.colors.teal900};}`];
9
+ _defaultExport.__hash = "3350116288";
10
10
  var _default = exports.default = _defaultExport;
@@ -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 = 0;
13
- let cumulativeValues = [];
12
+ let decimals;
13
+ let accValue;
14
+ let accData;
14
15
  series.forEach(seriesObj => {
15
- cumulativeValues = seriesObj.data.reduce((accumulator, value, index) => {
16
- decimals = Math.max(decimals, (0, _numberDecimals.default)(value));
17
- if (index > 0) {
18
- value += accumulator[index - 1];
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
- accumulator.push(value);
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 = cumulativeValues.map(value => {
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 = 0;
37
+ let decimals;
38
+ let accValue;
39
+ let accSeriesData;
40
+ let accSeriesDataByCategory;
36
41
  series.filter(seriesObj => !seriesObj.custom.isTwoCategoryFakeSerie).forEach(seriesObj => {
37
- const cumulativeValues = [];
38
- seriesObj.custom.data.forEach(groupObj => {
39
- const cumulativeGroupValues = [];
40
- groupObj.forEach((value, index) => {
41
- decimals = Math.max(decimals, (0, _numberDecimals.default)(value));
42
- if (index > 0) {
43
- value += cumulativeGroupValues[index - 1];
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
- cumulativeValues.push(cumulativeGroupValues);
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 = cumulativeValues.map(groupObj => groupObj.map(value => value ? parseFloat(value.toFixed(decimals)) : value));
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
  }
@@ -13,13 +13,16 @@ const fixedDimensions = [{
13
13
  }];
14
14
  const dynamicDimensions = [{
15
15
  id: '0000001',
16
- name: 'One'
16
+ name: 'Dietary diversity score based on variety of consumed food groups over a weekly period'
17
17
  }, {
18
18
  id: '0000002',
19
- name: 'Two'
19
+ name: 'Healthcare services access and utilization frequency including preventive check-ups and specialist care'
20
20
  }, {
21
21
  id: '0000003',
22
- name: 'Three'
22
+ name: 'Sleep quality index incorporating duration, time to sleep, frequency of awakenings, and restfulness'
23
+ }, {
24
+ id: '0000004',
25
+ name: 'Malaria incidence rate'
23
26
  }];
24
27
  const onDimensionClick = () => alert('click');
25
28
  export default {
@@ -105,4 +108,25 @@ export const WithMenu = () => {
105
108
  };
106
109
  WithMenu.story = {
107
110
  name: 'with menu'
111
+ };
112
+ export const TextWrapping = () => {
113
+ return /*#__PURE__*/React.createElement("div", {
114
+ style: {
115
+ width: '260px',
116
+ height: '400px',
117
+ borderInlineEnd: '1px dotted #CCC',
118
+ resize: 'both',
119
+ overflow: 'auto'
120
+ }
121
+ }, /*#__PURE__*/React.createElement(DimensionsPanel, {
122
+ dimensions: [...fixedDimensions, ...dynamicDimensions],
123
+ onDimensionClick: onDimensionClick,
124
+ onDimensionOptionsClick: () => alert('options click'),
125
+ recommendedDimension: dimension => dimension === '0000002',
126
+ lockedDimension: dimension => dimension === '0000003',
127
+ selectedIds: ['0000003', '0000002']
128
+ }));
129
+ };
130
+ TextWrapping.story = {
131
+ name: 'text wrapping'
108
132
  };
@@ -8,10 +8,10 @@ const OptionsButton = _ref => {
8
8
  } = _ref;
9
9
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("button", {
10
10
  onClick: onClick,
11
- className: "jsx-2728765288"
11
+ className: "jsx-2074438274"
12
12
  }, /*#__PURE__*/React.createElement(IconMore16, null)), /*#__PURE__*/React.createElement(_JSXStyle, {
13
- id: "2728765288"
14
- }, ["button.jsx-2728765288{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;-webkit-box-pack:center;-webkit-justify-content:center;-ms-flex-pack:center;justify-content:center;height:20px;width:20px;padding:0;border:none;background:none;outline:none;cursor:pointer;border-top-right-radius:2px;border-bottom-left-radius:2px;}", "button.jsx-2728765288:hover{background-color:rgba(0,0,0,0.09);}"]));
13
+ id: "2074438274"
14
+ }, ["button.jsx-2074438274{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;-webkit-box-pack:center;-webkit-justify-content:center;-ms-flex-pack:center;justify-content:center;height:100%;width:20px;padding:0;border:none;background:none;outline:none;cursor:pointer;border-top-right-radius:2px;border-bottom-left-radius:2px;}", "button.jsx-2074438274:hover{background-color:rgba(33,41,52,0.08);}", "button.jsx-2074438274:active{background-color:rgba(33,41,52,0.13);}"]));
15
15
  };
16
16
  OptionsButton.propTypes = {
17
17
  onClick: PropTypes.func
@@ -1,4 +1,4 @@
1
1
  import { colors } from '@dhis2/ui';
2
- const _defaultExport = [`.item.jsx-1684920521{color:${colors.grey900};background-color:transparent;fill:${colors.grey800};display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;outline:none;-webkit-box-pack:justify;-webkit-justify-content:space-between;-ms-flex-pack:justify;justify-content:space-between;padding:0 0 0 4px;margin:0;border-radius:2px;cursor:pointer;min-height:22px;border:1px solid transparent;}`, `.item.jsx-1684920521:not(.deactivated):not(.dragging):hover{background-color:${colors.grey100};border-color:${colors.grey400};}`, ".label.jsx-1684920521{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;}", ".labelWrapper.jsx-1684920521{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;}", ".labelText.jsx-1684920521{font-size:13px;line-height:15px;margin-top:1px;}", ".iconWrapper.jsx-1684920521{width:16px;height:16px;margin:2px 4px 0 0;-webkit-flex:0 0 auto;-ms-flex:0 0 auto;flex:0 0 auto;-webkit-align-self:flex-start;-ms-flex-item-align:start;align-self:flex-start;}", ".item.deactivated.jsx-1684920521{opacity:0.5;cursor:not-allowed;}", `.item.selected.jsx-1684920521{background-color:${colors.teal100};border:1px solid ${colors.teal200};color:${colors.teal900};fill:${colors.teal800};font-weight:400;}`, ".item.selected.jsx-1684920521:not(.deactivated):hover{background:#cdeae8;border-color:#93c4bf;box-shadow:0 1px 2px 0 rgb(0 0 0 / 0.05);}", ".optionsWrapper.jsx-1684920521{width:20px;height:20px;}", `.lockWrapper.jsx-1684920521 svg.jsx-1684920521 path.jsx-1684920521{fill:${colors.grey800};}`, `.lockWrapper.jsx-1684920521{background:${colors.grey300};height:20px;padding:0 2px 0 3px;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;-webkit-box-pack:center;-webkit-justify-content:center;-ms-flex-pack:center;justify-content:center;}`, ".item.selected.jsx-1684920521 .lockWrapper.jsx-1684920521{background:#cbe7e5;}", `.item.selected.jsx-1684920521 .lockWrapper.jsx-1684920521 svg.jsx-1684920521 path.jsx-1684920521{fill:${colors.teal900};}`];
3
- _defaultExport.__hash = "1684920521";
2
+ const _defaultExport = [`.item.jsx-3350116288{color:${colors.grey900};background-color:transparent;fill:${colors.grey800};display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;gap:4px;outline:none;-webkit-box-pack:justify;-webkit-justify-content:space-between;-ms-flex-pack:justify;justify-content:space-between;padding:0 0 0 4px;margin:0;border-radius:2px;cursor:pointer;min-height:22px;border:1px solid transparent;}`, `.item.jsx-3350116288:not(.deactivated):not(.dragging):hover{background-color:${colors.grey100};border-color:${colors.grey400};}`, ".label.jsx-3350116288{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;}", ".labelWrapper.jsx-3350116288{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;padding:2px 0;}", ".labelText.jsx-3350116288{font-size:13px;line-height:15px;margin-top:1px;-webkit-align-self:center;-ms-flex-item-align:center;align-self:center;}", ".iconWrapper.jsx-3350116288{width:16px;height:16px;margin:2px 4px 0 0;-webkit-flex:0 0 auto;-ms-flex:0 0 auto;flex:0 0 auto;-webkit-align-self:flex-start;-ms-flex-item-align:start;align-self:flex-start;}", ".item.deactivated.jsx-3350116288{opacity:0.5;cursor:not-allowed;}", `.item.selected.jsx-3350116288{background-color:${colors.teal100};border:1px solid ${colors.teal200};color:${colors.teal900};fill:${colors.teal800};font-weight:400;}`, ".item.selected.jsx-3350116288:not(.deactivated):hover{background:#cdeae8;border-color:#93c4bf;box-shadow:0 1px 2px 0 rgb(0 0 0 / 0.05);}", ".optionsWrapper.jsx-3350116288{width:20px;-webkit-flex-shrink:0;-ms-flex-negative:0;flex-shrink:0;-webkit-align-self:stretch;-ms-flex-item-align:stretch;align-self:stretch;}", `.lockWrapper.jsx-3350116288 svg.jsx-3350116288 path.jsx-3350116288{fill:${colors.grey800};}`, `.lockWrapper.jsx-3350116288{background:${colors.grey300};-webkit-align-self:stretch;-ms-flex-item-align:stretch;align-self:stretch;padding:0 2px 0 3px;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;-webkit-box-pack:center;-webkit-justify-content:center;-ms-flex-pack:center;justify-content:center;}`, ".item.selected.jsx-3350116288 .lockWrapper.jsx-3350116288{background:#cbe7e5;}", `.item.selected.jsx-3350116288 .lockWrapper.jsx-3350116288 svg.jsx-3350116288 path.jsx-3350116288{fill:${colors.teal900};}`];
3
+ _defaultExport.__hash = "3350116288";
4
4
  export default _defaultExport;
@@ -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 = 0;
6
- let cumulativeValues = [];
5
+ let decimals;
6
+ let accValue;
7
+ let accData;
7
8
  series.forEach(seriesObj => {
8
- cumulativeValues = seriesObj.data.reduce((accumulator, value, index) => {
9
- decimals = Math.max(decimals, numberDecimals(value));
10
- if (index > 0) {
11
- value += accumulator[index - 1];
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
- accumulator.push(value);
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 = cumulativeValues.map(value => {
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 = 0;
30
+ let decimals;
31
+ let accValue;
32
+ let accSeriesData;
33
+ let accSeriesDataByCategory;
29
34
  series.filter(seriesObj => !seriesObj.custom.isTwoCategoryFakeSerie).forEach(seriesObj => {
30
- const cumulativeValues = [];
31
- seriesObj.custom.data.forEach(groupObj => {
32
- const cumulativeGroupValues = [];
33
- groupObj.forEach((value, index) => {
34
- decimals = Math.max(decimals, numberDecimals(value));
35
- if (index > 0) {
36
- value += cumulativeGroupValues[index - 1];
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
- cumulativeValues.push(cumulativeGroupValues);
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 = cumulativeValues.map(groupObj => groupObj.map(value => value ? parseFloat(value.toFixed(decimals)) : value));
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhis2/analytics",
3
- "version": "26.12.1",
3
+ "version": "26.12.3",
4
4
  "main": "./build/cjs/index.js",
5
5
  "module": "./build/es/index.js",
6
6
  "exports": {