@dhis2/analytics 24.5.0-alpha.1 → 24.6.0

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.
@@ -182,6 +182,20 @@
182
182
  "Fixed periods": "Fixed periods",
183
183
  "Selected Periods": "Selected Periods",
184
184
  "No periods selected": "No periods selected",
185
+ "January": "January",
186
+ "February": "February",
187
+ "March": "March",
188
+ "April": "April",
189
+ "May": "May",
190
+ "June": "June",
191
+ "July": "July",
192
+ "August": "August",
193
+ "September": "September",
194
+ "October": "October",
195
+ "November": "November",
196
+ "December": "December",
197
+ "Week {{weekNumber}}": "Week {{weekNumber}}",
198
+ "Bi-Week {{biWeekNumber}}": "Bi-Week {{biWeekNumber}}",
185
199
  "Daily": "Daily",
186
200
  "Weekly": "Weekly",
187
201
  "Weekly (Start Wednesday)": "Weekly (Start Wednesday)",
@@ -1,14 +1,13 @@
1
- import { colors } from '@dhis2/ui';
2
- import { FONT_STYLE_VISUALIZATION_TITLE, FONT_STYLE_VISUALIZATION_SUBTITLE, FONT_STYLE_OPTION_FONT_SIZE, FONT_STYLE_OPTION_TEXT_COLOR, FONT_STYLE_OPTION_TEXT_ALIGN, FONT_STYLE_OPTION_ITALIC, FONT_STYLE_OPTION_BOLD, TEXT_ALIGN_LEFT, TEXT_ALIGN_RIGHT, TEXT_ALIGN_CENTER, mergeFontStyleWithDefault } from '../../../../modules/fontStyle.js';
3
- import { getColorByValueFromLegendSet } from '../../../../modules/legends.js';
1
+ import { colors, spacers } from '@dhis2/ui';
2
+ import { FONT_STYLE_VISUALIZATION_TITLE, FONT_STYLE_VISUALIZATION_SUBTITLE, FONT_STYLE_OPTION_FONT_SIZE, FONT_STYLE_OPTION_TEXT_COLOR, FONT_STYLE_OPTION_TEXT_ALIGN, FONT_STYLE_OPTION_ITALIC, FONT_STYLE_OPTION_BOLD, TEXT_ALIGN_LEFT, TEXT_ALIGN_RIGHT, TEXT_ALIGN_CENTER, mergeFontStyleWithDefault, defaultFontStyle } from '../../../../modules/fontStyle.js';
3
+ import { getColorByValueFromLegendSet, LEGEND_DISPLAY_STYLE_FILL } from '../../../../modules/legends.js';
4
4
  const svgNS = 'http://www.w3.org/2000/svg';
5
5
 
