@hisptz/dhis2-analytics 1.0.46 → 1.0.48

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.
@@ -27,8 +27,8 @@ class DHIS2Chart {
27
27
  };
28
28
  }
29
29
  getOptions() {
30
- var _this$config$colors, _this$config2, _this$config$highChar, _this$config3;
31
- return {
30
+ var _this$config$colors, _this$config2, _this$config3;
31
+ const options = {
32
32
  yAxis: this.getYAxis(),
33
33
  chart: this.getChartConfig(),
34
34
  colors: (_this$config$colors = (_this$config2 = this.config) === null || _this$config2 === void 0 ? void 0 : _this$config2.colors) !== null && _this$config$colors !== void 0 ? _this$config$colors : ["#2f7ed8", "#0d233a", "#8bbc21", "#910000", "#1aadce", "#492970", "#f28f43", "#77a1e5", "#c42525", "#a6c96a"],
@@ -44,8 +44,18 @@ class DHIS2Chart {
44
44
  },
45
45
  credits: {
46
46
  enabled: false
47
- },
48
- ...((_this$config$highChar = (_this$config3 = this.config) === null || _this$config3 === void 0 ? void 0 : _this$config3.highChartOverrides) !== null && _this$config$highChar !== void 0 ? _this$config$highChar : {})
47
+ }
48
+ };
49
+ let overrides = {};
50
+ if ((_this$config3 = this.config) !== null && _this$config3 !== void 0 && _this$config3.highChartOverrides) {
51
+ var _this$config4, _this$config$highChar, _this$config5, _this$config6;
52
+ overrides = {
53
+ ...(typeof ((_this$config4 = this.config) === null || _this$config4 === void 0 ? void 0 : _this$config4.highChartOverrides) === "object" ? (_this$config$highChar = (_this$config5 = this.config) === null || _this$config5 === void 0 ? void 0 : _this$config5.highChartOverrides) !== null && _this$config$highChar !== void 0 ? _this$config$highChar : {} : (_this$config6 = this.config) === null || _this$config6 === void 0 ? void 0 : _this$config6.highChartOverrides(options))
54
+ };
55
+ }
56
+ return {
57
+ ...options,
58
+ ...overrides
49
59
  };
50
60
  }
51
61
  getYAxis() {
@@ -86,8 +96,8 @@ class DHIS2Chart {
86
96
  }];
87
97
  }
