@dhis2/analytics 28.0.0 → 28.0.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.
Files changed (29) hide show
  1. package/build/cjs/__demo__/ScatterPlotPdfExport.stories.js +46 -0
  2. package/build/cjs/__demo__/SingleValue.stories.js +34 -2
  3. package/build/cjs/__fixtures__/scatterPlotData.js +863 -0
  4. package/build/cjs/locales/ar/translations.json +3 -1
  5. package/build/cjs/visualizations/config/adapters/dhis_highcharts/customSVGOptions/singleValue/getSingleValueBackgroundColor.js +2 -1
  6. package/build/cjs/visualizations/config/adapters/dhis_highcharts/events/loadCustomSVG/singleValue/addIconElement.js +2 -2
  7. package/build/cjs/visualizations/config/adapters/dhis_highcharts/events/loadCustomSVG/singleValue/index.js +13 -16
  8. package/build/cjs/visualizations/config/adapters/dhis_highcharts/events/loadCustomSVG/singleValue/positionElements.js +2 -5
  9. package/build/cjs/visualizations/config/adapters/dhis_highcharts/events/loadCustomSVG/singleValue/styles.js +13 -2
  10. package/build/cjs/visualizations/config/adapters/dhis_highcharts/exporting.js +33 -17
  11. package/build/cjs/visualizations/config/adapters/dhis_highcharts/index.js +1 -1
  12. package/build/cjs/visualizations/config/adapters/dhis_highcharts/title/index.js +2 -1
  13. package/build/cjs/visualizations/config/generators/highcharts/index.js +30 -16
  14. package/build/cjs/visualizations/util/colors/colorSets.js +1 -2
  15. package/build/es/__demo__/ScatterPlotPdfExport.stories.js +37 -0
  16. package/build/es/__demo__/SingleValue.stories.js +35 -3
  17. package/build/es/__fixtures__/scatterPlotData.js +857 -0
  18. package/build/es/locales/ar/translations.json +3 -1
  19. package/build/es/visualizations/config/adapters/dhis_highcharts/customSVGOptions/singleValue/getSingleValueBackgroundColor.js +2 -1
  20. package/build/es/visualizations/config/adapters/dhis_highcharts/events/loadCustomSVG/singleValue/addIconElement.js +2 -2
  21. package/build/es/visualizations/config/adapters/dhis_highcharts/events/loadCustomSVG/singleValue/index.js +13 -16
  22. package/build/es/visualizations/config/adapters/dhis_highcharts/events/loadCustomSVG/singleValue/positionElements.js +2 -5
  23. package/build/es/visualizations/config/adapters/dhis_highcharts/events/loadCustomSVG/singleValue/styles.js +13 -2
  24. package/build/es/visualizations/config/adapters/dhis_highcharts/exporting.js +33 -17
  25. package/build/es/visualizations/config/adapters/dhis_highcharts/index.js +1 -1
  26. package/build/es/visualizations/config/adapters/dhis_highcharts/title/index.js +2 -1
  27. package/build/es/visualizations/config/generators/highcharts/index.js +30 -16
  28. package/build/es/visualizations/util/colors/colorSets.js +1 -2
  29. package/package.json +4 -3
@@ -26,7 +26,7 @@
26
26
  "About this event chart": "",
27
27
  "About this event report": "",
28
28
  "This app could not retrieve required data.": "",
29
- "Network error": "",
29
+ "Network error": "خطأ في الشبكة",
30
30
  "Data / Edit calculation": "",
31
31
  "Data / New calculation": "",
32
32
  "Remove item": "",
@@ -166,6 +166,7 @@
166
166
  "line list": "",
167
167
  "map": "خريطة",
168
168
  "visualization": "",
169
+ "Untitled {{visualizationType}}, {{date}}": "",
169
170
  "Edit": "تعديل",
170
171
  "Write a reply": "كتابة رد",
171
172
  "Post reply": "",
@@ -471,6 +472,7 @@
471
472
  "Single value": "قيمة مفردة",
472
473
  "Outlier table": "",
473
474
  "All charts": "",
475
+ "Map": "الخريطة",
474
476
  "{{seriesName}} (trend)": "",
475
477
  "Trend": "الاتجاه",
476
478
  "No legend for this series": "لا معلومات مفاتيح إيضاحية لهذه السلسلة",
