@dhis2/analytics 26.8.7 → 26.9.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.
Files changed (127) hide show
  1. package/build/cjs/__demo__/SingleValue.stories.js +706 -0
  2. package/build/cjs/locales/lo/translations.json +16 -12
  3. package/build/cjs/visualizations/config/adapters/dhis_highcharts/chart/default.js +26 -0
  4. package/build/cjs/visualizations/config/adapters/dhis_highcharts/chart/index.js +18 -0
  5. package/build/cjs/visualizations/config/adapters/dhis_highcharts/chart/singleValue.js +19 -0
  6. package/build/cjs/visualizations/config/adapters/dhis_highcharts/customSVGOptions/index.js +36 -0
  7. package/build/cjs/visualizations/config/adapters/dhis_highcharts/customSVGOptions/singleValue/getSingleValueBackgroundColor.js +12 -0
  8. package/build/cjs/visualizations/config/adapters/{dhis_dhis/value/index.js → dhis_highcharts/customSVGOptions/singleValue/getSingleValueFormattedValue.js} +8 -6
  9. package/build/cjs/visualizations/config/adapters/dhis_highcharts/customSVGOptions/singleValue/getSingleValueLegendColor.js +11 -0
  10. package/build/cjs/visualizations/config/adapters/dhis_highcharts/customSVGOptions/singleValue/getSingleValueSubtext.js +11 -0
  11. package/build/cjs/visualizations/config/adapters/dhis_highcharts/customSVGOptions/singleValue/getSingleValueTextColor.js +20 -0
  12. package/build/cjs/visualizations/config/adapters/dhis_highcharts/customSVGOptions/singleValue/getSingleValueTitleColor.js +26 -0
  13. package/build/cjs/visualizations/config/adapters/dhis_highcharts/customSVGOptions/singleValue/index.js +31 -0
  14. package/build/cjs/visualizations/config/adapters/dhis_highcharts/events/index.js +24 -0
  15. package/build/cjs/visualizations/config/adapters/dhis_highcharts/events/loadCustomSVG/index.js +18 -0
  16. package/build/cjs/visualizations/config/adapters/dhis_highcharts/events/loadCustomSVG/singleValue/addIconElement.js +34 -0
  17. package/build/cjs/visualizations/config/adapters/dhis_highcharts/events/loadCustomSVG/singleValue/checkIfFitsWithinContainer.js +19 -0
  18. package/build/cjs/visualizations/config/adapters/dhis_highcharts/events/loadCustomSVG/singleValue/computeLayoutRect.js +39 -0
  19. package/build/cjs/visualizations/config/adapters/dhis_highcharts/events/loadCustomSVG/singleValue/computeSpacingTop.js +21 -0
  20. package/build/cjs/visualizations/config/adapters/dhis_highcharts/events/loadCustomSVG/singleValue/constants.js +11 -0
  21. package/build/cjs/visualizations/config/adapters/dhis_highcharts/events/loadCustomSVG/singleValue/getAvailableSpace.js +14 -0
  22. package/build/cjs/visualizations/config/adapters/dhis_highcharts/events/loadCustomSVG/singleValue/index.js +48 -0
  23. package/build/cjs/visualizations/config/adapters/dhis_highcharts/events/loadCustomSVG/singleValue/positionElements.js +46 -0
  24. package/build/cjs/visualizations/config/adapters/dhis_highcharts/events/loadCustomSVG/singleValue/styles.js +109 -0
  25. package/build/cjs/visualizations/config/adapters/dhis_highcharts/exporting.js +30 -0
  26. package/build/cjs/visualizations/config/adapters/dhis_highcharts/index.js +33 -23
  27. package/build/cjs/visualizations/config/adapters/dhis_highcharts/lang.js +17 -0
  28. package/build/cjs/visualizations/config/adapters/dhis_highcharts/plotOptions.js +1 -1
  29. package/build/cjs/visualizations/config/adapters/dhis_highcharts/series/index.js +5 -1
  30. package/build/cjs/visualizations/config/adapters/dhis_highcharts/subtitle/__tests__/singleValue.spec.js +62 -0
  31. package/build/cjs/visualizations/config/adapters/dhis_highcharts/subtitle/index.js +56 -22
  32. package/build/cjs/visualizations/config/adapters/dhis_highcharts/subtitle/singleValue.js +27 -0
  33. package/build/cjs/visualizations/config/adapters/dhis_highcharts/title/__tests__/singleValue.spec.js +44 -0
  34. package/build/cjs/visualizations/config/adapters/dhis_highcharts/title/index.js +50 -22
  35. package/build/cjs/visualizations/config/adapters/dhis_highcharts/title/singleValue.js +31 -0
  36. package/build/cjs/visualizations/config/adapters/dhis_highcharts/type.js +2 -0
  37. package/build/cjs/visualizations/config/adapters/dhis_highcharts/xAxis/index.js +1 -0
  38. package/build/cjs/visualizations/config/adapters/dhis_highcharts/yAxis/index.js +4 -5
  39. package/build/cjs/visualizations/config/adapters/index.js +2 -4
  40. package/build/cjs/visualizations/config/generators/highcharts/index.js +8 -0
  41. package/build/cjs/visualizations/config/generators/highcharts/pdfExportBugFixPlugin/index.js +13 -0
  42. package/build/cjs/visualizations/config/generators/highcharts/pdfExportBugFixPlugin/nonASCIIFont.js +17 -0
  43. package/build/cjs/visualizations/config/generators/highcharts/pdfExportBugFixPlugin/textShadow.js +289 -0
  44. package/build/cjs/visualizations/config/generators/index.js +2 -4
  45. package/build/cjs/visualizations/store/adapters/dhis_highcharts/index.js +3 -0
  46. package/build/cjs/visualizations/store/adapters/dhis_highcharts/singleValue.js +10 -0
  47. package/build/cjs/visualizations/store/adapters/index.js +2 -4
  48. package/build/cjs/visualizations/util/shouldUseContrastColor.js +24 -0
  49. package/build/es/__demo__/SingleValue.stories.js +702 -0
  50. package/build/es/locales/lo/translations.json +16 -12
  51. package/build/es/visualizations/config/adapters/dhis_highcharts/chart/default.js +19 -0
  52. package/build/es/visualizations/config/adapters/dhis_highcharts/chart/index.js +11 -0
  53. package/build/es/visualizations/config/adapters/dhis_highcharts/chart/singleValue.js +12 -0
  54. package/build/es/visualizations/config/adapters/dhis_highcharts/customSVGOptions/index.js +29 -0
  55. package/build/es/visualizations/config/adapters/dhis_highcharts/customSVGOptions/singleValue/getSingleValueBackgroundColor.js +6 -0
  56. package/build/es/visualizations/config/adapters/{dhis_dhis/value/index.js → dhis_highcharts/customSVGOptions/singleValue/getSingleValueFormattedValue.js} +4 -4
  57. package/build/es/visualizations/config/adapters/dhis_highcharts/customSVGOptions/singleValue/getSingleValueLegendColor.js +5 -0
  58. package/build/es/visualizations/config/adapters/dhis_highcharts/customSVGOptions/singleValue/getSingleValueSubtext.js +5 -0
  59. package/build/es/visualizations/config/adapters/dhis_highcharts/customSVGOptions/singleValue/getSingleValueTextColor.js +14 -0
  60. package/build/es/visualizations/config/adapters/dhis_highcharts/customSVGOptions/singleValue/getSingleValueTitleColor.js +20 -0
  61. package/build/es/visualizations/config/adapters/dhis_highcharts/customSVGOptions/singleValue/index.js +25 -0
  62. package/build/es/visualizations/config/adapters/dhis_highcharts/events/index.js +16 -0
  63. package/build/es/visualizations/config/adapters/dhis_highcharts/events/loadCustomSVG/index.js +11 -0
  64. package/build/es/visualizations/config/adapters/dhis_highcharts/events/loadCustomSVG/singleValue/addIconElement.js +28 -0
  65. package/build/es/visualizations/config/adapters/dhis_highcharts/events/loadCustomSVG/singleValue/checkIfFitsWithinContainer.js +13 -0
  66. package/build/es/visualizations/config/adapters/dhis_highcharts/events/loadCustomSVG/singleValue/computeLayoutRect.js +33 -0
  67. package/build/es/visualizations/config/adapters/dhis_highcharts/events/loadCustomSVG/singleValue/computeSpacingTop.js +15 -0
  68. package/build/es/visualizations/config/adapters/dhis_highcharts/events/loadCustomSVG/singleValue/constants.js +4 -0
  69. package/build/es/visualizations/config/adapters/dhis_highcharts/events/loadCustomSVG/singleValue/getAvailableSpace.js +8 -0
  70. package/build/es/visualizations/config/adapters/dhis_highcharts/events/loadCustomSVG/singleValue/index.js +42 -0
  71. package/build/es/visualizations/config/adapters/dhis_highcharts/events/loadCustomSVG/singleValue/positionElements.js +40 -0
  72. package/build/es/visualizations/config/adapters/dhis_highcharts/events/loadCustomSVG/singleValue/styles.js +101 -0
  73. package/build/es/visualizations/config/adapters/dhis_highcharts/exporting.js +23 -0
  74. package/build/es/visualizations/config/adapters/dhis_highcharts/index.js +23 -13
  75. package/build/es/visualizations/config/adapters/dhis_highcharts/lang.js +11 -0
  76. package/build/es/visualizations/config/adapters/dhis_highcharts/plotOptions.js +1 -1
  77. package/build/es/visualizations/config/adapters/dhis_highcharts/series/index.js +6 -2
  78. package/build/es/visualizations/config/adapters/dhis_highcharts/subtitle/__tests__/singleValue.spec.js +59 -0
  79. package/build/es/visualizations/config/adapters/dhis_highcharts/subtitle/index.js +56 -24
  80. package/build/es/visualizations/config/adapters/dhis_highcharts/subtitle/singleValue.js +14 -0
  81. package/build/es/visualizations/config/adapters/dhis_highcharts/title/__tests__/singleValue.spec.js +42 -0
  82. package/build/es/visualizations/config/adapters/dhis_highcharts/title/index.js +52 -24
  83. package/build/es/visualizations/config/adapters/dhis_highcharts/title/singleValue.js +18 -0
  84. package/build/es/visualizations/config/adapters/dhis_highcharts/type.js +3 -1
  85. package/build/es/visualizations/config/adapters/dhis_highcharts/xAxis/index.js +2 -1
  86. package/build/es/visualizations/config/adapters/dhis_highcharts/yAxis/index.js +5 -6
  87. package/build/es/visualizations/config/adapters/index.js +1 -3
  88. package/build/es/visualizations/config/generators/highcharts/index.js +8 -0
  89. package/build/es/visualizations/config/generators/highcharts/pdfExportBugFixPlugin/index.js +6 -0
  90. package/build/es/visualizations/config/generators/highcharts/pdfExportBugFixPlugin/nonASCIIFont.js +11 -0
  91. package/build/es/visualizations/config/generators/highcharts/pdfExportBugFixPlugin/textShadow.js +283 -0
  92. package/build/es/visualizations/config/generators/index.js +1 -3
  93. package/build/es/visualizations/store/adapters/dhis_highcharts/index.js +4 -1
  94. package/build/es/visualizations/store/adapters/dhis_highcharts/singleValue.js +4 -0
  95. package/build/es/visualizations/store/adapters/index.js +1 -3
  96. package/build/es/visualizations/util/shouldUseContrastColor.js +17 -0
  97. package/package.json +1 -1
  98. package/build/cjs/visualizations/config/adapters/dhis_dhis/index.js +0 -39
  99. package/build/cjs/visualizations/config/adapters/dhis_dhis/subtitle/__tests__/index.spec.js +0 -49
  100. package/build/cjs/visualizations/config/adapters/dhis_dhis/subtitle/__tests__/singleValue.spec.js +0 -15
  101. package/build/cjs/visualizations/config/adapters/dhis_dhis/subtitle/index.js +0 -34
  102. package/build/cjs/visualizations/config/adapters/dhis_dhis/subtitle/singleValue.js +0 -11
  103. package/build/cjs/visualizations/config/adapters/dhis_dhis/title/__tests__/index.spec.js +0 -39
  104. package/build/cjs/visualizations/config/adapters/dhis_dhis/title/__tests__/singleValue.spec.js +0 -17
  105. package/build/cjs/visualizations/config/adapters/dhis_dhis/title/index.js +0 -31
  106. package/build/cjs/visualizations/config/adapters/dhis_dhis/title/singleValue.js +0 -18
  107. package/build/cjs/visualizations/config/adapters/dhis_dhis/type.js +0 -19
  108. package/build/cjs/visualizations/config/adapters/dhis_highcharts/chart.js +0 -39
  109. package/build/cjs/visualizations/config/generators/dhis/index.js +0 -28
  110. package/build/cjs/visualizations/config/generators/dhis/singleValue.js +0 -359
  111. package/build/cjs/visualizations/store/adapters/dhis_dhis/index.js +0 -83
  112. package/build/cjs/visualizations/store/adapters/dhis_dhis/singleValue.js +0 -10
  113. package/build/es/visualizations/config/adapters/dhis_dhis/index.js +0 -30
  114. package/build/es/visualizations/config/adapters/dhis_dhis/subtitle/__tests__/index.spec.js +0 -46
  115. package/build/es/visualizations/config/adapters/dhis_dhis/subtitle/__tests__/singleValue.spec.js +0 -12
  116. package/build/es/visualizations/config/adapters/dhis_dhis/subtitle/index.js +0 -27
  117. package/build/es/visualizations/config/adapters/dhis_dhis/subtitle/singleValue.js +0 -4
  118. package/build/es/visualizations/config/adapters/dhis_dhis/title/__tests__/index.spec.js +0 -36
  119. package/build/es/visualizations/config/adapters/dhis_dhis/title/__tests__/singleValue.spec.js +0 -14
  120. package/build/es/visualizations/config/adapters/dhis_dhis/title/index.js +0 -24
  121. package/build/es/visualizations/config/adapters/dhis_dhis/title/singleValue.js +0 -11
  122. package/build/es/visualizations/config/adapters/dhis_dhis/type.js +0 -13
  123. package/build/es/visualizations/config/adapters/dhis_highcharts/chart.js +0 -32
  124. package/build/es/visualizations/config/generators/dhis/index.js +0 -21
  125. package/build/es/visualizations/config/generators/dhis/singleValue.js +0 -353
  126. package/build/es/visualizations/store/adapters/dhis_dhis/index.js +0 -76
  127. package/build/es/visualizations/store/adapters/dhis_dhis/singleValue.js +0 -4