88
98
  getExporting() {
89
- var _this$config$name, _this$config4;
90
- const name = (_this$config$name = (_this$config4 = this.config) === null || _this$config4 === void 0 ? void 0 : _this$config4.name) !== null && _this$config$name !== void 0 ? _this$config$name : "chart";
99
+ var _this$config$name, _this$config7;
100
+ const name = (_this$config$name = (_this$config7 = this.config) === null || _this$config7 === void 0 ? void 0 : _this$config7.name) !== null && _this$config$name !== void 0 ? _this$config$name : "chart";
91
101
  return {
92
102
  filename: `${name}`,
93
103
  sourceWidth: 1200,
@@ -8,6 +8,7 @@ exports.DimensionsProvider = DimensionsProvider;
8
8
  exports.useDimensions = useDimensions;
9
9
  var _react = _interopRequireWildcard(require("react"));
10
10
  var _lodash = require("lodash");
11
+ var _usehooksTs = require("usehooks-ts");
11
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); }
12
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; }
13
14
  const DimensionState = /*#__PURE__*/(0, _react.createContext)({
@@ -38,6 +39,16 @@ function DimensionsProvider(_ref2) {
38
39
  dimensions
39
40
  } = _ref2;
40
41
  const [state, dispatch] = (0, _react.useReducer)(reducer, dimensions);
42
+ (0, _usehooksTs.useUpdateEffect)(() => {
43
+ Object.keys(dimensions).forEach(dimension => {
44
+ var _dimensions$dimension;
45
+ console.log("updating");
46
+ dispatch({
47
+ dimension: dimension,
48
+ value: (_dimensions$dimension = dimensions[dimension]) !== null && _dimensions$dimension !== void 0 ? _dimensions$dimension : []
49
+ });
50
+ });
51
+ }, [dimensions]);
41
52
  return /*#__PURE__*/_react.default.createElement(DimensionState.Provider, {
42
53
  value: state
43
54
  }, /*#__PURE__*/_react.default.createElement(DimensionUpdateState.Provider, {
@@ -21,8 +21,8 @@ export class DHIS2Chart {
21
21
  };
22
22
  }
23
23
  getOptions() {
24
- var _this$config$colors, _this$config2, _this$config$highChar, _this$config3;
25
- return {
24
+ var _this$config$colors, _this$config2, _this$config3;
25
+ const options = {
26
26
  yAxis: this.getYAxis(),
27
27
  chart: this.getChartConfig(),
28
28
  colors: (_this$config$colors = (_this$config2 = this.config) === null || _this$config2 === void 0 ? void 0 : _this$config2.colors) !== null && _this$config$colors !== void 0 ? _this$config$colors : ["#2f7ed8", "#0d233a", "#8bbc21", "#910000", "#1aadce", "#492970", "#f28f43", "#77a1e5", "#c42525", "#a6c96a"],
@@ -38,8 +38,18 @@ export class DHIS2Chart {
38
38
  },
39
39
  credits: {
40
40
  enabled: false
41
- },
42
- ...((_this$config$highChar = (_this$config3 = this.config) === null || _this$config3 === void 0 ? void 0 : _this$config3.highChartOverrides) !== null && _this$config$highChar !== void 0 ? _this$config$highChar : {})
41
+ }
42
+ };
43
+ let overrides = {};
44
+ if ((_this$config3 = this.config) !== null && _this$config3 !== void 0 && _this$config3.highChartOverrides) {
45
+ var _this$config4, _this$config$highChar, _this$config5, _this$config6;
46
+ overrides = {
47
+ ...(typeof ((_this$config4 = this.config) === null || _this$config4 === void 0 ? void 0 : _this$config4.highChartOverrides) === "object" ? (_this$config$highChar = (_this$config5 = this.config) === null || _this$config5 === void 0 ? void 0 : _this$config5.highChartOverrides) !== null && _this$config$highChar !== void 0 ? _this$config$highChar : {} : (_this$config6 = this.config) === null || _this$config6 === void 0 ? void 0 : _this$config6.highChartOverrides(options))
48
+ };
49
+ }
50
+ return {
51
+ ...options,
52
+ ...overrides
43
53
  };
44
54
  }
45
55
  getYAxis() {
@@ -80,8 +90,8 @@ export class DHIS2Chart {
80
90
  }];
81
91
  }
82
92
  getExporting() {
83
- var _this$config$name, _this$config4;
84
- const name = (_this$config$name = (_this$config4 = this.config) === null || _this$config4 === void 0 ? void 0 : _this$config4.name) !== null && _this$config$name !== void 0 ? _this$config$name : "chart";
93
+ var _this$config$name, _this$config7;
94
+ const name = (_this$config$name = (_this$config7 = this.config) === null || _this$config7 === void 0 ? void 0 : _this$config7.name) !== null && _this$config$name !== void 0 ? _this$config$name : "chart";
85
95
  return {
86
96
  filename: `${name}`,
87
97
  sourceWidth: 1200,
@@ -1,5 +1,6 @@
1
1
  import React, { createContext, useContext, useReducer } from "react";
2
2
  import { set } from "lodash";
3
+ import { useUpdateEffect } from "usehooks-ts";
3
4
  export const DimensionState = /*#__PURE__*/createContext({
4
5
  dx: [],
5
6
  pe: [],
@@ -26,6 +27,16 @@ export function DimensionsProvider(_ref2) {
26
27
  dimensions
27
28
  } = _ref2;
28
29
  const [state, dispatch] = useReducer(reducer, dimensions);
30
+ useUpdateEffect(() => {
31
+ Object.keys(dimensions).forEach(dimension => {
32
+ var _dimensions$dimension;
33
+ console.log("updating");
34
+ dispatch({
35
+ dimension: dimension,
36
+ value: (_dimensions$dimension = dimensions[dimension]) !== null && _dimensions$dimension !== void 0 ? _dimensions$dimension : []
37
+ });
38
+ });
39
+ }, [dimensions]);
29
40
  return /*#__PURE__*/React.createElement(DimensionState.Provider, {
30
41
  value: state
31
42
  }, /*#__PURE__*/React.createElement(DimensionUpdateState.Provider, {
@@ -1,5 +1,5 @@
1
1
  import type { Analytics } from "@hisptz/dhis2-utils";
2
- import { DashStyleValue, YAxisOptions, YAxisPlotLinesLabelOptions } from "highcharts";
2
+ import HighCharts, { DashStyleValue, YAxisOptions, YAxisPlotLinesLabelOptions } from "highcharts";
3
3
  export type ChartType = "column" | "pie" | "stacked-column" | "line" | "multi-series";
4
4
  export interface MultiSeriesConfig {
5
5
  series?: Array<{
@@ -33,7 +33,7 @@ export type ChartConfig = {
33
33
  colors?: Array<string>;
34
34
  name?: string;
35
35
  allowChartTypeChange?: boolean;
36
- highChartOverrides?: Record<string, any>;
36
+ highChartOverrides?: Partial<HighCharts.Options> | ((config: HighCharts.Options) => Partial<HighCharts.Options>);
37
37
  multiSeries?: MultiSeriesConfig;
38
38
  };
39
39
  export type ChartAnalyticsProps = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hisptz/dhis2-analytics",
3
- "version": "1.0.46",
3
+ "version": "1.0.48",
4
4
  "description": "A collection of reusable react components for visualizing analytics data from DHIS2",
5
5
  "license": "BSD-3-Clause",
6
6
  "scripts": {
@@ -31,7 +31,7 @@
31
31
  },
32
32
  "dependencies": {
33
33
  "@dhis2/app-runtime": "^3.7.0",
34
- "@hisptz/dhis2-ui": "^1.0.45",
34
+ "@hisptz/dhis2-ui": "^1.0.48",
35
35
  "@hisptz/dhis2-utils": "*",
36
36
  "@react-leaflet/core": "^2.1.0",
37
37
  "async-es": "^3.2.4",
@@ -87,5 +87,5 @@
87
87
  "react-hook-form": "^7.43",
88
88
  "recoil": "*"
89
89
  },
90
- "gitHead": "7bd2883e4e4ebad6f2d45b81adbde2c41cf452d5"
90
+ "gitHead": "5dddaf337ef5f206f9bf156b587f8357b80b2196"
91
91
  }