@dhis2/analytics 21.8.0 → 21.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## [21.8.1](https://github.com/dhis2/analytics/compare/v21.8.0...v21.8.1) (2022-08-18)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * highcharts legend when exporting (DHIS2-12719) 21.x ([#1311](https://github.com/dhis2/analytics/issues/1311)) ([8015854](https://github.com/dhis2/analytics/commit/80158545b7e2dabb441c71a1989bcc74db6fb720))
7
+
1
8
  # [21.8.0](https://github.com/dhis2/analytics/compare/v21.7.0...v21.8.0) (2022-08-12)
2
9
 
3
10
 
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.getColorByValueFromLegendSet = exports.getLegendByValueFromLegendSet = 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.getColorByValueFromLegendSet = exports.getLegendByValueFromLegendSet = 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';
@@ -23,4 +23,20 @@ const getColorByValueFromLegendSet = (legendSet, value) => {
23
23
  return legend && legend.color;
24
24
  };
25
25
 
26
- exports.getColorByValueFromLegendSet = getColorByValueFromLegendSet;
26
+ exports.getColorByValueFromLegendSet = getColorByValueFromLegendSet;
27
+
28
+ const getLegendSetByDisplayStrategy = ({
29
+ displayStrategy,
30
+ legendSets,
31
+ legendSetId
32
+ }) => {
33
+ if (displayStrategy === LEGEND_DISPLAY_STRATEGY_FIXED && legendSets.length) {
34
+ return legendSets[0];
35
+ } else if (displayStrategy === LEGEND_DISPLAY_STRATEGY_BY_DATA_ITEM) {
36
+ return legendSets.find(legendSet => legendSet.id === legendSetId);
37
+ } else {
38
+ return null;
39
+ }
40
+ };
41
+
42
+ exports.getLegendSetByDisplayStrategy = getLegendSetByDisplayStrategy;
@@ -70,7 +70,7 @@ function _default({
70
70
  extraConfig,
71
71
  extraOptions
72
72
  }) {
73
- var _layout$seriesKey, _layout$seriesKey2, _layout$seriesKey2$la, _layout$legend, _config$xAxis;
73
+ var _layout$legend, _layout$seriesKey, _layout$seriesKey2, _layout$seriesKey2$la, _config$xAxis;
74
74
 
75
75
  const _layout = getTransformedLayout(layout);
76
76
 
@@ -108,16 +108,21 @@ function _default({
108
108
  // y-axis
109
109
  yAxis: (0, _index7.default)(_layout, series, _extraOptions),
110
110
  // series
111
- series: (0, _index3.default)(series.slice(), store.data[0].metaData, _layout, stacked, _extraOptions),
111
+ series: (0, _index3.default)({
112
+ series: series.slice(),
113
+ metaData: store.data[0].metaData.items,
114
+ layout: _layout,
115
+ isStacked: stacked,
116
+ extraOptions: _extraOptions,
117
+ legendSets,
118
+ displayStrategy: (_layout$legend = _layout.legend) === null || _layout$legend === void 0 ? void 0 : _layout$legend.strategy
119
+ }),
112
120
  // legend
113
121
  legend: (0, _legend.default)({
114
122
  isHidden: (_layout$seriesKey = _layout.seriesKey) === null || _layout$seriesKey === void 0 ? void 0 : _layout$seriesKey.hidden,
115
123
  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,
116
124
  visType: _layout.type,
117
- dashboard: _extraOptions.dashboard,
118
- legendSets,
119
- metaData: store.data[0].metaData.items,
120
- displayStrategy: (_layout$legend = _layout.legend) === null || _layout$legend === void 0 ? void 0 : _layout$legend.strategy
125
+ dashboard: _extraOptions.dashboard
121
126
  }),
122
127
  // pane
123
128
  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,96 +40,14 @@ function getLegend(fontStyle, dashboard, visType) {
48
40
  });
49
41
  }
50
42
 
51
- const getLegendSetByDisplayStrategy = ({
52
- displayStrategy,
53
- legendSets,
54
- legendSetId
55
- }) => {
56
- if (displayStrategy === _legends.LEGEND_DISPLAY_STRATEGY_FIXED && legendSets.length) {
57
- return legendSets[0];
58
- } else if (displayStrategy === _legends.LEGEND_DISPLAY_STRATEGY_BY_DATA_ITEM) {
59
- return legendSets.find(legendSet => legendSet.id === legendSetId);
60
- } else {
61
- return null;
62
- }
63
- };
64
-
65
- const formatLabel = ({
66
- seriesId,
67
- seriesColor,
68
- seriesName,
69
- seriesType,
70
- metaData,
71
- displayStrategy,
72
- legendSets,
73
- fontStyle,
74
- visType
75
- }) => {
76
- var _metaData$seriesId, _legendSet$legends;
77
-
78
- const legendSet = getLegendSetByDisplayStrategy({
79
- displayStrategy,
80
- legendSets,
81
- legendSetId: (_metaData$seriesId = metaData[seriesId]) === null || _metaData$seriesId === void 0 ? void 0 : _metaData$seriesId.legendSet
82
- });
83
- const result = []; // Note: Highcharts strips out 'data-test' and similar attributes, hence 'class="data-test-..." was used instead
84
-
85
- result.push('<div style="display: flex; align-items: center; margin-bottom: 4px;" class="data-test-series-key-item">');
86
-
87
- if ((!seriesId || seriesId.startsWith('trendline')) && seriesType === (0, _type.default)(_visTypes.VIS_TYPE_LINE).type) {
88
- // trendline
89
- 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>"));
90
- result.push("<span style=\"margin-left: 8px\" class=\"data-test-series-key-item-name\">".concat(seriesName, "</span>"));
91
- } 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) {
92
- // item with legend set
93
- legendSet.legends.sort((a, b) => a.startValue - b.startValue).forEach((legend, index) => result.push("<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"".concat(fontStyle[_fontStyle.FONT_STYLE_OPTION_FONT_SIZE], "\" height=\"").concat(fontStyle[_fontStyle.FONT_STYLE_OPTION_FONT_SIZE], "\" version=\"1.1\" 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>")));
94
- result.push("<span style=\"margin-left: 8px\" class=\"data-test-series-key-item-name\">".concat(seriesName, "</span>"));
95
- } else {
96
- // regular item (not a trendline, no applied legend set)
97
- if ((seriesColor === null || seriesColor === void 0 ? void 0 : seriesColor.patternIndex) !== undefined) {
98
- const pattern = _colorSets.colorSets[_colorSets.COLOR_SET_PATTERNS].patterns[seriesColor.patternIndex];
99
- result.push("<svg xmlns=\"http://www.w3.org/2000/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>"));
100
- } else {
101
- result.push("<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"".concat(fontStyle[_fontStyle.FONT_STYLE_OPTION_FONT_SIZE], "\" height=\"").concat(fontStyle[_fontStyle.FONT_STYLE_OPTION_FONT_SIZE], "\" version=\"1.1\" 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>"));
102
- }
103
-
104
- result.push("<span class=\"data-test-series-key-item-name\">".concat(seriesName, "</span>"));
105
- }
106
-
107
- result.push('</div>');
108
- return result.join('');
109
- };
110
-
111
43
  function _default({
112
44
  isHidden,
113
45
  fontStyle,
114
46
  visType,
115
- dashboard,
116
- legendSets = [],
117
- metaData,
118
- displayStrategy
47
+ dashboard
119
48
  }) {
120
49
  const mergedFontStyle = (0, _fontStyle.mergeFontStyleWithDefault)(fontStyle, _fontStyle.FONT_STYLE_LEGEND);
121
50
  return isHidden || visType === _visTypes.VIS_TYPE_SCATTER ? {
122
51
  enabled: false
123
- } : Object.assign({}, getLegend(mergedFontStyle, dashboard, visType), getItemStyle(mergedFontStyle, dashboard), {
124
- useHTML: true,
125
- symbolWidth: 0.001,
126
- symbolHeight: 0.001,
127
- labelFormatter: function () {
128
- var _this$userOptions, _this$userOptions2;
129
-
130
- return formatLabel({
131
- seriesId: (_this$userOptions = this.userOptions) === null || _this$userOptions === void 0 ? void 0 : _this$userOptions.id,
132
- seriesColor: this.color,
133
- seriesName: this.name,
134
- seriesType: (_this$userOptions2 = this.userOptions) === null || _this$userOptions2 === void 0 ? void 0 : _this$userOptions2.type,
135
- metaData,
136
- displayStrategy,
137
- legendSets,
138
- fontStyle: mergedFontStyle,
139
- visType
140
- });
141
- }
142
- });
52
+ } : Object.assign({}, getLegend(mergedFontStyle, dashboard, visType), getItemStyle(mergedFontStyle, dashboard));
143
53
  }