@@ -18,11 +18,13 @@
18
18
  "About this map": "ກ່ຽວກັບແຜນທີ່",
19
19
  "About this line list": "ກ່ຽວກັບບັນຊີລາຍຊື່",
20
20
  "About this visualization": "ກ່ຽວກັບການສ້າງພາບຂໍ້ມູນ",
21
+ "About this event chart": "ກ່ຽວກັບເຫດການແຜນຜັງ",
22
+ "About this event report": "ກ່ຽວກັບບົດລາຍງານເຫດການຕ່າງໆ",
21
23
  "This app could not retrieve required data.": "ແອັບນີ້ບໍ່ສາມາດດຶງຂໍ້ມູນທີ່ຕ້ອງການໄດ້",
22
24
  "Network error": "ຂໍ້ຜິດພາດທາງເຄື່ອຂ່າຍ",
23
25
  "Data / Edit calculation": "ຂໍ້ມູນ / ແກ້ໄຂການຄິດໄລ່",
24
26
  "Data / New calculation": "ຂໍ້ມູນ / ຄິດໄລ່ໃໝ່",
25
- "Remove item": "ລົບລາຍການ",
27
+ "Remove item": "ເອົາລາຍການອອກ",
26
28
  "Check formula": "ກວດເບິ່ງສູດ",
