@dhis2/analytics 28.0.0 → 28.0.2

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 (35) 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/index.js +29 -0
  5. package/build/cjs/locales/ar/translations.json +3 -1
  6. package/build/cjs/modules/hideEmptyRowItems.js +10 -0
  7. package/build/cjs/visualizations/config/adapters/dhis_highcharts/customSVGOptions/singleValue/getSingleValueBackgroundColor.js +2 -1
  8. package/build/cjs/visualizations/config/adapters/dhis_highcharts/events/loadCustomSVG/singleValue/addIconElement.js +2 -2
  9. package/build/cjs/visualizations/config/adapters/dhis_highcharts/events/loadCustomSVG/singleValue/index.js +13 -16
  10. package/build/cjs/visualizations/config/adapters/dhis_highcharts/events/loadCustomSVG/singleValue/positionElements.js +2 -5
  11. package/build/cjs/visualizations/config/adapters/dhis_highcharts/events/loadCustomSVG/singleValue/styles.js +13 -2
  12. package/build/cjs/visualizations/config/adapters/dhis_highcharts/exporting.js +33 -17
  13. package/build/cjs/visualizations/config/adapters/dhis_highcharts/getTrimmedConfig.js +5 -4
  14. package/build/cjs/visualizations/config/adapters/dhis_highcharts/index.js +3 -2
  15. package/build/cjs/visualizations/config/adapters/dhis_highcharts/title/index.js +2 -1
  16. package/build/cjs/visualizations/config/generators/highcharts/index.js +30 -16
  17. package/build/cjs/visualizations/util/colors/colorSets.js +1 -2
  18. package/build/es/__demo__/ScatterPlotPdfExport.stories.js +37 -0
  19. package/build/es/__demo__/SingleValue.stories.js +35 -3
  20. package/build/es/__fixtures__/scatterPlotData.js +857 -0
  21. package/build/es/index.js +4 -0
  22. package/build/es/locales/ar/translations.json +3 -1
  23. package/build/es/modules/hideEmptyRowItems.js +4 -0
  24. package/build/es/visualizations/config/adapters/dhis_highcharts/customSVGOptions/singleValue/getSingleValueBackgroundColor.js +2 -1
  25. package/build/es/visualizations/config/adapters/dhis_highcharts/events/loadCustomSVG/singleValue/addIconElement.js +2 -2
  26. package/build/es/visualizations/config/adapters/dhis_highcharts/events/loadCustomSVG/singleValue/index.js +13 -16
  27. package/build/es/visualizations/config/adapters/dhis_highcharts/events/loadCustomSVG/singleValue/positionElements.js +2 -5
  28. package/build/es/visualizations/config/adapters/dhis_highcharts/events/loadCustomSVG/singleValue/styles.js +13 -2
  29. package/build/es/visualizations/config/adapters/dhis_highcharts/exporting.js +33 -17
  30. package/build/es/visualizations/config/adapters/dhis_highcharts/getTrimmedConfig.js +5 -4
  31. package/build/es/visualizations/config/adapters/dhis_highcharts/index.js +3 -2
  32. package/build/es/visualizations/config/adapters/dhis_highcharts/title/index.js +2 -1
  33. package/build/es/visualizations/config/generators/highcharts/index.js +30 -16
  34. package/build/es/visualizations/util/colors/colorSets.js +1 -2
  35. package/package.json +4 -3
@@ -215,6 +215,10 @@ var _exportNames = {
215
215
  LEGEND_DISPLAY_STYLE_FILL: true,
216
216
  LEGEND_DISPLAY_STYLE_TEXT: true,
217
217
  getColorByValueFromLegendSet: true,
218
+ HIDE_EMPTY_ROW_ITEMS_BEFORE_FIRST: true,
219
+ HIDE_EMPTY_ROW_ITEMS_AFTER_LAST: true,
220
+ HIDE_EMPTY_ROW_ITEMS_BEFORE_FIRST_AFTER_LAST: true,
221
+ HIDE_EMPTY_ROW_ITEMS_ALL: true,
218
222
  formatValue: true,
219
223
  COLOR_SET_DEFAULT: true,
220
224
  COLOR_SET_BASIC: true,
@@ -713,6 +717,30 @@ Object.defineProperty(exports, "FixedPeriodSelect", {
713
717
  return _FixedPeriodSelect.default;
714
718
  }
715
719
  });
