@dhis2/analytics 26.2.0-alpha.2 → 26.2.0

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.
Files changed (27) hide show
  1. package/build/cjs/__demo__/PivotTable.stories.js +69 -29
  2. package/build/cjs/api/analytics/Analytics.js +0 -7
  3. package/build/cjs/api/analytics/AnalyticsBase.js +6 -24
  4. package/build/cjs/api/analytics/AnalyticsRequest.js +10 -33
  5. package/build/cjs/api/analytics/AnalyticsRequestBase.js +1 -3
  6. package/build/cjs/api/analytics/AnalyticsRequestPropertiesMixin.js +0 -19
  7. package/build/cjs/api/analytics/utils.js +2 -23
  8. package/build/cjs/components/Options/VisualizationOptions.js +1 -1
  9. package/build/cjs/components/Options/styles/VisualizationOptions.style.js +8 -1
  10. package/build/cjs/modules/layout/dimension.js +2 -9
  11. package/build/cjs/modules/layout/dimensionCreate.js +0 -3
  12. package/build/cjs/modules/pivotTable/PivotTableEngine.js +119 -57
  13. package/build/es/__demo__/PivotTable.stories.js +69 -29
  14. package/build/es/api/analytics/Analytics.js +0 -7
  15. package/build/es/api/analytics/AnalyticsBase.js +6 -24
  16. package/build/es/api/analytics/AnalyticsRequest.js +10 -33
  17. package/build/es/api/analytics/AnalyticsRequestBase.js +1 -3
  18. package/build/es/api/analytics/AnalyticsRequestPropertiesMixin.js +0 -19
  19. package/build/es/api/analytics/utils.js +1 -20
  20. package/build/es/components/Options/VisualizationOptions.js +2 -2
  21. package/build/es/components/Options/styles/VisualizationOptions.style.js +6 -0
  22. package/build/es/modules/layout/dimension.js +1 -7
  23. package/build/es/modules/layout/dimensionCreate.js +1 -4
  24. package/build/es/modules/pivotTable/PivotTableEngine.js +119 -57
  25. package/package.json +1 -1
  26. package/build/cjs/api/analytics/AnalyticsTrackedEntities.js +0 -31
  27. package/build/es/api/analytics/AnalyticsTrackedEntities.js +0 -24
@@ -4,7 +4,6 @@ import AnalyticsRequestBase from './AnalyticsRequestBase.js';
4
4
  import AnalyticsRequestDimensionsMixin from './AnalyticsRequestDimensionsMixin.js';
5
5
  import AnalyticsRequestFiltersMixin from './AnalyticsRequestFiltersMixin.js';
6
6
  import AnalyticsRequestPropertiesMixin from './AnalyticsRequestPropertiesMixin.js';
7
- import { formatDimension } from './utils.js';
8
7
 