27
29
  "Calculation name": "ຊື່ການຄິດໄລ່",
28
30
  "Shown in table headers and chart axes/legends": "ສະ​ແດງ​​ຢູ່​ເທິງຕາ​ຕະ​ລາງ​ ແລະ​ ແກນ​ແຜນ​ວາດ",
@@ -132,17 +134,6 @@
132
134
  "Manage sharing": "ຈັດການການເຜີຍແຜ່",
133
135
  "Could not update interpretation": "ບໍ່ສາມາດອັບເດດຂໍ້ຄວາມ",
134
136
  "Enter interpretation text": "ປ້ອນຂໍ້ຄວາມ",
135
- "Bold text": "ຕົວອັກສອນເຂັ້ມ",
136
- "Italic text": "ຕົວອັກສອນສະຫຼ່ຽງ",
137
- "Link to a URL": "ເຊື່ອມຕໍ່ກັບ URL",
138
- "Mention a user": "ກ່າວເຖິງຜູ້ໃຊ້",
139
- "Add emoji": "ເພີ່ມ emoji",
140
- "Preview": "ເບິ່ງຕົວຢ່າງ",
141
- "Back to write mode": "ກັບໄປທີ່ໂໝດຂຽນ",
142
- "Too many results. Try refining the search.": "ຜົນໄດ້ຮັບຫຼາຍເກີນໄປ. ປັບປຸງການຄົ້ນຫາ.",
143
- "Search for a user": "ຄົ້ນຫາຜູ້ໃຊ້",
144
- "Searching for \"{{- searchText}}\"": "ຄົ້ນຫາ \"{{- searchText}}\"",
145
- "No results found": "ບໍ່ພົບຜົນການຊອກຫາ",
146
137
  "Not available offline": "ບໍ່ສາມາດໃຊ້ໄດ້ອອບລາຍ",