720
+ Object.defineProperty(exports, "HIDE_EMPTY_ROW_ITEMS_AFTER_LAST", {
721
+ enumerable: true,
722
+ get: function () {
723
+ return _hideEmptyRowItems.HIDE_EMPTY_ROW_ITEMS_AFTER_LAST;
724
+ }
725
+ });
726
+ Object.defineProperty(exports, "HIDE_EMPTY_ROW_ITEMS_ALL", {
727
+ enumerable: true,
728
+ get: function () {
729
+ return _hideEmptyRowItems.HIDE_EMPTY_ROW_ITEMS_ALL;
730
+ }
731
+ });
732
+ Object.defineProperty(exports, "HIDE_EMPTY_ROW_ITEMS_BEFORE_FIRST", {
733
+ enumerable: true,
734
+ get: function () {
735
+ return _hideEmptyRowItems.HIDE_EMPTY_ROW_ITEMS_BEFORE_FIRST;
736
+ }
737
+ });
738
+ Object.defineProperty(exports, "HIDE_EMPTY_ROW_ITEMS_BEFORE_FIRST_AFTER_LAST", {
739
+ enumerable: true,
740
+ get: function () {
741
+ return _hideEmptyRowItems.HIDE_EMPTY_ROW_ITEMS_BEFORE_FIRST_AFTER_LAST;
742
+ }
743
+ });
716
744
  Object.defineProperty(exports, "ITEM", {
717
745
  enumerable: true,
718
746
  get: function () {
@@ -1951,6 +1979,7 @@ var _index10 = require("./modules/layoutUiRules/index.js");
1951
1979
  var _index11 = require("./visualizations/index.js");
1952
1980
  var _fontStyle = require("./modules/fontStyle.js");
1953
1981
  var _legends = require("./modules/legends.js");
1982
+ var _hideEmptyRowItems = require("./modules/hideEmptyRowItems.js");
1954
1983
  var _renderValue = require("./modules/renderValue.js");
1955
1984
  var _colorSets = require("./visualizations/util/colors/colorSets.js");
1956
1985
  var _index12 = require("./components/PeriodDimension/utils/index.js");
@@ -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": "لا معلومات مفاتيح إيضاحية لهذه السلسلة",
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.HIDE_EMPTY_ROW_ITEMS_BEFORE_FIRST_AFTER_LAST = exports.HIDE_EMPTY_ROW_ITEMS_BEFORE_FIRST = exports.HIDE_EMPTY_ROW_ITEMS_ALL = exports.HIDE_EMPTY_ROW_ITEMS_AFTER_LAST = void 0;
7
+ const HIDE_EMPTY_ROW_ITEMS_BEFORE_FIRST = exports.HIDE_EMPTY_ROW_ITEMS_BEFORE_FIRST = 'BEFORE_FIRST';
8
+ const HIDE_EMPTY_ROW_ITEMS_AFTER_LAST = exports.HIDE_EMPTY_ROW_ITEMS_AFTER_LAST = 'AFTER_LAST';
9
+ const HIDE_EMPTY_ROW_ITEMS_BEFORE_FIRST_AFTER_LAST = exports.HIDE_EMPTY_ROW_ITEMS_BEFORE_FIRST_AFTER_LAST = 'BEFORE_FIRST_AFTER_LAST';
10
+ const HIDE_EMPTY_ROW_ITEMS_ALL = exports.HIDE_EMPTY_ROW_ITEMS_ALL = 'ALL';
@@ -7,6 +7,7 @@ exports.getSingleValueBackgroundColor = getSingleValueBackgroundColor;
7
7
  var _legends = require("../../../../../../modules/legends.js");
8
8
  var _getSingleValueLegendColor = require("./getSingleValueLegendColor.js");
9
9
  function getSingleValueBackgroundColor(legendOptions, legendSets, value) {
10
+ let defaultColor = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'transparent';
10
11
  const legendColor = (0, _getSingleValueLegendColor.getSingleValueLegendColor)(legendOptions, legendSets, value);
11
- return legendColor && legendOptions.style === _legends.LEGEND_DISPLAY_STYLE_FILL ? legendColor : 'transparent';
12
+ return legendColor && legendOptions.style === _legends.LEGEND_DISPLAY_STYLE_FILL ? legendColor : defaultColor;
12
13
  }
@@ -11,8 +11,8 @@ function addIconElement(svgString, color) {
11
11
  const iconElWidth = svgIconDocument.documentElement.getAttribute('width');
12
12
  const iconGroup = this.renderer.g('icon').attr({
13
13
  color,
14
- 'data-test': 'visualization-icon'
15
- }).css({
14
+ fill: color,
15
+ 'data-test': 'visualization-icon',
16
16
  visibility: 'hidden'
17
17
  });
18
18
 
@@ -10,19 +10,22 @@ var _getAvailableSpace = require("./getAvailableSpace.js");
10
10
  var _positionElements = require("./positionElements.js");
11
11
  var _styles = require("./styles.js");
12
12
  function loadSingleValueSVG() {
13
+ var _this$userOptions;
13
14
  const {
14
15
  formattedValue,
15
16
  icon,
16
17
  subText,
17
18
  fontColor
18
19
  } = this.userOptions.customSVGOptions;
19
- const dynamicStyles = new _styles.DynamicStyles();
20
- const valueElement = this.renderer.text(formattedValue).attr('data-test', 'visualization-primary-value').css({
21
- color: fontColor,
20
+ const dynamicStyles = new _styles.DynamicStyles((_this$userOptions = this.userOptions) === null || _this$userOptions === void 0 ? void 0 : _this$userOptions.isPdfExport);
21
+ const valueElement = this.renderer.text(formattedValue).attr({
22
+ 'data-test': 'visualization-primary-value',
23
+ fill: fontColor,
22
24
  visibility: 'hidden'
23
25
  }).add();
24
- const subTextElement = subText ? this.renderer.text(subText).attr('data-test', 'visualization-subtext').css({
25
- color: fontColor,
26
+ const subTextElement = subText ? this.renderer.text(subText).attr({
27
+ 'data-test': 'visualization-subtext',
28
+ fill: fontColor,
26
29
  visibility: 'hidden'
27
30
  }).add() : null;
28
31
  const iconElement = icon ? _addIconElement.addIconElement.call(this, icon, fontColor) : null;
@@ -30,18 +33,12 @@ function loadSingleValueSVG() {
30
33
  let styles = {};
31
34
  while (!fitsWithinContainer && dynamicStyles.hasNext()) {
32
35
  styles = dynamicStyles.next();
33
- valueElement.css(styles.value);
34
- subTextElement === null || subTextElement === void 0 ? void 0 : subTextElement.css(styles.subText);
36
+ valueElement.attr(styles.value);
37
+ subTextElement === null || subTextElement === void 0 ? void 0 : subTextElement.attr(styles.subText);
35
38
  fitsWithinContainer = (0, _checkIfFitsWithinContainer.checkIfFitsWithinContainer)(_getAvailableSpace.getAvailableSpace.call(this, styles.spacing.valueTop), valueElement, subTextElement, icon, subText, styles.spacing);
36
39
  }
37
40
  _positionElements.positionElements.call(this, valueElement, subTextElement, iconElement, styles.spacing);
38
- valueElement.css({
39
- visibility: 'visible'
40
- });
41
- iconElement === null || iconElement === void 0 ? void 0 : iconElement.css({
42
- visibility: 'visible'
43
- });
44
- subTextElement === null || subTextElement === void 0 ? void 0 : subTextElement.css({
45
- visibility: 'visible'
46
- });
41
+ valueElement.attr('visibility', 'visible');
42
+ iconElement === null || iconElement === void 0 ? void 0 : iconElement.attr('visibility', 'visible');
43
+ subTextElement === null || subTextElement === void 0 ? void 0 : subTextElement.attr('visibility', 'visible');
47
44
  }
@@ -28,11 +28,8 @@ function positionElements(valueElement, subTextElement, iconElement, spacing) {
28
28
  const iconHeight = height * scale;
29
29
  const valueElementHeight = valueElementBox.height * _constants.ACTUAL_NUMBER_HEIGHT_FACTOR;
30
30
  const translateY = layoutRect.y + (valueElementHeight - iconHeight) / 2;
31
-
32
- /* The icon is a <g> with <path> elements that contain coordinates.
33
- * These path-coordinates only scale correctly when using CSS translate */
34
- iconElement.css({
35
- transform: `translate(${translateX}px, ${translateY}px) scale(${scale})`
31
+ iconElement.attr({
32
+ transform: `translate(${translateX} ${translateY}) scale(${scale})`
36
33
  });
37
34
  }
38
35
  if (subTextElement) {
@@ -75,11 +75,12 @@ const spacings = [{
75
75
  }];
76
76
  const MIN_SIDE_WHITESPACE = exports.MIN_SIDE_WHITESPACE = 4;
77
77
  class DynamicStyles {
78
- constructor() {
78
+ constructor(isPdfExport) {
79
79
  this.currentIndex = 0;
80
+ this.isPdfExport = isPdfExport;
80
81
  }
81
82
  getStyle() {
82
- return {
83
+ const style = {
83
84
  value: {
84
85
  ...valueStyles[this.currentIndex],
85
86
  'font-weight': '300'
@@ -87,6 +88,16 @@ class DynamicStyles {
87
88
  subText: subTextStyles[this.currentIndex],
88
89
  spacing: spacings[this.currentIndex]
89
90
  };
91
+ if (this.isPdfExport) {
92
+ /* font-weight is not supported for offline PDF export and providing
93
+ * a specific value will cause the PDF to show a serif font instead */
94
+ style.value['font-weight'] = 'normal';
95
+ /* letter-spacing is also not supported and providing a specific
96
+ * value will cause misalignment issues in the PDF */
97
+ style.value['letter-spacing'] = 'normal';
98
+ style.subText['letter-spacing'] = 'normal';
99
+ }
100
+ return style;
90
101
  }
91
102
  next() {
92
103
  if (this.currentIndex === valueStyles.length - 1) {
@@ -5,26 +5,42 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = getExporting;
7
7
  var _visTypes = require("../../../../modules/visTypes.js");
8
+ var _getSingleValueBackgroundColor = require("./customSVGOptions/singleValue/getSingleValueBackgroundColor.js");
8
9
  var _index = _interopRequireDefault(require("./events/loadCustomSVG/singleValue/index.js"));
9
10
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
10
- function getExporting(visType) {
11
- const exporting = {
12
- // disable exporting context menu
13
- enabled: false
14
- };
15
- switch (visType) {
16
- case _visTypes.VIS_TYPE_SINGLE_VALUE:
17
- return {
18
- ...exporting,
19
- chartOptions: {
20
- chart: {
21
- events: {
22
- load: _index.default
23
- }
11
+ const DEFAULT_EXPORT_BACKGROUND_COLOR = '#ffffff';
12
+ const BASE_EXPORTING_CONFIG = {
13
+ // disable exporting context menu
14
+ enabled: false,
15
+ // use offline exporting only
16
+ fallbackToExportServer: false,
17
+ allowHTML: true,
18
+ showExportInProgress: true,
19
+ applyStyleSheets: true,
20
+ sourceHeight: 768,
21
+ sourceWidth: 1024,
22
+ scale: 1,
23
+ chartOptions: {
24
+ chart: {
25
+ backgroundColor: DEFAULT_EXPORT_BACKGROUND_COLOR
26
+ }
27
+ }
28
+ };
29
+ function getExporting(layout, legendSets, series) {
30
+ if (layout.type === _visTypes.VIS_TYPE_SINGLE_VALUE) {
31
+ return {
32
+ ...BASE_EXPORTING_CONFIG,
33
+ chartOptions: {
34
+ ...BASE_EXPORTING_CONFIG.chartOptions,
35
+ chart: {
36
+ ...BASE_EXPORTING_CONFIG.chartOptions.chart,
37
+ backgroundColor: (0, _getSingleValueBackgroundColor.getSingleValueBackgroundColor)(layout.legend, legendSets, series[0], DEFAULT_EXPORT_BACKGROUND_COLOR),
38
+ events: {
39
+ load: _index.default
24
40
  }
25
41
  }
26
- };
27
- default:
28
- return exporting;
42
+ }
43
+ };
29
44
  }
45
+ return BASE_EXPORTING_CONFIG;
30
46
  }
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = _default;
7
7
  var _arrayContains = _interopRequireDefault(require("d2-utilizr/lib/arrayContains"));
8
8
  var _arrayUnique = _interopRequireDefault(require("d2-utilizr/lib/arrayUnique"));
9
+ var _hideEmptyRowItems = require("../../../../modules/hideEmptyRowItems.js");
9
10
  var _visTypes = require("../../../../modules/visTypes.js");
10
11
  var _getTwoCategorySplitSerieData = _interopRequireDefault(require("./getTwoCategorySplitSerieData.js"));
11
12
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
@@ -60,16 +61,16 @@ function getFirstLastValueIndexes(series) {
60
61
  function cleanData(data, emptySeriesIndexes, firstValueIndex, lastValueIndex, hideEmptyRowItems) {
61
62
  let cleanedData;
62
63
  switch (hideEmptyRowItems) {
63
- case 'ALL':
64
+ case _hideEmptyRowItems.HIDE_EMPTY_ROW_ITEMS_ALL:
64
65
  cleanedData = arrayCleanUndefined(data.map((value, index) => (0, _arrayContains.default)(emptySeriesIndexes, index) ? undefined : value));
65
66
  break;
66
- case 'BEFORE_FIRST':
67
+ case _hideEmptyRowItems.HIDE_EMPTY_ROW_ITEMS_BEFORE_FIRST:
67
68
  cleanedData = data.slice(firstValueIndex);
68
69
  break;
69
- case 'AFTER_LAST':
70
+ case _hideEmptyRowItems.HIDE_EMPTY_ROW_ITEMS_AFTER_LAST:
70
71
  cleanedData = data.slice(0, lastValueIndex + 1);
71
72
  break;
72
- case 'BEFORE_FIRST_AFTER_LAST':
73
+ case _hideEmptyRowItems.HIDE_EMPTY_ROW_ITEMS_BEFORE_FIRST_AFTER_LAST:
73
74
  cleanedData = data.slice(firstValueIndex, lastValueIndex + 1);
74
75
  break;
75
76
  default:
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = _default;
7
7
  var _isString = _interopRequireDefault(require("d2-utilizr/lib/isString"));
8
8
  var _objectClean = _interopRequireDefault(require("d2-utilizr/lib/objectClean"));
9
+ var _hideEmptyRowItems = require("../../../../modules/hideEmptyRowItems.js");
9
10
  var _legends = require("../../../../modules/legends.js");
10
11
  var _index = require("../../../../modules/outliers/index.js");
11
12
  var _visTypes = require("../../../../modules/visTypes.js");
@@ -106,7 +107,7 @@ function _default(_ref) {
106
107
  enabled: false
107
108
  },
108
109
  // exporting
109
- exporting: (0, _exporting.default)(_layout.type),
110
+ exporting: (0, _exporting.default)(_layout, _extraOptions.legendSets, series),
110
111
  /* The config object passed to the Highcharts Chart constructor
111
112
  * can contain arbitrary properties, which are made accessible
112
113
  * under the Chart instance's `userOptions` member. This means
@@ -144,7 +145,7 @@ function _default(_ref) {
144
145
  }
145
146
 
146
147
  // hide empty categories
147
- if (_layout.hideEmptyRowItems !== 'NONE') {
148
+ if (_layout.hideEmptyRowItems && [_hideEmptyRowItems.HIDE_EMPTY_ROW_ITEMS_BEFORE_FIRST, _hideEmptyRowItems.HIDE_EMPTY_ROW_ITEMS_AFTER_LAST, _hideEmptyRowItems.HIDE_EMPTY_ROW_ITEMS_BEFORE_FIRST_AFTER_LAST, _hideEmptyRowItems.HIDE_EMPTY_ROW_ITEMS_ALL].includes(_layout.hideEmptyRowItems)) {
148
149
  config = (0, _getTrimmedConfig.default)(config, _layout);
149
150
  }
150
151
 
@@ -44,7 +44,8 @@ function _default(layout, metaData, extraOptions, series) {
44
44
  const legendOptions = layout.legend;
45
45
  const fontStyle = (0, _fontStyle.mergeFontStyleWithDefault)(layout.fontStyle && layout.fontStyle[_fontStyle.FONT_STYLE_VISUALIZATION_TITLE], _fontStyle.FONT_STYLE_VISUALIZATION_TITLE);
46
46
  const title = Object.assign({
47
- text: undefined
47
+ text: undefined,
48
+ minScale: 1
48
49
  }, dashboard ? DASHBOARD_TITLE_STYLE : {
49
50
  margin: 30,
50
51
  align: (0, _getTextAlignOption.getTextAlignOption)(fontStyle[_fontStyle.FONT_STYLE_OPTION_TEXT_ALIGN], _fontStyle.FONT_STYLE_VISUALIZATION_TITLE, (0, _visTypes.isVerticalType)(layout.type)),
@@ -5,24 +5,38 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = _default;
7
7
  var _highcharts = _interopRequireDefault(require("highcharts"));
8
- var _highchartsMore = _interopRequireDefault(require("highcharts/highcharts-more"));
9
- var _boost = _interopRequireDefault(require("highcharts/modules/boost"));
10
- var _exporting = _interopRequireDefault(require("highcharts/modules/exporting"));
11
- var _noDataToDisplay = _interopRequireDefault(require("highcharts/modules/no-data-to-display"));
12
- var _patternFill = _interopRequireDefault(require("highcharts/modules/pattern-fill"));
13
- var _solidGauge = _interopRequireDefault(require("highcharts/modules/solid-gauge"));
8
+ require("highcharts/highcharts-more");
9
+ require("highcharts/modules/boost");
10
+ require("highcharts/modules/exporting");
11
+ require("highcharts/modules/no-data-to-display");
12
+ require("highcharts/modules/offline-exporting");
13
+ require("highcharts/modules/pattern-fill");
14
+ require("highcharts/modules/solid-gauge");
14
15
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
15
- // apply
16
- (0, _highchartsMore.default)(_highcharts.default);
17
- (0, _solidGauge.default)(_highcharts.default);
18
- (0, _noDataToDisplay.default)(_highcharts.default);
19
- (0, _exporting.default)(_highcharts.default);
20
- (0, _patternFill.default)(_highcharts.default);
21
- (0, _boost.default)(_highcharts.default);
16
+ /* Whitelist some additional SVG attributes and tags here. Without this,
17
+ * the PDF export for the SingleValue visualization and charts in boost-mode
18
+ * breaks. For more info about the boost mode issue, see:
19
+ * https://github.com/highcharts/highcharts/issues/8333 */
20
+ _highcharts.default.AST.allowedTags.push('fedropshadow', 'image');
21
+ _highcharts.default.AST.allowedAttributes.push('transform-origin', 'preserveAspectRatio', 'fill-rule', 'clip-rule');
22
22
 
23
- /* Whitelist some additional SVG attributes here. Without this,
24
- * the PDF export for the SingleValue visualization breaks. */
25
- _highcharts.default.AST.allowedAttributes.push('fill-rule', 'clip-rule');
23
+ /* This is a workaround for https://github.com/highcharts/highcharts/issues/22008
24
+ * We add some transparent text in a non-ASCII script to the chart to prevent
25
+ * the chart from being exported in a serif font */
26
+ _highcharts.default.addEvent(_highcharts.default.Chart, 'load', function () {
27
+ this.renderer.text('모', 20, 20).attr({
28
+ opacity: 0
29
+ }).add();
30
+ });
31
+
32
+ /* Workaround for https://github.com/highcharts/highcharts/issues/23049
33
+ * (there happen to be 10 colors and 10 patterns)*/
34
+ const {
35
+ colors
36
+ } = _highcharts.default.getOptions();
37
+ _highcharts.default.patterns.forEach((pattern, i) => {
38
+ pattern.color = colors[i];
39
+ });
26
40
  function drawLegendSymbolWrap() {
27
41
  const pick = _highcharts.default.pick;
28
42
  _highcharts.default.wrap(_highcharts.default.seriesTypes.column.prototype, 'drawLegendSymbol', function (proceed, legend, item) {
@@ -5,9 +5,8 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.colorSets = exports.COLOR_SET_PATTERNS = exports.COLOR_SET_GRAY = exports.COLOR_SET_EXTENDED = exports.COLOR_SET_DEFAULT = exports.COLOR_SET_DARK = exports.COLOR_SET_COLOR_BLIND = exports.COLOR_SET_BRIGHT = exports.COLOR_SET_BASIC = void 0;
7
7
  var _highcharts = _interopRequireDefault(require("highcharts"));
8
- var _patternFill = _interopRequireDefault(require("highcharts/modules/pattern-fill"));
8
+ require("highcharts/modules/pattern-fill");
9
9
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
10
- (0, _patternFill.default)(_highcharts.default);
11
10
  const COLOR_SET_DEFAULT = exports.COLOR_SET_DEFAULT = 'DEFAULT';
12
11
  const COLOR_SET_BASIC = exports.COLOR_SET_BASIC = 'BASIC';
13
12
  const COLOR_SET_EXTENDED = exports.COLOR_SET_EXTENDED = 'EXTENDED';
@@ -0,0 +1,37 @@
1
+ import React, { useCallback, useEffect, useRef, useState } from 'react';
2
+ import { extraOptions, responses, visualization } from '../__fixtures__/scatterPlotData.js';
3
+ import { createVisualization } from '../index.js';
4
+ export default {
5
+ title: 'ScatterPlot'
6
+ };
7
+ export const Default = () => {
8
+ const ref = useRef(null);
9
+ const [chart, setChart] = useState(null);
10
+ const exportToPdf = useCallback(() => {
11
+ chart.update({
12
+ exporting: {
13
+ chartOptions: {
14
+ isPdfExport: true
15
+ }
16
+ }
17
+ });
18
+ chart.exportChartLocal({
19
+ filename: 'PDF export',
20
+ type: 'application/pdf'
21
+ });
22
+ }, [chart]);
23
+ useEffect(() => {
24
+ const obj = createVisualization(responses, visualization, ref.current, extraOptions, undefined, undefined, 'highcharts');
25
+ setChart(obj.visualization);
26
+ }, []);
27
+ return /*#__PURE__*/React.createElement(React.Fragment, null, chart && /*#__PURE__*/React.createElement("button", {
28
+ onClick: exportToPdf
29
+ }, "Export PDF"), /*#__PURE__*/React.createElement("div", {
30
+ style: {
31
+ width: 800,
32
+ height: 800,
33
+ border: '2px solid magenta'
34
+ },
35
+ ref: ref
36
+ }));
37
+ };
@@ -1,4 +1,4 @@
1
- import React, { useState, useMemo, useRef, useEffect } from 'react';
1
+ import React, { useState, useMemo, useRef, useEffect, useCallback } from 'react';
2
2
  import { createVisualization } from '../index.js';
3
3
  const constainerStyleBase = {
4
4
  width: 800,
@@ -585,6 +585,7 @@ export const Default = () => {
585
585
  const [dashboard, setDashboard] = useState(false);
586
586
  const [showIcon, setShowIcon] = useState(true);
587
587
  const [indicatorType, setIndicatorType] = useState('plain');
588
+ const [exportAsPdf, setExportAsPdf] = useState(true);
588
589
  const [width, setWidth] = useState(constainerStyleBase.width);
589
590
  const [height, setHeight] = useState(constainerStyleBase.height);
590
591
  const containerStyle = useMemo(() => ({
@@ -592,6 +593,31 @@ export const Default = () => {
592
593
  width,
593
594
  height
594
595
  }), [width, height]);
596
+ const downloadOffline = useCallback(() => {
597
+ if (newChartRef.current) {
598
+ const currentBackgroundColor = newChartRef.current.userOptions.chart.backgroundColor;
599
+ newChartRef.current.update({
600
+ exporting: {
601
+ chartOptions: {
602
+ isPdfExport: exportAsPdf
603
+ }
604
+ }
605
+ });
606
+ newChartRef.current.exportChartLocal({
607
+ sourceHeight: 768,
608
+ sourceWidth: 1024,
609
+ scale: 1,
610
+ fallbackToExportServer: false,
611
+ filename: 'testOfflineDownload',
612
+ showExportInProgress: true,
613
+ type: exportAsPdf ? 'application/pdf' : 'image/png'
614
+ }, {
615
+ chart: {
616
+ backgroundColor: currentBackgroundColor === 'transparent' ? '#ffffff' : currentBackgroundColor
617
+ }
618
+ });
619
+ }
620
+ }, [exportAsPdf]);
595
621
  useEffect(() => {
596
622
  if (newContainerRef.current) {
597
623
  requestAnimationFrame(() => {
@@ -652,13 +678,19 @@ export const Default = () => {
652
678
  checked: showIcon,
653
679
  onChange: () => setShowIcon(!showIcon),
654
680
  type: "checkbox"
655
- }), "\xA0Show icon"), /*#__PURE__*/React.createElement("label", null, "Indicator type\xA0", /*#__PURE__*/React.createElement("select", {
681
+ }), "\xA0Show icon"), /*#__PURE__*/React.createElement("label", null, "Indicator type", ' ', /*#__PURE__*/React.createElement("select", {
656
682
  onChange: event => setIndicatorType(event.target.value)
657
683
  }, indicatorTypes.map((type, index) => {
658
684
  return /*#__PURE__*/React.createElement("option", {
659
685
  key: index
660
686
  }, type);
661
- })))), /*#__PURE__*/React.createElement("div", {
687
+ }))), /*#__PURE__*/React.createElement("label", null, /*#__PURE__*/React.createElement("input", {
688
+ checked: exportAsPdf,
689
+ onChange: () => setExportAsPdf(!exportAsPdf),
690
+ type: "checkbox"
691
+ }), ' ', "Export as PDF"), /*#__PURE__*/React.createElement("button", {
692
+ onClick: downloadOffline
693
+ }, "Download offline")), /*#__PURE__*/React.createElement("div", {
662
694
  style: {
663
695
  display: 'flex',
664
696
  gap: 12