6
6
  const generateValueSVG = _ref => {
7
7
  let {
8
- value,
9
8
  formattedValue,
10
9
  subText,
11
- legendSet,
10
+ valueColor,
12
11
  noData,
13
12
  y
14
13
  } = _ref;
@@ -23,8 +22,8 @@ const generateValueSVG = _ref => {
23
22
 
24
23
  let fillColor = colors.grey900;
25
24
 
26
- if (legendSet) {
27
- fillColor = getColorByValueFromLegendSet(legendSet, value);
25
+ if (valueColor) {
26
+ fillColor = valueColor;
28
27
  } else if (formattedValue === noData.text) {
29
28
  fillColor = colors.grey600;
30
29
  }
@@ -65,7 +64,7 @@ const generateValueSVG = _ref => {
65
64
 
66
65
  const generateDashboardItem = (config, _ref2) => {
67
66
  let {
68
- legendSet,
67
+ valueColor,
69
68
  noData
70
69
  } = _ref2;
71
70
  const container = document.createElement('div');
@@ -88,10 +87,9 @@ const generateDashboardItem = (config, _ref2) => {
88
87
  }
89
88
 
90
89
  container.appendChild(generateValueSVG({
91
- value: config.value,
92
90
  formattedValue: config.formattedValue,
93
91
  subText: config.subText,
94
- legendSet,
92
+ valueColor,
95
93
  noData,
96
94
  y: 40
97
95
  }));
@@ -128,7 +126,8 @@ const getXFromTextAlign = textAlign => {
128
126
 
129
127
  const generateDVItem = (config, _ref3) => {
130
128
  let {
131
- legendSet,
129
+ valueColor,
130
+ titleColor,
132
131
  parentEl,
133
132
  fontStyle,
134
133
  noData
@@ -151,7 +150,13 @@ const generateDVItem = (config, _ref3) => {
151
150
  title.setAttribute('font-size', "".concat(titleFontStyle[FONT_STYLE_OPTION_FONT_SIZE], "px"));
152
151
  title.setAttribute('font-weight', titleFontStyle[FONT_STYLE_OPTION_BOLD] ? FONT_STYLE_OPTION_BOLD : 'normal');
153
152
  title.setAttribute('font-style', titleFontStyle[FONT_STYLE_OPTION_ITALIC] ? FONT_STYLE_OPTION_ITALIC : 'normal');
154
- title.setAttribute('fill', titleFontStyle[FONT_STYLE_OPTION_TEXT_COLOR]);
153
+
154
+ if (titleColor && titleFontStyle[FONT_STYLE_OPTION_TEXT_COLOR] === defaultFontStyle[FONT_STYLE_VISUALIZATION_TITLE][FONT_STYLE_OPTION_TEXT_COLOR]) {
155
+ title.setAttribute('fill', titleColor);
156
+ } else {
157
+ title.setAttribute('fill', titleFontStyle[FONT_STYLE_OPTION_TEXT_COLOR]);
158
+ }
159
+
155
160
  title.setAttribute('data-test', 'visualization-title');
156
161
 
157
162
  if (config.title) {
@@ -168,7 +173,13 @@ const generateDVItem = (config, _ref3) => {
168
173
  subtitle.setAttribute('font-size', "".concat(subtitleFontStyle[FONT_STYLE_OPTION_FONT_SIZE], "px"));
169
174
  subtitle.setAttribute('font-weight', subtitleFontStyle[FONT_STYLE_OPTION_BOLD] ? FONT_STYLE_OPTION_BOLD : 'normal');
170
175
  subtitle.setAttribute('font-style', subtitleFontStyle[FONT_STYLE_OPTION_ITALIC] ? FONT_STYLE_OPTION_ITALIC : 'normal');
171
- subtitle.setAttribute('fill', subtitleFontStyle[FONT_STYLE_OPTION_TEXT_COLOR]);
176
+
177
+ if (titleColor && subtitleFontStyle[FONT_STYLE_OPTION_TEXT_COLOR] === defaultFontStyle[FONT_STYLE_VISUALIZATION_SUBTITLE][FONT_STYLE_OPTION_TEXT_COLOR]) {
178
+ subtitle.setAttribute('fill', titleColor);
179
+ } else {
180
+ subtitle.setAttribute('fill', subtitleFontStyle[FONT_STYLE_OPTION_TEXT_COLOR]);
181
+ }
182
+
172
183
  subtitle.setAttribute('data-test', 'visualization-subtitle');
173
184
 
174
185
  if (config.subtitle) {
@@ -177,34 +188,76 @@ const generateDVItem = (config, _ref3) => {
177
188
  }
178
189
 
179
190
  svg.appendChild(generateValueSVG({
180
- value: config.value,
181
191
  formattedValue: config.formattedValue,
182
192
  subText: config.subText,
183
- legendSet,
193
+ valueColor,
184
194
  noData,
185
195
  y: 20
186
196
  }));
187
197
  return svg;
188
198
  };
189
199
 
200
+ const shouldUseContrastColor = inputColor => {
201
+ // based on https://stackoverflow.com/questions/3942878/how-to-decide-font-color-in-white-or-black-depending-on-background-color
202
+ var color = inputColor.charAt(0) === '#' ? inputColor.substring(1, 7) : inputColor;
203
+ var r = parseInt(color.substring(0, 2), 16); // hexToR
204
+
205
+ var g = parseInt(color.substring(2, 4), 16); // hexToG
206
+
207
+ var b = parseInt(color.substring(4, 6), 16); // hexToB
208
+
209
+ var uicolors = [r / 255, g / 255, b / 255];
210
+ var c = uicolors.map(col => {
211
+ if (col <= 0.03928) {
212
+ return col / 12.92;
213
+ }
214
+
215
+ return Math.pow((col + 0.055) / 1.055, 2.4);
216
+ });
217
+ var L = 0.2126 * c[0] + 0.7152 * c[1] + 0.0722 * c[2];
218
+ return L <= 0.179;
219
+ };
220
+
190
221
  export default function (config, parentEl, _ref4) {
191
222
  let {
192
223
  dashboard,
193
224
  legendSets,
194
225
  fontStyle,
195
- noData
226
+ noData,
227
+ legendOptions
196
228
  } = _ref4;
197
- const legendSet = legendSets[0];
229
+ const legendSet = legendOptions && legendSets[0];
230
+ const legendColor = legendSet && getColorByValueFromLegendSet(legendSet, config.value);
231
+ let valueColor, titleColor;
232
+
233
+ if (legendColor) {
234
+ if (legendOptions.style === LEGEND_DISPLAY_STYLE_FILL) {
235
+ parentEl.style.background = legendColor;
236
+ valueColor = titleColor = shouldUseContrastColor(legendColor) && colors.white;
237
+ } else {
238
+ valueColor = legendColor;
239
+ }
240
+ }
241
+
198
242
  parentEl.style.overflow = 'hidden';
199
243
  parentEl.style.display = 'flex';
200
244
  parentEl.style.justifyContent = 'center';
201
- return dashboard ? generateDashboardItem(config, {
202
- legendSet,
203
- noData
204
- }) : generateDVItem(config, {
205
- legendSet,
206
- parentEl,
207
- fontStyle,
208
- noData
209
- });
245
+ parentEl.style.borderRadius = spacers.dp8;
246
+
247
+ if (dashboard) {
248
+ return generateDashboardItem(config, {
249
+ valueColor,
250
+ noData
251
+ });
252
+ } else {
253
+ parentEl.style.margin = spacers.dp8;
254
+ parentEl.style.height = "calc(100% - (".concat(spacers.dp8, " * 2))");
255
+ return generateDVItem(config, {
256
+ valueColor,
257
+ titleColor,
258
+ parentEl,
259
+ fontStyle,
260
+ noData
261
+ });
262
+ }
210
263
  }
@@ -66,6 +66,7 @@ export default function (_ref) {
66
66
 
67
67
  this.createVisualization = () => _generator(this.getConfig(), el, { ...extraOptions,
68
68
  noData: DEFAULT_EXTRA_OPTIONS.noData,
69
- fontStyle: layout.fontStyle
69
+ fontStyle: layout.fontStyle,
70
+ legendOptions: layout.legend
70
71
  });
71
72
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhis2/analytics",
3
- "version": "24.5.0-alpha.1",
3
+ "version": "24.6.0",
4
4
  "main": "./build/cjs/index.js",
5
5
  "module": "./build/es/index.js",
6
6
  "exports": {
@@ -48,11 +48,6 @@
48
48
  "styled-jsx": "^4.0.1",
49
49
  "typeface-roboto": "^0.0.75"
50
50
  },
51
- "jest": {
52
- "transformIgnorePatterns": [
53
- "/!node_modules\\/multi-calendar-dates/"
54
- ]
55
- },
56
51
  "peerDependencies": {
57
52
  "@dhis2/app-runtime": "^3",
58
53
  "@dhis2/d2-i18n": "^1.1",
@@ -64,7 +59,6 @@
64
59
  },
65
60
  "dependencies": {
66
61
  "@dhis2/d2-ui-rich-text": "^7.4.0",
67
- "@dhis2/multi-calendar-dates": "1.0.0-beta.21",
68
62
  "classnames": "^2.3.1",
69
63
  "d2-utilizr": "^0.2.16",
70
64
  "d3-color": "^1.2.3",