147
138
  "Created by": "ສ້າງໂດຍ",
148
139
  "Anyone": "ທຸກຄົນ",
@@ -271,6 +262,14 @@
271
262
  "Six-months": "6 ເດືອນ",
272
263
  "Financial Years": "ສົກປີງົບປະມານ",
273
264
  "Years": "ປີ",
265
+ "Value: {{value}}": "",
266
+ "Bold text": "ຕົວອັກສອນເຂັ້ມ",
267
+ "Italic text": "ຕົວອັກສອນສະຫຼ່ຽງ",
268
+ "Link to a URL": "ເຊື່ອມຕໍ່ກັບ URL",
269
+ "Mention a user": "ກ່າວເຖິງຜູ້ໃຊ້",
270
+ "Add emoji": "ເພີ່ມ emoji",
271
+ "Preview": "ເບິ່ງຕົວຢ່າງ",
272
+ "Back to write mode": "ກັບໄປທີ່ໂໝດຂຽນ",
274
273
  "Interpretations and details": "ຂໍ້ມູນ ແລະ ລາຍລະອຽດ",
275
274
  "Translating to": "ແປເປັນ",
276
275
  "Choose a locale": "ເລືອກສະຖານທີ່ເກີດເຫດ",
@@ -281,6 +280,10 @@
281
280
  "Cannot save while offline": "ບໍ່ສາມາດບັນທຶກແບບອອບລາຍ",
282
281
  "Could not load translations": "ບໍ່ສາມາດໂຫຼດການແປ",
283
282
  "Retry": "ລອງໃໝ່",
283
+ "Too many results. Try refining the search.": "ຜົນໄດ້ຮັບຫຼາຍເກີນໄປ. ປັບປຸງການຄົ້ນຫາ.",
284
+ "Search for a user": "ຄົ້ນຫາຜູ້ໃຊ້",
285
+ "Searching for \"{{- searchText}}\"": "ຄົ້ນຫາ \"{{- searchText}}\"",
286
+ "No results found": "ບໍ່ພົບຜົນການຊອກຫາ",
284
287
  "Series": "ແທ່ງ",
285
288
  "Category": "ລວງນອນ",
286
289
  "Filter": "ຕົວກອງ",
@@ -350,6 +353,7 @@
350
353
  "{{thresholdFactor}} × Modified Z-score high": "{{thresholdFactor}} x ແກ້ໄຂຄະແນນ z ສູງ",
351
354
  "{{thresholdFactor}} × Z-score low": "{{thresholdFactor}} x ຄະແນນ z ຕ່ຳ",
352
355
  "{{thresholdFactor}} × Z-score high": "{{thresholdFactor}} x ຄະແນນ z ສູງ",
356
+ "Not applicable": "",
353
357
  "Data": "ຂໍ້ມູນ",
354
358
  "Organisation unit": "​ຫົວ​ໜ່ວຍ​ການ​ຈັດ​ຕັ້ງ",
355
359
  "Assigned Categories": "ຈັດໝວດໝູ່",
