@hisptz/dhis2-analytics 1.0.41 → 1.0.43
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cjs/components/Map/components/MapLayer/components/GoogleEngineLayer/services/engine.js +9 -1
- package/build/cjs/components/Map/components/MapProvider/components/MapLayerProvider/hooks/index.js +3 -0
- package/build/cjs/components/Map/constants/colors.js +1 -0
- package/build/cjs/components/Visualization/Visualization.stories.js +138 -0
- package/build/cjs/components/Visualization/components/AnalyticsDataProvider/index.js +99 -0
- package/build/cjs/components/Visualization/components/DimensionsProvider/index.js +46 -0
- package/build/cjs/components/Visualization/components/LayoutProvider/index.js +31 -0
- package/build/cjs/components/Visualization/components/VisualizationDimensionSelector/index.js +73 -0
- package/build/cjs/components/Visualization/components/VisualizationProvider/index.js +29 -0
- package/build/cjs/components/Visualization/components/VisualizationSelector/index.js +188 -0
- package/build/cjs/components/Visualization/components/VisualizationTypeProvider/index.js +40 -0
- package/build/cjs/components/Visualization/components/VisualizationTypeSelector/index.js +54 -0
- package/build/cjs/components/Visualization/index.js +104 -0
- package/build/cjs/index.js +11 -0
- package/build/cjs/locales/en/translations.json +11 -1
- package/build/es/components/Map/components/MapProvider/components/MapLayerProvider/hooks/index.js +3 -0
- package/build/es/components/Map/constants/colors.js +1 -0
- package/build/es/components/Visualization/Visualization.stories.js +129 -0
- package/build/es/components/Visualization/components/AnalyticsDataProvider/index.js +90 -0
- package/build/es/components/Visualization/components/DimensionsProvider/index.js +34 -0
- package/build/es/components/Visualization/components/LayoutProvider/index.js +20 -0
- package/build/es/components/Visualization/components/VisualizationDimensionSelector/index.js +64 -0
- package/build/es/components/Visualization/components/VisualizationProvider/index.js +22 -0
- package/build/es/components/Visualization/components/VisualizationSelector/index.js +174 -0
- package/build/es/components/Visualization/components/VisualizationTypeProvider/index.js +25 -0
- package/build/es/components/Visualization/components/VisualizationTypeSelector/index.js +45 -0
- package/build/es/components/Visualization/index.js +97 -0
- package/build/es/index.js +1 -0
- package/build/es/locales/en/translations.json +11 -1
- package/build/types/components/CustomPivotTable/components/Table/index.d.ts +7 -6
- package/build/types/components/CustomPivotTable/index.d.ts +12 -11
- package/build/types/components/Visualization/components/AnalyticsDataProvider/index.d.ts +10 -0
- package/build/types/components/Visualization/components/DimensionsProvider/index.d.ts +15 -0
- package/build/types/components/Visualization/components/LayoutProvider/index.d.ts +14 -0
- package/build/types/components/Visualization/components/VisualizationDimensionSelector/index.d.ts +2 -0
- package/build/types/components/Visualization/components/VisualizationProvider/index.d.ts +13 -0
- package/build/types/components/Visualization/components/VisualizationSelector/index.d.ts +25 -0
- package/build/types/components/Visualization/components/VisualizationTypeProvider/index.d.ts +14 -0
- package/build/types/components/Visualization/components/VisualizationTypeSelector/index.d.ts +2 -0
- package/build/types/components/Visualization/index.d.ts +21 -0
- package/build/types/index.d.ts +1 -0
- package/package.json +5 -4
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.VisualizationTypeContext = exports.VisualizationConfigContext = void 0;
|
|
7
|
+
exports.VisualizationTypeProvider = VisualizationTypeProvider;
|
|
8
|
+
exports.VisualizationTypeSetter = void 0;
|
|
9
|
+
exports.useVisualizationConfig = useVisualizationConfig;
|
|
10
|
+
exports.useVisualizationType = useVisualizationType;
|
|
11
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
12
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
13
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
14
|
+
const VisualizationTypeContext = /*#__PURE__*/(0, _react.createContext)('pivotTable');
|
|
15
|
+
exports.VisualizationTypeContext = VisualizationTypeContext;
|
|
16
|
+
const VisualizationConfigContext = /*#__PURE__*/(0, _react.createContext)(undefined);
|
|
17
|
+
exports.VisualizationConfigContext = VisualizationConfigContext;
|
|
18
|
+
const VisualizationTypeSetter = /*#__PURE__*/(0, _react.createContext)(undefined);
|
|
19
|
+
exports.VisualizationTypeSetter = VisualizationTypeSetter;
|
|
20
|
+
function useVisualizationType() {
|
|
21
|
+
return [(0, _react.useContext)(VisualizationTypeContext), (0, _react.useContext)(VisualizationTypeSetter)];
|
|
22
|
+
}
|
|
23
|
+
function useVisualizationConfig() {
|
|
24
|
+
return (0, _react.useContext)(VisualizationConfigContext);
|
|
25
|
+
}
|
|
26
|
+
function VisualizationTypeProvider(_ref) {
|
|
27
|
+
let {
|
|
28
|
+
children,
|
|
29
|
+
defaultType,
|
|
30
|
+
config
|
|
31
|
+
} = _ref;
|
|
32
|
+
const [type, setType] = (0, _react.useState)(defaultType);
|
|
33
|
+
return /*#__PURE__*/_react.default.createElement(VisualizationTypeContext.Provider, {
|
|
34
|
+
value: type
|
|
35
|
+
}, /*#__PURE__*/_react.default.createElement(VisualizationConfigContext.Provider, {
|
|
36
|
+
value: config
|
|
37
|
+
}, /*#__PURE__*/_react.default.createElement(VisualizationTypeSetter.Provider, {
|
|
38
|
+
value: setType
|
|
39
|
+
}, children)));
|
|
40
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.VisualizationTypeSelector = VisualizationTypeSelector;
|
|
7
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
8
|
+
var _VisualizationTypeProvider = require("../VisualizationTypeProvider");
|
|
9
|
+
var _ui = require("@dhis2/ui");
|
|
10
|
+
var _d2I18n = _interopRequireDefault(require("@dhis2/d2-i18n"));
|
|
11
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
13
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
14
|
+
const supportedVisualizationTypes = [{
|
|
15
|
+
id: "pivotTable",
|
|
16
|
+
icon: /*#__PURE__*/_react.default.createElement(_ui.IconTable24, null),
|
|
17
|
+
label: _d2I18n.default.t("Pivot table")
|
|
18
|
+
}, {
|
|
19
|
+
id: "chart",
|
|
20
|
+
icon: /*#__PURE__*/_react.default.createElement(_ui.IconVisualizationColumn24, null),
|
|
21
|
+
label: _d2I18n.default.t("Chart")
|
|
22
|
+
}, {
|
|
23
|
+
id: "map",
|
|
24
|
+
icon: /*#__PURE__*/_react.default.createElement(_ui.IconWorld24, null),
|
|
25
|
+
label: _d2I18n.default.t("Map")
|
|
26
|
+
}];
|
|
27
|
+
function VisualizationTypeSelector() {
|
|
28
|
+
const [type, setType] = (0, _VisualizationTypeProvider.useVisualizationType)();
|
|
29
|
+
const config = (0, _VisualizationTypeProvider.useVisualizationConfig)();
|
|
30
|
+
const types = (0, _react.useMemo)(() => supportedVisualizationTypes.filter(supportedType => {
|
|
31
|
+
return Object.keys(config !== null && config !== void 0 ? config : {}).includes(supportedType.id) && supportedType.id !== type;
|
|
32
|
+
}), [type, config]);
|
|
33
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
34
|
+
style: {
|
|
35
|
+
display: "flex",
|
|
36
|
+
gap: 8
|
|
37
|
+
}
|
|
38
|
+
}, types.map(_ref => {
|
|
39
|
+
let {
|
|
40
|
+
icon,
|
|
41
|
+
label,
|
|
42
|
+
id
|
|
43
|
+
} = _ref;
|
|
44
|
+
return /*#__PURE__*/_react.default.createElement(_ui.Tooltip, {
|
|
45
|
+
key: `${label}-tooltip`,
|
|
46
|
+
content: _d2I18n.default.t("View as {{type}}", {
|
|
47
|
+
type: label.toLowerCase()
|
|
48
|
+
})
|
|
49
|
+
}, /*#__PURE__*/_react.default.createElement(_ui.Button, {
|
|
50
|
+
onClick: () => setType(id),
|
|
51
|
+
icon: icon
|
|
52
|
+
}));
|
|
53
|
+
}));
|
|
54
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.Visualization = Visualization;
|
|
7
|
+
var _react = _interopRequireDefault(require("react"));
|
|
8
|
+
var _VisualizationProvider = require("./components/VisualizationProvider");
|
|
9
|
+
var _VisualizationTypeSelector = require("./components/VisualizationTypeSelector");
|
|
10
|
+
var _VisualizationDimensionSelector = require("./components/VisualizationDimensionSelector");
|
|
11
|
+
var _VisualizationSelector = require("./components/VisualizationSelector");
|
|
12
|
+
var _reactErrorBoundary = require("react-error-boundary");
|
|
13
|
+
var _d2I18n = _interopRequireDefault(require("@dhis2/d2-i18n"));
|
|
14
|
+
var _ui = require("@dhis2/ui");
|
|
15
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
|
+
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); }
|
|
17
|
+
/**
|
|
18
|
+
* An analytics component that allows visualization of `chart`, `map`, and `pivot table` by passing analytics object and the default layout and type
|
|
19
|
+
*
|
|
20
|
+
* */
|
|
21
|
+
|
|
22
|
+
function ErrorFallback(_ref) {
|
|
23
|
+
let {
|
|
24
|
+
error,
|
|
25
|
+
resetErrorBoundary,
|
|
26
|
+
height
|
|
27
|
+
} = _ref;
|
|
28
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
29
|
+
style: {
|
|
30
|
+
width: "100%",
|
|
31
|
+
textAlign: "center",
|
|
32
|
+
height: height !== null && height !== void 0 ? height : 500,
|
|
33
|
+
display: "flex",
|
|
34
|
+
flexDirection: "column",
|
|
35
|
+
alignItems: "center",
|
|
36
|
+
justifyContent: "center",
|
|
37
|
+
gap: 16,
|
|
38
|
+
padding: 16
|
|
39
|
+
}
|
|
40
|
+
}, /*#__PURE__*/_react.default.createElement(_ui.IconError24, null), /*#__PURE__*/_react.default.createElement("h3", {
|
|
41
|
+
style: {
|
|
42
|
+
color: _ui.colors.grey800,
|
|
43
|
+
margin: 0
|
|
44
|
+
}
|
|
45
|
+
}, _d2I18n.default.t("Could not load visualization")), /*#__PURE__*/_react.default.createElement("p", {
|
|
46
|
+
style: {
|
|
47
|
+
margin: 0
|
|
48
|
+
}
|
|
49
|
+
}, error.message), resetErrorBoundary && /*#__PURE__*/_react.default.createElement(_ui.Button, {
|
|
50
|
+
onClick: resetErrorBoundary,
|
|
51
|
+
small: true
|
|
52
|
+
}, _d2I18n.default.t("Try again")));
|
|
53
|
+
}
|
|
54
|
+
function Visualization(_ref2) {
|
|
55
|
+
let {
|
|
56
|
+
dimensions,
|
|
57
|
+
layout,
|
|
58
|
+
defaultVisualizationType,
|
|
59
|
+
config,
|
|
60
|
+
height,
|
|
61
|
+
showToolbar
|
|
62
|
+
} = _ref2;
|
|
63
|
+
return /*#__PURE__*/_react.default.createElement(_reactErrorBoundary.ErrorBoundary, {
|
|
64
|
+
onReset: () => {
|
|
65
|
+
//TODO: reset the visualization
|
|
66
|
+
},
|
|
67
|
+
resetKeys: [dimensions, layout, defaultVisualizationType, config],
|
|
68
|
+
fallbackRender: props => /*#__PURE__*/_react.default.createElement(ErrorFallback, _extends({
|
|
69
|
+
height: height
|
|
70
|
+
}, props))
|
|
71
|
+
}, /*#__PURE__*/_react.default.createElement(_VisualizationProvider.VisualizationProvider, {
|
|
72
|
+
config: config,
|
|
73
|
+
type: defaultVisualizationType,
|
|
74
|
+
layout: layout,
|
|
75
|
+
dimensions: dimensions
|
|
76
|
+
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
77
|
+
style: {
|
|
78
|
+
display: "flex",
|
|
79
|
+
flexDirection: "column",
|
|
80
|
+
width: "100%",
|
|
81
|
+
height: "100%",
|
|
82
|
+
padding: 16,
|
|
83
|
+
gap: 16
|
|
84
|
+
}
|
|
85
|
+
}, showToolbar && /*#__PURE__*/_react.default.createElement("div", {
|
|
86
|
+
style: {
|
|
87
|
+
display: "flex",
|
|
88
|
+
flexDirection: "row",
|
|
89
|
+
gap: 16,
|
|
90
|
+
justifyContent: "space-between"
|
|
91
|
+
}
|
|
92
|
+
}, /*#__PURE__*/_react.default.createElement(_VisualizationTypeSelector.VisualizationTypeSelector, null), /*#__PURE__*/_react.default.createElement(_VisualizationDimensionSelector.VisualizationDimensionSelector, null)), /*#__PURE__*/_react.default.createElement("div", {
|
|
93
|
+
style: {
|
|
94
|
+
display: "flex",
|
|
95
|
+
flexDirection: "column",
|
|
96
|
+
alignItems: "center",
|
|
97
|
+
justifyContent: "center",
|
|
98
|
+
height: height !== null && height !== void 0 ? height : 500
|
|
99
|
+
}
|
|
100
|
+
}, /*#__PURE__*/_react.default.createElement(_VisualizationSelector.VisualizationSelector, {
|
|
101
|
+
height: height !== null && height !== void 0 ? height : 500,
|
|
102
|
+
config: config
|
|
103
|
+
})))));
|
|
104
|
+
}
|
package/build/cjs/index.js
CHANGED
|
@@ -57,4 +57,15 @@ Object.keys(_CustomPivotTable).forEach(function (key) {
|
|
|
57
57
|
return _CustomPivotTable[key];
|
|
58
58
|
}
|
|
59
59
|
});
|
|
60
|
+
});
|
|
61
|
+
var _Visualization = require("./components/Visualization");
|
|
62
|
+
Object.keys(_Visualization).forEach(function (key) {
|
|
63
|
+
if (key === "default" || key === "__esModule") return;
|
|
64
|
+
if (key in exports && exports[key] === _Visualization[key]) return;
|
|
65
|
+
Object.defineProperty(exports, key, {
|
|
66
|
+
enumerable: true,
|
|
67
|
+
get: function () {
|
|
68
|
+
return _Visualization[key];
|
|
69
|
+
}
|
|
70
|
+
});
|
|
60
71
|
});
|
|
@@ -124,5 +124,15 @@
|
|
|
124
124
|
"Legend set is required": "Legend set is required",
|
|
125
125
|
"Radius": "Radius",
|
|
126
126
|
"Configure Thematic Layer": "Configure Thematic Layer",
|
|
127
|
-
"Loading ...": "Loading ..."
|
|
127
|
+
"Loading ...": "Loading ...",
|
|
128
|
+
"Select location(s)": "Select location(s)",
|
|
129
|
+
"Location": "Location",
|
|
130
|
+
"Organisation unit": "Organisation unit",
|
|
131
|
+
"Data": "Data",
|
|
132
|
+
"Pivot table": "Pivot table",
|
|
133
|
+
"Chart": "Chart",
|
|
134
|
+
"Map": "Map",
|
|
135
|
+
"View as {{type}}": "View as {{type}}",
|
|
136
|
+
"Could not load visualization": "Could not load visualization",
|
|
137
|
+
"Try again": "Try again"
|
|
128
138
|
}
|
package/build/es/components/Map/components/MapProvider/components/MapLayerProvider/hooks/index.js
CHANGED
|
@@ -186,6 +186,9 @@ export function useThematicLayers() {
|
|
|
186
186
|
const layersWithData = differenceBy(layers, layersWithoutData, "id");
|
|
187
187
|
const dx = layersWithoutData.map(layer => layer.dataItem.id);
|
|
188
188
|
let sanitizedLayersWithData = [];
|
|
189
|
+
console.log({
|
|
190
|
+
layersWithoutData
|
|
191
|
+
});
|
|
189
192
|
if (!isEmpty(dx)) {
|
|
190
193
|
const data = await engine.query(analyticsQuery, {
|
|
191
194
|
variables: {
|
|
@@ -416,5 +416,6 @@ export const COLOR_PALETTES = {
|
|
|
416
416
|
9: ["#000000", "#252525", "#525252", "#737373", "#969696", "#bdbdbd", "#d9d9d9", "#f0f0f0", "#ffffff"]
|
|
417
417
|
}
|
|
418
418
|
};
|
|
419
|
+
|
|
419
420
|
// Qualitative colors From ColorBrewer (reordered 12-class)
|
|
420
421
|
export const qualitativeColors = ["#1f78b4", "#ff7f00", "#33a02c", "#a6cee3", "#b2df8a", "#fb9a99", "#fdbf6f", "#cab2d6", "#ffff99", "#b15928", "#6a3d9a", "#e31a1c"];
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { setupHighchartsModules } from "../ChartAnalytics";
|
|
2
|
+
import { Visualization } from "./index";
|
|
3
|
+
import HighCharts from "highcharts";
|
|
4
|
+
import React from "react";
|
|
5
|
+
import { Box, Card, CssReset } from "@dhis2/ui";
|
|
6
|
+
const Template = args => /*#__PURE__*/React.createElement(Visualization, args);
|
|
7
|
+
setupHighchartsModules(HighCharts);
|
|
8
|
+
export const Default = Template.bind({});
|
|
9
|
+
Default.args = {
|
|
10
|
+
dimensions: {
|
|
11
|
+
dx: ["Uvn6LCg7dVU", "OdiHJayrsKo", "sB79w2hiLp8", "AUqdhY4mpvp"],
|
|
12
|
+
pe: ["LAST_6_MONTHS"],
|
|
13
|
+
ou: ["USER_ORGUNIT_CHILDREN"]
|
|
14
|
+
},
|
|
15
|
+
layout: {
|
|
16
|
+
columns: ["dx"],
|
|
17
|
+
filters: [],
|
|
18
|
+
rows: ["ou", "pe"]
|
|
19
|
+
},
|
|
20
|
+
defaultVisualizationType: "pivot-table",
|
|
21
|
+
config: {
|
|
22
|
+
chart: {
|
|
23
|
+
layout: {
|
|
24
|
+
series: ["dx"],
|
|
25
|
+
category: ["pe"],
|
|
26
|
+
filter: ["ou"]
|
|
27
|
+
},
|
|
28
|
+
type: "column"
|
|
29
|
+
},
|
|
30
|
+
map: {
|
|
31
|
+
thematicLayers: [{
|
|
32
|
+
type: "choropleth",
|
|
33
|
+
id: "Uvn6LCg7dVU",
|
|
34
|
+
enabled: true,
|
|
35
|
+
control: {
|
|
36
|
+
enabled: true,
|
|
37
|
+
position: "topright"
|
|
38
|
+
},
|
|
39
|
+
dataItem: {
|
|
40
|
+
displayName: "Uvn6LCg7dVU",
|
|
41
|
+
id: "Uvn6LCg7dVU",
|
|
42
|
+
type: "indicator",
|
|
43
|
+
legendConfig: {
|
|
44
|
+
colorClass: "BrBG",
|
|
45
|
+
scale: 7
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}, {
|
|
49
|
+
type: "choropleth",
|
|
50
|
+
id: "OdiHJayrsKo",
|
|
51
|
+
enabled: true,
|
|
52
|
+
control: {
|
|
53
|
+
enabled: true,
|
|
54
|
+
position: "topright"
|
|
55
|
+
},
|
|
56
|
+
dataItem: {
|
|
57
|
+
displayName: "OdiHJayrsKo",
|
|
58
|
+
id: "OdiHJayrsKo",
|
|
59
|
+
type: "indicator",
|
|
60
|
+
legendConfig: {
|
|
61
|
+
colorClass: "BrBG",
|
|
62
|
+
scale: 7
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}, {
|
|
66
|
+
type: "choropleth",
|
|
67
|
+
id: "sB79w2hiLp8",
|
|
68
|
+
enabled: true,
|
|
69
|
+
control: {
|
|
70
|
+
enabled: true,
|
|
71
|
+
position: "topright"
|
|
72
|
+
},
|
|
73
|
+
dataItem: {
|
|
74
|
+
displayName: "sB79w2hiLp8",
|
|
75
|
+
id: "sB79w2hiLp8",
|
|
76
|
+
type: "indicator",
|
|
77
|
+
legendConfig: {
|
|
78
|
+
colorClass: "BrBG",
|
|
79
|
+
scale: 7
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}, {
|
|
83
|
+
type: "choropleth",
|
|
84
|
+
id: "AUqdhY4mpvp",
|
|
85
|
+
enabled: true,
|
|
86
|
+
control: {
|
|
87
|
+
enabled: true,
|
|
88
|
+
position: "topright"
|
|
89
|
+
},
|
|
90
|
+
dataItem: {
|
|
91
|
+
displayName: "AUqdhY4mpvp",
|
|
92
|
+
id: "AUqdhY4mpvp",
|
|
93
|
+
type: "indicator",
|
|
94
|
+
legendConfig: {
|
|
95
|
+
colorClass: "BrBG",
|
|
96
|
+
scale: 7
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}],
|
|
100
|
+
legends: {
|
|
101
|
+
enabled: true,
|
|
102
|
+
position: "topright",
|
|
103
|
+
collapsible: true
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
pivotTable: {
|
|
107
|
+
fixColumnHeaders: true,
|
|
108
|
+
fixRowHeaders: true
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
export default {
|
|
113
|
+
title: "Analytics/Visualization",
|
|
114
|
+
component: Visualization,
|
|
115
|
+
decorators: [ChartStory => {
|
|
116
|
+
return /*#__PURE__*/React.createElement(Box, {
|
|
117
|
+
width: "600",
|
|
118
|
+
height: "500"
|
|
119
|
+
}, /*#__PURE__*/React.createElement(Card, null, /*#__PURE__*/React.createElement("div", {
|
|
120
|
+
style: {
|
|
121
|
+
width: 1000,
|
|
122
|
+
height: "100%",
|
|
123
|
+
display: "flex",
|
|
124
|
+
gap: 8,
|
|
125
|
+
flexDirection: "column"
|
|
126
|
+
}
|
|
127
|
+
}, /*#__PURE__*/React.createElement(CssReset, null), /*#__PURE__*/React.createElement(ChartStory, null))));
|
|
128
|
+
}]
|
|
129
|
+
};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import React, { createContext, useContext, useEffect, useMemo } from "react";
|
|
2
|
+
import { useDimensions } from "../DimensionsProvider";
|
|
3
|
+
import { useDataQuery } from "@dhis2/app-runtime";
|
|
4
|
+
import { useLayout } from "../LayoutProvider";
|
|
5
|
+
import { forEach, set } from "lodash";
|
|
6
|
+
const AnalyticsContext = /*#__PURE__*/createContext(undefined);
|
|
7
|
+
const analyticsQuery = {
|
|
8
|
+
analytics: {
|
|
9
|
+
resource: "analytics",
|
|
10
|
+
params: _ref => {
|
|
11
|
+
let {
|
|
12
|
+
dimensions,
|
|
13
|
+
filters
|
|
14
|
+
} = _ref;
|
|
15
|
+
return {
|
|
16
|
+
dimension: Object.keys(dimensions).map(dimension => {
|
|
17
|
+
var _dimensions$dimension;
|
|
18
|
+
return `${dimension}:${(_dimensions$dimension = dimensions[dimension]) === null || _dimensions$dimension === void 0 ? void 0 : _dimensions$dimension.join(';')}`;
|
|
19
|
+
}),
|
|
20
|
+
filters: Object.keys(filters).map(dimension => {
|
|
21
|
+
var _dimensions$dimension2;
|
|
22
|
+
return `${dimension}:${(_dimensions$dimension2 = dimensions[dimension]) === null || _dimensions$dimension2 === void 0 ? void 0 : _dimensions$dimension2.join(';')}`;
|
|
23
|
+
}),
|
|
24
|
+
includeMetadataDetails: true
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
export function useAnalyticsData() {
|
|
30
|
+
var _useContext;
|
|
31
|
+
return (_useContext = useContext(AnalyticsContext)) !== null && _useContext !== void 0 ? _useContext : {
|
|
32
|
+
analytics: {},
|
|
33
|
+
loading: false
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
export function AnalyticsDataProvider(_ref2) {
|
|
37
|
+
let {
|
|
38
|
+
children
|
|
39
|
+
} = _ref2;
|
|
40
|
+
const [analyticsDimensions] = useDimensions();
|
|
41
|
+
const [layout] = useLayout();
|
|
42
|
+
const {
|
|
43
|
+
dimensions,
|
|
44
|
+
filters
|
|
45
|
+
} = useMemo(() => {
|
|
46
|
+
var _layout$columns, _layout$rows, _layout$filters;
|
|
47
|
+
const dimensions = {};
|
|
48
|
+
const filters = {};
|
|
49
|
+
forEach([...((_layout$columns = layout === null || layout === void 0 ? void 0 : layout.columns) !== null && _layout$columns !== void 0 ? _layout$columns : []), ...((_layout$rows = layout === null || layout === void 0 ? void 0 : layout.rows) !== null && _layout$rows !== void 0 ? _layout$rows : [])], dimension => {
|
|
50
|
+
set(dimensions, [dimension], analyticsDimensions === null || analyticsDimensions === void 0 ? void 0 : analyticsDimensions[dimension]);
|
|
51
|
+
});
|
|
52
|
+
forEach([...((_layout$filters = layout === null || layout === void 0 ? void 0 : layout.filters) !== null && _layout$filters !== void 0 ? _layout$filters : [])], dimension => {
|
|
53
|
+
set(dimensions, [dimension], analyticsDimensions === null || analyticsDimensions === void 0 ? void 0 : analyticsDimensions[dimension]);
|
|
54
|
+
});
|
|
55
|
+
return {
|
|
56
|
+
dimensions,
|
|
57
|
+
filters
|
|
58
|
+
};
|
|
59
|
+
}, [layout, analyticsDimensions.pe, analyticsDimensions.ou]);
|
|
60
|
+
const {
|
|
61
|
+
data: analytics,
|
|
62
|
+
error,
|
|
63
|
+
loading,
|
|
64
|
+
refetch,
|
|
65
|
+
called
|
|
66
|
+
} = useDataQuery(analyticsQuery, {
|
|
67
|
+
variables: {
|
|
68
|
+
dimensions,
|
|
69
|
+
filters
|
|
70
|
+
},
|
|
71
|
+
lazy: true
|
|
72
|
+
});
|
|
73
|
+
useEffect(() => {
|
|
74
|
+
refetch({
|
|
75
|
+
dimensions,
|
|
76
|
+
filters
|
|
77
|
+
});
|
|
78
|
+
}, [dimensions, filters]);
|
|
79
|
+
useEffect(() => {
|
|
80
|
+
if (error) {
|
|
81
|
+
throw error;
|
|
82
|
+
}
|
|
83
|
+
}, [error]);
|
|
84
|
+
return /*#__PURE__*/React.createElement(AnalyticsContext.Provider, {
|
|
85
|
+
value: {
|
|
86
|
+
analytics: analytics === null || analytics === void 0 ? void 0 : analytics.analytics,
|
|
87
|
+
loading
|
|
88
|
+
}
|
|
89
|
+
}, children);
|
|
90
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import React, { createContext, useContext, useReducer } from "react";
|
|
2
|
+
import { set } from "lodash";
|
|
3
|
+
export const DimensionState = /*#__PURE__*/createContext({
|
|
4
|
+
dx: [],
|
|
5
|
+
pe: [],
|
|
6
|
+
ou: []
|
|
7
|
+
});
|
|
8
|
+
export const DimensionUpdateState = /*#__PURE__*/createContext(undefined);
|
|
9
|
+
function reducer(state, _ref) {
|
|
10
|
+
let {
|
|
11
|
+
dimension,
|
|
12
|
+
value
|
|
13
|
+
} = _ref;
|
|
14
|
+
const updatedState = {
|
|
15
|
+
...(state !== null && state !== void 0 ? state : {})
|
|
16
|
+
};
|
|
17
|
+
set(updatedState, [dimension], value);
|
|
18
|
+
return updatedState;
|
|
19
|
+
}
|
|
20
|
+
export function useDimensions() {
|
|
21
|
+
return [useContext(DimensionState), useContext(DimensionUpdateState)];
|
|
22
|
+
}
|
|
23
|
+
export function DimensionsProvider(_ref2) {
|
|
24
|
+
let {
|
|
25
|
+
children,
|
|
26
|
+
dimensions
|
|
27
|
+
} = _ref2;
|
|
28
|
+
const [state, dispatch] = useReducer(reducer, dimensions);
|
|
29
|
+
return /*#__PURE__*/React.createElement(DimensionState.Provider, {
|
|
30
|
+
value: state
|
|
31
|
+
}, /*#__PURE__*/React.createElement(DimensionUpdateState.Provider, {
|
|
32
|
+
value: dispatch
|
|
33
|
+
}, children));
|
|
34
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import React, { createContext, useContext, useState } from "react";
|
|
2
|
+
export const LayoutState = /*#__PURE__*/createContext(undefined);
|
|
3
|
+
export function useLayout() {
|
|
4
|
+
var _useContext;
|
|
5
|
+
return [(_useContext = useContext(LayoutState)) !== null && _useContext !== void 0 ? _useContext : {
|
|
6
|
+
rows: [],
|
|
7
|
+
filters: [],
|
|
8
|
+
columns: []
|
|
9
|
+
}];
|
|
10
|
+
}
|
|
11
|
+
export function LayoutProvider(_ref) {
|
|
12
|
+
let {
|
|
13
|
+
defaultLayout,
|
|
14
|
+
children
|
|
15
|
+
} = _ref;
|
|
16
|
+
const [layout, setLayout] = useState(defaultLayout);
|
|
17
|
+
return /*#__PURE__*/React.createElement(LayoutState.Provider, {
|
|
18
|
+
value: layout
|
|
19
|
+
}, children);
|
|
20
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import React, { useCallback, useMemo, useState } from "react";
|
|
2
|
+
import { Button, IconClock24, IconLocation24, Tooltip } from "@dhis2/ui";
|
|
3
|
+
import i18n from '@dhis2/d2-i18n';
|
|
4
|
+
import { useDimensions } from "../DimensionsProvider";
|
|
5
|
+
import { OrgUnitSelectorModal, PeriodSelectorModal } from "@hisptz/dhis2-ui";
|
|
6
|
+
import { getOrgUnitSelectionFromIds } from "../VisualizationSelector";
|
|
7
|
+
import { getOrgUnitsSelection } from "../../../Map/utils/map";
|
|
8
|
+
export function VisualizationDimensionSelector() {
|
|
9
|
+
const [dimensions, setDimensions] = useDimensions();
|
|
10
|
+
const periods = useMemo(() => dimensions.pe, [dimensions.pe]);
|
|
11
|
+
const orgUnitSelection = useMemo(() => {
|
|
12
|
+
var _dimensions$ou;
|
|
13
|
+
return getOrgUnitSelectionFromIds((_dimensions$ou = dimensions.ou) !== null && _dimensions$ou !== void 0 ? _dimensions$ou : []);
|
|
14
|
+
}, [dimensions.ou]);
|
|
15
|
+
const [openFilter, setOpenFilter] = useState();
|
|
16
|
+
const onFilterUpdate = useCallback(type => data => {
|
|
17
|
+
setOpenFilter(undefined);
|
|
18
|
+
if (type === "ou") {
|
|
19
|
+
setDimensions({
|
|
20
|
+
dimension: "ou",
|
|
21
|
+
value: getOrgUnitsSelection(data)
|
|
22
|
+
});
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
if (type === "pe") {
|
|
26
|
+
setDimensions({
|
|
27
|
+
dimension: "pe",
|
|
28
|
+
value: data
|
|
29
|
+
});
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
}, [setDimensions]);
|
|
33
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(PeriodSelectorModal, {
|
|
34
|
+
position: "middle",
|
|
35
|
+
enablePeriodSelector: true,
|
|
36
|
+
selectedPeriods: periods,
|
|
37
|
+
onClose: () => setOpenFilter(undefined),
|
|
38
|
+
hide: openFilter !== "pe",
|
|
39
|
+
onUpdate: onFilterUpdate("pe")
|
|
40
|
+
}), /*#__PURE__*/React.createElement(OrgUnitSelectorModal, {
|
|
41
|
+
showUserOptions: true,
|
|
42
|
+
searchable: true,
|
|
43
|
+
title: i18n.t("Select location(s)"),
|
|
44
|
+
value: orgUnitSelection,
|
|
45
|
+
onClose: () => setOpenFilter(undefined),
|
|
46
|
+
hide: openFilter !== "ou",
|
|
47
|
+
onUpdate: onFilterUpdate("ou")
|
|
48
|
+
}), /*#__PURE__*/React.createElement("div", {
|
|
49
|
+
style: {
|
|
50
|
+
display: "flex",
|
|
51
|
+
gap: 8
|
|
52
|
+
}
|
|
53
|
+
}, /*#__PURE__*/React.createElement(Tooltip, {
|
|
54
|
+
content: i18n.t("Period")
|
|
55
|
+
}, /*#__PURE__*/React.createElement(Button, {
|
|
56
|
+
onClick: () => setOpenFilter("pe"),
|
|
57
|
+
icon: /*#__PURE__*/React.createElement(IconClock24, null)
|
|
58
|
+
})), /*#__PURE__*/React.createElement(Tooltip, {
|
|
59
|
+
content: i18n.t("Location")
|
|
60
|
+
}, /*#__PURE__*/React.createElement(Button, {
|
|
61
|
+
onClick: () => setOpenFilter("ou"),
|
|
62
|
+
icon: /*#__PURE__*/React.createElement(IconLocation24, null)
|
|
63
|
+
}))));
|
|
64
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { LayoutProvider } from "../LayoutProvider";
|
|
3
|
+
import { DimensionsProvider } from "../DimensionsProvider";
|
|
4
|
+
import { AnalyticsDataProvider } from "../AnalyticsDataProvider";
|
|
5
|
+
import { VisualizationTypeProvider } from "../VisualizationTypeProvider";
|
|
6
|
+
export function VisualizationProvider(_ref) {
|
|
7
|
+
let {
|
|
8
|
+
layout,
|
|
9
|
+
dimensions,
|
|
10
|
+
children,
|
|
11
|
+
type,
|
|
12
|
+
config
|
|
13
|
+
} = _ref;
|
|
14
|
+
return /*#__PURE__*/React.createElement(DimensionsProvider, {
|
|
15
|
+
dimensions: dimensions
|
|
16
|
+
}, /*#__PURE__*/React.createElement(VisualizationTypeProvider, {
|
|
17
|
+
config: config,
|
|
18
|
+
defaultType: type
|
|
19
|
+
}, /*#__PURE__*/React.createElement(LayoutProvider, {
|
|
20
|
+
defaultLayout: layout
|
|
21
|
+
}, /*#__PURE__*/React.createElement(AnalyticsDataProvider, null, children))));
|
|
22
|
+
}
|