@@ -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,20 @@ function getIdColorMap(series, layout, extraOptions) {
95
97
  }
96
98
  }
97
99
 
98
- function getDefault(series, metaData, layout, isStacked, extraOptions) {
100
+ function getDefault({
101
+ series,
102
+ metaData,
103
+ layout,
104
+ isStacked,
105
+ extraOptions,
106
+ legendSets,
107
+ displayStrategy
108
+ }) {
99
109
  const fullIdAxisMap = (0, _customAxes.getFullIdAxisMap)(layout.series, series);
100
110
  const idColorMap = getIdColorMap(series, layout, extraOptions);
101
111
  const indexColorPatternMap = getIndexColorPatternMap(series, layout, extraOptions);
102
112
  series.forEach((seriesObj, index) => {
103
- var _seriesObj$custom, _layout$series2;
113
+ var _seriesObj$custom, _layout$series2, _metaData$seriesObj$i;
104
114
 
105
115
  // show values
106
116
  if (!seriesObj.dataLabels && (layout.showValues || layout.showData)) {
@@ -160,6 +170,15 @@ function getDefault(series, metaData, layout, isStacked, extraOptions) {
160
170
  if (extraOptions.yearlySeries) {
161
171
  seriesObj.name = extraOptions.yearlySeries[index];
162
172
  }
173
+
174
+ seriesObj.legendSet = (0, _legends.getLegendSetByDisplayStrategy)({
175
+ displayStrategy,
176
+ legendSets,
177
+ legendSetId: (_metaData$seriesObj$i = metaData[seriesObj.id]) === null || _metaData$seriesObj$i === void 0 ? void 0 : _metaData$seriesObj$i.legendSet
178
+ });
179
+ seriesObj.marker = {
180
+ enabled: false
181
+ };
163
182
  }); // DHIS2-701: use cumulative values
164
183
 
165
184
  if (layout.cumulativeValues === true) {
@@ -169,7 +188,15 @@ function getDefault(series, metaData, layout, isStacked, extraOptions) {
169
188
  return series;
170
189
  }
171
190
 
172
- function _default(series, metaData, layout, isStacked, extraOptions) {
191
+ function _default({
192
+ series,
193
+ metaData,
194
+ layout,
195
+ isStacked,
196
+ extraOptions,
197
+ legendSets,
198
+ displayStrategy
199
+ }) {
173
200
  switch (layout.type) {
174
201
  case _visTypes.VIS_TYPE_PIE:
175
202
  series = (0, _pie.default)(series, Object.values(getIdColorMap(series, layout, extraOptions)));
@@ -184,7 +211,15 @@ function _default(series, metaData, layout, isStacked, extraOptions) {
184
211
  break;
185
212
 
186
213
  default:
187
- series = getDefault(series, metaData, layout, isStacked, extraOptions);
214
+ series = getDefault({
215
+ series,
216
+ metaData,
217
+ layout,
218
+ isStacked,
219
+ extraOptions,
220
+ legendSets,
221
+ displayStrategy
222
+ });
188
223
  }
189
224
 
190
225
  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.at(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.at(legends.length >= 5 ? -2 : -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;
@@ -39,6 +71,7 @@ function _default(config, el) {
39
71
  });
40
72
  }
41
73
 
74
+ drawLegendSymbolWrap();
42
75
  return new _highcharts.default.Chart(config);
43
76
  }
44
77
  }
@@ -7,4 +7,17 @@ export const getLegendByValueFromLegendSet = (legendSet, value) => legendSet.leg
7
7
  export const getColorByValueFromLegendSet = (legendSet, value) => {
8
8
  const legend = getLegendByValueFromLegendSet(legendSet, value);
9
9
  return legend && legend.color;
10
+ };
11
+ export const getLegendSetByDisplayStrategy = ({
12
+ displayStrategy,
13
+ legendSets,
14
+ legendSetId
15
+ }) => {
16
+ if (displayStrategy === LEGEND_DISPLAY_STRATEGY_FIXED && legendSets.length) {
17
+ return legendSets[0];
18
+ } else if (displayStrategy === LEGEND_DISPLAY_STRATEGY_BY_DATA_ITEM) {
19
+ return legendSets.find(legendSet => legendSet.id === legendSetId);
20
+ } else {
21
+ return null;
22
+ }
10
23
  };
@@ -37,7 +37,7 @@ export default function ({
37
37
  extraConfig,
38
38
  extraOptions
39
39
  }) {
40
- var _layout$seriesKey, _layout$seriesKey2, _layout$seriesKey2$la, _layout$legend, _config$xAxis;
40
+ var _layout$legend, _layout$seriesKey, _layout$seriesKey2, _layout$seriesKey2$la, _config$xAxis;
41
41
 
42
42
  const _layout = getTransformedLayout(layout);
43
43
 
@@ -75,16 +75,21 @@ export default function ({
75
75
  // y-axis
76
76
  yAxis: getYAxis(_layout, series, _extraOptions),
77
77
  // series
78
- series: getSeries(series.slice(), store.data[0].metaData, _layout, stacked, _extraOptions),
78
+ series: getSeries({
79
+ series: series.slice(),
80
+ metaData: store.data[0].metaData.items,
81
+ layout: _layout,
82
+ isStacked: stacked,
83
+ extraOptions: _extraOptions,
84
+ legendSets,
85
+ displayStrategy: (_layout$legend = _layout.legend) === null || _layout$legend === void 0 ? void 0 : _layout$legend.strategy
86
+ }),
79
87
  // legend
80
88
  legend: getLegend({
81
89
  isHidden: (_layout$seriesKey = _layout.seriesKey) === null || _layout$seriesKey === void 0 ? void 0 : _layout$seriesKey.hidden,
82
90
  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,
83
91
  visType: _layout.type,
84
- dashboard: _extraOptions.dashboard,
85
- legendSets,
86
- metaData: store.data[0].metaData.items,
87
- displayStrategy: (_layout$legend = _layout.legend) === null || _layout$legend === void 0 ? void 0 : _layout$legend.strategy
92
+ dashboard: _extraOptions.dashboard
88
93
  }),
89
94
  // pane
90
95
  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,96 +30,14 @@ function getLegend(fontStyle, dashboard, visType) {
33
30
  });
34
31
  }
35
32
 
36
- const getLegendSetByDisplayStrategy = ({
37
- displayStrategy,
38
- legendSets,
39
- legendSetId
40
- }) => {
41
- if (displayStrategy === LEGEND_DISPLAY_STRATEGY_FIXED && legendSets.length) {
42
- return legendSets[0];
43
- } else if (displayStrategy === LEGEND_DISPLAY_STRATEGY_BY_DATA_ITEM) {
44
- return legendSets.find(legendSet => legendSet.id === legendSetId);
45
- } else {
46
- return null;
47
- }
48
- };
49
-
50
- const formatLabel = ({
51
- seriesId,
52
- seriesColor,
53
- seriesName,
54
- seriesType,
55
- metaData,
56
- displayStrategy,
57
- legendSets,
58
- fontStyle,
59
- visType
60
- }) => {
61
- var _metaData$seriesId, _legendSet$legends;
62
-
63
- const legendSet = getLegendSetByDisplayStrategy({
64
- displayStrategy,
65
- legendSets,
66
- legendSetId: (_metaData$seriesId = metaData[seriesId]) === null || _metaData$seriesId === void 0 ? void 0 : _metaData$seriesId.legendSet
67
- });
68
- const result = []; // Note: Highcharts strips out 'data-test' and similar attributes, hence 'class="data-test-..." was used instead
69
-
70
- result.push('<div style="display: flex; align-items: center; margin-bottom: 4px;" class="data-test-series-key-item">');
71
-
72
- if ((!seriesId || seriesId.startsWith('trendline')) && seriesType === getType(VIS_TYPE_LINE).type) {
73
- // trendline
74
- 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>"));
75
- result.push("<span style=\"margin-left: 8px\" class=\"data-test-series-key-item-name\">".concat(seriesName, "</span>"));
76
- } 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) {
77
- // item with legend set
78
- legendSet.legends.sort((a, b) => a.startValue - b.startValue).forEach((legend, index) => result.push("<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"".concat(fontStyle[FONT_STYLE_OPTION_FONT_SIZE], "\" height=\"").concat(fontStyle[FONT_STYLE_OPTION_FONT_SIZE], "\" version=\"1.1\" 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>")));
79
- result.push("<span style=\"margin-left: 8px\" class=\"data-test-series-key-item-name\">".concat(seriesName, "</span>"));
80
- } else {
81
- // regular item (not a trendline, no applied legend set)
82
- if ((seriesColor === null || seriesColor === void 0 ? void 0 : seriesColor.patternIndex) !== undefined) {
83
- const pattern = colorSets[COLOR_SET_PATTERNS].patterns[seriesColor.patternIndex];
84
- result.push("<svg xmlns=\"http://www.w3.org/2000/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>"));
85
- } else {
86
- result.push("<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"".concat(fontStyle[FONT_STYLE_OPTION_FONT_SIZE], "\" height=\"").concat(fontStyle[FONT_STYLE_OPTION_FONT_SIZE], "\" version=\"1.1\" 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>"));
87
- }
88
-
89
- result.push("<span class=\"data-test-series-key-item-name\">".concat(seriesName, "</span>"));
90
- }
91
-
92
- result.push('</div>');
93
- return result.join('');
94
- };
95
-
96
33
  export default function ({
97
34
  isHidden,
98
35
  fontStyle,
99
36
  visType,
100
- dashboard,
101
- legendSets = [],
102
- metaData,
103
- displayStrategy
37
+ dashboard
104
38
  }) {
105
39
  const mergedFontStyle = mergeFontStyleWithDefault(fontStyle, FONT_STYLE_LEGEND);
106
40
  return isHidden || visType === VIS_TYPE_SCATTER ? {
107
41
  enabled: false
108
- } : Object.assign({}, getLegend(mergedFontStyle, dashboard, visType), getItemStyle(mergedFontStyle, dashboard), {
109
- useHTML: true,
110
- symbolWidth: 0.001,
111
- symbolHeight: 0.001,
112
- labelFormatter: function () {
113
- var _this$userOptions, _this$userOptions2;
114
-
115
- return formatLabel({
116
- seriesId: (_this$userOptions = this.userOptions) === null || _this$userOptions === void 0 ? void 0 : _this$userOptions.id,
117
- seriesColor: this.color,
118
- seriesName: this.name,
119
- seriesType: (_this$userOptions2 = this.userOptions) === null || _this$userOptions2 === void 0 ? void 0 : _this$userOptions2.type,
120
- metaData,
121
- displayStrategy,
122
- legendSets,
123
- fontStyle: mergedFontStyle,
124
- visType
125
- });
126
- }
127
- });
42
+ } : Object.assign({}, getLegend(mergedFontStyle, dashboard, visType), getItemStyle(mergedFontStyle, dashboard));
128
43
  }
@@ -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,20 @@ function getIdColorMap(series, layout, extraOptions) {
73
74
  }
74
75
  }
75
76
 
76
- function getDefault(series, metaData, layout, isStacked, extraOptions) {
77
+ function getDefault({
78
+ series,
79
+ metaData,
80
+ layout,
81
+ isStacked,
82
+ extraOptions,
83
+ legendSets,
84
+ displayStrategy
85
+ }) {
77
86
  const fullIdAxisMap = getFullIdAxisMap(layout.series, series);
78
87
  const idColorMap = getIdColorMap(series, layout, extraOptions);
79
88
  const indexColorPatternMap = getIndexColorPatternMap(series, layout, extraOptions);
80
89
  series.forEach((seriesObj, index) => {
81
- var _seriesObj$custom, _layout$series2;
90
+ var _seriesObj$custom, _layout$series2, _metaData$seriesObj$i;
82
91
 
83
92
  // show values
84
93
  if (!seriesObj.dataLabels && (layout.showValues || layout.showData)) {
@@ -138,6 +147,15 @@ function getDefault(series, metaData, layout, isStacked, extraOptions) {
138
147
  if (extraOptions.yearlySeries) {
139
148
  seriesObj.name = extraOptions.yearlySeries[index];
140
149
  }
150
+
151
+ seriesObj.legendSet = getLegendSetByDisplayStrategy({
152
+ displayStrategy,
153
+ legendSets,
154
+ legendSetId: (_metaData$seriesObj$i = metaData[seriesObj.id]) === null || _metaData$seriesObj$i === void 0 ? void 0 : _metaData$seriesObj$i.legendSet
155
+ });
156
+ seriesObj.marker = {
157
+ enabled: false
158
+ };
141
159
  }); // DHIS2-701: use cumulative values
142
160
 
143
161
  if (layout.cumulativeValues === true) {
@@ -147,7 +165,15 @@ function getDefault(series, metaData, layout, isStacked, extraOptions) {
147
165
  return series;
148
166
  }
149
167
 
150
- export default function (series, metaData, layout, isStacked, extraOptions) {
168
+ export default function ({
169
+ series,
170
+ metaData,
171
+ layout,
172
+ isStacked,
173
+ extraOptions,
174
+ legendSets,
175
+ displayStrategy
176
+ }) {
151
177
  switch (layout.type) {
152
178
  case VIS_TYPE_PIE:
153
179
  series = getPie(series, Object.values(getIdColorMap(series, layout, extraOptions)));
@@ -162,7 +188,15 @@ export default function (series, metaData, layout, isStacked, extraOptions) {
162
188
  break;
163
189
 
164
190
  default:
165
- series = getDefault(series, metaData, layout, isStacked, extraOptions);
191
+ series = getDefault({
192
+ series,
193
+ metaData,
194
+ layout,
195
+ isStacked,
196
+ extraOptions,
197
+ legendSets,
198
+ displayStrategy
199
+ });
166
200
  }
167
201
 
168
202
  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.at(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.at(legends.length >= 5 ? -2 : -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;
@@ -22,6 +54,7 @@ export default function (config, el) {
22
54
  });
23
55
  }
24
56
 
57
+ drawLegendSymbolWrap();
25
58
  return new H.Chart(config);
26
59
  }
27
60
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhis2/analytics",
3
- "version": "21.8.0",
3
+ "version": "21.8.1",
4
4
  "main": "./build/cjs/index.js",
5
5
  "module": "./build/es/index.js",
6
6
  "exports": {