@@ -0,0 +1,19 @@
1
+ import { getEvents } from '../events/index.js';
2
+ import getType from '../type.js';
3
+ const DEFAULT_CHART = {
4
+ spacingTop: 20,
5
+ style: {
6
+ fontFamily: 'Roboto,Helvetica Neue,Helvetica,Arial,sans-serif'
7
+ }
8
+ };
9
+ const DASHBOARD_CHART = {
10
+ spacingTop: 0,
11
+ spacingRight: 5,
12
+ spacingBottom: 2,
13
+ spacingLeft: 5
14
+ };
15
+ export default function getDefaultChart(layout, el, extraOptions) {
16
+ return Object.assign({}, getType(layout.type), {
17
+ renderTo: el || layout.el
18
+ }, DEFAULT_CHART, extraOptions.dashboard ? DASHBOARD_CHART : undefined, getEvents(layout.type));
19
+ }
@@ -0,0 +1,11 @@
1
+ import { VIS_TYPE_SINGLE_VALUE } from '../../../../../modules/visTypes.js';
2
+ import getDefaultChart from './default.js';
3
+ import getSingleValueChart from './singleValue.js';
4
+ export default function getChart(layout, el, extraOptions, series) {
5
+ switch (layout.type) {
6
+ case VIS_TYPE_SINGLE_VALUE:
7
+ return getSingleValueChart(layout, el, extraOptions, series);
8
+ default:
9
+ return getDefaultChart(layout, el, extraOptions);
10
+ }
11
+ }
@@ -0,0 +1,12 @@
1
+ import { getSingleValueBackgroundColor } from '../customSVGOptions/singleValue/getSingleValueBackgroundColor.js';
2
+ import getDefaultChart from './default.js';
3
+ export default function getSingleValueChart(layout, el, extraOptions, series) {
4
+ const chart = {
5
+ ...getDefaultChart(layout, el, extraOptions),
6
+ backgroundColor: getSingleValueBackgroundColor(layout.legend, extraOptions.legendSets, series[0])
7
+ };
8
+ if (extraOptions.dashboard) {
9
+ chart.spacingTop = 7;
10
+ }
11
+ return chart;
12
+ }
@@ -0,0 +1,29 @@
1
+ import { VIS_TYPE_SINGLE_VALUE } from '../../../../../modules/visTypes.js';
2
+ import getSingleValueCustomSVGOptions from './singleValue/index.js';
3
+ export default function getCustomSVGOptions(_ref) {
4
+ let {
5
+ extraConfig,
6
+ layout,
7
+ extraOptions,
8
+ metaData,
9
+ series
10
+ } = _ref;
11
+ const baseOptions = {
12
+ visualizationType: layout.type
13
+ };
14
+ switch (layout.type) {
15
+ case VIS_TYPE_SINGLE_VALUE:
16
+ return {
17
+ ...baseOptions,
18
+ ...getSingleValueCustomSVGOptions({
19
+ extraConfig,
20
+ layout,
21
+ extraOptions,
22
+ metaData,
23
+ series
24
+ })
25
+ };
26
+ default:
27
+ break;
28
+ }
29
+ }
@@ -0,0 +1,6 @@
1
+ import { LEGEND_DISPLAY_STYLE_FILL } from '../../../../../../modules/legends.js';
2
+ import { getSingleValueLegendColor } from './getSingleValueLegendColor.js';
3
+ export function getSingleValueBackgroundColor(legendOptions, legendSets, value) {
4
+ const legendColor = getSingleValueLegendColor(legendOptions, legendSets, value);
5
+ return legendColor && legendOptions.style === LEGEND_DISPLAY_STYLE_FILL ? legendColor : 'transparent';
6
+ }
@@ -1,7 +1,7 @@
1
- import { renderValue } from '../../../../../modules/renderValue.js';
2
- import { VALUE_TYPE_TEXT } from '../../../../../modules/valueTypes.js';
3
- import { INDICATOR_FACTOR_100 } from '../index.js';
4
- export default function (value, layout, metaData) {
1
+ import { renderValue } from '../../../../../../modules/renderValue.js';
2
+ import { VALUE_TYPE_TEXT } from '../../../../../../modules/valueTypes.js';
3
+ export const INDICATOR_FACTOR_100 = 100;
4
+ export function getSingleValueFormattedValue(value, layout, metaData) {
5
5
  const valueType = metaData.items[metaData.dimensions.dx[0]].valueType;
6
6
  const indicatorType = metaData.items[metaData.dimensions.dx[0]].indicatorType;
7
7
  let formattedValue = renderValue(value, valueType || VALUE_TYPE_TEXT, {
@@ -0,0 +1,5 @@
1
+ import { getColorByValueFromLegendSet } from '../../../../../../modules/legends.js';
2
+ export function getSingleValueLegendColor(legendOptions, legendSets, value) {
3
+ const legendSet = legendOptions && legendSets[0];
4
+ return legendSet ? getColorByValueFromLegendSet(legendSet, value) : undefined;
5
+ }
@@ -0,0 +1,5 @@
1
+ import { INDICATOR_FACTOR_100 } from './getSingleValueFormattedValue.js';
2
+ export function getSingleValueSubtext(metaData) {
3
+ const indicatorType = metaData.items[metaData.dimensions.dx[0]].indicatorType;
4
+ return indicatorType !== null && indicatorType !== void 0 && indicatorType.displayName && (indicatorType === null || indicatorType === void 0 ? void 0 : indicatorType.factor) !== INDICATOR_FACTOR_100 ? indicatorType === null || indicatorType === void 0 ? void 0 : indicatorType.displayName : undefined;
5
+ }
@@ -0,0 +1,14 @@
1
+ import { colors } from '@dhis2/ui';
2
+ import { LEGEND_DISPLAY_STYLE_TEXT } from '../../../../../../modules/legends.js';
3
+ import { shouldUseContrastColor } from '../../../../../util/shouldUseContrastColor.js';
4
+ import { getSingleValueLegendColor } from './getSingleValueLegendColor.js';
5
+ export function getSingleValueTextColor(baseColor, value, legendOptions, legendSets) {
6
+ const legendColor = getSingleValueLegendColor(legendOptions, legendSets, value);
7
+ if (!legendColor) {
8
+ return baseColor;
9
+ }
10
+ if (legendOptions.style === LEGEND_DISPLAY_STYLE_TEXT) {
11
+ return legendColor;
12
+ }
13
+ return shouldUseContrastColor(legendColor) ? colors.white : baseColor;
14
+ }
@@ -0,0 +1,20 @@
1
+ import { colors } from '@dhis2/ui';
2
+ import { LEGEND_DISPLAY_STYLE_FILL } from '../../../../../../modules/legends.js';
3
+ import { shouldUseContrastColor } from '../../../../../util/shouldUseContrastColor.js';
4
+ import { getSingleValueLegendColor } from './getSingleValueLegendColor.js';
5
+ export function getSingleValueTitleColor(customColor, defaultColor, value, legendOptions, legendSets) {
6
+ // Never override custom color
7
+ if (customColor) {
8
+ return customColor;
9
+ }
10
+ const isUsingLegendBackground = (legendOptions === null || legendOptions === void 0 ? void 0 : legendOptions.style) === LEGEND_DISPLAY_STYLE_FILL;
11
+
12
+ // If not using legend background, always return default color
13
+ if (!isUsingLegendBackground) {
14
+ return defaultColor;
15
+ }
16
+ const legendColor = getSingleValueLegendColor(legendOptions, legendSets, value);
17
+
18
+ // Return default color or contrasting color when using legend background and default color
19
+ return shouldUseContrastColor(legendColor) ? colors.white : defaultColor;
20
+ }
@@ -0,0 +1,25 @@
1
+ import { colors } from '@dhis2/ui';
2
+ import { getSingleValueFormattedValue } from './getSingleValueFormattedValue.js';
3
+ import { getSingleValueSubtext } from './getSingleValueSubtext.js';
4
+ import { getSingleValueTextColor } from './getSingleValueTextColor.js';
5
+ export default function getSingleValueCustomSVGOptions(_ref) {
6
+ let {
7
+ layout,
8
+ extraOptions,
9
+ metaData,
10
+ series
11
+ } = _ref;
12
+ const {
13
+ dashboard,
14
+ icon
15
+ } = extraOptions;
16
+ const value = series[0];
17
+ return {
18
+ value,
19
+ fontColor: getSingleValueTextColor(colors.grey900, value, layout.legend, extraOptions.legendSets),
20
+ formattedValue: getSingleValueFormattedValue(value, layout, metaData),
21
+ icon,
22
+ dashboard,
23
+ subText: getSingleValueSubtext(metaData)
24
+ };
25
+ }
@@ -0,0 +1,16 @@
1
+ import loadCustomSVG from './loadCustomSVG/index.js';
2
+ export const getEvents = visType => ({
3
+ events: {
4
+ load: function () {
5
+ // Align legend icon with legend text
6
+ this.legend.allItems.forEach(item => {
7
+ if (item.legendSymbol) {
8
+ item.legendSymbol.attr({
9
+ translateY: -(item.legendItem.label.getBBox().height * 0.75 / 4) + item.legendSymbol.r / 2
10
+ });
11
+ }
12
+ });
13
+ loadCustomSVG.call(this, visType);
14
+ }
15
+ }
16
+ });
@@ -0,0 +1,11 @@
1
+ import { VIS_TYPE_SINGLE_VALUE } from '../../../../../../modules/visTypes.js';
2
+ import loadSingleValueSVG from './singleValue/index.js';
3
+ export default function loadCustomSVG(visType) {
4
+ switch (visType) {
5
+ case VIS_TYPE_SINGLE_VALUE:
6
+ loadSingleValueSVG.call(this);
7
+ break;
8
+ default:
9
+ break;
10
+ }
11
+ }
@@ -0,0 +1,28 @@
1
+ const parser = new DOMParser();
2
+ export function addIconElement(svgString, color) {
3
+ const svgIconDocument = parser.parseFromString(svgString, 'image/svg+xml');
4
+ const iconElHeight = svgIconDocument.documentElement.getAttribute('height');
5
+ const iconElWidth = svgIconDocument.documentElement.getAttribute('width');
6
+ const iconGroup = this.renderer.g('icon').attr({
7
+ color,
8
+ 'data-test': 'visualization-icon'
9
+ }).css({
10
+ visibility: 'hidden'
11
+ });
12
+
13
+ /* Force the group element to have the same dimensions as the original
14
+ * SVG image by adding this rect. This ensures the icon has the intended
15
+ * whitespace around it and makes scaling and translating easier. */
16
+ this.renderer.rect(0, 0, iconElWidth, iconElHeight).add(iconGroup);
17
+ Array.from(svgIconDocument.documentElement.children).forEach(pathNode => {
18
+ /* It is also possible to use the SVGRenderer to draw the icon but that
19
+ * approach is more error prone, so during review it was decided to just
20
+ * append the SVG children to the iconGroup using native the native DOM
21
+ * API. For reference see this commit, for an implementation using the
22
+ * SVVGRenderer:
23
+ * https://github.com/dhis2/analytics/pull/1698/commits/f95bee838e07f4cdfc3cab6e92f28f49a386a0ad */
24
+ iconGroup.element.appendChild(pathNode);
25
+ });
26
+ iconGroup.add();
27
+ return iconGroup;
28
+ }
@@ -0,0 +1,13 @@
1
+ import { ACTUAL_NUMBER_HEIGHT_FACTOR } from './constants.js';
2
+ export function checkIfFitsWithinContainer(availableSpace, valueElement, subTextElement, icon, subText, spacing) {
3
+ const valueRect = valueElement.getBBox(true);
4
+ const subTextRect = subText ? subTextElement.getBBox(true) : {
5
+ width: 0,
6
+ height: 0
7
+ };
8
+ const requiredValueWidth = icon ? valueRect.width + spacing.iconGap + spacing.iconSize : valueRect.width;
9
+ const requiredHeight = subText ? valueRect.height * ACTUAL_NUMBER_HEIGHT_FACTOR + spacing.subTextTop + subTextRect.height : valueRect.height * ACTUAL_NUMBER_HEIGHT_FACTOR;
10
+ const fitsHorizontally = availableSpace.width > requiredValueWidth && availableSpace.width > subTextRect.width;
11
+ const fitsVertically = availableSpace.height > requiredHeight;
12
+ return fitsHorizontally && fitsVertically;
13
+ }
@@ -0,0 +1,33 @@
1
+ import { computeSpacingTop } from './computeSpacingTop.js';
2
+ import { ACTUAL_NUMBER_HEIGHT_FACTOR } from './constants.js';
3
+ export function computeLayoutRect(valueElement, subTextElement, iconElement, spacing) {
4
+ const valueRect = valueElement.getBBox();
5
+ const containerCenterY = this.chartHeight / 2;
6
+ const containerCenterX = this.chartWidth / 2;
7
+ const minY = computeSpacingTop.call(this, spacing.valueTop);
8
+ let width = valueRect.width;
9
+ let height = valueRect.height * ACTUAL_NUMBER_HEIGHT_FACTOR;
10
+ let sideMarginTop = 0;
11
+ let sideMarginBottom = 0;
12
+ if (iconElement) {
13
+ width += spacing.iconGap + spacing.iconSize;
14
+ }
15
+ if (subTextElement) {
16
+ const subTextRect = subTextElement.getBBox();
17
+ if (subTextRect.width > width) {
18
+ sideMarginTop = (subTextRect.width - width) / 2;
19
+ width = subTextRect.width;
20
+ } else {
21
+ sideMarginBottom = (width - subTextRect.width) / 2;
22
+ }
23
+ height += spacing.subTextTop + subTextRect.height;
24
+ }
25
+ return {
26
+ x: containerCenterX - width / 2,
27
+ y: Math.max(containerCenterY - height / 2, minY),
28
+ width,
29
+ height,
30
+ sideMarginTop,
31
+ sideMarginBottom
32
+ };
33
+ }
@@ -0,0 +1,15 @@
1
+ export function computeSpacingTop(valueSpacingTop) {
2
+ if (this.subtitle.textStr) {
3
+ /* If a subtitle is present this will be below the title so base
4
+ * the value X position on this */
5
+ const subTitleRect = this.subtitle.element.getBBox();
6
+ return subTitleRect.y + subTitleRect.height + valueSpacingTop;
7
+ } else if (this.title.textStr) {
8
+ // Otherwise base on title
9
+ const titleRect = this.title.element.getBBox();
10
+ return titleRect.y + titleRect.height + valueSpacingTop;
11
+ } else {
12
+ // If neither are present only adjust for valueSpacingTop
13
+ return valueSpacingTop;
14
+ }
15
+ }
@@ -0,0 +1,4 @@
1
+ // multiply value text size with this factor
2
+ // to get very close to the actual number height
3
+ // as numbers don't go below the baseline like e.g. "j" and "g"
4
+ export const ACTUAL_NUMBER_HEIGHT_FACTOR = 2 / 3;
@@ -0,0 +1,8 @@
1
+ import { computeSpacingTop } from './computeSpacingTop.js';
2
+ import { MIN_SIDE_WHITESPACE } from './styles.js';
3
+ export function getAvailableSpace(valueSpacingTop) {
4
+ return {
5
+ height: this.chartHeight - computeSpacingTop.call(this, valueSpacingTop),
6
+ width: this.chartWidth - MIN_SIDE_WHITESPACE * 2
7
+ };
8
+ }
@@ -0,0 +1,42 @@
1
+ import { addIconElement } from './addIconElement.js';
2
+ import { checkIfFitsWithinContainer } from './checkIfFitsWithinContainer.js';
3
+ import { getAvailableSpace } from './getAvailableSpace.js';
4
+ import { positionElements } from './positionElements.js';
5
+ import { DynamicStyles } from './styles.js';
6
+ export default function loadSingleValueSVG() {
7
+ var _this$userOptions;
8
+ const {
9
+ formattedValue,
10
+ icon,
11
+ subText,
12
+ fontColor
13
+ } = this.userOptions.customSVGOptions;
14
+ const dynamicStyles = new DynamicStyles((_this$userOptions = this.userOptions) === null || _this$userOptions === void 0 ? void 0 : _this$userOptions.isPdfExport);
15
+ const valueElement = this.renderer.text(formattedValue).attr('data-test', 'visualization-primary-value').css({
16
+ color: fontColor,
17
+ visibility: 'hidden'
18
+ }).add();
19
+ const subTextElement = subText ? this.renderer.text(subText).attr('data-test', 'visualization-subtext').css({
20
+ color: fontColor,
21
+ visibility: 'hidden'
22
+ }).add() : null;
23
+ const iconElement = icon ? addIconElement.call(this, icon, fontColor) : null;
24
+ let fitsWithinContainer = false;
25
+ let styles = {};
26
+ while (!fitsWithinContainer && dynamicStyles.hasNext()) {
27
+ styles = dynamicStyles.next();
28
+ valueElement.css(styles.value);
29
+ subTextElement === null || subTextElement === void 0 ? void 0 : subTextElement.css(styles.subText);
30
+ fitsWithinContainer = checkIfFitsWithinContainer(getAvailableSpace.call(this, styles.spacing.valueTop), valueElement, subTextElement, icon, subText, styles.spacing);
31
+ }
32
+ positionElements.call(this, valueElement, subTextElement, iconElement, styles.spacing);
33
+ valueElement.css({
34
+ visibility: 'visible'
35
+ });
36
+ iconElement === null || iconElement === void 0 ? void 0 : iconElement.css({
37
+ visibility: 'visible'
38
+ });
39
+ subTextElement === null || subTextElement === void 0 ? void 0 : subTextElement.css({
40
+ visibility: 'visible'
41
+ });
42
+ }
@@ -0,0 +1,40 @@
1
+ import { computeLayoutRect } from './computeLayoutRect.js';
2
+ import { ACTUAL_NUMBER_HEIGHT_FACTOR } from './constants.js';
3
+ export function positionElements(valueElement, subTextElement, iconElement, spacing) {
4
+ const valueElementBox = valueElement.getBBox();
5
+ /* Layout here refers to a virtual rect that wraps
6
+ * all indiviual parts of the single value visualization
7
+ * (value, subtext and icon) */
8
+ const layoutRect = computeLayoutRect.call(this, valueElement, subTextElement, iconElement, spacing);
9
+ valueElement.align({
10
+ align: 'right',
11
+ verticalAlign: 'top',
12
+ alignByTranslate: false,
13
+ x: (valueElementBox.width + layoutRect.sideMarginTop) * -1,
14
+ y: valueElementBox.height * ACTUAL_NUMBER_HEIGHT_FACTOR
15
+ }, false, layoutRect);
16
+ if (iconElement) {
17
+ const {
18
+ height
19
+ } = iconElement.getBBox();
20
+ const scale = spacing.iconSize / height;
21
+ const translateX = layoutRect.x + layoutRect.sideMarginTop;
22
+ const iconHeight = height * scale;
23
+ const valueElementHeight = valueElementBox.height * ACTUAL_NUMBER_HEIGHT_FACTOR;
24
+ const translateY = layoutRect.y + (valueElementHeight - iconHeight) / 2;
25
+
26
+ /* The icon is a <g> with <path> elements that contain coordinates.
27
+ * These path-coordinates only scale correctly when using CSS translate */
28
+ iconElement.css({
29
+ transform: `translate(${translateX}px, ${translateY}px) scale(${scale})`
30
+ });
31
+ }
32
+ if (subTextElement) {
33
+ subTextElement.align({
34
+ align: 'left',
35
+ verticalAlign: 'bottom',
36
+ alignByTranslate: false,
37
+ x: layoutRect.sideMarginBottom
38
+ }, false, layoutRect);
39
+ }
40
+ }
@@ -0,0 +1,101 @@
1
+ const valueStyles = [{
2
+ 'font-size': '164px',
3
+ 'letter-spacing': '-5px'
4
+ }, {
5
+ 'font-size': '128px',
6
+ 'letter-spacing': '-4px'
7
+ }, {
8
+ 'font-size': '96px',
9
+ 'letter-spacing': '-3px'
10
+ }, {
11
+ 'font-size': '64px',
12
+ 'letter-spacing': '-2.5px'
13
+ }, {
14
+ 'font-size': '40px',
15
+ 'letter-spacing': '-1.5px'
16
+ }, {
17
+ 'font-size': '20px',
18
+ 'letter-spacing': '-1px'
19
+ }];
20
+ const subTextStyles = [{
21
+ 'font-size': '36px',
22
+ 'letter-spacing': '-1.4px'
23
+ }, {
24
+ 'font-size': '32px',
25
+ 'letter-spacing': '-1.2px'
26
+ }, {
27
+ 'font-size': '26px',
28
+ 'letter-spacing': '-0.8px'
29
+ }, {
30
+ 'font-size': '20px',
31
+ 'letter-spacing': '-0.6px'
32
+ }, {
33
+ 'font-size': '14px',
34
+ 'letter-spacing': '0.2px'
35
+ }, {
36
+ 'font-size': '9px',
37
+ 'letter-spacing': '0px'
38
+ }];
39
+ const spacings = [{
40
+ valueTop: 8,
41
+ subTextTop: 12,
42
+ iconGap: 8,
43
+ iconSize: 164
44
+ }, {
45
+ valueTop: 8,
46
+ subTextTop: 12,
47
+ iconGap: 6,
48
+ iconSize: 128
49
+ }, {
50
+ valueTop: 8,
51
+ subTextTop: 8,
52
+ iconGap: 4,
53
+ iconSize: 96
54
+ }, {
55
+ valueTop: 8,
56
+ subTextTop: 8,
57
+ iconGap: 4,
58
+ iconSize: 64
59
+ }, {
60
+ valueTop: 8,
61
+ subTextTop: 8,
62
+ iconGap: 4,
63
+ iconSize: 40
64
+ }, {
65
+ valueTop: 8,
66
+ subTextTop: 4,
67
+ iconGap: 2,
68
+ iconSize: 20
69
+ }];
70
+ export const MIN_SIDE_WHITESPACE = 4;
71
+ export class DynamicStyles {
72
+ constructor(isPdfExport) {
73
+ this.currentIndex = 0;
74
+ this.isPdfExport = isPdfExport;
75
+ }
76
+ getStyle() {
77
+ return {
78
+ value: {
79
+ ...valueStyles[this.currentIndex],
80
+ 'font-weight': this.isPdfExport ? 'normal' : '300'
81
+ },
82
+ subText: subTextStyles[this.currentIndex],
83
+ spacing: spacings[this.currentIndex]
84
+ };
85
+ }
86
+ next() {
87
+ if (this.currentIndex === valueStyles.length - 1) {
88
+ throw new Error('No next available, already on the smallest style');
89
+ } else {
90
+ ++this.currentIndex;
91
+ }
92
+ return this.getStyle();
93
+ }
94
+ first() {
95
+ this.currentIndex = 0;
96
+ return this.getStyle();
97
+ }
98
+ hasNext() {
99
+ return this.currentIndex < valueStyles.length - 1;
100
+ }
101
+ }
@@ -0,0 +1,23 @@
1
+ import { VIS_TYPE_SINGLE_VALUE } from '../../../../modules/visTypes.js';
2
+ import loadSingleValueSVG from './events/loadCustomSVG/singleValue/index.js';
3
+ export default function getExporting(visType) {
4
+ const exporting = {
5
+ // disable exporting context menu
6
+ enabled: false
7
+ };
8
+ switch (visType) {
9
+ case VIS_TYPE_SINGLE_VALUE:
10
+ return {
11
+ ...exporting,
12
+ chartOptions: {
13
+ chart: {
14
+ events: {
15
+ load: loadSingleValueSVG
16
+ }
17
+ }
18
+ }
19
+ };
20
+ default:
21
+ return exporting;
22
+ }
23
+ }