@dhis2/analytics 24.9.3 → 24.10.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,17 @@
1
+ ## [24.10.1](https://github.com/dhis2/analytics/compare/v24.10.0...v24.10.1) (2023-04-24)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * sv size when downloading is a small square (DHIS2-15178) ([245d799](https://github.com/dhis2/analytics/commit/245d799d9513e0407e4a6b6ba24c3da15754618d))
7
+
8
+ # [24.10.0](https://github.com/dhis2/analytics/compare/v24.9.3...v24.10.0) (2023-04-19)
9
+
10
+
11
+ ### Features
12
+
13
+ * single value background color change based upon legend (DHIS2-13702) part 2 ([#1453](https://github.com/dhis2/analytics/issues/1453)) ([d32c7b8](https://github.com/dhis2/analytics/commit/d32c7b8b8cce03e634caeb036e3412b8b7bcbf19))
14
+
1
15
  ## [24.9.3](https://github.com/dhis2/analytics/compare/v24.9.2...v24.9.3) (2023-03-15)
2
16
 
3
17
 
@@ -75,11 +75,13 @@ const generateValueSVG = _ref => {
75
75
  const generateDashboardItem = (config, _ref2) => {
76
76
  let {
77
77
  valueColor,
78
+ titleColor,
79
+ backgroundColor,
78
80
  noData
79
81
  } = _ref2;
80
82
  const container = document.createElement('div');
81
- container.setAttribute('style', 'display: flex; flex-direction: column; align-items: center; justify-content: center; width: 100%; height: 100%');
82
- const titleStyle = 'font-size: 12px; color: #666;';
83
+ container.setAttribute('style', "display: flex; flex-direction: column; align-items: center; justify-content: center; width: 100%; height: 100%; background-color:".concat(backgroundColor, ";"));
84
+ const titleStyle = "font-size: 12px; color: ".concat(titleColor || '#666', ";");
83
85
  const title = document.createElement('span');
84
86
  title.setAttribute('style', titleStyle);
85
87
 
@@ -88,10 +90,9 @@ const generateDashboardItem = (config, _ref2) => {
88
90
  container.appendChild(title);
89
91
  }
90
92
 
91
- const subtitle = document.createElement('span');
92
- subtitle.setAttribute('style', titleStyle + ' margin-top: 4px');
93
-
94
93
  if (config.subtitle) {
94
+ const subtitle = document.createElement('span');
95
+ subtitle.setAttribute('style', titleStyle + ' margin-top: 4px; padding: 0 8px');
95
96
  subtitle.appendChild(document.createTextNode(config.subtitle));
96
97
  container.appendChild(subtitle);
97
98
  }
@@ -137,6 +138,7 @@ const getXFromTextAlign = textAlign => {
137
138
  const generateDVItem = (config, _ref3) => {
138
139
  let {
139
140
  valueColor,
141
+ backgroundColor,
140
142
  titleColor,
141
143
  parentEl,
142
144
  fontStyle,
@@ -149,9 +151,19 @@ const generateDVItem = (config, _ref3) => {
149
151
  const svg = document.createElementNS(svgNS, 'svg');
150
152
  svg.setAttribute('xmlns', svgNS);
151
153
  svg.setAttribute('viewBox', "0 0 ".concat(width, " ").concat(height));
152
- svg.setAttribute('width', '100%');
153
- svg.setAttribute('height', '100%');
154
+ svg.setAttribute('width', width);
155
+ svg.setAttribute('height', height);
154
156
  svg.setAttribute('data-test', 'visualization-container');
157
+
158
+ if (backgroundColor) {
159
+ svg.setAttribute('style', "background-color: ".concat(backgroundColor, ";"));
160
+ const background = document.createElementNS(svgNS, 'rect');
161
+ background.setAttribute('width', '100%');
162
+ background.setAttribute('height', '100%');
163
+ background.setAttribute('fill', backgroundColor);
164
+ svg.appendChild(background);
165
+ }
166
+
155
167
  const title = document.createElementNS(svgNS, 'text');
156
168
  const titleFontStyle = (0, _fontStyle.mergeFontStyleWithDefault)(fontStyle && fontStyle[_fontStyle.FONT_STYLE_VISUALIZATION_TITLE], _fontStyle.FONT_STYLE_VISUALIZATION_TITLE);
157
169
  title.setAttribute('x', getXFromTextAlign(titleFontStyle[_fontStyle.FONT_STYLE_OPTION_TEXT_ALIGN]));
@@ -238,11 +250,11 @@ function _default(config, parentEl, _ref4) {
238
250
  } = _ref4;
239
251
  const legendSet = legendOptions && legendSets[0];
240
252
  const legendColor = legendSet && (0, _legends.getColorByValueFromLegendSet)(legendSet, config.value);
241
- let valueColor, titleColor;
253
+ let valueColor, titleColor, backgroundColor;
242
254
 
243
255
  if (legendColor) {
244
256
  if (legendOptions.style === _legends.LEGEND_DISPLAY_STYLE_FILL) {
245
- parentEl.style.background = legendColor;
257
+ backgroundColor = legendColor;
246
258
  valueColor = titleColor = shouldUseContrastColor(legendColor) && _ui.colors.white;
247
259
  } else {
248
260
  valueColor = legendColor;
@@ -252,18 +264,22 @@ function _default(config, parentEl, _ref4) {
252
264
  parentEl.style.overflow = 'hidden';
253
265
  parentEl.style.display = 'flex';
254
266
  parentEl.style.justifyContent = 'center';
255
- parentEl.style.borderRadius = _ui.spacers.dp8;
256
267
 
257
268
  if (dashboard) {
269
+ parentEl.style.borderRadius = _ui.spacers.dp8;
258
270
  return generateDashboardItem(config, {
259
271
  valueColor,
260
- noData
272
+ backgroundColor,
273
+ noData,
274
+ ...(shouldUseContrastColor(legendColor) ? {
275
+ titleColor: _ui.colors.white
276
+ } : {})
261
277
  });
262
278
  } else {
263
- parentEl.style.margin = _ui.spacers.dp8;
264
- parentEl.style.height = "calc(100% - (".concat(_ui.spacers.dp8, " * 2))");
279
+ parentEl.style.height = "100%";
265
280
  return generateDVItem(config, {
266
281
  valueColor,
282
+ backgroundColor,
267
283
  titleColor,
268
284
  parentEl,
269
285
  fontStyle,
@@ -65,11 +65,13 @@ const generateValueSVG = _ref => {
65
65
  const generateDashboardItem = (config, _ref2) => {
66
66
  let {
67
67
  valueColor,
68
+ titleColor,
69
+ backgroundColor,
68
70
  noData
69
71
  } = _ref2;
70
72
  const container = document.createElement('div');
71
- container.setAttribute('style', 'display: flex; flex-direction: column; align-items: center; justify-content: center; width: 100%; height: 100%');
72
- const titleStyle = 'font-size: 12px; color: #666;';
73
+ container.setAttribute('style', "display: flex; flex-direction: column; align-items: center; justify-content: center; width: 100%; height: 100%; background-color:".concat(backgroundColor, ";"));
74
+ const titleStyle = "font-size: 12px; color: ".concat(titleColor || '#666', ";");
73
75
  const title = document.createElement('span');
74
76
  title.setAttribute('style', titleStyle);
75
77
 
@@ -78,10 +80,9 @@ const generateDashboardItem = (config, _ref2) => {
78
80
  container.appendChild(title);
79
81
  }
80
82
 
81
- const subtitle = document.createElement('span');
82
- subtitle.setAttribute('style', titleStyle + ' margin-top: 4px');
83
-
84
83
  if (config.subtitle) {
84
+ const subtitle = document.createElement('span');
85
+ subtitle.setAttribute('style', titleStyle + ' margin-top: 4px; padding: 0 8px');
85
86
  subtitle.appendChild(document.createTextNode(config.subtitle));
86
87
  container.appendChild(subtitle);
87
88
  }
@@ -127,6 +128,7 @@ const getXFromTextAlign = textAlign => {
127
128
  const generateDVItem = (config, _ref3) => {
128
129
  let {
129
130
  valueColor,
131
+ backgroundColor,
130
132
  titleColor,
131
133
  parentEl,
132
134
  fontStyle,
@@ -139,9 +141,19 @@ const generateDVItem = (config, _ref3) => {
139
141
  const svg = document.createElementNS(svgNS, 'svg');
140
142
  svg.setAttribute('xmlns', svgNS);
141
143
  svg.setAttribute('viewBox', "0 0 ".concat(width, " ").concat(height));
142
- svg.setAttribute('width', '100%');
143
- svg.setAttribute('height', '100%');
144
+ svg.setAttribute('width', width);
145
+ svg.setAttribute('height', height);
144
146
  svg.setAttribute('data-test', 'visualization-container');
147
+
148
+ if (backgroundColor) {
149
+ svg.setAttribute('style', "background-color: ".concat(backgroundColor, ";"));
150
+ const background = document.createElementNS(svgNS, 'rect');
151
+ background.setAttribute('width', '100%');
152
+ background.setAttribute('height', '100%');
153
+ background.setAttribute('fill', backgroundColor);
154
+ svg.appendChild(background);
155
+ }
156
+
145
157
  const title = document.createElementNS(svgNS, 'text');
146
158
  const titleFontStyle = mergeFontStyleWithDefault(fontStyle && fontStyle[FONT_STYLE_VISUALIZATION_TITLE], FONT_STYLE_VISUALIZATION_TITLE);
147
159
  title.setAttribute('x', getXFromTextAlign(titleFontStyle[FONT_STYLE_OPTION_TEXT_ALIGN]));
@@ -228,11 +240,11 @@ export default function (config, parentEl, _ref4) {
228
240
  } = _ref4;
229
241
  const legendSet = legendOptions && legendSets[0];
230
242
  const legendColor = legendSet && getColorByValueFromLegendSet(legendSet, config.value);
231
- let valueColor, titleColor;
243
+ let valueColor, titleColor, backgroundColor;
232
244
 
233
245
  if (legendColor) {
234
246
  if (legendOptions.style === LEGEND_DISPLAY_STYLE_FILL) {
235
- parentEl.style.background = legendColor;
247
+ backgroundColor = legendColor;
236
248
  valueColor = titleColor = shouldUseContrastColor(legendColor) && colors.white;
237
249
  } else {
238
250
  valueColor = legendColor;
@@ -242,18 +254,22 @@ export default function (config, parentEl, _ref4) {
242
254
  parentEl.style.overflow = 'hidden';
243
255
  parentEl.style.display = 'flex';
244
256
  parentEl.style.justifyContent = 'center';
245
- parentEl.style.borderRadius = spacers.dp8;
246
257
 
247
258
  if (dashboard) {
259
+ parentEl.style.borderRadius = spacers.dp8;
248
260
  return generateDashboardItem(config, {
249
261
  valueColor,
250
- noData
262
+ backgroundColor,
263
+ noData,
264
+ ...(shouldUseContrastColor(legendColor) ? {
265
+ titleColor: colors.white
266
+ } : {})
251
267
  });
252
268
  } else {
253
- parentEl.style.margin = spacers.dp8;
254
- parentEl.style.height = "calc(100% - (".concat(spacers.dp8, " * 2))");
269
+ parentEl.style.height = "100%";
255
270
  return generateDVItem(config, {
256
271
  valueColor,
272
+ backgroundColor,
257
273
  titleColor,
258
274
  parentEl,
259
275
  fontStyle,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhis2/analytics",
3
- "version": "24.9.3",
3
+ "version": "24.10.1",
4
4
  "main": "./build/cjs/index.js",
5
5
  "module": "./build/es/index.js",
6
6
  "exports": {