@hisptz/dhis2-analytics 1.0.9 → 1.0.11

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 (162) hide show
  1. package/build/cjs/components/ChartAnalytics/ChartAnalytics.stories.js +6 -6
  2. package/build/cjs/components/ChartAnalytics/components/DownloadMenu/index.js +2 -4
  3. package/build/cjs/components/ChartAnalytics/index.js +25 -17
  4. package/build/cjs/components/CircularProgressDashboard/CircularProgressIndicator.stories.js +1 -1
  5. package/build/cjs/components/Map/Map.stories.js +1 -1
  6. package/build/cjs/components/Map/components/EarthEngineLayerConfiguration/EarthEngineLayerConfigModal.stories.js +1 -1
  7. package/build/cjs/components/Map/components/EarthEngineLayerConfiguration/EarthEngineLayerConfiguration.stories.js +1 -1
  8. package/build/cjs/components/Map/components/MapLayer/components/GoogleEngineLayer/services/engine.js +3 -12
  9. package/build/cjs/components/Map/components/MapProvider/components/MapLayerProvider/hooks/index.js +8 -1
  10. package/build/cjs/components/Map/components/ThematicLayerConfiguration/ThematicLayerConfigModal.stories.js +1 -1
  11. package/build/cjs/components/Map/components/ThematicLayerConfiguration/ThematicLayerConfiguration.stories.js +1 -1
  12. package/build/cjs/components/PivotTable/PivotTable.stories.js +277 -0
  13. package/build/cjs/components/PivotTable/components/AssignedCategoriesIcon/index.js +32 -0
  14. package/build/cjs/components/PivotTable/components/PivotTable.js +60 -0
  15. package/build/cjs/components/PivotTable/components/PivotTableBody.js +41 -0
  16. package/build/cjs/components/PivotTable/components/PivotTableCell.js +40 -0
  17. package/build/cjs/components/PivotTable/components/PivotTableClippedAxis.js +26 -0
  18. package/build/cjs/components/PivotTable/components/PivotTableColumnHeaderCell.js +71 -0
  19. package/build/cjs/components/PivotTable/components/PivotTableColumnHeaders.js +60 -0
  20. package/build/cjs/components/PivotTable/components/PivotTableContainer.js +33 -0
  21. package/build/cjs/components/PivotTable/components/PivotTableDimensionLabelCell.js +77 -0
  22. package/build/cjs/components/PivotTable/components/PivotTableEmptyCell.js +22 -0
  23. package/build/cjs/components/PivotTable/components/PivotTableEmptyRow.js +33 -0
  24. package/build/cjs/components/PivotTable/components/PivotTableEngineContext.js +25 -0
  25. package/build/cjs/components/PivotTable/components/PivotTableHead.js +35 -0
  26. package/build/cjs/components/PivotTable/components/PivotTableHeaderCell.js +37 -0
  27. package/build/cjs/components/PivotTable/components/PivotTableRow.js +65 -0
  28. package/build/cjs/components/PivotTable/components/PivotTableRowHeaderCell.js +49 -0
  29. package/build/cjs/components/PivotTable/components/PivotTableTitleRow.js +52 -0
  30. package/build/cjs/components/PivotTable/components/PivotTableTitleRows.js +46 -0
  31. package/build/cjs/components/PivotTable/components/PivotTableValueCell.js +69 -0
  32. package/build/cjs/components/PivotTable/constants/dataTypes.js +129 -0
  33. package/build/cjs/components/PivotTable/constants/pivotTable.js +64 -0
  34. package/build/cjs/components/PivotTable/constants/predefinedDimensions.js +62 -0
  35. package/build/cjs/components/PivotTable/constants/valueTypes.js +55 -0
  36. package/build/cjs/components/PivotTable/data/column-data.json +210 -0
  37. package/build/cjs/components/PivotTable/hooks/useParentSize.js +41 -0
  38. package/build/cjs/components/PivotTable/hooks/useScrollPosition.js +38 -0
  39. package/build/cjs/components/PivotTable/hooks/useSortableColumns.js +34 -0
  40. package/build/cjs/components/PivotTable/hooks/useTableClipping.js +53 -0
  41. package/build/cjs/components/PivotTable/index.js +47 -0
  42. package/build/cjs/components/PivotTable/interfaces/index.js +1 -0
  43. package/build/cjs/components/PivotTable/services/adaptiveClippingController.js +197 -0
  44. package/build/cjs/components/PivotTable/services/engine.js +901 -0
  45. package/build/cjs/components/PivotTable/utils/getOuLevelAndGroupText.js +71 -0
  46. package/build/cjs/components/PivotTable/utils/index.js +322 -0
  47. package/build/cjs/components/PivotTable/utils/isColorBright.js +29 -0
  48. package/build/cjs/components/PivotTable/utils/layout/dimension.js +61 -0
  49. package/build/cjs/components/PivotTable/utils/layout/dimensionGetId.js +12 -0
  50. package/build/cjs/components/PivotTable/utils/layout/dimensionGetItems.js +12 -0
  51. package/build/cjs/components/PivotTable/utils/layout/dimensionIs.js +9 -0
  52. package/build/cjs/components/PivotTable/utils/layout/dimensionIsEmpty.js +9 -0
  53. package/build/cjs/components/PivotTable/utils/layout/dimensionIsValid.js +25 -0
  54. package/build/cjs/components/PivotTable/utils/legend.js +40 -0
  55. package/build/cjs/components/PivotTable/utils/ouIdHelper/index.js +27 -0
  56. package/build/cjs/components/SingleValueContainer/SingleValueContainer.stories.js +1 -1
  57. package/build/cjs/index.js +11 -0
  58. package/build/cjs/locales/en/translations.json +33 -0
  59. package/build/es/components/ChartAnalytics/ChartAnalytics.stories.js +3 -3
  60. package/build/es/components/ChartAnalytics/components/DownloadMenu/index.js +2 -3
  61. package/build/es/components/ChartAnalytics/index.js +2 -3
  62. package/build/es/components/CircularProgressDashboard/CircularProgressIndicator.stories.js +1 -1
  63. package/build/es/components/Map/Map.stories.js +1 -1
  64. package/build/es/components/Map/components/EarthEngineLayerConfiguration/EarthEngineLayerConfigModal.stories.js +1 -1
  65. package/build/es/components/Map/components/EarthEngineLayerConfiguration/EarthEngineLayerConfiguration.stories.js +1 -1
  66. package/build/es/components/Map/components/MapLayer/components/GoogleEngineLayer/services/engine.js +9 -8
  67. package/build/es/components/Map/components/MapProvider/components/MapLayerProvider/hooks/index.js +8 -1
  68. package/build/es/components/Map/components/ThematicLayerConfiguration/ThematicLayerConfigModal.stories.js +1 -1
  69. package/build/es/components/Map/components/ThematicLayerConfiguration/ThematicLayerConfiguration.stories.js +1 -1
  70. package/build/es/components/PivotTable/PivotTable.stories.js +268 -0
  71. package/build/es/components/PivotTable/components/AssignedCategoriesIcon/index.js +24 -0
  72. package/build/es/components/PivotTable/components/PivotTable.js +51 -0
  73. package/build/es/components/PivotTable/components/PivotTableBody.js +33 -0
  74. package/build/es/components/PivotTable/components/PivotTableCell.js +32 -0
  75. package/build/es/components/PivotTable/components/PivotTableClippedAxis.js +18 -0
  76. package/build/es/components/PivotTable/components/PivotTableColumnHeaderCell.js +62 -0
  77. package/build/es/components/PivotTable/components/PivotTableColumnHeaders.js +52 -0
  78. package/build/es/components/PivotTable/components/PivotTableContainer.js +25 -0
  79. package/build/es/components/PivotTable/components/PivotTableDimensionLabelCell.js +68 -0
  80. package/build/es/components/PivotTable/components/PivotTableEmptyCell.js +14 -0
  81. package/build/es/components/PivotTable/components/PivotTableEmptyRow.js +25 -0
  82. package/build/es/components/PivotTable/components/PivotTableEngineContext.js +14 -0
  83. package/build/es/components/PivotTable/components/PivotTableHead.js +27 -0
  84. package/build/es/components/PivotTable/components/PivotTableHeaderCell.js +29 -0
  85. package/build/es/components/PivotTable/components/PivotTableRow.js +57 -0
  86. package/build/es/components/PivotTable/components/PivotTableRowHeaderCell.js +41 -0
  87. package/build/es/components/PivotTable/components/PivotTableTitleRow.js +42 -0
  88. package/build/es/components/PivotTable/components/PivotTableTitleRows.js +37 -0
  89. package/build/es/components/PivotTable/components/PivotTableValueCell.js +60 -0
  90. package/build/es/components/PivotTable/constants/dataTypes.js +98 -0
  91. package/build/es/components/PivotTable/constants/pivotTable.js +29 -0
  92. package/build/es/components/PivotTable/constants/predefinedDimensions.js +44 -0
  93. package/build/es/components/PivotTable/constants/valueTypes.js +27 -0
  94. package/build/es/components/PivotTable/data/column-data.json +210 -0
  95. package/build/es/components/PivotTable/hooks/useParentSize.js +33 -0
  96. package/build/es/components/PivotTable/hooks/useScrollPosition.js +30 -0
  97. package/build/es/components/PivotTable/hooks/useSortableColumns.js +27 -0
  98. package/build/es/components/PivotTable/hooks/useTableClipping.js +46 -0
  99. package/build/es/components/PivotTable/index.js +26 -0
  100. package/build/es/components/PivotTable/interfaces/index.js +1 -0
  101. package/build/es/components/PivotTable/services/adaptiveClippingController.js +191 -0
  102. package/build/es/components/PivotTable/services/engine.js +894 -0
  103. package/build/es/components/PivotTable/utils/getOuLevelAndGroupText.js +63 -0
  104. package/build/es/components/PivotTable/utils/index.js +309 -0
  105. package/build/es/components/PivotTable/utils/isColorBright.js +22 -0
  106. package/build/es/components/PivotTable/utils/layout/dimension.js +48 -0
  107. package/build/es/components/PivotTable/utils/layout/dimensionGetId.js +5 -0
  108. package/build/es/components/PivotTable/utils/layout/dimensionGetItems.js +5 -0
  109. package/build/es/components/PivotTable/utils/layout/dimensionIs.js +2 -0
  110. package/build/es/components/PivotTable/utils/layout/dimensionIsEmpty.js +2 -0
  111. package/build/es/components/PivotTable/utils/layout/dimensionIsValid.js +18 -0
  112. package/build/es/components/PivotTable/utils/legend.js +27 -0
  113. package/build/es/components/PivotTable/utils/ouIdHelper/index.js +17 -0
  114. package/build/es/components/SingleValueContainer/SingleValueContainer.stories.js +1 -1
  115. package/build/es/index.js +1 -0
  116. package/build/es/locales/en/translations.json +33 -0
  117. package/build/types/components/ChartAnalytics/components/DownloadMenu/index.d.ts +1 -2
  118. package/build/types/components/ChartAnalytics/index.d.ts +3 -3
  119. package/build/types/components/PivotTable/components/AssignedCategoriesIcon/index.d.ts +3 -0
  120. package/build/types/components/PivotTable/components/PivotTable.d.ts +12 -0
  121. package/build/types/components/PivotTable/components/PivotTableBody.d.ts +7 -0
  122. package/build/types/components/PivotTable/components/PivotTableCell.d.ts +17 -0
  123. package/build/types/components/PivotTable/components/PivotTableClippedAxis.d.ts +7 -0
  124. package/build/types/components/PivotTable/components/PivotTableColumnHeaderCell.d.ts +13 -0
  125. package/build/types/components/PivotTable/components/PivotTableColumnHeaders.d.ts +11 -0
  126. package/build/types/components/PivotTable/components/PivotTableContainer.d.ts +8 -0
  127. package/build/types/components/PivotTable/components/PivotTableDimensionLabelCell.d.ts +13 -0
  128. package/build/types/components/PivotTable/components/PivotTableEmptyCell.d.ts +7 -0
  129. package/build/types/components/PivotTable/components/PivotTableEmptyRow.d.ts +5 -0
  130. package/build/types/components/PivotTable/components/PivotTableEngineContext.d.ts +8 -0
  131. package/build/types/components/PivotTable/components/PivotTableHead.d.ts +21 -0
  132. package/build/types/components/PivotTable/components/PivotTableHeaderCell.d.ts +22 -0
  133. package/build/types/components/PivotTable/components/PivotTableRow.d.ts +19 -0
  134. package/build/types/components/PivotTable/components/PivotTableRowHeaderCell.d.ts +8 -0
  135. package/build/types/components/PivotTable/components/PivotTableTitleRow.d.ts +21 -0
  136. package/build/types/components/PivotTable/components/PivotTableTitleRows.d.ts +12 -0
  137. package/build/types/components/PivotTable/components/PivotTableValueCell.d.ts +8 -0
  138. package/build/types/components/PivotTable/constants/dataTypes.d.ts +90 -0
  139. package/build/types/components/PivotTable/constants/pivotTable.d.ts +29 -0
  140. package/build/types/components/PivotTable/constants/predefinedDimensions.d.ts +80 -0
  141. package/build/types/components/PivotTable/constants/valueTypes.d.ts +22 -0
  142. package/build/types/components/PivotTable/hooks/useParentSize.d.ts +8 -0
  143. package/build/types/components/PivotTable/hooks/useScrollPosition.d.ts +5 -0
  144. package/build/types/components/PivotTable/hooks/useSortableColumns.d.ts +8 -0
  145. package/build/types/components/PivotTable/hooks/useTableClipping.d.ts +24 -0
  146. package/build/types/components/PivotTable/index.d.ts +26 -0
  147. package/build/types/components/PivotTable/interfaces/index.d.ts +72 -0
  148. package/build/types/components/PivotTable/services/adaptiveClippingController.d.ts +44 -0
  149. package/build/types/components/PivotTable/services/engine.d.ts +252 -0
  150. package/build/types/components/PivotTable/utils/getOuLevelAndGroupText.d.ts +1 -0
  151. package/build/types/components/PivotTable/utils/index.d.ts +38 -0
  152. package/build/types/components/PivotTable/utils/isColorBright.d.ts +1 -0
  153. package/build/types/components/PivotTable/utils/layout/dimension.d.ts +35 -0
  154. package/build/types/components/PivotTable/utils/layout/dimensionGetId.d.ts +3 -0
  155. package/build/types/components/PivotTable/utils/layout/dimensionGetItems.d.ts +3 -0
  156. package/build/types/components/PivotTable/utils/layout/dimensionIs.d.ts +1 -0
  157. package/build/types/components/PivotTable/utils/layout/dimensionIsEmpty.d.ts +3 -0
  158. package/build/types/components/PivotTable/utils/layout/dimensionIsValid.d.ts +5 -0
  159. package/build/types/components/PivotTable/utils/legend.d.ts +11 -0
  160. package/build/types/components/PivotTable/utils/ouIdHelper/index.d.ts +10 -0
  161. package/build/types/index.d.ts +1 -0
  162. package/package.json +6 -3