9
8
  /**
10
9
  * @description
@@ -42,7 +41,6 @@ class AnalyticsRequest extends AnalyticsRequestDimensionsMixin(AnalyticsRequestF
42
41
  fromVisualization(visualization) {
43
42
  let passFilterAsDimension = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
44
43
  let request = this;
45
- const outputType = visualization.outputType;
46
44
 
47
45
  // extract dimensions from visualization
48
46
  const columns = visualization.columns || [];
@@ -53,28 +51,19 @@ class AnalyticsRequest extends AnalyticsRequestDimensionsMixin(AnalyticsRequestF
53
51
  if ((_d$legendSet = d.legendSet) !== null && _d$legendSet !== void 0 && _d$legendSet.id) {
54
52
  dimension += `-${d.legendSet.id}`;
55
53
  }
54
+ if ((_d$programStage = d.programStage) !== null && _d$programStage !== void 0 && _d$programStage.id) {
55
+ dimension = `${d.programStage.id}.${dimension}`;
56
+ }
56
57
  if (d.filter) {
57
58
  dimension += `:${d.filter}`;
58
59
  }
59
- const programStageId = (_d$programStage = d.programStage) === null || _d$programStage === void 0 ? void 0 : _d$programStage.id;
60
60
  if ((_d$repetition = d.repetition) !== null && _d$repetition !== void 0 && (_d$repetition$indexes = _d$repetition.indexes) !== null && _d$repetition$indexes !== void 0 && _d$repetition$indexes.length) {
61
61
  d.repetition.indexes.forEach(index => {
62
- var _d$program;
63
- request = request.addDimension(formatDimension({
64
- programId: (_d$program = d.program) === null || _d$program === void 0 ? void 0 : _d$program.id,
65
- programStageId: `${programStageId}[${index}]`,
66
- dimension,
67
- outputType
68
- }));
62
+ request = request.addDimension(dimension.replace(/\./, `[${index}].`));
69
63
  });
70
64
  } else {
71
- var _d$program2, _d$items;
72
- request = request.addDimension(formatDimension({
73
- programId: (_d$program2 = d.program) === null || _d$program2 === void 0 ? void 0 : _d$program2.id,
74
- programStageId,
75
- dimension,
76
- outputType
77
- }), (_d$items = d.items) === null || _d$items === void 0 ? void 0 : _d$items.map(item => item.id));
65
+ var _d$items;
66
+ request = request.addDimension(dimension, (_d$items = d.items) === null || _d$items === void 0 ? void 0 : _d$items.map(item => item.id));
78
67
  }
79
68
  });
80
69
 
@@ -89,29 +78,17 @@ class AnalyticsRequest extends AnalyticsRequestDimensionsMixin(AnalyticsRequestF
89
78
  request = request.addDimension(f.dimension, (_f$items = f.items) === null || _f$items === void 0 ? void 0 : _f$items.map(item => item.id));
90
79
  } else {
91
80
  var _f$programStage, _f$repetition, _f$repetition$indexes;
92
- let filterString = f.dimension;
81
+ let filterString = (_f$programStage = f.programStage) !== null && _f$programStage !== void 0 && _f$programStage.id ? `${f.programStage.id}.${f.dimension}` : f.dimension;
93
82
  if (f.filter) {
94
83
  filterString += `:${f.filter}`;
95
84
  }
96
- const programStageId = (_f$programStage = f.programStage) === null || _f$programStage === void 0 ? void 0 : _f$programStage.id;
97
85
  if ((_f$repetition = f.repetition) !== null && _f$repetition !== void 0 && (_f$repetition$indexes = _f$repetition.indexes) !== null && _f$repetition$indexes !== void 0 && _f$repetition$indexes.length) {
98
86
  f.repetition.indexes.forEach(index => {
99
- var _f$program;
100
- request = request.addFilter(formatDimension({
101
- programId: (_f$program = f.program) === null || _f$program === void 0 ? void 0 : _f$program.id,
102
- programStageId: `${programStageId}[${index}]`,
103
- dimension: filterString,
104
- outputType
105
- }));
87
+ request = request.addFilter(filterString.replace(/\./, `[${index}].`));
106
88
  });
107
89
  } else {
108
- var _f$program2, _f$items2;
109
- request = request.addFilter(formatDimension({
110
- programId: (_f$program2 = f.program) === null || _f$program2 === void 0 ? void 0 : _f$program2.id,
111
- programStageId,
112
- dimension: filterString,
113
- outputType
114
- }), (_f$items2 = f.items) === null || _f$items2 === void 0 ? void 0 : _f$items2.map(item => item.id));
90
+ var _f$items2;
91
+ request = request.addFilter(filterString, (_f$items2 = f.items) === null || _f$items2 === void 0 ? void 0 : _f$items2.map(item => item.id));
115
92
  }
116
93
  }
117
94
  });
@@ -18,7 +18,6 @@ class AnalyticsRequestBase {
18
18
  format = 'json',
19
19
  path,
20
20
  program,
21
- trackedEntityType,
22
21
  dimensions = [],
23
22
  filters = [],
24
23
  parameters = {}
@@ -27,7 +26,6 @@ class AnalyticsRequestBase {
27
26
  this.format = format.toLowerCase();
28
27
  this.path = path;
29
28
  this.program = program;
30
- this.trackedEntityType = trackedEntityType;
31
29
  this.dimensions = dimensions;
32
30
  this.filters = filters;
33
31
  this.parameters = {
@@ -66,7 +64,7 @@ class AnalyticsRequestBase {
66
64
  }
67
65
  return dimension;
68
66
  });
69
- const endPoint = [this.endPoint, this.path, this.program, this.trackedEntityType].filter(Boolean).join('/');
67
+ const endPoint = [this.endPoint, this.path, this.program].filter(e => !!e).join('/');
70
68
  return `${endPoint}.${this.format}?dimension=${encodedDimensions.join('&dimension=')}`;
71
69
  }
72
70
 
@@ -491,25 +491,6 @@ class extends base {
491
491
  return new AnalyticsRequest(this);
492
492
  }
493
493
 
494
- /**
495
- * Sets the tracked entity type for the request.
496
- * It appends the tracked entity type id to the request's path.
497
- *
498
- * @param {!String} trackedEntityType The tracked entity type id
499
- *
500
- * @returns {AnalyticsRequest} A new instance of the class for chaining purposes
501
- *
502
- * @example
503
- * const req = new analytics.request()
504
- * .withTrackedEntityType('nEenWmSyUEp');
505
- */
506
- withTrackedEntityType(trackedEntityType) {
507
- if (trackedEntityType) {
508
- this.trackedEntityType = trackedEntityType;
509
- }
510
- return new AnalyticsRequest(this);
511
- }
512
-
513
494
  /**
514
495
  * Sets the program for the request.
515
496
  * It appends the program id to the request's path.
@@ -2,23 +2,4 @@
2
2
  const whitelistURI = ',&$=/;:';
3
3
  const whitelistURICodes = whitelistURI.split('').map(c => encodeURIComponent(c));
4
4
  const whitelistRegExp = new RegExp(`(?:${whitelistURICodes.join('|')})`, 'g');
5
- export const customEncodeURIComponent = uri => encodeURIComponent(uri).replace(whitelistRegExp, decodeURIComponent);
6
- export const formatRequestPath = _ref => {
7
- let {
8
- path,
9
- program,
10
- trackedEntityType
11
- } = _ref;
12
- return [path, program, trackedEntityType].filter(Boolean).join('/');
13
- };
14
- export const formatDimension = _ref2 => {
15
- let {
16
- outputType,
17
- programId,
18
- programStageId,
19
- dimension
20
- } = _ref2;
21
- return [
22
- // XXX it would be clearer to have this consistent with what is sent in the request as for EVENT/ENROLLMENT
23
- outputType === 'TRACKED_ENTITY' ? programId : undefined, programStageId, dimension].filter(Boolean).join('.');
24
- };
5
+ export const customEncodeURIComponent = uri => encodeURIComponent(uri).replace(whitelistRegExp, decodeURIComponent);
@@ -2,7 +2,7 @@ import i18n from '@dhis2/d2-i18n';
2
2
  import { ButtonStrip, Modal, ModalTitle, ModalContent, ModalActions, Button, FieldSet, Legend, TabBar, Tab, Help } from '@dhis2/ui';
3
3
  import PropTypes from 'prop-types';
4
4
  import React, { useState } from 'react';
5
- import { modalContent, tabSection, tabSectionTitle, tabSectionTitleMargin, tabSectionOption, tabSectionOptionItem, tabSectionOptionToggleable, tabSectionToggleableSubsection, tabSectionOptionComplexInline, tabSectionOptionText, tabBar, tabContent, tabSectionOptionIcon } from './styles/VisualizationOptions.style.js';
5
+ import { modalContent, tabSection, tabSectionTitle, tabSectionTitleDisabled, tabSectionTitleMargin, tabSectionOption, tabSectionOptionItem, tabSectionOptionToggleable, tabSectionToggleableSubsection, tabSectionOptionComplexInline, tabSectionOptionText, tabBar, tabContent, tabSectionOptionIcon } from './styles/VisualizationOptions.style.js';
6
6
  const VisualizationOptions = _ref => {
7
7
  let {
8
8
  initiallyActiveTabKey,
@@ -59,7 +59,7 @@ const VisualizationOptions = _ref => {
59
59
  }, label);
60
60
  })), tabBar.styles), /*#__PURE__*/React.createElement("div", {
61
61
  className: tabContent.className
62
- }, tabs[activeTabIndex].content, tabContent.styles, tabSection.styles, tabSectionTitle.styles, tabSectionTitleMargin.styles, tabSectionOption.styles, tabSectionOptionItem.styles, tabSectionOptionToggleable.styles, tabSectionToggleableSubsection.styles, tabSectionOptionComplexInline.styles, tabSectionOptionText.styles, tabSectionOptionIcon.styles));
62
+ }, tabs[activeTabIndex].content, tabContent.styles, tabSection.styles, tabSectionTitle.styles, tabSectionTitleDisabled.styles, tabSectionTitleMargin.styles, tabSectionOption.styles, tabSectionOptionItem.styles, tabSectionOptionToggleable.styles, tabSectionToggleableSubsection.styles, tabSectionOptionComplexInline.styles, tabSectionOptionText.styles, tabSectionOptionIcon.styles));
63
63
  };