@@ -1,6 +1,7 @@
1
1
  import { LEGEND_DISPLAY_STYLE_FILL } from '../../../../../../modules/legends.js';
2
2
  import { getSingleValueLegendColor } from './getSingleValueLegendColor.js';
3
3
  export function getSingleValueBackgroundColor(legendOptions, legendSets, value) {
4
+ let defaultColor = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'transparent';
4
5
  const legendColor = getSingleValueLegendColor(legendOptions, legendSets, value);
5
- return legendColor && legendOptions.style === LEGEND_DISPLAY_STYLE_FILL ? legendColor : 'transparent';
6
+ return legendColor && legendOptions.style === LEGEND_DISPLAY_STYLE_FILL ? legendColor : defaultColor;
6
7
  }
@@ -5,8 +5,8 @@ export function addIconElement(svgString, color) {
5
5
  const iconElWidth = svgIconDocument.documentElement.getAttribute('width');
6
6
  const iconGroup = this.renderer.g('icon').attr({
7
7
  color,
8
- 'data-test': 'visualization-icon'
9
- }).css({
8
+ fill: color,
9
+ 'data-test': 'visualization-icon',
10
10
  visibility: 'hidden'
11
11
  });
12
12
 
@@ -4,19 +4,22 @@ import { getAvailableSpace } from './getAvailableSpace.js';
4
4
  import { positionElements } from './positionElements.js';
5
5
  import { DynamicStyles } from './styles.js';
6
6
  export default function loadSingleValueSVG() {
7
+ var _this$userOptions;
7
8
  const {
8
9
  formattedValue,
9
10
  icon,
10
11
  subText,
11
12
  fontColor
12
13
  } = this.userOptions.customSVGOptions;
13
- const dynamicStyles = new DynamicStyles();
14
- const valueElement = this.renderer.text(formattedValue).attr('data-test', 'visualization-primary-value').css({
15
- color: fontColor,
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({
16
+ 'data-test': 'visualization-primary-value',
17
+ fill: fontColor,
16
18
  visibility: 'hidden'
17
19
  }).add();
18
- const subTextElement = subText ? this.renderer.text(subText).attr('data-test', 'visualization-subtext').css({
19
- color: fontColor,
20
+ const subTextElement = subText ? this.renderer.text(subText).attr({
21
+ 'data-test': 'visualization-subtext',
22
+ fill: fontColor,
20
23
  visibility: 'hidden'
21
24
  }).add() : null;
22
25
  const iconElement = icon ? addIconElement.call(this, icon, fontColor) : null;
@@ -24,18 +27,12 @@ export default function loadSingleValueSVG() {
24
27
  let styles = {};
25
28
  while (!fitsWithinContainer && dynamicStyles.hasNext()) {
26
29
  styles = dynamicStyles.next();
27
- valueElement.css(styles.value);
28
- subTextElement === null || subTextElement === void 0 ? void 0 : subTextElement.css(styles.subText);
30
+ valueElement.attr(styles.value);
31
+ subTextElement === null || subTextElement === void 0 ? void 0 : subTextElement.attr(styles.subText);
29
32
  fitsWithinContainer = checkIfFitsWithinContainer(getAvailableSpace.call(this, styles.spacing.valueTop), valueElement, subTextElement, icon, subText, styles.spacing);
30
33
  }
31
34
  positionElements.call(this, valueElement, subTextElement, iconElement, styles.spacing);
32
- valueElement.css({
33
- visibility: 'visible'
34
- });
35
- iconElement === null || iconElement === void 0 ? void 0 : iconElement.css({
36
- visibility: 'visible'
37
- });
38
- subTextElement === null || subTextElement === void 0 ? void 0 : subTextElement.css({
39
- visibility: 'visible'
40
- });
35
+ valueElement.attr('visibility', 'visible');
36
+ iconElement === null || iconElement === void 0 ? void 0 : iconElement.attr('visibility', 'visible');
37
+ subTextElement === null || subTextElement === void 0 ? void 0 : subTextElement.attr('visibility', 'visible');
41
38
  }
@@ -22,11 +22,8 @@ export function positionElements(valueElement, subTextElement, iconElement, spac
22
22
  const iconHeight = height * scale;
23
23
  const valueElementHeight = valueElementBox.height * ACTUAL_NUMBER_HEIGHT_FACTOR;
24
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})`
25
+ iconElement.attr({
26
+ transform: `translate(${translateX} ${translateY}) scale(${scale})`
30
27
  });
31
28
  }
32
29
  if (subTextElement) {
@@ -69,11 +69,12 @@ const spacings = [{
69
69
  }];
70
70
  export const MIN_SIDE_WHITESPACE = 4;
71
71
  export class DynamicStyles {
72
- constructor() {
72
+ constructor(isPdfExport) {
73
73
  this.currentIndex = 0;
74
+ this.isPdfExport = isPdfExport;
74
75
  }
75
76
  getStyle() {
76
- return {
77
+ const style = {
77
78
  value: {
78
79
  ...valueStyles[this.currentIndex],
79
80
  'font-weight': '300'
@@ -81,6 +82,16 @@ export class DynamicStyles {
81
82
  subText: subTextStyles[this.currentIndex],
82
83
  spacing: spacings[this.currentIndex]
83
84
  };
85
+ if (this.isPdfExport) {
86
+ /* font-weight is not supported for offline PDF export and providing
87
+ * a specific value will cause the PDF to show a serif font instead */
88
+ style.value['font-weight'] = 'normal';
89
+ /* letter-spacing is also not supported and providing a specific
90
+ * value will cause misalignment issues in the PDF */
91
+ style.value['letter-spacing'] = 'normal';
92
+ style.subText['letter-spacing'] = 'normal';
93
+ }
94
+ return style;
84
95
  }
85
96
  next() {
86
97
  if (this.currentIndex === valueStyles.length - 1) {
@@ -1,23 +1,39 @@
1
1
  import { VIS_TYPE_SINGLE_VALUE } from '../../../../modules/visTypes.js';
2
+ import { getSingleValueBackgroundColor } from './customSVGOptions/singleValue/getSingleValueBackgroundColor.js';
2
3
  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
- }
4
+ const DEFAULT_EXPORT_BACKGROUND_COLOR = '#ffffff';
5
+ const BASE_EXPORTING_CONFIG = {
6
+ // disable exporting context menu
7
+ enabled: false,
8
+ // use offline exporting only
9
+ fallbackToExportServer: false,
10
+ allowHTML: true,
11
+ showExportInProgress: true,
12
+ applyStyleSheets: true,
13
+ sourceHeight: 768,
14
+ sourceWidth: 1024,
15
+ scale: 1,
16
+ chartOptions: {
17
+ chart: {
18
+ backgroundColor: DEFAULT_EXPORT_BACKGROUND_COLOR
19
+ }
20
+ }
21
+ };
22
+ export default function getExporting(layout, legendSets, series) {
23
+ if (layout.type === VIS_TYPE_SINGLE_VALUE) {
24
+ return {
25
+ ...BASE_EXPORTING_CONFIG,
26
+ chartOptions: {
27
+ ...BASE_EXPORTING_CONFIG.chartOptions,
28
+ chart: {
29
+ ...BASE_EXPORTING_CONFIG.chartOptions.chart,
30
+ backgroundColor: getSingleValueBackgroundColor(layout.legend, legendSets, series[0], DEFAULT_EXPORT_BACKGROUND_COLOR),
31
+ events: {
32
+ load: loadSingleValueSVG
17
33
  }
18
34
  }
19
- };
20
- default:
21
- return exporting;
35
+ }
36
+ };
22
37
  }
38
+ return BASE_EXPORTING_CONFIG;
23
39
  }
@@ -97,7 +97,7 @@ export default function (_ref) {
97
97
  enabled: false
98
98
  },
99
99
  // exporting
100
- exporting: getExporting(_layout.type),
100
+ exporting: getExporting(_layout, _extraOptions.legendSets, series),
101
101
  /* The config object passed to the Highcharts Chart constructor
102
102
  * can contain arbitrary properties, which are made accessible
103
103
  * under the Chart instance's `userOptions` member. This means
@@ -37,7 +37,8 @@ export default function (layout, metaData, extraOptions, series) {
37
37
  const legendOptions = layout.legend;
38
38
  const fontStyle = mergeFontStyleWithDefault(layout.fontStyle && layout.fontStyle[FONT_STYLE_VISUALIZATION_TITLE], FONT_STYLE_VISUALIZATION_TITLE);
39
39
  const title = Object.assign({
40
- text: undefined
40
+ text: undefined,
41
+ minScale: 1
41
42
  }, dashboard ? DASHBOARD_TITLE_STYLE : {
42
43
  margin: 30,
43
44
  align: getTextAlignOption(fontStyle[FONT_STYLE_OPTION_TEXT_ALIGN], FONT_STYLE_VISUALIZATION_TITLE, isVerticalType(layout.type)),
@@ -1,22 +1,36 @@
1
1
  import H from 'highcharts';
2
- import HM from 'highcharts/highcharts-more';
3
- import HB from 'highcharts/modules/boost';
4
- import HE from 'highcharts/modules/exporting';
5
- import HNDTD from 'highcharts/modules/no-data-to-display';
6
- import HPF from 'highcharts/modules/pattern-fill';
7
- import HSG from 'highcharts/modules/solid-gauge';
2
+ import 'highcharts/highcharts-more';
3
+ import 'highcharts/modules/boost';
4
+ import 'highcharts/modules/exporting';
5
+ import 'highcharts/modules/no-data-to-display';
6
+ import 'highcharts/modules/offline-exporting';
7
+ import 'highcharts/modules/pattern-fill';
8
+ import 'highcharts/modules/solid-gauge';
8
9
 
9
- // apply
10
- HM(H);
11
- HSG(H);
12
- HNDTD(H);
13
- HE(H);
14
- HPF(H);
15
- HB(H);
10
+ /* Whitelist some additional SVG attributes and tags here. Without this,
11
+ * the PDF export for the SingleValue visualization and charts in boost-mode
12
+ * breaks. For more info about the boost mode issue, see:
13
+ * https://github.com/highcharts/highcharts/issues/8333 */
14
+ H.AST.allowedTags.push('fedropshadow', 'image');
15
+ H.AST.allowedAttributes.push('transform-origin', 'preserveAspectRatio', 'fill-rule', 'clip-rule');
16
16
 
17
- /* Whitelist some additional SVG attributes here. Without this,
18
- * the PDF export for the SingleValue visualization breaks. */
19
- H.AST.allowedAttributes.push('fill-rule', 'clip-rule');
17
+ /* This is a workaround for https://github.com/highcharts/highcharts/issues/22008
18
+ * We add some transparent text in a non-ASCII script to the chart to prevent
19
+ * the chart from being exported in a serif font */
20
+ H.addEvent(H.Chart, 'load', function () {
21
+ this.renderer.text('모', 20, 20).attr({
22
+ opacity: 0
23
+ }).add();
24
+ });
25
+
26
+ /* Workaround for https://github.com/highcharts/highcharts/issues/23049
27
+ * (there happen to be 10 colors and 10 patterns)*/
28
+ const {
29
+ colors
30
+ } = H.getOptions();
31
+ H.patterns.forEach((pattern, i) => {
32
+ pattern.color = colors[i];
33
+ });
20
34
  function drawLegendSymbolWrap() {
21
35
  const pick = H.pick;
22
36
  H.wrap(H.seriesTypes.column.prototype, 'drawLegendSymbol', function (proceed, legend, item) {
@@ -1,6 +1,5 @@
1
1
  import H from 'highcharts';
2
- import HPF from 'highcharts/modules/pattern-fill';
3
- HPF(H);
2
+ import 'highcharts/modules/pattern-fill';
4
3
  export const COLOR_SET_DEFAULT = 'DEFAULT';
5
4
  export const COLOR_SET_BASIC = 'BASIC';
6
5
  export const COLOR_SET_EXTENDED = 'EXTENDED';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhis2/analytics",
3
- "version": "28.0.0",
3
+ "version": "28.0.1",
4
4
  "main": "./build/cjs/index.js",
5
5
  "module": "./build/es/index.js",
6
6
  "exports": {
@@ -68,7 +68,7 @@
68
68
  "crypto-js": "^4.2.0",
69
69
  "d2-utilizr": "^0.2.16",
70
70
  "d3-color": "^1.2.3",
71
- "highcharts": "^10.3.3",
71
+ "highcharts": "^12.1.2",
72
72
  "lodash": "^4.17.21",
73
73
  "markdown-it": "^13.0.1",
74
74
  "mathjs": "^9.4.2",
@@ -81,5 +81,6 @@
81
81
  },
82
82
  "files": [
83
83
  "build"
84
- ]
84
+ ],
85
+ "packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
85
86
  }