@@ -0,0 +1,62 @@
1
+ // @ts-nocheck
2
+ import React from 'react';
3
+ import { PivotTableCell } from './PivotTableCell';
4
+ import { usePivotTableEngine } from './PivotTableEngineContext';
5
+ import { PivotTableHeaderCell } from './PivotTableHeaderCell';
6
+ export const PivotTableColumnHeaderCell = _ref => {
7
+ var _engine$adaptiveClipp;
8
+ let {
9
+ clippingResult,
10
+ index,
11
+ level,
12
+ onSortByColumn,
13
+ sortBy
14
+ } = _ref;
15
+ const engine = usePivotTableEngine();
16
+ if (!engine) {
17
+ return null;
18
+ }
19
+ const width = (_engine$adaptiveClipp = engine.adaptiveClippingController.columns.sizes[engine.columnMap[index]]) === null || _engine$adaptiveClipp === void 0 ? void 0 : _engine$adaptiveClipp.size;
20
+ const height = engine.adaptiveClippingController.rows.headerSizes[level];
21
+ return /*#__PURE__*/React.createElement(PivotTableHeaderCell, {
22
+ axisClippingResult: clippingResult.columns,
23
+ index: index,
24
+ level: level,
25
+ getHeader: idx => engine.getColumnHeader(idx),
26
+ showHierarchy: engine.visualization.showHierarchy,
27
+ render: header => {
28
+ const isSortable = level === engine.columnDepth - 1 && header.span === 1 && engine.isSortable(index);
29
+ const style = {
30
+ cursor: isSortable ? "pointer" : "default",
31
+ width,
32
+ height,
33
+ whiteSpace: level === engine.columnDepth - 1 ? "pre-line" : "nowrap"
34
+ };
35
+ if (engine.options.fixColumnHeaders) {
36
+ style.top = level * (engine.fontSize + engine.cellPadding * 2 + 2);
37
+ // left value for the column header cells should be sum of row headers' width when engine.options.fixRowHeaders is true
38
+ style.left = engine.options.fixRowHeaders ? engine.rowHeaderPixelWidth : 0;
39
+ }
40
+ return /*#__PURE__*/React.createElement(PivotTableCell, {
41
+ index: index,
42
+ isSortable: isSortable,
43
+ sortOrder: sortBy,
44
+ onSortClick: isSortable ? () => onSortByColumn(index) : undefined,
45
+ isHeader: true,
46
+ classes: [header.label && header.label !== "Total" && header.label !== "Subtotal" // TODO: Actually look up the column type!
47
+ ? "column-header" : "empty-header", {
48
+ "fixed-header": engine.options.fixColumnHeaders
49
+ }],
50
+ colSpan: header.span,
51
+ title: header.label,
52
+ style: style,
53
+ onClick: isSortable ? () => onSortByColumn(index) : undefined
54
+ }, /*#__PURE__*/React.createElement("div", {
55
+ className: "column-header-inner"
56
+ }, /*#__PURE__*/React.createElement("span", {
57
+ className: "column-header-label",
58
+ "data-test": "visualization-column-header"
59
+ }, header.label)));
60
+ }
61
+ });
62
+ };
@@ -0,0 +1,52 @@
1
+ import times from 'lodash/times';
2
+ import React from 'react';
3
+ import { PivotTableClippedAxis } from './PivotTableClippedAxis';
4
+ import { PivotTableColumnHeaderCell } from './PivotTableColumnHeaderCell';
5
+ import { PivotTableDimensionLabelCell } from './PivotTableDimensionLabelCell';
6
+ import { PivotTableEmptyCell } from './PivotTableEmptyCell';
7
+ import { usePivotTableEngine } from './PivotTableEngineContext';
8
+ export const PivotTableColumnHeaders = _ref => {
9
+ let {
10
+ clippingResult,
11
+ onSortByColumn,
12
+ sortBy
13
+ } = _ref;
14
+ const engine = usePivotTableEngine();
15
+ if (!engine) {
16
+ return null;
17
+ }
18
+ const columns = times(engine.columnDepth, x => x);
19
+ const rows = times(engine.rowDepth, x => x);
20
+ return /*#__PURE__*/React.createElement(React.Fragment, null, columns.map(columnLevel => /*#__PURE__*/React.createElement("tr", {
21
+ key: columnLevel
22
+ }, rows.map(rowLevel => /*#__PURE__*/React.createElement(PivotTableDimensionLabelCell, {
23
+ key: rowLevel,
24
+ rowLevel: rowLevel,
25
+ columnLevel: columnLevel
26
+ })), /*#__PURE__*/React.createElement(PivotTableClippedAxis, {
27
+ axisClippingResult: clippingResult.columns,
28
+ EmptyComponent: _ref2 => {
29
+ let {
30
+ size
31
+ } = _ref2;
32
+ return /*#__PURE__*/React.createElement(PivotTableEmptyCell, {
33
+ classes: "column-header",
34
+ style: {
35
+ minWidth: size
36
+ }
37
+ });
38
+ },
39
+ ItemComponent: _ref3 => {
40
+ let {
41
+ index
42
+ } = _ref3;
43
+ return /*#__PURE__*/React.createElement(PivotTableColumnHeaderCell, {
44
+ clippingResult: clippingResult,
45
+ index: index,
46
+ level: columnLevel,
47
+ onSortByColumn: onSortByColumn,
48
+ sortBy: sortBy
49
+ });
50
+ }
51
+ }))));
52
+ };
@@ -0,0 +1,25 @@
1
+ import React from 'react';
2
+ import { usePivotTableEngine } from './PivotTableEngineContext';
3
+ import { DataTable } from '@dhis2/ui';
4
+ export const PivotTableContainer = /*#__PURE__*/React.forwardRef((_ref, ref) => {
5
+ let {
6
+ width,
7
+ height,
8
+ children,
9
+ tableProps
10
+ } = _ref;
11
+ const engine = usePivotTableEngine();
12
+ if (!engine) {
13
+ return null;
14
+ }
15
+ return /*#__PURE__*/React.createElement("div", {
16
+ className: "pivot-table-container",
17
+ style: {
18
+ width,
19
+ height
20
+ },
21
+ ref: ref,
22
+ "data-test": "visualization-container"
23
+ }, width === 0 || height === 0 ? null : /*#__PURE__*/React.createElement(DataTable, tableProps !== null && tableProps !== void 0 ? tableProps : {}, children));
24
+ });
25
+ PivotTableContainer.displayName = "PivotTableContainer";
@@ -0,0 +1,68 @@
1
+ // @ts-nocheck
2
+ import PropTypes from 'prop-types';
3
+ import React from 'react';
4
+ import { PivotTableCell } from './PivotTableCell';
5
+ import { usePivotTableEngine } from './PivotTableEngineContext';
6
+ export const PivotTableDimensionLabelCell = _ref => {
7
+ let {
8
+ rowLevel,
9
+ columnLevel
10
+ } = _ref;
11
+ const engine = usePivotTableEngine();
12
+ if (!engine) {
13
+ return null;
14
+ }
15
+ const colCount = engine.rowDepth;
16
+ const rowCount = engine.columnDepth;
17
+ let colSpan = 1,
18
+ rowSpan = 1,
19
+ label;
20
+ if (!engine.visualization.showDimensionLabels) {
21
+ if (rowLevel > 0 || columnLevel > 0) {
22
+ colSpan = rowSpan = 0;
23
+ } else {
24
+ colSpan = colCount;
25
+ rowSpan = rowCount;
26
+ }
27
+ } else {
28
+ label = engine.getDimensionLabel(rowLevel, columnLevel);
29
+ if (!label) {
30
+ if (rowLevel > 0 || columnLevel > 0) {
31
+ colSpan = rowSpan = 0;
32
+ } else {
33
+ colSpan = colCount - 1;
34
+ rowSpan = rowCount - 1;
35
+ }
36
+ }
37
+ }
38
+ if (!colSpan || !rowSpan) {
39
+ return null;
40
+ }
41
+ const width = engine.adaptiveClippingController.columns.headerSizes[rowLevel];
42
+ const height = engine.adaptiveClippingController.rows.headerSizes[columnLevel];
43
+ const style = {
44
+ width,
45
+ height
46
+ };
47
+ if (engine.options.fixColumnHeaders || engine.options.fixRowHeaders) {
48
+ style.zIndex = engine.options.fixColumnHeaders && engine.options.fixRowHeaders ? 2 : 1;
49
+ style.top = engine.options.fixColumnHeaders ? columnLevel * (engine.fontSize + engine.cellPadding * 2 + 2) : 0;
50
+ style.left = engine.options.fixRowHeaders ?
51
+ // calculate the width of all row header cells on the left of current cell
52
+ engine.adaptiveClippingController.columns.headerSizes.slice(0, rowLevel).reduce((width, acc) => acc += width, 0) : 0;
53
+ }
54
+ return /*#__PURE__*/React.createElement(PivotTableCell, {
55
+ isHeader: true,
56
+ classes: ["empty-header", "column-header", {
57
+ "fixed-header": engine.options.fixColumnHeaders || engine.options.fixRowHeaders
58
+ }],
59
+ colSpan: colSpan,
60
+ rowSpan: rowSpan,
61
+ title: label,
62
+ style: style
63
+ }, label);
64
+ };
65
+ PivotTableDimensionLabelCell.propTypes = {
66
+ columnLevel: PropTypes.number.isRequired,
67
+ rowLevel: PropTypes.number.isRequired
68
+ };
@@ -0,0 +1,14 @@
1
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
+ import React from 'react';
3
+ import { PivotTableCell } from './PivotTableCell';
4
+ export const PivotTableEmptyCell = /*#__PURE__*/React.forwardRef((_ref, ref) => {
5
+ let {
6
+ onClick,
7
+ classes,
8
+ ...props
9
+ } = _ref;
10
+ return /*#__PURE__*/React.createElement(PivotTableCell, _extends({
11
+ ref: ref
12
+ }, props));
13
+ });
14
+ PivotTableEmptyCell.displayName = "PivotTableEmptyCell";
@@ -0,0 +1,25 @@
1
+ import React from 'react';
2
+ import { PivotTableCell } from './PivotTableCell';
3
+ import { usePivotTableEngine } from './PivotTableEngineContext';
4
+ export const PivotTableEmptyRow = _ref => {
5
+ let {
6
+ height,
7
+ columns
8
+ } = _ref;
9
+ const engine = usePivotTableEngine();
10
+ if (!engine) {
11
+ return null;
12
+ }
13
+ return /*#__PURE__*/React.createElement("tr", null, /*#__PURE__*/React.createElement(PivotTableCell, {
14
+ isHeader: true,
15
+ colSpan: engine.rowDepth,
16
+ style: {
17
+ height
18
+ },
19
+ classes: ["row-header", {
20
+ "fixed-header": engine.options.fixRowHeaders
21
+ }]
22
+ }), columns.map(i => /*#__PURE__*/React.createElement(PivotTableCell, {
23
+ key: i
24
+ })));
25
+ };
@@ -0,0 +1,14 @@
1
+ import React, { createContext, useContext } from 'react';
2
+ export const PivotTableEngineContext = /*#__PURE__*/createContext(null);
3
+ export const Provider = _ref => {
4
+ let {
5
+ engine,
6
+ children
7
+ } = _ref;
8
+ return /*#__PURE__*/React.createElement(PivotTableEngineContext.Provider, {
9
+ value: engine
10
+ }, children);
11
+ };
12
+ export const usePivotTableEngine = () => {
13
+ return useContext(PivotTableEngineContext);
14
+ };
@@ -0,0 +1,27 @@
1
+ import PropTypes from 'prop-types';
2
+ import React from 'react';
3
+ import { PivotTableColumnHeaders } from './PivotTableColumnHeaders.js';
4
+ import { PivotTableTitleRows } from './PivotTableTitleRows';
5
+ import { TableHead } from '@dhis2/ui';
6
+ export const PivotTableHead = _ref => {
7
+ let {
8
+ clippingResult,
9
+ width,
10
+ sortBy,
11
+ onSortByColumn
12
+ } = _ref;
13
+ return /*#__PURE__*/React.createElement(TableHead, null, /*#__PURE__*/React.createElement(PivotTableTitleRows, {
14
+ clippingResult: clippingResult,
15
+ width: width
16
+ }), /*#__PURE__*/React.createElement(PivotTableColumnHeaders, {
17
+ clippingResult: clippingResult,
18
+ sortBy: sortBy,
19
+ onSortByColumn: onSortByColumn
20
+ }));
21
+ };
22
+ PivotTableHead.propTypes = {
23
+ clippingResult: PropTypes.object.isRequired,
24
+ width: PropTypes.number.isRequired,
25
+ onSortByColumn: PropTypes.func.isRequired,
26
+ sortBy: PropTypes.object
27
+ };
@@ -0,0 +1,29 @@
1
+ import PropTypes from 'prop-types';
2
+ import { getHeaderForDisplay } from "../utils";
3
+ export const PivotTableHeaderCell = _ref => {
4
+ let {
5
+ axisClippingResult,
6
+ index,
7
+ level,
8
+ getHeader,
9
+ render,
10
+ showHierarchy
11
+ } = _ref;
12
+ const header = getHeaderForDisplay({
13
+ start: axisClippingResult.indices[0],
14
+ count: axisClippingResult.indices.length,
15
+ index,
16
+ dimensionLevel: level,
17
+ getHeader,
18
+ showHierarchy
19
+ });
20
+ return !header ? null : render(header);
21
+ };
22
+ PivotTableHeaderCell.propTypes = {
23
+ axisClippingResult: PropTypes.object.isRequired,
24
+ getHeader: PropTypes.func.isRequired,
25
+ index: PropTypes.number.isRequired,
26
+ level: PropTypes.number.isRequired,
27
+ render: PropTypes.func.isRequired,
28
+ showHierarchy: PropTypes.bool.isRequired
29
+ };
@@ -0,0 +1,57 @@
1
+ import times from 'lodash/times';
2
+ import PropTypes from 'prop-types';
3
+ import React from 'react';
4
+ import { PivotTableClippedAxis } from './PivotTableClippedAxis.js';
5
+ import { PivotTableEmptyCell } from './PivotTableEmptyCell';
6
+ import { usePivotTableEngine } from './PivotTableEngineContext';
7
+ import { PivotTableRowHeaderCell } from './PivotTableRowHeaderCell.js';
8
+ import { PivotTableValueCell } from './PivotTableValueCell';
9
+ import { DataTableRow } from '@dhis2/ui';
10
+ export const PivotTableRow = _ref => {
11
+ let {
12
+ clippingResult,
13
+ rowIndex,
14
+ onToggleContextualMenu
15
+ } = _ref;
16
+ const engine = usePivotTableEngine();
17
+ if (!engine) {
18
+ return null;
19
+ }
20
+ return /*#__PURE__*/React.createElement(DataTableRow, null, times(engine.rowDepth, x => x).map(rowLevel => /*#__PURE__*/React.createElement(PivotTableRowHeaderCell, {
21
+ key: rowLevel,
22
+ clippingResult: clippingResult,
23
+ rowIndex: rowIndex,
24
+ rowLevel: rowLevel
25
+ })), /*#__PURE__*/React.createElement(PivotTableClippedAxis, {
26
+ axisClippingResult: clippingResult.columns,
27
+ EmptyComponent: _ref2 => {
28
+ let {
29
+ size
30
+ } = _ref2;
31
+ return /*#__PURE__*/React.createElement(PivotTableEmptyCell, {
32
+ classes: "value",
33
+ style: {
34
+ width: size
35
+ }
36
+ });
37
+ },
38
+ ItemComponent: _ref3 => {
39
+ let {
40
+ index: columnIndex
41
+ } = _ref3;
42
+ return /*#__PURE__*/React.createElement(PivotTableValueCell, {
43
+ row: rowIndex,
44
+ column: columnIndex,
45
+ onToggleContextualMenu: onToggleContextualMenu
46
+ });
47
+ }
48
+ }));
49
+ };
50
+ PivotTableRow.propTypes = {
51
+ clippingResult: PropTypes.shape({
52
+ columns: PropTypes.object.isRequired,
53
+ rows: PropTypes.object.isRequired
54
+ }).isRequired,
55
+ rowIndex: PropTypes.number.isRequired,
56
+ onToggleContextualMenu: PropTypes.func
57
+ };
@@ -0,0 +1,41 @@
1
+ import React from 'react';
2
+ import { PivotTableCell } from './PivotTableCell';
3
+ import { usePivotTableEngine } from './PivotTableEngineContext';
4
+ import { PivotTableHeaderCell } from './PivotTableHeaderCell.js';
5
+ export const PivotTableRowHeaderCell = _ref => {
6
+ var _engine$adaptiveClipp;
7
+ let {
8
+ clippingResult,
9
+ rowIndex,
10
+ rowLevel
11
+ } = _ref;
12
+ const engine = usePivotTableEngine();
13
+ if (!engine) {
14
+ return null;
15
+ }
16
+ const width = engine.adaptiveClippingController.columns.headerSizes[rowLevel];
17
+ const height = (_engine$adaptiveClipp = engine.adaptiveClippingController.rows.sizes[engine.rowMap[rowIndex]]) === null || _engine$adaptiveClipp === void 0 ? void 0 : _engine$adaptiveClipp.size;
18
+ return /*#__PURE__*/React.createElement(PivotTableHeaderCell, {
19
+ axisClippingResult: clippingResult.rows,
20
+ index: rowIndex,
21
+ level: rowLevel,
22
+ getHeader: idx => engine.getRowHeader(idx),
23
+ showHierarchy: engine.visualization.showHierarchy,
24
+ render: header => /*#__PURE__*/React.createElement(PivotTableCell, {
25
+ isHeader: true,
26
+ classes: [header.label && header.label !== "Total" && header.label !== "Subtotal" ? "row-header" : "empty-header", header.includesHierarchy && "row-header-hierarchy", {
27
+ "fixed-header": engine.options.fixRowHeaders
28
+ }],
29
+ rowSpan: header.span,
30
+ title: header.label,
31
+ style: {
32
+ width,
33
+ height,
34
+ left: rowLevel > 0 ?
35
+ // calculate the width of all row header cells on the left of current cell
36
+ engine.adaptiveClippingController.columns.headerSizes.slice(0, rowLevel).reduce((width, acc) => acc += width, 0) : 0
37
+ },
38
+ dataTest: "visualization-row-header"
39
+ }, header.label)
40
+ });
41
+ };
@@ -0,0 +1,42 @@
1
+ import PropTypes from 'prop-types';
2
+ import React, { useEffect, useState } from 'react';
3
+ import { PivotTableCell } from './PivotTableCell';
4
+ import { usePivotTableEngine } from './PivotTableEngineContext';
5
+ import { DataTableRow } from '@dhis2/ui';
6
+ export const PivotTableTitleRow = _ref => {
7
+ let {
8
+ title,
9
+ scrollPosition,
10
+ containerWidth,
11
+ totalWidth
12
+ } = _ref;
13
+ const engine = usePivotTableEngine();
14
+ if (!engine) {
15
+ return null;
16
+ }
17
+ const columnCount = engine.width + engine.rowDepth;
18
+ const [position, setPosition] = useState(scrollPosition.x);
19
+ useEffect(() => {
20
+ setPosition(Math.max(0, Math.min(scrollPosition.x, totalWidth - containerWidth)));
21
+ }, [containerWidth, scrollPosition.x, totalWidth]);
22
+ return /*#__PURE__*/React.createElement(DataTableRow, null, /*#__PURE__*/React.createElement(PivotTableCell, {
23
+ isHeader: true,
24
+ classes: ["column-header", "title"],
25
+ colSpan: columnCount
26
+ }, /*#__PURE__*/React.createElement("div", {
27
+ style: {
28
+ marginLeft: position,
29
+ maxWidth: containerWidth,
30
+ textAlign: "center"
31
+ },
32
+ "data-test": "visualization-title"
33
+ }, title)));
34
+ };
35
+ PivotTableTitleRow.propTypes = {
36
+ containerWidth: PropTypes.number.isRequired,
37
+ scrollPosition: PropTypes.shape({
38
+ x: PropTypes.number.isRequired
39
+ }).isRequired,
40
+ title: PropTypes.string.isRequired,
41
+ totalWidth: PropTypes.number.isRequired
42
+ };
@@ -0,0 +1,37 @@
1
+ // @ts-nocheck
2
+ import PropTypes from 'prop-types';
3
+ import React from 'react';
4
+ import { getFilterText } from '../utils';
5
+ import { usePivotTableEngine } from './PivotTableEngineContext';
6
+ import { PivotTableTitleRow } from './PivotTableTitleRow.js';
7
+ export const PivotTableTitleRows = _ref => {
8
+ var _engine$visualization, _engine$visualization2, _engine$visualization3;
9
+ let {
10
+ clippingResult,
11
+ width
12
+ } = _ref;
13
+ const engine = usePivotTableEngine();
14
+ if (!engine) {
15
+ return null;
16
+ }
17
+ return /*#__PURE__*/React.createElement(React.Fragment, null, engine.options.title ? /*#__PURE__*/React.createElement(PivotTableTitleRow, {
18
+ title: engine.options.title,
19
+ scrollPosition: clippingResult.scrollPosition,
20
+ containerWidth: width,
21
+ totalWidth: engine.adaptiveClippingController.columns.totalSize + engine.adaptiveClippingController.columns.headerSize
22
+ }) : null, engine.options.subtitle ? /*#__PURE__*/React.createElement(PivotTableTitleRow, {
23
+ title: engine.options.subtitle,
24
+ scrollPosition: clippingResult.scrollPosition,
25
+ containerWidth: width,
26
+ totalWidth: engine.adaptiveClippingController.columns.totalSize + engine.adaptiveClippingController.columns.headerSize
27
+ }) : null, (_engine$visualization = engine.visualization) !== null && _engine$visualization !== void 0 && (_engine$visualization2 = _engine$visualization.filters) !== null && _engine$visualization2 !== void 0 && _engine$visualization2.length ? /*#__PURE__*/React.createElement(PivotTableTitleRow, {
28
+ title: getFilterText((_engine$visualization3 = engine.visualization) === null || _engine$visualization3 === void 0 ? void 0 : _engine$visualization3.filters, engine.rawData.metaData),
29
+ scrollPosition: clippingResult.scrollPosition,
30
+ containerWidth: width,
31
+ totalWidth: engine.adaptiveClippingController.columns.totalSize + engine.adaptiveClippingController.columns.headerSize
32
+ }) : null);
33
+ };
34
+ PivotTableTitleRows.propTypes = {
35
+ clippingResult: PropTypes.object.isRequired,
36
+ width: PropTypes.number.isRequired
37
+ };
@@ -0,0 +1,60 @@
1
+ import React, { useRef } from 'react';
2
+ import { applyLegendSet } from '../utils';
3
+ import { CELL_TYPE_VALUE } from '../constants/pivotTable';
4
+ import { VALUE_TYPE_NUMBER } from '../constants/valueTypes.js';
5
+ import { PivotTableCell } from './PivotTableCell.js';
6
+ import { PivotTableEmptyCell } from './PivotTableEmptyCell';
7
+ import { usePivotTableEngine } from './PivotTableEngineContext.js';
8
+ export const PivotTableValueCell = _ref => {
9
+ var _cellContent$rendered;
10
+ let {
11
+ row,
12
+ column,
13
+ onToggleContextualMenu
14
+ } = _ref;
15
+ const engine = usePivotTableEngine();
16
+ const cellRef = useRef(null);
17
+ if (!engine) {
18
+ return null;
19
+ }
20
+ const cellContent = engine.get({
21
+ row,
22
+ column
23
+ });
24
+ const isClickable = !!cellContent && onToggleContextualMenu && cellContent.cellType === CELL_TYPE_VALUE && cellContent.ouId;
25
+ const classes = !!cellContent ? [cellContent.cellType, cellContent.valueType, isClickable && 'clickable'] : [];
26
+ const onClick = () => {
27
+ if (onToggleContextualMenu) {
28
+ onToggleContextualMenu(cellRef.current, {
29
+ ouId: cellContent === null || cellContent === void 0 ? void 0 : cellContent.ouId
30
+ });
31
+ }
32
+ };
33
+ if (!cellContent || cellContent.empty) {
34
+ return /*#__PURE__*/React.createElement(PivotTableEmptyCell, {
35
+ onClick: isClickable ? onClick : undefined,
36
+ ref: cellRef,
37
+ classes: [cellContent === null || cellContent === void 0 ? void 0 : cellContent.cellType, isClickable && 'clickable']
38
+ });
39
+ }
40
+
41
+ // TODO: Add support for 'INTEGER' type (requires server changes)
42
+ const legendStyle = cellContent.cellType === CELL_TYPE_VALUE && cellContent.valueType === VALUE_TYPE_NUMBER ? applyLegendSet(cellContent.rawValue, cellContent.dxDimension, engine) : undefined;
43
+ const width = engine.adaptiveClippingController.columns.sizes[engine.columnMap[column]].size;
44
+ const height = engine.adaptiveClippingController.rows.sizes[engine.rowMap[row]].size;
45
+ const style = {
46
+ ...legendStyle,
47
+ width,
48
+ height,
49
+ whiteSpace: 'pre-line'
50
+ };
51
+ return /*#__PURE__*/React.createElement(PivotTableCell, {
52
+ key: column,
53
+ classes: classes,
54
+ title: cellContent.renderedValue,
55
+ style: style,
56
+ onClick: isClickable ? onClick : undefined,
57
+ ref: cellRef,
58
+ dataTest: 'visualization-value-cell'
59
+ }, (_cellContent$rendered = cellContent.renderedValue) !== null && _cellContent$rendered !== void 0 ? _cellContent$rendered : null);
60
+ };
@@ -0,0 +1,98 @@
1
+ // @ts-nocheck
2
+
3
+ import i18n from '@dhis2/d2-i18n';
4
+ export const DIMENSION_TYPE_ALL = 'ALL';
5
+ export const DIMENSION_TYPE_INDICATOR = 'INDICATOR';
6
+ export const DIMENSION_TYPE_DATA_ELEMENT = 'DATA_ELEMENT';
7
+ export const DIMENSION_TYPE_DATA_SET = 'DATA_SET';
8
+ export const DIMENSION_TYPE_EVENT_DATA_ITEM = 'EVENT_DATA_ITEM';
9
+ export const DIMENSION_TYPE_PROGRAM_INDICATOR = 'PROGRAM_INDICATOR';
10
+ export const DIMENSION_TYPE_PROGRAM_DATA_ELEMENT = 'PROGRAM_DATA_ELEMENT';
11
+ export const DIMENSION_TYPE_PROGRAM_ATTRIBUTE = 'PROGRAM_ATTRIBUTE';
12
+ export const DIMENSION_TYPE_DATA_ELEMENT_OPERAND = 'DATA_ELEMENT_OPERAND';
13
+ export const DIMENSION_TYPE_CATEGORY = 'CATEGORY';
14
+ export const DIMENSION_TYPE_CATEGORY_OPTION_GROUP_SET = 'CATEGORY_OPTION_GROUP_SET';
15
+ export const DIMENSION_TYPE_DATA_ELEMENT_GROUP_SET = 'DATA_ELEMENT_GROUP_SET';
16
+ export const DIMENSION_TYPE_DATA = 'DATA_X';
17
+ export const DIMENSION_TYPE_PERIOD = 'PERIOD';
18
+ export const DIMENSION_TYPE_ORGANISATION_UNIT = 'ORGANISATION_UNIT';
19
+ export const DIMENSION_TYPE_ORGANISATION_UNIT_GROUP_SET = 'ORGANISATION_UNIT_GROUP_SET';
20
+ export const TOTALS = 'totals';
21
+ export const DETAIL = 'detail';
22
+ export const SUB_GROUP_DETAIL = 'DETAIL';
23
+ export const SUB_GROUP_METRIC = 'METRIC';
24
+ const getProgramText = () => i18n.t('Program');
25
+ const getSelectProgramText = () => i18n.t('Select a program');
26
+ export const dataTypeMap = {
27
+ [DIMENSION_TYPE_INDICATOR]: {
28
+ id: DIMENSION_TYPE_INDICATOR,
29
+ getName: () => i18n.t('Indicators'),
30
+ getGroupLabel: () => i18n.t('Indicator group'),
31
+ defaultGroup: {
32
+ id: DIMENSION_TYPE_ALL,
33
+ getName: () => i18n.t('All groups')
34
+ },
35
+ getItemName: () => i18n.t('Indicator'),
36
+ getGroupEmptyLabel: () => i18n.t('No indicator groups found'),
37
+ getGroupLoadingLabel: () => i18n.t('Loading indicator groups')
38
+ },
39
+ [DIMENSION_TYPE_DATA_ELEMENT]: {
40
+ id: DIMENSION_TYPE_DATA_ELEMENT,
41
+ getName: () => i18n.t('Data elements'),
42
+ getGroupLabel: () => i18n.t('Data element group'),
43
+ defaultGroup: {
44
+ id: DIMENSION_TYPE_ALL,
45
+ getName: () => i18n.t('All groups')
46
+ },
47
+ subGroup: SUB_GROUP_DETAIL,
48
+ getItemName: () => i18n.t('Data element'),
49
+ getGroupEmptyLabel: () => i18n.t('No data element groups found'),
50
+ getGroupLoadingLabel: () => i18n.t('Loading data element groups')
51
+ },
52
+ [DIMENSION_TYPE_DATA_SET]: {
53
+ id: DIMENSION_TYPE_DATA_SET,
54
+ getName: () => i18n.t('Data sets'),
55
+ getGroupLabel: () => i18n.t('Data set'),
56
+ defaultGroup: {
57
+ id: DIMENSION_TYPE_ALL,
58
+ getName: () => i18n.t('All data sets')
59
+ },
60
+ subGroup: SUB_GROUP_METRIC,
61
+ getItemName: () => i18n.t('Data set'),
62
+ getGroupEmptyLabel: () => i18n.t('No data sets found'),
63
+ getGroupLoadingLabel: () => i18n.t('Loading data sets')
64
+ },
65
+ [DIMENSION_TYPE_EVENT_DATA_ITEM]: {
66
+ id: DIMENSION_TYPE_EVENT_DATA_ITEM,
67
+ getName: () => i18n.t('Event data items'),
68
+ getGroupLabel: getProgramText,
69
+ getPlaceholder: getSelectProgramText,
70
+ defaultGroup: {
71
+ id: DIMENSION_TYPE_ALL,
72
+ getName: () => i18n.t('All programs')
73
+ },
74
+ getItemName: () => i18n.t('Event data item'),
75
+ getGroupEmptyLabel: () => i18n.t('No programs found'),
76
+ getGroupLoadingLabel: () => i18n.t('Loading programs')
77
+ },
78
+ [DIMENSION_TYPE_PROGRAM_INDICATOR]: {
79
+ id: DIMENSION_TYPE_PROGRAM_INDICATOR,
80
+ getName: () => i18n.t('Program indicators'),
81
+ getGroupLabel: getProgramText,
82
+ getPlaceholder: getSelectProgramText,
83
+ defaultGroup: {
84
+ id: DIMENSION_TYPE_ALL,
85
+ getName: () => i18n.t('All programs')
86
+ },
87
+ getItemName: () => i18n.t('Program indicator'),
88
+ getGroupEmptyLabel: () => i18n.t('No programs found'),
89
+ getGroupLoadingLabel: () => i18n.t('Loading programs')
90
+ }
91
+ };
92
+ export function defaultGroupId(dataType) {
93
+ return dataTypeMap[dataType].defaultGroup ? dataTypeMap[dataType].defaultGroup.id : '';
94
+ }
95
+ export function defaultGroupDetail(dataType) {
96
+ return dataTypeMap[dataType].groupDetail ? dataTypeMap[dataType].groupDetail.default : '';
97
+ }
98
+ export const DEFAULT_DATATYPE_ID = DIMENSION_TYPE_INDICATOR;