64
64
  return /*#__PURE__*/React.createElement(Modal, {
65
65
  onClose: onClose,
@@ -38,6 +38,12 @@ export const tabSectionTitle = {
38
38
  }, [`span.jsx-3115295887{display:inline-block;padding-bottom:${spacers.dp12};font-size:15px;color:${colors.grey900};font-weight:500;-webkit-letter-spacing:0.2px;-moz-letter-spacing:0.2px;-ms-letter-spacing:0.2px;letter-spacing:0.2px;}`]),
39
39
  className: "jsx-3115295887"
40
40
  };
41
+ export const tabSectionTitleDisabled = {
42
+ styles: /*#__PURE__*/React.createElement(_JSXStyle, {
43
+ id: "3352433486"
44
+ }, [`span.jsx-3352433486{color:${colors.grey600};}`]),
45
+ className: "jsx-3352433486"
46
+ };
41
47
  export const tabSectionTitleMargin = {
42
48
  styles: /*#__PURE__*/React.createElement(_JSXStyle, {
43
49
  id: "642558349"
@@ -33,12 +33,6 @@ export const DIMENSION_PROP_LEGEND_SET = {
33
33
  required: false,
34
34
  isValid: prop => isString(prop)
35
35
  };
36
- export const DIMENSION_PROP_PROGRAM = {
37
- name: 'program',
38
- defaultValue: {},
39
- required: false,
40
- isValid: prop => isObject(prop)
41
- };
42
36
  export const DIMENSION_PROP_PROGRAM_STAGE = {
43
37
  name: 'programStage',
44
38
  defaultValue: {},
@@ -51,4 +45,4 @@ export const DIMENSION_PROP_REPETITION = {
51
45
  required: false,
52
46
  isValid: prop => Array.isArray(prop)
53
47
  };
54
- export const DIMENSION_PROPS = [DIMENSION_PROP_ID, DIMENSION_PROP_ITEMS, DIMENSION_PROP_FILTER, DIMENSION_PROP_LEGEND_SET, DIMENSION_PROP_PROGRAM, DIMENSION_PROP_PROGRAM_STAGE, DIMENSION_PROP_REPETITION];
48
+ export const DIMENSION_PROPS = [DIMENSION_PROP_ID, DIMENSION_PROP_ITEMS, DIMENSION_PROP_FILTER, DIMENSION_PROP_LEGEND_SET, DIMENSION_PROP_PROGRAM_STAGE, DIMENSION_PROP_REPETITION];
@@ -1,4 +1,4 @@
1
- import { DIMENSION_PROP_ID, DIMENSION_PROP_ITEMS, DIMENSION_PROP_FILTER, DIMENSION_PROP_LEGEND_SET, DIMENSION_PROP_PROGRAM, DIMENSION_PROP_PROGRAM_STAGE, DIMENSION_PROP_REPETITION } from './dimension.js';
1
+ import { DIMENSION_PROP_ID, DIMENSION_PROP_ITEMS, DIMENSION_PROP_FILTER, DIMENSION_PROP_LEGEND_SET, DIMENSION_PROP_PROGRAM_STAGE, DIMENSION_PROP_REPETITION } from './dimension.js';
2
2
  export const dimensionCreate = function (dimensionId) {
3
3
  let itemIds = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
4
4
  let args = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
@@ -15,9 +15,6 @@ export const dimensionCreate = function (dimensionId) {
15
15
  ...(args.legendSet && {
16
16
  [DIMENSION_PROP_LEGEND_SET.name]: args.legendSet
17
17
  }),
18
- ...(args.program && {
19
- [DIMENSION_PROP_PROGRAM.name]: args.program
20
- }),
21
18
  ...(args.programStage && {
22
19
  [DIMENSION_PROP_PROGRAM_STAGE.name]: args.programStage
23
20
  }),
@@ -20,7 +20,8 @@ const defaultOptions = {
20
20
  showRowSubtotals: false,
21
21
  showColumnSubtotals: false,
22
22
  fixColumnHeaders: false,
23
- fixRowHeaders: false
23
+ fixRowHeaders: false,
24
+ cumulativeValues: false
24
25
  };
25
26
  const defaultVisualizationProps = {
26
27
  fontSize: FONT_SIZE_OPTION_NORMAL,
@@ -175,6 +176,9 @@ export class PivotTableEngine {
175
176
  _defineProperty(this, "data", []);
176
177
  _defineProperty(this, "rowMap", []);
177
178
  _defineProperty(this, "columnMap", []);
179
+ _defineProperty(this, "accumulators", {
180
+ rows: {}
181
+ });
178
182
  this.visualization = Object.assign({}, defaultVisualizationProps, visualization);
179
183
  this.legendSets = (legendSets || []).reduce((sets, set) => {
180
184
  sets[set.id] = set;
@@ -194,7 +198,8 @@ export class PivotTableEngine {
194
198
  subtitle: visualization.hideSubtitle ? undefined : visualization.subtitle,
195
199
  // turn on fixed headers only when there are dimensions
196
200
  fixColumnHeaders: this.dimensionLookup.columns.length ? visualization.fixColumnHeaders : false,
197
- fixRowHeaders: this.dimensionLookup.rows.length ? visualization.fixRowHeaders : false
201
+ fixRowHeaders: this.dimensionLookup.rows.length ? visualization.fixRowHeaders : false,
202
+ cumulativeValues: visualization.cumulativeValues
198
203
  };
199
204
  this.adaptiveClippingController = new AdaptiveClippingController(this);
200
205
  const doColumnSubtotals = this.options.showColumnSubtotals && this.dimensionLookup.rows.length > 1;
@@ -218,51 +223,68 @@ export class PivotTableEngine {
218
223
  row,
219
224
  column
220
225
  });
226
+ const valueType = (dxDimension === null || dxDimension === void 0 ? void 0 : dxDimension.valueType) || VALUE_TYPE_TEXT;
221
227
  const headers = [...this.getRawRowHeader(row), ...this.getRawColumnHeader(column)];
222
228
  const peId = (_headers$find = headers.find(header => (header === null || header === void 0 ? void 0 : header.dimensionItemType) === DIMENSION_TYPE_PERIOD)) === null || _headers$find === void 0 ? void 0 : _headers$find.uid;
223
229
  const ouId = (_headers$find2 = headers.find(header => (header === null || header === void 0 ? void 0 : header.dimensionItemType) === DIMENSION_TYPE_ORGANISATION_UNIT)) === null || _headers$find2 === void 0 ? void 0 : _headers$find2.uid;
224
- if (!this.data[row] || !this.data[row][column]) {
225
- return {
226
- cellType,
227
- empty: true,
228
- ouId,
229
- peId
230
- };
231
- }
232
- const dataRow = this.data[row][column];
233
- let rawValue = cellType === CELL_TYPE_VALUE ? dataRow[this.dimensionLookup.dataHeaders.value] : dataRow.value;
234
- let renderedValue = rawValue;
235
- const valueType = (dxDimension === null || dxDimension === void 0 ? void 0 : dxDimension.valueType) || VALUE_TYPE_TEXT;
236
- if (valueType === VALUE_TYPE_NUMBER) {
237
- rawValue = parseValue(rawValue);
238
- switch (this.visualization.numberType) {
239
- case NUMBER_TYPE_ROW_PERCENTAGE:
240
- renderedValue = rawValue / this.percentageTotals[row].value;
241
- break;
242
- case NUMBER_TYPE_COLUMN_PERCENTAGE:
243
- renderedValue = rawValue / this.percentageTotals[column].value;
244
- break;
245
- default:
246
- break;
247
- }
248
- }
249
- renderedValue = renderValue(renderedValue, valueType, this.visualization);
250
- return {
230
+ const rawCell = {
251
231
  cellType,
252
- empty: false,
253
232
  valueType,
254
- rawValue,
255
- renderedValue,
256
- dxDimension,
257
233
  ouId,
258
234
  peId
259
235
  };
236
+ if (!this.data[row] || !this.data[row][column]) {
237
+ rawCell.empty = true;
238
+ } else {
239
+ const dataRow = this.data[row][column];
240
+ let rawValue = cellType === CELL_TYPE_VALUE ? dataRow[this.dimensionLookup.dataHeaders.value] : dataRow.value;
241
+ let renderedValue = rawValue;
242
+ if (valueType === VALUE_TYPE_NUMBER) {
243
+ rawValue = parseValue(rawValue);
244
+ switch (this.visualization.numberType) {
245
+ case NUMBER_TYPE_ROW_PERCENTAGE:
246
+ renderedValue = rawValue / this.percentageTotals[row].value;
247
+ break;
248
+ case NUMBER_TYPE_COLUMN_PERCENTAGE:
249
+ renderedValue = rawValue / this.percentageTotals[column].value;
250
+ break;
251
+ default:
252
+ break;
253
+ }
254
+ }
255
+ renderedValue = renderValue(renderedValue, valueType, this.visualization);
256
+ rawCell.dxDimension = dxDimension;
257
+ rawCell.empty = false;
258
+ rawCell.rawValue = rawValue;
259
+ rawCell.renderedValue = renderedValue;
260
+ }
261
+ if (this.options.cumulativeValues) {
262
+ const cumulativeValue = this.getCumulative({
263
+ row,
264
+ column
265
+ });
266
+ if (cumulativeValue !== undefined && cumulativeValue !== null) {
267
+ // force to NUMBER for accumulated values
268
+ rawCell.valueType = valueType === undefined || valueType === null ? VALUE_TYPE_NUMBER : valueType;
269
+ rawCell.empty = false;
270
+ rawCell.rawValue = cumulativeValue;
271
+ rawCell.renderedValue = renderValue(cumulativeValue, valueType, this.visualization);
272
+ }
273
+ }
274
+ return rawCell;
260
275
  }
261
- get(_ref4) {
276
+ getCumulative(_ref4) {
262
277
  let {
263
278
  row,
264
279
  column
265
280
  } = _ref4;
281
+ return this.accumulators.rows[row][column];
282
+ }
283
+ get(_ref5) {
284
+ let {
285
+ row,
286
+ column
287
+ } = _ref5;
266
288
  const mappedRow = this.rowMap[row],
267
289
  mappedColumn = this.columnMap[column];
268
290
  if (!mappedRow && mappedRow !== 0 || !mappedColumn && mappedColumn !== 0) {
@@ -273,11 +295,11 @@ export class PivotTableEngine {
273
295
  column: mappedColumn
274
296
  });
275
297
  }
276
- getRawCellType(_ref5) {
298
+ getRawCellType(_ref6) {
277
299
  let {
278
300
  row,
279
301
  column
280
- } = _ref5;
302
+ } = _ref6;
281
303
  const isRowTotal = this.doRowTotals && column === this.dataWidth - 1;
282
304
  const isColumnTotal = this.doColumnTotals && row === this.dataHeight - 1;
283
305
  if (isRowTotal || isColumnTotal) {
@@ -290,11 +312,11 @@ export class PivotTableEngine {
290
312
  }
291
313
  return CELL_TYPE_VALUE;
292
314
  }
293
- getCellType(_ref6) {
315
+ getCellType(_ref7) {
294
316
  let {
295
317
  row,
296
318
  column
297
- } = _ref6;
319
+ } = _ref7;
298
320
  row = this.rowMap[row];
299
321
  column = this.columnMap[column];
300
322
  return this.getRawCellType({
@@ -324,29 +346,26 @@ export class PivotTableEngine {
324
346
  return i18n.t(this.dimensionLookup.rows[rowLevel].meta.name);
325
347
  }
326
348
  }
327
- getCellDxDimension(_ref7) {
349
+ getCellDxDimension(_ref8) {
328
350
  let {
329
351
  row,
330
352
  column
331
- } = _ref7;
353
+ } = _ref8;
332
354
  return this.getRawCellDxDimension({
333
355
  row: this.rowMap[row],
334
356
  column: this.columnMap[column]
335
357
  });
336
358
  }
337
- getRawCellDxDimension(_ref8) {
359
+ getRawCellDxDimension(_ref9) {
338
360
  let {
339
361
  row,
340
362
  column
341
- } = _ref8;
363
+ } = _ref9;
342
364
  if (!this.data[row]) {
343
365
  return undefined;
344
366
  }
345
367
  const cellValue = this.data[row][column];
346
- if (!cellValue) {
347
- return undefined;
348
- }
349
- if (!Array.isArray(cellValue)) {
368
+ if (cellValue && !Array.isArray(cellValue)) {
350
369
  // This is a total cell
351
370
  return {
352
371
  valueType: cellValue.valueType,
@@ -373,6 +392,11 @@ export class PivotTableEngine {
373
392
  };
374
393
  }
375
394
 
395
+ // Empty cell
396
+ // The cell still needs to get the valueType to render correctly 0 and cumulative values
397
+ //
398
+ // OR
399
+ //
376
400
  // Data is in Filter
377
401
  // TODO : This assumes the server ignores text types, we should confirm this is the case
378
402
  return {
@@ -384,7 +408,7 @@ export class PivotTableEngine {
384
408
  return !this.data[row] || this.data[row].length === 0;
385
409
  }
386
410
  columnIsEmpty(column) {
387
- return !this.adaptiveClippingController.columns.sizes[column];
411
+ return !this.rowMap.some(row => this.data[row][column]);
388
412
  }
389
413
  getRawColumnHeader(column) {
390
414
  if (this.doRowTotals && column === this.dataWidth - 1) {
@@ -430,12 +454,12 @@ export class PivotTableEngine {
430
454
  getRowHeader(row) {
431
455
  return this.getRawRowHeader(this.rowMap[row]);
432
456
  }
433
- getDependantTotalCells(_ref9) {
457
+ getDependantTotalCells(_ref10) {
434
458
  var _this$dimensionLookup, _this$dimensionLookup2;
435
459
  let {
436
460
  row,
437
461
  column
438
- } = _ref9;
462
+ } = _ref10;
439
463
  const rowSubtotalSize = ((_this$dimensionLookup = this.dimensionLookup.columns[0]) === null || _this$dimensionLookup === void 0 ? void 0 : _this$dimensionLookup.size) + 1;
440
464
  const rowSubtotal = rowSubtotalSize && this.doRowSubtotals && {
441
465
  row,
@@ -610,11 +634,11 @@ export class PivotTableEngine {
610
634
  }
611
635
  }
612
636
  }
613
- finalizeTotal(_ref10) {
637
+ finalizeTotal(_ref11) {
614
638
  let {
615
639
  row,
616
640
  column
617
- } = _ref10;
641
+ } = _ref11;
618
642
  if (!this.data[row]) {
619
643
  return;
620
644
  }
@@ -710,6 +734,40 @@ export class PivotTableEngine {
710
734
  resetColumnMap() {
711
735
  this.columnMap = this.options.hideEmptyColumns ? times(this.dataWidth, n => n).filter(idx => !this.columnIsEmpty(idx)) : times(this.dataWidth, n => n);
712
736
  }
737
+ resetAccumulators() {
738
+ if (this.options.cumulativeValues) {
739
+ this.rowMap.forEach(row => {
740
+ this.accumulators.rows[row] = {};
741
+ this.columnMap.reduce((acc, column) => {
742
+ const cellType = this.getRawCellType({
743
+ row,
744
+ column
745
+ });
746
+ const dxDimension = this.getRawCellDxDimension({
747
+ row,
748
+ column
749
+ });
750
+ const valueType = (dxDimension === null || dxDimension === void 0 ? void 0 : dxDimension.valueType) || VALUE_TYPE_TEXT;
751
+
752
+ // only accumulate numeric values
753
+ // accumulating text values does not make sense
754
+ if (valueType === VALUE_TYPE_NUMBER) {
755
+ if (this.data[row] && this.data[row][column]) {
756
+ const dataRow = this.data[row][column];
757
+ const rawValue = cellType === CELL_TYPE_VALUE ? dataRow[this.dimensionLookup.dataHeaders.value] : dataRow.value;
758
+ acc += parseValue(rawValue);
759
+ }
760
+ this.accumulators.rows[row][column] = acc;
761
+ }
762
+ return acc;
763
+ }, 0);
764
+ });
765
+ } else {
766
+ this.accumulators = {
767
+ rows: {}
768
+ };
769
+ }
770
+ }
713
771
  get cellPadding() {
714
772
  switch (this.visualization.displayDensity) {
715
773
  case DISPLAY_DENSITY_OPTION_COMPACT:
@@ -780,14 +838,18 @@ export class PivotTableEngine {
780
838
  }
781
839
  });
782
840
  this.finalizeTotals();
783
- this.rawData.rows.forEach(dataRow => {
784
- const pos = lookup(dataRow, this.dimensionLookup, this);
785
- if (pos) {
786
- this.adaptiveClippingController.add(pos, this.getRaw(pos).renderedValue);
787
- }
788
- });
789
841
  this.resetRowMap();
790
842
  this.resetColumnMap();
843
+ this.resetAccumulators();
844
+ this.rowMap.forEach(row => {
845
+ this.columnMap.forEach(column => {
846
+ const pos = {
847
+ row,
848
+ column
849
+ };
850
+ this.adaptiveClippingController.add(pos, this.getRaw(pos).renderedValue);
851
+ });
852
+ });
791
853
  this.height = this.rowMap.length;
792
854
  this.width = this.columnMap.length;
793
855
  this.adaptiveClippingController.finalize();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhis2/analytics",
3
- "version": "26.2.0-alpha.2",
3
+ "version": "26.2.0",
4
4
  "main": "./build/cjs/index.js",
5
5
  "module": "./build/es/index.js",
6
6
  "exports": {
@@ -1,31 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var _AnalyticsBase = _interopRequireDefault(require("./AnalyticsBase.js"));
8
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
- /**
10
- * @extends module:analytics.AnalyticsBase
11
- *
12
- * @description
13
- * Analytics tracked entities class used to request analytics tracked entities data from Web API.
14
- *
15
- * @memberof module:analytics
16
- */
17
- class AnalyticsTrackedEntities extends _AnalyticsBase.default {
18
- /**
19
- * @param {!AnalyticsRequest} req Request object
20
- *
21
- * @returns {Promise} Promise that resolves with the analytics query data from the api.
22
- *
23
- * @example
24
- // TODO: provide working example
25
- */
26
- getQuery(req) {
27
- return this.fetch(req.withPath('trackedEntities/query'));
28
- }
29
- }
30
- var _default = AnalyticsTrackedEntities;
31
- exports.default = _default;
@@ -1,24 +0,0 @@
1
- import AnalyticsBase from './AnalyticsBase.js';
2
-
3
- /**
4
- * @extends module:analytics.AnalyticsBase
5
- *
6
- * @description
7
- * Analytics tracked entities class used to request analytics tracked entities data from Web API.
8
- *
9
- * @memberof module:analytics
10
- */
11
- class AnalyticsTrackedEntities extends AnalyticsBase {
12
- /**
13
- * @param {!AnalyticsRequest} req Request object
14
- *
15
- * @returns {Promise} Promise that resolves with the analytics query data from the api.
16
- *
17
- * @example
18
- // TODO: provide working example
19
- */
20
- getQuery(req) {
21
- return this.fetch(req.withPath('trackedEntities/query'));
22
- }
23
- }
24
- export default AnalyticsTrackedEntities;