@dhis2/analytics 26.2.0-alpha.2 → 26.2.0-cumulative-values-alpha.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.
Files changed (49) 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/__tests__/AnalyticsTrackedEntities.spec.js +44 -0
  8. package/build/cjs/api/analytics/__tests__/__snapshots__/AnalyticsTrackedEntities.spec.js.snap +3 -0
  9. package/build/cjs/api/analytics/utils.js +2 -23
  10. package/build/cjs/components/Options/VisualizationOptions.js +1 -1
  11. package/build/cjs/components/Options/styles/VisualizationOptions.style.js +8 -1
  12. package/build/cjs/components/RichText/Editor.bk/Editor.js +40 -0
  13. package/build/cjs/components/RichText/Editor.bk/__tests__/Editor.spec.js +29 -0
  14. package/build/cjs/components/RichText/Editor.bk/__tests__/convertCtrlKey.spec.js +205 -0
  15. package/build/cjs/components/RichText/Editor.bk/convertCtrlKey.js +87 -0
  16. package/build/cjs/components/RichText/Parser.bk/MdParser.js +107 -0
  17. package/build/cjs/components/RichText/Parser.bk/Parser.js +34 -0
  18. package/build/cjs/components/RichText/Parser.bk/__tests__/MdParser.spec.js +34 -0
  19. package/build/cjs/components/RichText/Parser.bk/__tests__/Parser.spec.js +41 -0
  20. package/build/cjs/modules/layout/dimension.js +2 -9
  21. package/build/cjs/modules/layout/dimensionCreate.js +0 -3
  22. package/build/cjs/modules/pivotTable/PivotTableEngine.js +119 -57
  23. package/build/cjs/visualizations/config/generators/dhis/singleValue.js.xp1 +478 -0
  24. package/build/es/__demo__/PivotTable.stories.js +69 -29
  25. package/build/es/api/analytics/Analytics.js +0 -7
  26. package/build/es/api/analytics/AnalyticsBase.js +6 -24
  27. package/build/es/api/analytics/AnalyticsRequest.js +10 -33
  28. package/build/es/api/analytics/AnalyticsRequestBase.js +1 -3
  29. package/build/es/api/analytics/AnalyticsRequestPropertiesMixin.js +0 -19
  30. package/build/es/api/analytics/__tests__/AnalyticsTrackedEntities.spec.js +41 -0
  31. package/build/es/api/analytics/__tests__/__snapshots__/AnalyticsTrackedEntities.spec.js.snap +3 -0
  32. package/build/es/api/analytics/utils.js +1 -20
  33. package/build/es/components/Options/VisualizationOptions.js +2 -2
  34. package/build/es/components/Options/styles/VisualizationOptions.style.js +6 -0
  35. package/build/es/components/RichText/Editor.bk/Editor.js +30 -0
  36. package/build/es/components/RichText/Editor.bk/__tests__/Editor.spec.js +26 -0
  37. package/build/es/components/RichText/Editor.bk/__tests__/convertCtrlKey.spec.js +202 -0
  38. package/build/es/components/RichText/Editor.bk/convertCtrlKey.js +80 -0
  39. package/build/es/components/RichText/Parser.bk/MdParser.js +99 -0
  40. package/build/es/components/RichText/Parser.bk/Parser.js +24 -0
  41. package/build/es/components/RichText/Parser.bk/__tests__/MdParser.spec.js +31 -0
  42. package/build/es/components/RichText/Parser.bk/__tests__/Parser.spec.js +38 -0
  43. package/build/es/modules/layout/dimension.js +1 -7
  44. package/build/es/modules/layout/dimensionCreate.js +1 -4
  45. package/build/es/modules/pivotTable/PivotTableEngine.js +119 -57
  46. package/build/es/visualizations/config/generators/dhis/singleValue.js.xp1 +478 -0
  47. package/package.json +1 -1
  48. package/build/cjs/api/analytics/AnalyticsTrackedEntities.js +0 -31
  49. package/build/es/api/analytics/AnalyticsTrackedEntities.js +0 -24
@@ -27,7 +27,8 @@ const defaultOptions = {
27
27
  showRowSubtotals: false,
28
28
  showColumnSubtotals: false,
29
29
  fixColumnHeaders: false,
30
- fixRowHeaders: false
30
+ fixRowHeaders: false,
31
+ cumulativeValues: false
31
32
  };
