@dhis2/analytics 23.13.0 → 23.13.4

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/CHANGELOG.md CHANGED
@@ -1,3 +1,31 @@
1
+ ## [23.13.4](https://github.com/dhis2/analytics/compare/v23.13.3...v23.13.4) (2022-08-05)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * request first page when sorting/filtering ([#1301](https://github.com/dhis2/analytics/issues/1301)) ([125e2af](https://github.com/dhis2/analytics/commit/125e2af84c19c81a9f8665d3e0cf2a88aaffdbda))
7
+
8
+ ## [23.13.3](https://github.com/dhis2/analytics/compare/v23.13.2...v23.13.3) (2022-08-02)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * avoid ES2022 functions ([#1300](https://github.com/dhis2/analytics/issues/1300)) ([93ab848](https://github.com/dhis2/analytics/commit/93ab848e89e4c22a2d9ca20625287af892ef8d89))
14
+
15
+ ## [23.13.2](https://github.com/dhis2/analytics/compare/v23.13.1...v23.13.2) (2022-08-01)
16
+
17
+
18
+ ### Bug Fixes
19
+
20
+ * highcharts legend when exporting (DHIS2-12719) ([#1279](https://github.com/dhis2/analytics/issues/1279)) ([5f62e20](https://github.com/dhis2/analytics/commit/5f62e2050a1ff7411308a32f87f3e427cdbb4bb4))
21
+
22
+ ## [23.13.1](https://github.com/dhis2/analytics/compare/v23.13.0...v23.13.1) (2022-07-28)
23
+
24
+
25
+ ### Bug Fixes
26
+
27
+ * **translations:** sync translations from transifex (master) ([d3a1f4e](https://github.com/dhis2/analytics/commit/d3a1f4e861cf29e95f9615f3585e814d52aa837f))
28
+
1
29
  # [23.13.0](https://github.com/dhis2/analytics/compare/v23.12.5...v23.13.0) (2022-07-25)
2
30
 
3
31
 
@@ -79,25 +79,28 @@ const OpenFileDialog = _ref2 => {
79
79
  onNew,
80
80
  currentUser
81
81
  } = _ref2;
82
- const filesQuery = (0, _react.useMemo)(() => getQuery(type), []);
82
+ const filesQuery = (0, _react.useMemo)(() => getQuery(type), [type]);
83
83
  const defaultFilters = {
84
84
  searchTerm: '',
85
85
  createdBy: _CreatedByFilter.CREATED_BY_ALL,
86
86
  visType: defaultFilterVisType
87
87
  };
88
88
  const [{
89
+ page,
89
90
  sortField,
90
- sortDirection
91
- }, setSorting] = (0, _react.useState)({
91
+ sortDirection,
92
+ filters
93
+ }, setState] = (0, _react.useReducer)((state, newState) => ({ ...state,
94
+ ...newState
95
+ }), {
96
+ page: 1,
92
97
  sortField: 'displayName',
93
- sortDirection: 'asc'
98
+ sortDirection: 'asc',
99
+ filters: defaultFilters
94
100
  });
95
- const [page, setPage] = (0, _react.useState)(1);
96
101
  const [nameFilterValue, setNameFilterValue] = (0, _react.useState)(defaultFilters.searchTerm);
97
102
  const [searchTimeout, setSearchTimeout] = (0, _react.useState)(null);
98
- const [filters, setFilters] = (0, _react.useState)(defaultFilters);
99
-
100
- const formatFilters = () => {
103
+ const formatFilters = (0, _react.useCallback)(() => {
101
104
  const queryFilters = [];
102
105
 
103
106
  switch (filters.createdBy) {
@@ -134,8 +137,7 @@ const OpenFileDialog = _ref2 => {
134
137
  }
135
138
 
136
139
  return queryFilters;
137
- };
138
-
140
+ }, [currentUser, filters]);
139
141
  const {
140
142
  loading,
141
143
  error,
@@ -146,10 +148,29 @@ const OpenFileDialog = _ref2 => {
146
148
  });
147
149
 
148
150
  const resetFilters = () => {
149
- setFilters(defaultFilters);
151
+ setState({
152
+ filters: defaultFilters,
153
+ page: 1
154
+ });
150
155
  setNameFilterValue(defaultFilters.searchTerm);
151
156
  };
152
157
 
158
+ const setPage = pageNum => setState({
159
+ page: pageNum
160
+ });
161
+
162
+ const sortData = _ref3 => {
163
+ let {
164
+ name,
165
+ direction
166
+ } = _ref3;
167
+ return setState({
168
+ sortField: name,
169
+ sortDirection: direction,
170
+ page: 1
171
+ });
172
+ };
173
+
153
174
  (0, _react.useEffect)(() => {
154
175
  // only fetch data when the dialog is open
155
176
  if (open) {
@@ -160,19 +181,7 @@ const OpenFileDialog = _ref2 => {
160
181
  filters: formatFilters()
161
182
  });
162
183
  }
163
- }, [open, page, sortField, sortDirection]);
164
- (0, _react.useEffect)(() => {
165
- // avoid fetching data when the dialog is first rendered (hidden)
166
- if (open) {
167
- // reset pagination when filters are applied/changed
168
- setPage(1);
169
- refetch({
170
- sortField,
171
- sortDirection,
172
- filters: formatFilters()
173
- });
174
- }
175
- }, [filters]);
184
+ }, [open, page, sortField, sortDirection, filters, refetch, formatFilters]);
176
185
  const headers = [{
177
186
  field: 'displayName',
178
187
  label: _d2I18n.default.t('Name'),
@@ -216,8 +225,11 @@ const OpenFileDialog = _ref2 => {
216
225
  onChange: value => {
217
226
  setNameFilterValue(value);
218
227
  clearTimeout(searchTimeout);
219
- setSearchTimeout(setTimeout(() => setFilters({ ...filters,
220
- searchTerm: value
228
+ setSearchTimeout(setTimeout(() => setState({
229
+ page: 1,
230
+ filters: { ...filters,
231
+ searchTerm: value
232
+ }
221
233
  }), 200));
222
234
  }
223
235
  })), (filterVisTypes === null || filterVisTypes === void 0 ? void 0 : filterVisTypes.length) && /*#__PURE__*/_react.default.createElement("div", {
@@ -225,15 +237,21 @@ const OpenFileDialog = _ref2 => {
225
237
  }, /*#__PURE__*/_react.default.createElement(_VisTypeFilter.VisTypeFilter, {
226
238
  visTypes: filterVisTypes,
227
239
  selected: filters.visType,
228
- onChange: value => setFilters({ ...filters,
229
- visType: value
240
+ onChange: value => setState({
241
+ page: 1,
242
+ filters: { ...filters,
243
+ visType: value
244
+ }
230
245
  })
231
246
  })), /*#__PURE__*/_react.default.createElement("div", {
232
247
  className: "jsx-".concat(_OpenFileDialogStyles.styles.__hash) + " " + "created-by-field-container"
233
248
  }, /*#__PURE__*/_react.default.createElement(_CreatedByFilter.CreatedByFilter, {
234
249
  selected: filters.createdBy,
235
- onChange: value => setFilters({ ...filters,
236
- createdBy: value
250
+ onChange: value => setState({
251
+ page: 1,
252
+ filters: { ...filters,
253
+ createdBy: value
254
+ }
237
255
  })
238
256
  })), !(0, _isEqual.default)(filters, defaultFilters) && /*#__PURE__*/_react.default.createElement(_ui.Button, {
239
257
  onClick: resetFilters,
@@ -246,26 +264,17 @@ const OpenFileDialog = _ref2 => {
246
264
  className: "jsx-".concat(_OpenFileDialogStyles.styles.__hash) + " " + "data-table-wrapper"
247
265
  }, /*#__PURE__*/_react.default.createElement(_ui.DataTable, {
248
266
  layout: "fixed"
249
- }, /*#__PURE__*/_react.default.createElement(_ui.DataTableHead, null, /*#__PURE__*/_react.default.createElement(_ui.DataTableRow, null, data !== null && data !== void 0 && data.files[_utils.AOTypeMap[type].apiEndpoint].length ? headers.map(_ref3 => {
267
+ }, /*#__PURE__*/_react.default.createElement(_ui.DataTableHead, null, /*#__PURE__*/_react.default.createElement(_ui.DataTableRow, null, data !== null && data !== void 0 && data.files[_utils.AOTypeMap[type].apiEndpoint].length ? headers.map(_ref4 => {
250
268
  let {
251
269
  field,
252
270
  label,
253
271
  width
254
- } = _ref3;
272
+ } = _ref4;
255
273
  return /*#__PURE__*/_react.default.createElement(_ui.DataTableColumnHeader, {
256
274
  width: width,
257
275
  key: field,
258
276
  name: field,
259
- onSortIconClick: _ref4 => {
260
- let {
261
- name,
262
- direction
263
- } = _ref4;
264
- return setSorting({
265
- sortField: name,
266
- sortDirection: direction
267
- });
268
- },
277
+ onSortIconClick: sortData,
269
278
  sortDirection: getSortDirection(field)
270
279
  }, label);
271
280
  }) : /*#__PURE__*/_react.default.createElement(_ui.DataTableColumnHeader, null))), /*#__PURE__*/_react.default.createElement(_ui.DataTableBody, {
@@ -200,9 +200,9 @@
200
200
  "Bi-weekly": "Tweewekelijks",
201
201
  "Monthly": "Maandelijks",
202
202
  "Bi-monthly": "Tweemaandelijks",
203
- "Quarterly": "",
204
- "Six-monthly": "",
205
- "Six-monthly April": "",
203
+ "Quarterly": "Driemaandelijks",
204
+ "Six-monthly": "Zesmaandelijks",
205
+ "Six-monthly April": "Zesmaandelijks april",
206
206
  "Yearly": "Jaarlijks",
207
207
  "Financial year (Start November)": "Financieel jaar (Start november)",
208
208
  "Financial year (Start October)": "Financieel jaar (Start oktober)",
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.getLegendByValueFromLegendSet = exports.getColorByValueFromLegendSet = exports.LEGEND_DISPLAY_STYLE_TEXT = exports.LEGEND_DISPLAY_STYLE_FILL = exports.LEGEND_DISPLAY_STRATEGY_FIXED = exports.LEGEND_DISPLAY_STRATEGY_BY_DATA_ITEM = void 0;
6
+ exports.getLegendSetByDisplayStrategy = exports.getLegendByValueFromLegendSet = exports.getColorByValueFromLegendSet = exports.LEGEND_DISPLAY_STYLE_TEXT = exports.LEGEND_DISPLAY_STYLE_FILL = exports.LEGEND_DISPLAY_STRATEGY_FIXED = exports.LEGEND_DISPLAY_STRATEGY_BY_DATA_ITEM = void 0;
7
7
  const LEGEND_DISPLAY_STRATEGY_BY_DATA_ITEM = 'BY_DATA_ITEM';
8
8
  exports.LEGEND_DISPLAY_STRATEGY_BY_DATA_ITEM = LEGEND_DISPLAY_STRATEGY_BY_DATA_ITEM;
9
9
  const LEGEND_DISPLAY_STRATEGY_FIXED = 'FIXED';
@@ -27,4 +27,22 @@ const getColorByValueFromLegendSet = (legendSet, value) => {
27
27
  return legend && legend.color;
28
28
  };
29
29
 
30
- exports.getColorByValueFromLegendSet = getColorByValueFromLegendSet;
30
+ exports.getColorByValueFromLegendSet = getColorByValueFromLegendSet;
31
+
32
+ const getLegendSetByDisplayStrategy = _ref => {
33
+ let {
34
+ displayStrategy,
35
+ legendSets,
36
+ legendSetId
37
+ } = _ref;
38
+
39
+ if (displayStrategy === LEGEND_DISPLAY_STRATEGY_FIXED && legendSets.length) {
40
+ return legendSets[0];
41
+ } else if (displayStrategy === LEGEND_DISPLAY_STRATEGY_BY_DATA_ITEM) {
42
+ return legendSets.find(legendSet => legendSet.id === legendSetId);
43
+ } else {
44
+ return null;
45
+ }
46
+ };
47
+
48
+ exports.getLegendSetByDisplayStrategy = getLegendSetByDisplayStrategy;
@@ -64,7 +64,7 @@ const getTransformedExtraOptions = extraOptions => ({ ...extraOptions,
64
64
  });
65
65
 
66
66
  function _default(_ref) {
67
- var _layout$seriesKey, _layout$seriesKey2, _layout$seriesKey2$la, _layout$legend, _config$xAxis;
67
+ var _layout$legend, _layout$seriesKey, _layout$seriesKey2, _layout$seriesKey2$la, _config$xAxis;
68
68
 
69
69
  let {
70
70
  store,
@@ -110,16 +110,21 @@ function _default(_ref) {
110
110
  // y-axis
111
111
  yAxis: (0, _index7.default)(_layout, series, _extraOptions),
112
112
  // series
113
- series: (0, _index3.default)(series.slice(), store.data[0].metaData, _layout, stacked, _extraOptions),
113
+ series: (0, _index3.default)({
114
+ series: series.slice(),
115
+ metaData: store.data[0].metaData.items,
116
+ layout: _layout,
117
+ isStacked: stacked,
118
+ extraOptions: _extraOptions,
119
+ legendSets,
120
+ displayStrategy: (_layout$legend = _layout.legend) === null || _layout$legend === void 0 ? void 0 : _layout$legend.strategy
121
+ }),
114
122
  // legend
115
123
  legend: (0, _legend.default)({
116
124
  isHidden: (_layout$seriesKey = _layout.seriesKey) === null || _layout$seriesKey === void 0 ? void 0 : _layout$seriesKey.hidden,
117
125
  fontStyle: (_layout$seriesKey2 = _layout.seriesKey) === null || _layout$seriesKey2 === void 0 ? void 0 : (_layout$seriesKey2$la = _layout$seriesKey2.label) === null || _layout$seriesKey2$la === void 0 ? void 0 : _layout$seriesKey2$la.fontStyle,
118
126
  visType: _layout.type,
119
- dashboard: _extraOptions.dashboard,
120
- legendSets,
121
- metaData: store.data[0].metaData.items,
122
- displayStrategy: (_layout$legend = _layout.legend) === null || _layout$legend === void 0 ? void 0 : _layout$legend.strategy
127
+ dashboard: _extraOptions.dashboard
123
128
  }),
124
129
  // pane
125
130
  pane: (0, _index2.default)(_layout.type),
@@ -7,18 +7,10 @@ exports.default = _default;
7
7
 
8
8
  var _fontStyle = require("../../../../modules/fontStyle.js");
9
9
 
10
- var _legends = require("../../../../modules/legends.js");
11
-
12
10
  var _visTypes = require("../../../../modules/visTypes.js");
13
11
 
14
- var _colorSets = require("../../../util/colors/colorSets.js");
15
-
16
12
  var _getTextAlignOption = require("./getTextAlignOption.js");
17
13
 
18
- var _type = _interopRequireDefault(require("./type.js"));
19
-
20
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
-
22
14
  const DASHBOARD_ITEM_STYLE = {
23
15
  fontSize: '11px',
24
16
  fontWeight: 500
@@ -48,100 +40,15 @@ function getLegend(fontStyle, dashboard, visType) {
48
40
  });
49
41
  }
50
42
 
51
- const getLegendSetByDisplayStrategy = _ref => {
52
- let {
53
- displayStrategy,
54
- legendSets,
55
- legendSetId
56
- } = _ref;
57
-
58
- if (displayStrategy === _legends.LEGEND_DISPLAY_STRATEGY_FIXED && legendSets.length) {
59
- return legendSets[0];
60
- } else if (displayStrategy === _legends.LEGEND_DISPLAY_STRATEGY_BY_DATA_ITEM) {
61
- return legendSets.find(legendSet => legendSet.id === legendSetId);
62
- } else {
63
- return null;
64
- }
65
- };
66
-
67
- const formatLabel = _ref2 => {
68
- var _metaData$seriesId, _legendSet$legends;
69
-
70
- let {
71
- seriesId,
72
- seriesColor,
73
- seriesName,
74
- seriesType,
75
- metaData,
76
- displayStrategy,
77
- legendSets,
78
- fontStyle,
79
- visType
80
- } = _ref2;
81
- const legendSet = getLegendSetByDisplayStrategy({
82
- displayStrategy,
83
- legendSets,
84
- legendSetId: (_metaData$seriesId = metaData[seriesId]) === null || _metaData$seriesId === void 0 ? void 0 : _metaData$seriesId.legendSet
85
- });
86
- const result = []; // Note: Highcharts strips out 'data-test' and similar attributes, hence 'class="data-test-..." was used instead
87
-
88
- result.push('<div style="display: flex; align-items: center; margin-bottom: 4px;" class="data-test-series-key-item">');
89
-
90
- if ((!seriesId || seriesId.startsWith('trendline')) && seriesType === (0, _type.default)(_visTypes.VIS_TYPE_LINE).type) {
91
- // trendline
92
- result.push("<span style=\"height: ".concat(fontStyle[_fontStyle.FONT_STYLE_OPTION_FONT_SIZE] / 6.5, "px; width: ").concat(fontStyle[_fontStyle.FONT_STYLE_OPTION_FONT_SIZE], "px; background-color: ").concat(seriesColor, "; display: inline-block;\"></span>"));
93
- result.push("<span style=\"margin-left: 8px\" class=\"data-test-series-key-item-name\">".concat(seriesName, "</span>"));
94
- } else if (legendSet !== null && legendSet !== void 0 && (_legendSet$legends = legendSet.legends) !== null && _legendSet$legends !== void 0 && _legendSet$legends.length && (0, _visTypes.isLegendSetType)(visType) && seriesType !== (0, _type.default)(_visTypes.VIS_TYPE_LINE).type) {
95
- // item with legend set
96
- legendSet.legends.sort((a, b) => a.startValue - b.startValue).forEach((legend, index) => result.push("<svg width=\"".concat(fontStyle[_fontStyle.FONT_STYLE_OPTION_FONT_SIZE], "\" height=\"").concat(fontStyle[_fontStyle.FONT_STYLE_OPTION_FONT_SIZE], "\" style=\"margin-right:-5px; z-index: ").concat(legendSet.legends.length - index, "\" class=\"data-test-series-key-item-bullet\">\n <circle cx=\"").concat(fontStyle[_fontStyle.FONT_STYLE_OPTION_FONT_SIZE] / 2, "\" cy=\"").concat(fontStyle[_fontStyle.FONT_STYLE_OPTION_FONT_SIZE] / 2, "\" r=\"").concat(fontStyle[_fontStyle.FONT_STYLE_OPTION_FONT_SIZE] / 2, "\" fill=\"").concat(legend.color, "\"></circle>\n </svg>")));
97
- result.push("<span style=\"margin-left: 8px\" class=\"data-test-series-key-item-name\">".concat(seriesName, "</span>"));
98
- } else {
99
- // regular item (not a trendline, no applied legend set)
100
- if ((seriesColor === null || seriesColor === void 0 ? void 0 : seriesColor.patternIndex) !== undefined) {
101
- const pattern = _colorSets.colorSets[_colorSets.COLOR_SET_PATTERNS].patterns[seriesColor.patternIndex];
102
- result.push("<svg style=\"height: ".concat(fontStyle[_fontStyle.FONT_STYLE_OPTION_FONT_SIZE], "px; width: ").concat(fontStyle[_fontStyle.FONT_STYLE_OPTION_FONT_SIZE], "px; display: inline-block; margin-right:5px\" class=\"data-test-series-key-item-bullet\">\n <defs>\n <pattern id=\"pattern").concat(seriesColor.patternIndex, "\" patternUnits=\"userSpaceOnUse\" width=\"").concat(pattern.width, "\" height=\"").concat(pattern.height, "\">\n <path stroke=\"").concat(pattern.color, "\" d=\"").concat(pattern.path, "\"/>\n </pattern>\n </defs>\n <circle cx=\"").concat(fontStyle[_fontStyle.FONT_STYLE_OPTION_FONT_SIZE] / 2, "\" cy=\"").concat(fontStyle[_fontStyle.FONT_STYLE_OPTION_FONT_SIZE] / 2, "\" r=\"").concat(fontStyle[_fontStyle.FONT_STYLE_OPTION_FONT_SIZE] / 2, "\" fill=\"url(#pattern").concat(seriesColor.patternIndex, ")\"/>\n </svg>"));
103
- } else {
104
- result.push("<svg width=\"".concat(fontStyle[_fontStyle.FONT_STYLE_OPTION_FONT_SIZE], "\" height=\"").concat(fontStyle[_fontStyle.FONT_STYLE_OPTION_FONT_SIZE], "\" style=\"margin-right:5px\" class=\"data-test-series-key-item-bullet\">\n <circle cx=\"").concat(fontStyle[_fontStyle.FONT_STYLE_OPTION_FONT_SIZE] / 2, "\" cy=\"").concat(fontStyle[_fontStyle.FONT_STYLE_OPTION_FONT_SIZE] / 2, "\" r=\"").concat(fontStyle[_fontStyle.FONT_STYLE_OPTION_FONT_SIZE] / 2, "\" fill=\"").concat(seriesColor, "\"></circle>\n </svg>"));
105
- }
106
-
107
- result.push("<span class=\"data-test-series-key-item-name\">".concat(seriesName, "</span>"));
108
- }
109
-
110
- result.push('</div>');
111
- return result.join('');
112
- };
113
-
114
- function _default(_ref3) {
43
+ function _default(_ref) {
115
44
  let {
116
45
  isHidden,
117
46
  fontStyle,
118
47
  visType,
119
- dashboard,
120
- legendSets = [],
121
- metaData,
122
- displayStrategy
123
- } = _ref3;
48
+ dashboard
49
+ } = _ref;
124
50
  const mergedFontStyle = (0, _fontStyle.mergeFontStyleWithDefault)(fontStyle, _fontStyle.FONT_STYLE_LEGEND);
125
51
  return isHidden || visType === _visTypes.VIS_TYPE_SCATTER ? {
126
52
  enabled: false
127
- } : Object.assign({}, getLegend(mergedFontStyle, dashboard, visType), getItemStyle(mergedFontStyle, dashboard), {
128
- useHTML: true,
129
- symbolWidth: 0.001,
130
- symbolHeight: 0.001,
131
- labelFormatter: function () {
132
- var _this$userOptions, _this$userOptions2;
133
-
134
- return formatLabel({
135
- seriesId: (_this$userOptions = this.userOptions) === null || _this$userOptions === void 0 ? void 0 : _this$userOptions.id,
136
- seriesColor: this.color,
137
- seriesName: this.name,
138
- seriesType: (_this$userOptions2 = this.userOptions) === null || _this$userOptions2 === void 0 ? void 0 : _this$userOptions2.type,
139
- metaData,
140
- displayStrategy,
141
- legendSets,
142
- fontStyle: mergedFontStyle,
143
- visType
144
- });
145
- }
146
- });
53
+ } : Object.assign({}, getLegend(mergedFontStyle, dashboard, visType), getItemStyle(mergedFontStyle, dashboard));
147
54
  }
@@ -11,6 +11,8 @@ var _axis = require("../../../../../modules/axis.js");
11
11
 
12
12
  var _axisHasRelativeItems = require("../../../../../modules/layout/axisHasRelativeItems.js");
13
13
 
14
+ var _legends = require("../../../../../modules/legends.js");
15
+
14
16
  var _visTypes = require("../../../../../modules/visTypes.js");
15
17
 
16
18
  var _axisId = require("../../../../util/axisId.js");
@@ -95,12 +97,21 @@ function getIdColorMap(series, layout, extraOptions) {
95
97
  }
96
98
  }
97
99
 
98
- function getDefault(series, metaData, layout, isStacked, extraOptions) {
100
+ function getDefault(_ref) {
101
+ let {
102
+ series,
103
+ metaData,
104
+ layout,
105
+ isStacked,
106
+ extraOptions,
107
+ legendSets,
108
+ displayStrategy
109
+ } = _ref;
99
110
  const fullIdAxisMap = (0, _customAxes.getFullIdAxisMap)(layout.series, series);
100
111
  const idColorMap = getIdColorMap(series, layout, extraOptions);
101
112
  const indexColorPatternMap = getIndexColorPatternMap(series, layout, extraOptions);
102
113
  series.forEach((seriesObj, index) => {
103
- var _seriesObj$custom, _layout$series2;
114
+ var _seriesObj$custom, _layout$series2, _metaData$seriesObj$i;
104
115
 
105
116
  // show values
106
117
  if (!seriesObj.dataLabels && (layout.showValues || layout.showData)) {
@@ -160,6 +171,15 @@ function getDefault(series, metaData, layout, isStacked, extraOptions) {
160
171
  if (extraOptions.yearlySeries) {
161
172
  seriesObj.name = extraOptions.yearlySeries[index];
162
173
  }
174
+
175
+ seriesObj.legendSet = (0, _legends.getLegendSetByDisplayStrategy)({
176
+ displayStrategy,
177
+ legendSets,
178
+ legendSetId: (_metaData$seriesObj$i = metaData[seriesObj.id]) === null || _metaData$seriesObj$i === void 0 ? void 0 : _metaData$seriesObj$i.legendSet
179
+ });
180
+ seriesObj.marker = {
181
+ enabled: false
182
+ };
163
183
  }); // DHIS2-701: use cumulative values
164
184
 
165
185
  if (layout.cumulativeValues === true) {
@@ -169,7 +189,17 @@ function getDefault(series, metaData, layout, isStacked, extraOptions) {
169
189
  return series;
170
190
  }
171
191
 
172
- function _default(series, metaData, layout, isStacked, extraOptions) {
192
+ function _default(_ref2) {
193
+ let {
194
+ series,
195
+ metaData,
196
+ layout,
197
+ isStacked,
198
+ extraOptions,
199
+ legendSets,
200
+ displayStrategy
201
+ } = _ref2;
202
+
173
203
  switch (layout.type) {
174
204
  case _visTypes.VIS_TYPE_PIE:
175
205
  series = (0, _pie.default)(series, Object.values(getIdColorMap(series, layout, extraOptions)));
@@ -184,7 +214,15 @@ function _default(series, metaData, layout, isStacked, extraOptions) {
184
214
  break;
185
215
 
186
216
  default:
187
- series = getDefault(series, metaData, layout, isStacked, extraOptions);
217
+ series = getDefault({
218
+ series,
219
+ metaData,
220
+ layout,
221
+ isStacked,
222
+ extraOptions,
223
+ legendSets,
224
+ displayStrategy
225
+ });
188
226
  }
189
227
 
190
228
  series.forEach(seriesObj => {
@@ -29,6 +29,38 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
29
29
  (0, _patternFill.default)(_highcharts.default);
30
30
  (0, _boost.default)(_highcharts.default);
31
31
 
32
+ function drawLegendSymbolWrap() {
33
+ const pick = _highcharts.default.pick;
34
+
35
+ _highcharts.default.wrap(_highcharts.default.seriesTypes.column.prototype, 'drawLegendSymbol', function (proceed, legend, item) {
36
+ var _this$options$legendS, _this$options$legendS2;
37
+
38
+ if ((_this$options$legendS = this.options.legendSet) !== null && _this$options$legendS !== void 0 && (_this$options$legendS2 = _this$options$legendS.legends) !== null && _this$options$legendS2 !== void 0 && _this$options$legendS2.length) {
39
+ const ys = legend.baseline - legend.symbolHeight + 1,
40
+ // y start
41
+ x = legend.symbolWidth / 2 > 8 ? legend.symbolWidth / 2 : 8,
42
+ // x start
43
+ ye = legend.symbolHeight + ys; // y end
44
+
45
+ const legends = this.options.legendSet.legends.sort((a, b) => a.startValue - b.startValue);
46
+ this.chart.renderer.path(['M', x, ys, 'A', 1, 1, 0, 0, 0, x, ye, 'V', ys]).attr({
47
+ fill: legends[legends.length >= 5 ? 1 : 0].color
48
+ }).add(this.legendGroup);
49
+ this.chart.renderer.path(['M', x, ye, 'A', 1, 1, 0, 0, 0, x, ys, 'V', ye]).attr({
50
+ fill: legends[legends.length >= 5 ? legends.length - 2 : legends.length - 1].color
51
+ }).add(this.legendGroup);
52
+ } else {
53
+ var options = legend.options,
54
+ symbolHeight = legend.symbolHeight,
55
+ square = options.squareSymbol,
56
+ symbolWidth = square ? symbolHeight : legend.symbolWidth;
57
+ item.legendSymbol = this.chart.renderer.rect(square ? (legend.symbolWidth - symbolHeight) / 2 : 0, legend.baseline - symbolHeight + 1, symbolWidth, symbolHeight, pick(legend.options.symbolRadius, symbolHeight / 2)).addClass('highcharts-point').attr({
58
+ zIndex: 3
59
+ }).add(item.legendGroup);
60
+ }
61
+ });
62
+ }
63
+
32
64
  function _default(config, el) {
33
65
  if (config) {
34
66
  config.chart.renderTo = el || config.chart.renderTo; // silence warning about accessibility
@@ -43,6 +75,7 @@ function _default(config, el) {
43
75
  });
44
76
  }
45
77
 
78
+ drawLegendSymbolWrap();
46
79
  return new _highcharts.default.Chart(config);
47
80
  }
48
81
  }
@@ -4,7 +4,7 @@ import i18n from '@dhis2/d2-i18n';
4
4
  import { Box, Modal, ModalTitle, ModalContent, DataTable, DataTableHead, DataTableBody, DataTableRow, DataTableCell, DataTableColumnHeader, NoticeBox, CircularLoader, Button } from '@dhis2/ui';
5
5
  import isEqual from 'lodash/isEqual';
6
6
  import PropTypes from 'prop-types';
7
- import React, { useEffect, useMemo, useState } from 'react';
7
+ import React, { useCallback, useEffect, useMemo, useReducer, useState } from 'react';
8
8
  import { VIS_TYPE_GROUP_ALL, VIS_TYPE_GROUP_CHARTS } from '../../modules/visTypes.js';
9
9
  import { CreatedByFilter, CREATED_BY_ALL, CREATED_BY_ALL_BUT_CURRENT_USER, CREATED_BY_CURRENT_USER } from './CreatedByFilter.js';
10
10
  import { FileList } from './FileList.js';
@@ -52,25 +52,28 @@ export const OpenFileDialog = _ref2 => {
52
52
  onNew,
53
53
  currentUser
54
54
  } = _ref2;
55
- const filesQuery = useMemo(() => getQuery(type), []);
55
+ const filesQuery = useMemo(() => getQuery(type), [type]);
56
56
  const defaultFilters = {
57
57
  searchTerm: '',
58
58
  createdBy: CREATED_BY_ALL,
59
59
  visType: defaultFilterVisType
60
60
  };
61
61
  const [{
62
+ page,
62
63
  sortField,
63
- sortDirection
64
- }, setSorting] = useState({
64
+ sortDirection,
65
+ filters
66
+ }, setState] = useReducer((state, newState) => ({ ...state,
67
+ ...newState
68
+ }), {
69
+ page: 1,
65
70
  sortField: 'displayName',
66
- sortDirection: 'asc'
71
+ sortDirection: 'asc',
72
+ filters: defaultFilters
67
73
  });
68
- const [page, setPage] = useState(1);
69
74
  const [nameFilterValue, setNameFilterValue] = useState(defaultFilters.searchTerm);
70
75
  const [searchTimeout, setSearchTimeout] = useState(null);
71
- const [filters, setFilters] = useState(defaultFilters);
72
-
73
- const formatFilters = () => {
76
+ const formatFilters = useCallback(() => {
74
77
  const queryFilters = [];
75
78
 
76
79
  switch (filters.createdBy) {
@@ -107,8 +110,7 @@ export const OpenFileDialog = _ref2 => {
107
110
  }
108
111
 
109
112
  return queryFilters;
110
- };
111
-
113
+ }, [currentUser, filters]);
112
114
  const {
113
115
  loading,
114
116
  error,
@@ -119,10 +121,29 @@ export const OpenFileDialog = _ref2 => {
119
121
  });
120
122
 
121
123
  const resetFilters = () => {
122
- setFilters(defaultFilters);
124
+ setState({
125
+ filters: defaultFilters,
126
+ page: 1
127
+ });
123
128
  setNameFilterValue(defaultFilters.searchTerm);
124
129
  };
125
130
 
131
+ const setPage = pageNum => setState({
132
+ page: pageNum
133
+ });
134
+
135
+ const sortData = _ref3 => {
136
+ let {
137
+ name,
138
+ direction
139
+ } = _ref3;
140
+ return setState({
141
+ sortField: name,
142
+ sortDirection: direction,
143
+ page: 1
144
+ });
145
+ };
146
+
126
147
  useEffect(() => {
127
148
  // only fetch data when the dialog is open
128
149
  if (open) {
@@ -133,19 +154,7 @@ export const OpenFileDialog = _ref2 => {
133
154
  filters: formatFilters()
134
155
  });
135
156
  }
136
- }, [open, page, sortField, sortDirection]);
137
- useEffect(() => {
138
- // avoid fetching data when the dialog is first rendered (hidden)
139
- if (open) {
140
- // reset pagination when filters are applied/changed
141
- setPage(1);
142
- refetch({
143
- sortField,
144
- sortDirection,
145
- filters: formatFilters()
146
- });
147
- }
148
- }, [filters]);
157
+ }, [open, page, sortField, sortDirection, filters, refetch, formatFilters]);
149
158
  const headers = [{
150
159
  field: 'displayName',
151
160
  label: i18n.t('Name'),
@@ -189,8 +198,11 @@ export const OpenFileDialog = _ref2 => {
189
198
  onChange: value => {
190
199
  setNameFilterValue(value);
191
200
  clearTimeout(searchTimeout);
192
- setSearchTimeout(setTimeout(() => setFilters({ ...filters,
193
- searchTerm: value
201
+ setSearchTimeout(setTimeout(() => setState({
202
+ page: 1,
203
+ filters: { ...filters,
204
+ searchTerm: value
205
+ }
194
206
  }), 200));
195
207
  }
196
208
  })), (filterVisTypes === null || filterVisTypes === void 0 ? void 0 : filterVisTypes.length) && /*#__PURE__*/React.createElement("div", {
@@ -198,15 +210,21 @@ export const OpenFileDialog = _ref2 => {
198
210
  }, /*#__PURE__*/React.createElement(VisTypeFilter, {
199
211
  visTypes: filterVisTypes,
200
212
  selected: filters.visType,
201
- onChange: value => setFilters({ ...filters,
202
- visType: value
213
+ onChange: value => setState({
214
+ page: 1,
215
+ filters: { ...filters,
216
+ visType: value
217
+ }
203
218
  })
204
219
  })), /*#__PURE__*/React.createElement("div", {
205
220
  className: "jsx-".concat(styles.__hash) + " " + "created-by-field-container"
206
221
  }, /*#__PURE__*/React.createElement(CreatedByFilter, {
207
222
  selected: filters.createdBy,
208
- onChange: value => setFilters({ ...filters,
209
- createdBy: value
223
+ onChange: value => setState({
224
+ page: 1,
225
+ filters: { ...filters,
226
+ createdBy: value
227
+ }
210
228
  })
211
229
  })), !isEqual(filters, defaultFilters) && /*#__PURE__*/React.createElement(Button, {
212
230
  onClick: resetFilters,
@@ -219,26 +237,17 @@ export const OpenFileDialog = _ref2 => {
219
237
  className: "jsx-".concat(styles.__hash) + " " + "data-table-wrapper"
220
238
  }, /*#__PURE__*/React.createElement(DataTable, {
221
239
  layout: "fixed"
222
- }, /*#__PURE__*/React.createElement(DataTableHead, null, /*#__PURE__*/React.createElement(DataTableRow, null, data !== null && data !== void 0 && data.files[AOTypeMap[type].apiEndpoint].length ? headers.map(_ref3 => {
240
+ }, /*#__PURE__*/React.createElement(DataTableHead, null, /*#__PURE__*/React.createElement(DataTableRow, null, data !== null && data !== void 0 && data.files[AOTypeMap[type].apiEndpoint].length ? headers.map(_ref4 => {
223
241
  let {
224
242
  field,
225
243
  label,
226
244
  width
227
- } = _ref3;
245
+ } = _ref4;
228
246
  return /*#__PURE__*/React.createElement(DataTableColumnHeader, {
229
247
  width: width,
230
248
  key: field,
231
249
  name: field,
232
- onSortIconClick: _ref4 => {
233
- let {
234
- name,
235
- direction
236
- } = _ref4;
237
- return setSorting({
238
- sortField: name,
239
- sortDirection: direction
240
- });
241
- },
250
+ onSortIconClick: sortData,
242
251
  sortDirection: getSortDirection(field)
243
252
  }, label);
244
253
  }) : /*#__PURE__*/React.createElement(DataTableColumnHeader, null))), /*#__PURE__*/React.createElement(DataTableBody, {
@@ -200,9 +200,9 @@
200
200
  "Bi-weekly": "Tweewekelijks",
201
201
  "Monthly": "Maandelijks",
202
202
  "Bi-monthly": "Tweemaandelijks",
203
- "Quarterly": "",
204
- "Six-monthly": "",
205
- "Six-monthly April": "",
203
+ "Quarterly": "Driemaandelijks",
204
+ "Six-monthly": "Zesmaandelijks",
205
+ "Six-monthly April": "Zesmaandelijks april",
206
206
  "Yearly": "Jaarlijks",
207
207
  "Financial year (Start November)": "Financieel jaar (Start november)",
208
208
  "Financial year (Start October)": "Financieel jaar (Start oktober)",
@@ -11,4 +11,19 @@ export const getLegendByValueFromLegendSet = (legendSet, value) => {
11
11
  export const getColorByValueFromLegendSet = (legendSet, value) => {
12
12
  const legend = getLegendByValueFromLegendSet(legendSet, value);
13
13
  return legend && legend.color;
14
+ };
15
+ export const getLegendSetByDisplayStrategy = _ref => {
16
+ let {
17
+ displayStrategy,
18
+ legendSets,
19
+ legendSetId
20
+ } = _ref;
21
+
22
+ if (displayStrategy === LEGEND_DISPLAY_STRATEGY_FIXED && legendSets.length) {
23
+ return legendSets[0];
24
+ } else if (displayStrategy === LEGEND_DISPLAY_STRATEGY_BY_DATA_ITEM) {
25
+ return legendSets.find(legendSet => legendSet.id === legendSetId);
26
+ } else {
27
+ return null;
28
+ }
14
29
  };
@@ -31,7 +31,7 @@ const getTransformedExtraOptions = extraOptions => ({ ...extraOptions,
31
31
  });
32
32
 
33
33
  export default function (_ref) {
34
- var _layout$seriesKey, _layout$seriesKey2, _layout$seriesKey2$la, _layout$legend, _config$xAxis;
34
+ var _layout$legend, _layout$seriesKey, _layout$seriesKey2, _layout$seriesKey2$la, _config$xAxis;
35
35
 
36
36
  let {
37
37
  store,
@@ -77,16 +77,21 @@ export default function (_ref) {
77
77
  // y-axis
78
78
  yAxis: getYAxis(_layout, series, _extraOptions),
79
79
  // series
80
- series: getSeries(series.slice(), store.data[0].metaData, _layout, stacked, _extraOptions),
80
+ series: getSeries({
81
+ series: series.slice(),
82
+ metaData: store.data[0].metaData.items,
83
+ layout: _layout,
84
+ isStacked: stacked,
85
+ extraOptions: _extraOptions,
86
+ legendSets,
87
+ displayStrategy: (_layout$legend = _layout.legend) === null || _layout$legend === void 0 ? void 0 : _layout$legend.strategy
88
+ }),
81
89
  // legend
82
90
  legend: getLegend({
83
91
  isHidden: (_layout$seriesKey = _layout.seriesKey) === null || _layout$seriesKey === void 0 ? void 0 : _layout$seriesKey.hidden,
84
92
  fontStyle: (_layout$seriesKey2 = _layout.seriesKey) === null || _layout$seriesKey2 === void 0 ? void 0 : (_layout$seriesKey2$la = _layout$seriesKey2.label) === null || _layout$seriesKey2$la === void 0 ? void 0 : _layout$seriesKey2$la.fontStyle,
85
93
  visType: _layout.type,
86
- dashboard: _extraOptions.dashboard,
87
- legendSets,
88
- metaData: store.data[0].metaData.items,
89
- displayStrategy: (_layout$legend = _layout.legend) === null || _layout$legend === void 0 ? void 0 : _layout$legend.strategy
94
+ dashboard: _extraOptions.dashboard
90
95
  }),
91
96
  // pane
92
97
  pane: getPane(_layout.type),
@@ -1,9 +1,6 @@
1
1
  import { FONT_STYLE_OPTION_FONT_SIZE, FONT_STYLE_OPTION_TEXT_COLOR, FONT_STYLE_OPTION_BOLD, FONT_STYLE_OPTION_ITALIC, FONT_STYLE_OPTION_TEXT_ALIGN, FONT_STYLE_LEGEND, mergeFontStyleWithDefault } from '../../../../modules/fontStyle.js';
2
- import { LEGEND_DISPLAY_STRATEGY_BY_DATA_ITEM, LEGEND_DISPLAY_STRATEGY_FIXED } from '../../../../modules/legends.js';
3
- import { isLegendSetType, isVerticalType, VIS_TYPE_LINE, VIS_TYPE_SCATTER } from '../../../../modules/visTypes.js';
4
- import { colorSets, COLOR_SET_PATTERNS } from '../../../util/colors/colorSets.js';
2
+ import { isVerticalType, VIS_TYPE_SCATTER } from '../../../../modules/visTypes.js';
5
3
  import { getTextAlignOption } from './getTextAlignOption.js';
6
- import getType from './type.js';
7
4
  const DASHBOARD_ITEM_STYLE = {
8
5
  fontSize: '11px',
9
6
  fontWeight: 500
@@ -33,100 +30,15 @@ function getLegend(fontStyle, dashboard, visType) {
33
30
  });
34
31
  }
35
32
 
36
- const getLegendSetByDisplayStrategy = _ref => {
37
- let {
38
- displayStrategy,
39
- legendSets,
40
- legendSetId
41
- } = _ref;
42
-
43
- if (displayStrategy === LEGEND_DISPLAY_STRATEGY_FIXED && legendSets.length) {
44
- return legendSets[0];
45
- } else if (displayStrategy === LEGEND_DISPLAY_STRATEGY_BY_DATA_ITEM) {
46
- return legendSets.find(legendSet => legendSet.id === legendSetId);
47
- } else {
48
- return null;
49
- }
50
- };
51
-
52
- const formatLabel = _ref2 => {
53
- var _metaData$seriesId, _legendSet$legends;
54
-
55
- let {
56
- seriesId,
57
- seriesColor,
58
- seriesName,
59
- seriesType,
60
- metaData,
61
- displayStrategy,
62
- legendSets,
63
- fontStyle,
64
- visType
65
- } = _ref2;
66
- const legendSet = getLegendSetByDisplayStrategy({
67
- displayStrategy,
68
- legendSets,
69
- legendSetId: (_metaData$seriesId = metaData[seriesId]) === null || _metaData$seriesId === void 0 ? void 0 : _metaData$seriesId.legendSet
70
- });
71
- const result = []; // Note: Highcharts strips out 'data-test' and similar attributes, hence 'class="data-test-..." was used instead
72
-
73
- result.push('<div style="display: flex; align-items: center; margin-bottom: 4px;" class="data-test-series-key-item">');
74
-
75
- if ((!seriesId || seriesId.startsWith('trendline')) && seriesType === getType(VIS_TYPE_LINE).type) {
76
- // trendline
77
- result.push("<span style=\"height: ".concat(fontStyle[FONT_STYLE_OPTION_FONT_SIZE] / 6.5, "px; width: ").concat(fontStyle[FONT_STYLE_OPTION_FONT_SIZE], "px; background-color: ").concat(seriesColor, "; display: inline-block;\"></span>"));
78
- result.push("<span style=\"margin-left: 8px\" class=\"data-test-series-key-item-name\">".concat(seriesName, "</span>"));
79
- } else if (legendSet !== null && legendSet !== void 0 && (_legendSet$legends = legendSet.legends) !== null && _legendSet$legends !== void 0 && _legendSet$legends.length && isLegendSetType(visType) && seriesType !== getType(VIS_TYPE_LINE).type) {
80
- // item with legend set
81
- legendSet.legends.sort((a, b) => a.startValue - b.startValue).forEach((legend, index) => result.push("<svg width=\"".concat(fontStyle[FONT_STYLE_OPTION_FONT_SIZE], "\" height=\"").concat(fontStyle[FONT_STYLE_OPTION_FONT_SIZE], "\" style=\"margin-right:-5px; z-index: ").concat(legendSet.legends.length - index, "\" class=\"data-test-series-key-item-bullet\">\n <circle cx=\"").concat(fontStyle[FONT_STYLE_OPTION_FONT_SIZE] / 2, "\" cy=\"").concat(fontStyle[FONT_STYLE_OPTION_FONT_SIZE] / 2, "\" r=\"").concat(fontStyle[FONT_STYLE_OPTION_FONT_SIZE] / 2, "\" fill=\"").concat(legend.color, "\"></circle>\n </svg>")));
82
- result.push("<span style=\"margin-left: 8px\" class=\"data-test-series-key-item-name\">".concat(seriesName, "</span>"));
83
- } else {
84
- // regular item (not a trendline, no applied legend set)
85
- if ((seriesColor === null || seriesColor === void 0 ? void 0 : seriesColor.patternIndex) !== undefined) {
86
- const pattern = colorSets[COLOR_SET_PATTERNS].patterns[seriesColor.patternIndex];
87
- result.push("<svg style=\"height: ".concat(fontStyle[FONT_STYLE_OPTION_FONT_SIZE], "px; width: ").concat(fontStyle[FONT_STYLE_OPTION_FONT_SIZE], "px; display: inline-block; margin-right:5px\" class=\"data-test-series-key-item-bullet\">\n <defs>\n <pattern id=\"pattern").concat(seriesColor.patternIndex, "\" patternUnits=\"userSpaceOnUse\" width=\"").concat(pattern.width, "\" height=\"").concat(pattern.height, "\">\n <path stroke=\"").concat(pattern.color, "\" d=\"").concat(pattern.path, "\"/>\n </pattern>\n </defs>\n <circle cx=\"").concat(fontStyle[FONT_STYLE_OPTION_FONT_SIZE] / 2, "\" cy=\"").concat(fontStyle[FONT_STYLE_OPTION_FONT_SIZE] / 2, "\" r=\"").concat(fontStyle[FONT_STYLE_OPTION_FONT_SIZE] / 2, "\" fill=\"url(#pattern").concat(seriesColor.patternIndex, ")\"/>\n </svg>"));
88
- } else {
89
- result.push("<svg width=\"".concat(fontStyle[FONT_STYLE_OPTION_FONT_SIZE], "\" height=\"").concat(fontStyle[FONT_STYLE_OPTION_FONT_SIZE], "\" style=\"margin-right:5px\" class=\"data-test-series-key-item-bullet\">\n <circle cx=\"").concat(fontStyle[FONT_STYLE_OPTION_FONT_SIZE] / 2, "\" cy=\"").concat(fontStyle[FONT_STYLE_OPTION_FONT_SIZE] / 2, "\" r=\"").concat(fontStyle[FONT_STYLE_OPTION_FONT_SIZE] / 2, "\" fill=\"").concat(seriesColor, "\"></circle>\n </svg>"));
90
- }
91
-
92
- result.push("<span class=\"data-test-series-key-item-name\">".concat(seriesName, "</span>"));
93
- }
94
-
95
- result.push('</div>');
96
- return result.join('');
97
- };
98
-
99
- export default function (_ref3) {
33
+ export default function (_ref) {
100
34
  let {
101
35
  isHidden,
102
36
  fontStyle,
103
37
  visType,
104
- dashboard,
105
- legendSets = [],
106
- metaData,
107
- displayStrategy
108
- } = _ref3;
38
+ dashboard
39
+ } = _ref;
109
40
  const mergedFontStyle = mergeFontStyleWithDefault(fontStyle, FONT_STYLE_LEGEND);
110
41
  return isHidden || visType === VIS_TYPE_SCATTER ? {
111
42
  enabled: false
112
- } : Object.assign({}, getLegend(mergedFontStyle, dashboard, visType), getItemStyle(mergedFontStyle, dashboard), {
113
- useHTML: true,
114
- symbolWidth: 0.001,
115
- symbolHeight: 0.001,
116
- labelFormatter: function () {
117
- var _this$userOptions, _this$userOptions2;
118
-
119
- return formatLabel({
120
- seriesId: (_this$userOptions = this.userOptions) === null || _this$userOptions === void 0 ? void 0 : _this$userOptions.id,
121
- seriesColor: this.color,
122
- seriesName: this.name,
123
- seriesType: (_this$userOptions2 = this.userOptions) === null || _this$userOptions2 === void 0 ? void 0 : _this$userOptions2.type,
124
- metaData,
125
- displayStrategy,
126
- legendSets,
127
- fontStyle: mergedFontStyle,
128
- visType
129
- });
130
- }
131
- });
43
+ } : Object.assign({}, getLegend(mergedFontStyle, dashboard, visType), getItemStyle(mergedFontStyle, dashboard));
132
44
  }
@@ -1,6 +1,7 @@
1
1
  import { colors } from '@dhis2/ui';
2
2
  import { hasCustomAxes } from '../../../../../modules/axis.js';
3
3
  import { axisHasRelativeItems } from '../../../../../modules/layout/axisHasRelativeItems.js';
4
+ import { getLegendSetByDisplayStrategy } from '../../../../../modules/legends.js';
4
5
  import { VIS_TYPE_PIE, VIS_TYPE_GAUGE, isDualAxisType, isYearOverYear, VIS_TYPE_LINE, VIS_TYPE_SCATTER } from '../../../../../modules/visTypes.js';
5
6
  import { getAxisStringFromId } from '../../../../util/axisId.js';
6
7
  import { colorSets, COLOR_SET_PATTERNS } from '../../../../util/colors/colorSets.js';
@@ -73,12 +74,21 @@ function getIdColorMap(series, layout, extraOptions) {
73
74
  }
74
75
  }
75
76
 
76
- function getDefault(series, metaData, layout, isStacked, extraOptions) {
77
+ function getDefault(_ref) {
78
+ let {
79
+ series,
80
+ metaData,
81
+ layout,
82
+ isStacked,
83
+ extraOptions,
84
+ legendSets,
85
+ displayStrategy
86
+ } = _ref;
77
87
  const fullIdAxisMap = getFullIdAxisMap(layout.series, series);
78
88
  const idColorMap = getIdColorMap(series, layout, extraOptions);
79
89
  const indexColorPatternMap = getIndexColorPatternMap(series, layout, extraOptions);
80
90
  series.forEach((seriesObj, index) => {
81
- var _seriesObj$custom, _layout$series2;
91
+ var _seriesObj$custom, _layout$series2, _metaData$seriesObj$i;
82
92
 
83
93
  // show values
84
94
  if (!seriesObj.dataLabels && (layout.showValues || layout.showData)) {
@@ -138,6 +148,15 @@ function getDefault(series, metaData, layout, isStacked, extraOptions) {
138
148
  if (extraOptions.yearlySeries) {
139
149
  seriesObj.name = extraOptions.yearlySeries[index];
140
150
  }
151
+
152
+ seriesObj.legendSet = getLegendSetByDisplayStrategy({
153
+ displayStrategy,
154
+ legendSets,
155
+ legendSetId: (_metaData$seriesObj$i = metaData[seriesObj.id]) === null || _metaData$seriesObj$i === void 0 ? void 0 : _metaData$seriesObj$i.legendSet
156
+ });
157
+ seriesObj.marker = {
158
+ enabled: false
159
+ };
141
160
  }); // DHIS2-701: use cumulative values
142
161
 
143
162
  if (layout.cumulativeValues === true) {
@@ -147,7 +166,17 @@ function getDefault(series, metaData, layout, isStacked, extraOptions) {
147
166
  return series;
148
167
  }
149
168
 
150
- export default function (series, metaData, layout, isStacked, extraOptions) {
169
+ export default function (_ref2) {
170
+ let {
171
+ series,
172
+ metaData,
173
+ layout,
174
+ isStacked,
175
+ extraOptions,
176
+ legendSets,
177
+ displayStrategy
178
+ } = _ref2;
179
+
151
180
  switch (layout.type) {
152
181
  case VIS_TYPE_PIE:
153
182
  series = getPie(series, Object.values(getIdColorMap(series, layout, extraOptions)));
@@ -162,7 +191,15 @@ export default function (series, metaData, layout, isStacked, extraOptions) {
162
191
  break;
163
192
 
164
193
  default:
165
- series = getDefault(series, metaData, layout, isStacked, extraOptions);
194
+ series = getDefault({
195
+ series,
196
+ metaData,
197
+ layout,
198
+ isStacked,
199
+ extraOptions,
200
+ legendSets,
201
+ displayStrategy
202
+ });
166
203
  }
167
204
 
168
205
  series.forEach(seriesObj => {
@@ -12,6 +12,38 @@ HNDTD(H);
12
12
  HE(H);
13
13
  HPF(H);
14
14
  HB(H);
15
+
16
+ function drawLegendSymbolWrap() {
17
+ const pick = H.pick;
18
+ H.wrap(H.seriesTypes.column.prototype, 'drawLegendSymbol', function (proceed, legend, item) {
19
+ var _this$options$legendS, _this$options$legendS2;
20
+
21
+ if ((_this$options$legendS = this.options.legendSet) !== null && _this$options$legendS !== void 0 && (_this$options$legendS2 = _this$options$legendS.legends) !== null && _this$options$legendS2 !== void 0 && _this$options$legendS2.length) {
22
+ const ys = legend.baseline - legend.symbolHeight + 1,
23
+ // y start
24
+ x = legend.symbolWidth / 2 > 8 ? legend.symbolWidth / 2 : 8,
25
+ // x start
26
+ ye = legend.symbolHeight + ys; // y end
27
+
28
+ const legends = this.options.legendSet.legends.sort((a, b) => a.startValue - b.startValue);
29
+ this.chart.renderer.path(['M', x, ys, 'A', 1, 1, 0, 0, 0, x, ye, 'V', ys]).attr({
30
+ fill: legends[legends.length >= 5 ? 1 : 0].color
31
+ }).add(this.legendGroup);
32
+ this.chart.renderer.path(['M', x, ye, 'A', 1, 1, 0, 0, 0, x, ys, 'V', ye]).attr({
33
+ fill: legends[legends.length >= 5 ? legends.length - 2 : legends.length - 1].color
34
+ }).add(this.legendGroup);
35
+ } else {
36
+ var options = legend.options,
37
+ symbolHeight = legend.symbolHeight,
38
+ square = options.squareSymbol,
39
+ symbolWidth = square ? symbolHeight : legend.symbolWidth;
40
+ item.legendSymbol = this.chart.renderer.rect(square ? (legend.symbolWidth - symbolHeight) / 2 : 0, legend.baseline - symbolHeight + 1, symbolWidth, symbolHeight, pick(legend.options.symbolRadius, symbolHeight / 2)).addClass('highcharts-point').attr({
41
+ zIndex: 3
42
+ }).add(item.legendGroup);
43
+ }
44
+ });
45
+ }
46
+
15
47
  export default function (config, el) {
16
48
  if (config) {
17
49
  config.chart.renderTo = el || config.chart.renderTo; // silence warning about accessibility
@@ -26,6 +58,7 @@ export default function (config, el) {
26
58
  });
27
59
  }
28
60
 
61
+ drawLegendSymbolWrap();
29
62
  return new H.Chart(config);
30
63
  }
31
64
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhis2/analytics",
3
- "version": "23.13.0",
3
+ "version": "23.13.4",
4
4
  "main": "./build/cjs/index.js",
5
5
  "module": "./build/es/index.js",
6
6
  "exports": {