32
33
  const defaultVisualizationProps = {
33
34
  fontSize: _pivotTableConstants.FONT_SIZE_OPTION_NORMAL,
@@ -182,6 +183,9 @@ class PivotTableEngine {
182
183
  _defineProperty(this, "data", []);
183
184
  _defineProperty(this, "rowMap", []);
184
185
  _defineProperty(this, "columnMap", []);
186
+ _defineProperty(this, "accumulators", {
187
+ rows: {}
188
+ });
185
189
  this.visualization = Object.assign({}, defaultVisualizationProps, visualization);
186
190
  this.legendSets = (legendSets || []).reduce((sets, set) => {
187
191
  sets[set.id] = set;
@@ -201,7 +205,8 @@ class PivotTableEngine {
201
205
  subtitle: visualization.hideSubtitle ? undefined : visualization.subtitle,
202
206
  // turn on fixed headers only when there are dimensions
203
207
  fixColumnHeaders: this.dimensionLookup.columns.length ? visualization.fixColumnHeaders : false,
204
- fixRowHeaders: this.dimensionLookup.rows.length ? visualization.fixRowHeaders : false
208
+ fixRowHeaders: this.dimensionLookup.rows.length ? visualization.fixRowHeaders : false,
209
+ cumulativeValues: visualization.cumulativeValues
205
210
  };
206
211
  this.adaptiveClippingController = new _AdaptiveClippingController.AdaptiveClippingController(this);
207
212
  const doColumnSubtotals = this.options.showColumnSubtotals && this.dimensionLookup.rows.length > 1;
@@ -225,51 +230,68 @@ class PivotTableEngine {
225
230
  row,
226
231
  column
227
232
  });
233
+ const valueType = (dxDimension === null || dxDimension === void 0 ? void 0 : dxDimension.valueType) || _valueTypes.VALUE_TYPE_TEXT;
228
234
  const headers = [...this.getRawRowHeader(row), ...this.getRawColumnHeader(column)];
229
235
  const peId = (_headers$find = headers.find(header => (header === null || header === void 0 ? void 0 : header.dimensionItemType) === _dataTypes.DIMENSION_TYPE_PERIOD)) === null || _headers$find === void 0 ? void 0 : _headers$find.uid;
230
236
  const ouId = (_headers$find2 = headers.find(header => (header === null || header === void 0 ? void 0 : header.dimensionItemType) === _dataTypes.DIMENSION_TYPE_ORGANISATION_UNIT)) === null || _headers$find2 === void 0 ? void 0 : _headers$find2.uid;
231
- if (!this.data[row] || !this.data[row][column]) {
232
- return {
233
- cellType,
234
- empty: true,
235
- ouId,
236
- peId
237
- };
238
- }
239
- const dataRow = this.data[row][column];
240
- let rawValue = cellType === _pivotTableConstants.CELL_TYPE_VALUE ? dataRow[this.dimensionLookup.dataHeaders.value] : dataRow.value;
241
- let renderedValue = rawValue;
242
- const valueType = (dxDimension === null || dxDimension === void 0 ? void 0 : dxDimension.valueType) || _valueTypes.VALUE_TYPE_TEXT;
243
- if (valueType === _valueTypes.VALUE_TYPE_NUMBER) {
244
- rawValue = (0, _parseValue.parseValue)(rawValue);
245
- switch (this.visualization.numberType) {
246
- case _pivotTableConstants.NUMBER_TYPE_ROW_PERCENTAGE:
247
- renderedValue = rawValue / this.percentageTotals[row].value;
248
- break;
249
- case _pivotTableConstants.NUMBER_TYPE_COLUMN_PERCENTAGE:
250
- renderedValue = rawValue / this.percentageTotals[column].value;
251
- break;
252
- default:
253
- break;
254
- }
255
- }
256
- renderedValue = (0, _renderValue.renderValue)(renderedValue, valueType, this.visualization);
257
- return {
237
+ const rawCell = {
258
238
  cellType,
259
- empty: false,
260
239
  valueType,
261
- rawValue,
262
- renderedValue,
263
- dxDimension,
264
240
  ouId,
265
241
  peId
266
242
  };
243
+ if (!this.data[row] || !this.data[row][column]) {
244
+ rawCell.empty = true;
245
+ } else {
246
+ const dataRow = this.data[row][column];
247
+ let rawValue = cellType === _pivotTableConstants.CELL_TYPE_VALUE ? dataRow[this.dimensionLookup.dataHeaders.value] : dataRow.value;
248
+ let renderedValue = rawValue;
249
+ if (valueType === _valueTypes.VALUE_TYPE_NUMBER) {
250
+ rawValue = (0, _parseValue.parseValue)(rawValue);
251
+ switch (this.visualization.numberType) {
252
+ case _pivotTableConstants.NUMBER_TYPE_ROW_PERCENTAGE:
253
+ renderedValue = rawValue / this.percentageTotals[row].value;
254
+ break;
255
+ case _pivotTableConstants.NUMBER_TYPE_COLUMN_PERCENTAGE:
256
+ renderedValue = rawValue / this.percentageTotals[column].value;
257
+ break;
258
+ default:
259
+ break;
260
+ }
261
+ }
262
+ renderedValue = (0, _renderValue.renderValue)(renderedValue, valueType, this.visualization);
263
+ rawCell.dxDimension = dxDimension;
264
+ rawCell.empty = false;
265
+ rawCell.rawValue = rawValue;
266
+ rawCell.renderedValue = renderedValue;
267
+ }
268
+ if (this.options.cumulativeValues) {
269
+ const cumulativeValue = this.getCumulative({
270
+ row,
271
+ column
272
+ });
273
+ if (cumulativeValue !== undefined && cumulativeValue !== null) {
274
+ // force to NUMBER for accumulated values
275
+ rawCell.valueType = valueType === undefined || valueType === null ? _valueTypes.VALUE_TYPE_NUMBER : valueType;
276
+ rawCell.empty = false;
277
+ rawCell.rawValue = cumulativeValue;
278
+ rawCell.renderedValue = (0, _renderValue.renderValue)(cumulativeValue, valueType, this.visualization);
279
+ }
280
+ }
281
+ return rawCell;
267
282
  }
268
- get(_ref4) {
283
+ getCumulative(_ref4) {
269
284
  let {
270
285
  row,
271
286
  column
272
287
  } = _ref4;
288
+ return this.accumulators.rows[row][column];
289
+ }
290
+ get(_ref5) {
291
+ let {
292
+ row,
293
+ column
294
+ } = _ref5;
273
295
  const mappedRow = this.rowMap[row],
274
296
  mappedColumn = this.columnMap[column];
275
297
  if (!mappedRow && mappedRow !== 0 || !mappedColumn && mappedColumn !== 0) {
@@ -280,11 +302,11 @@ class PivotTableEngine {
280
302
  column: mappedColumn
281
303
  });
282
304
  }
283
- getRawCellType(_ref5) {
305
+ getRawCellType(_ref6) {
284
306
  let {
285
307
  row,
286
308
  column
287
- } = _ref5;
309
+ } = _ref6;
288
310
  const isRowTotal = this.doRowTotals && column === this.dataWidth - 1;
289
311
  const isColumnTotal = this.doColumnTotals && row === this.dataHeight - 1;
290
312
  if (isRowTotal || isColumnTotal) {
@@ -297,11 +319,11 @@ class PivotTableEngine {
297
319
  }
298
320
  return _pivotTableConstants.CELL_TYPE_VALUE;
299
321
  }
300
- getCellType(_ref6) {
322
+ getCellType(_ref7) {
301
323
  let {
302
324
  row,
303
325
  column
304
- } = _ref6;
326
+ } = _ref7;
305
327
  row = this.rowMap[row];
306
328
  column = this.columnMap[column];
307
329
  return this.getRawCellType({
@@ -331,29 +353,26 @@ class PivotTableEngine {
331
353
  return _d2I18n.default.t(this.dimensionLookup.rows[rowLevel].meta.name);
332
354
  }
333
355
  }
334
- getCellDxDimension(_ref7) {
356
+ getCellDxDimension(_ref8) {
335
357
  let {
336
358
  row,
337
359
  column
338
- } = _ref7;
360
+ } = _ref8;
339
361
  return this.getRawCellDxDimension({
340
362
  row: this.rowMap[row],
341
363
  column: this.columnMap[column]
342
364
  });
343
365
  }
344
- getRawCellDxDimension(_ref8) {
366
+ getRawCellDxDimension(_ref9) {
345
367
  let {
346
368
  row,
347
369
  column
348
- } = _ref8;
370
+ } = _ref9;
349
371
  if (!this.data[row]) {
350
372
  return undefined;
351
373
  }
352
374
  const cellValue = this.data[row][column];
353
- if (!cellValue) {
354
- return undefined;
355
- }
356
- if (!Array.isArray(cellValue)) {
375
+ if (cellValue && !Array.isArray(cellValue)) {
357
376
  // This is a total cell
358
377
  return {
359
378
  valueType: cellValue.valueType,
@@ -380,6 +399,11 @@ class PivotTableEngine {
380
399
  };
381
400
  }
382
401
 
402
+ // Empty cell
403
+ // The cell still needs to get the valueType to render correctly 0 and cumulative values
404
+ //
405
+ // OR
406
+ //
383
407
  // Data is in Filter
384
408
  // TODO : This assumes the server ignores text types, we should confirm this is the case
385
409
  return {
@@ -391,7 +415,7 @@ class PivotTableEngine {
391
415
  return !this.data[row] || this.data[row].length === 0;
392
416
  }
393
417
  columnIsEmpty(column) {
394
- return !this.adaptiveClippingController.columns.sizes[column];
418
+ return !this.rowMap.some(row => this.data[row][column]);
395
419
  }
396
420
  getRawColumnHeader(column) {
397
421
  if (this.doRowTotals && column === this.dataWidth - 1) {
@@ -437,12 +461,12 @@ class PivotTableEngine {
437
461
  getRowHeader(row) {
438
462
  return this.getRawRowHeader(this.rowMap[row]);
439
463
  }
440
- getDependantTotalCells(_ref9) {
464
+ getDependantTotalCells(_ref10) {
441
465
  var _this$dimensionLookup, _this$dimensionLookup2;
442
466
  let {
443
467
  row,
444
468
  column
445
- } = _ref9;
469
+ } = _ref10;
446
470
  const rowSubtotalSize = ((_this$dimensionLookup = this.dimensionLookup.columns[0]) === null || _this$dimensionLookup === void 0 ? void 0 : _this$dimensionLookup.size) + 1;
447
471
  const rowSubtotal = rowSubtotalSize && this.doRowSubtotals && {
448
472
  row,
@@ -617,11 +641,11 @@ class PivotTableEngine {
617
641
  }
618
642
  }
619
643
  }
620
- finalizeTotal(_ref10) {
644
+ finalizeTotal(_ref11) {
621
645
  let {
622
646
  row,
623
647
  column
624
- } = _ref10;
648
+ } = _ref11;
625
649
  if (!this.data[row]) {
626
650
  return;
627
651
  }
@@ -717,6 +741,40 @@ class PivotTableEngine {
717
741
  resetColumnMap() {
718
742
  this.columnMap = this.options.hideEmptyColumns ? (0, _times.default)(this.dataWidth, n => n).filter(idx => !this.columnIsEmpty(idx)) : (0, _times.default)(this.dataWidth, n => n);
719
743
  }
744
+ resetAccumulators() {
745
+ if (this.options.cumulativeValues) {
746
+ this.rowMap.forEach(row => {
747
+ this.accumulators.rows[row] = {};
748
+ this.columnMap.reduce((acc, column) => {
749
+ const cellType = this.getRawCellType({
750
+ row,
751
+ column
752
+ });
753
+ const dxDimension = this.getRawCellDxDimension({
754
+ row,
755
+ column
756
+ });
757
+ const valueType = (dxDimension === null || dxDimension === void 0 ? void 0 : dxDimension.valueType) || _valueTypes.VALUE_TYPE_TEXT;
758
+
759
+ // only accumulate numeric values
760
+ // accumulating text values does not make sense
761
+ if (valueType === _valueTypes.VALUE_TYPE_NUMBER) {
762
+ if (this.data[row] && this.data[row][column]) {
763
+ const dataRow = this.data[row][column];
764
+ const rawValue = cellType === _pivotTableConstants.CELL_TYPE_VALUE ? dataRow[this.dimensionLookup.dataHeaders.value] : dataRow.value;
765
+ acc += (0, _parseValue.parseValue)(rawValue);
766
+ }
767
+ this.accumulators.rows[row][column] = acc;
768
+ }
769
+ return acc;
770
+ }, 0);
771
+ });
772
+ } else {
773
+ this.accumulators = {
774
+ rows: {}
775
+ };
776
+ }
777
+ }
720
778
  get cellPadding() {
721
779
  switch (this.visualization.displayDensity) {
722
780
  case _pivotTableConstants.DISPLAY_DENSITY_OPTION_COMPACT:
@@ -787,14 +845,18 @@ class PivotTableEngine {
787
845
  }
788
846
  });
789
847
  this.finalizeTotals();
790
- this.rawData.rows.forEach(dataRow => {
791
- const pos = lookup(dataRow, this.dimensionLookup, this);
792
- if (pos) {
793
- this.adaptiveClippingController.add(pos, this.getRaw(pos).renderedValue);
794
- }
795
- });
796
848
  this.resetRowMap();
797
849
  this.resetColumnMap();
850
+ this.resetAccumulators();
851
+ this.rowMap.forEach(row => {
852
+ this.columnMap.forEach(column => {
853
+ const pos = {
854
+ row,
855
+ column
856
+ };
857
+ this.adaptiveClippingController.add(pos, this.getRaw(pos).renderedValue);
858
+ });
859
+ });
798
860
  this.height = this.rowMap.length;
799
861
  this.width = this.columnMap.length;
800
862
  this.adaptiveClippingController.finalize();