@gravity-ui/chartkit 0.9.1 → 0.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.
Files changed (189) hide show
  1. package/CHANGELOG.md +19 -1
  2. package/build/components/ChartKit.css +23 -0
  3. package/build/components/ChartKit.d.ts +0 -1
  4. package/build/components/ChartKit.js +4 -5
  5. package/build/i18n/keysets/en.json +60 -0
  6. package/build/i18n/keysets/ru.json +62 -0
  7. package/build/libs/chartkit-error/chartkit-error.d.ts +1 -0
  8. package/build/libs/chartkit-error/chartkit-error.js +1 -0
  9. package/build/libs/settings/__tests__/settings.test.js +1 -1
  10. package/build/libs/settings/settings.d.ts +6 -3
  11. package/build/libs/settings/settings.js +4 -2
  12. package/build/plugins/highcharts/__stories__/AreaRange.stories.d.ts +4 -0
  13. package/build/plugins/highcharts/__stories__/AreaRange.stories.js +22 -0
  14. package/build/plugins/highcharts/__stories__/Line.stories.d.ts +4 -0
  15. package/build/plugins/highcharts/__stories__/Line.stories.js +21 -0
  16. package/build/plugins/highcharts/__stories__/mocks/area-range.d.ts +2 -0
  17. package/build/plugins/highcharts/__stories__/mocks/area-range.js +61 -0
  18. package/build/plugins/highcharts/__stories__/mocks/holidays.d.ts +7070 -0
  19. package/build/plugins/highcharts/__stories__/mocks/holidays.js +7065 -0
  20. package/build/plugins/highcharts/__stories__/mocks/line.d.ts +2 -0
  21. package/build/plugins/highcharts/__stories__/mocks/line.js +129 -0
  22. package/build/plugins/highcharts/index.d.ts +2 -0
  23. package/build/plugins/highcharts/index.js +5 -0
  24. package/build/plugins/highcharts/renderer/HighchartsWidget.d.ts +23 -0
  25. package/build/plugins/highcharts/renderer/HighchartsWidget.js +6 -0
  26. package/build/plugins/highcharts/renderer/components/HighchartsComponent.css +4 -0
  27. package/build/plugins/highcharts/renderer/components/HighchartsComponent.d.ts +575 -0
  28. package/build/plugins/highcharts/renderer/components/HighchartsComponent.js +115 -0
  29. package/build/plugins/highcharts/renderer/components/StyledSplitPane/StyledSplitPane.css +50 -0
  30. package/build/plugins/highcharts/renderer/components/StyledSplitPane/StyledSplitPane.d.ts +10 -0
  31. package/build/plugins/highcharts/renderer/components/StyledSplitPane/StyledSplitPane.js +32 -0
  32. package/build/plugins/highcharts/renderer/components/withSplitPane/WithSplitPane.css +4 -0
  33. package/build/plugins/highcharts/renderer/components/withSplitPane/withSplitPane.d.ts +10 -0
  34. package/build/plugins/highcharts/renderer/components/withSplitPane/withSplitPane.js +207 -0
  35. package/build/plugins/highcharts/renderer/helpers/add-holidays.d.ts +1 -0
  36. package/build/plugins/highcharts/renderer/helpers/add-holidays.js +43 -0
  37. package/build/plugins/highcharts/renderer/helpers/comments/drawing.d.ts +11 -0
  38. package/build/plugins/highcharts/renderer/helpers/comments/drawing.js +571 -0
  39. package/build/plugins/highcharts/renderer/helpers/config/config.d.ts +575 -0
  40. package/build/plugins/highcharts/renderer/helpers/config/config.js +1483 -0
  41. package/build/plugins/highcharts/renderer/helpers/config/handleLegendItemClick.d.ts +1 -0
  42. package/build/plugins/highcharts/renderer/helpers/config/handleLegendItemClick.js +57 -0
  43. package/build/plugins/highcharts/renderer/helpers/config/options.d.ts +465 -0
  44. package/build/plugins/highcharts/renderer/helpers/config/options.js +350 -0
  45. package/build/plugins/highcharts/renderer/helpers/config/types.d.ts +6 -0
  46. package/build/plugins/highcharts/renderer/helpers/config/types.js +1 -0
  47. package/build/plugins/highcharts/renderer/helpers/config/utils/addShowInNavigatorToSeries.d.ts +10 -0
  48. package/build/plugins/highcharts/renderer/helpers/config/utils/addShowInNavigatorToSeries.js +42 -0
  49. package/build/plugins/highcharts/renderer/helpers/config/utils/addShowInNavigatorToSeries.test.d.ts +1 -0
  50. package/build/plugins/highcharts/renderer/helpers/config/utils/addShowInNavigatorToSeries.test.js +99 -0
  51. package/build/plugins/highcharts/renderer/helpers/config/utils/buildNavigatorFallback.d.ts +1 -0
  52. package/build/plugins/highcharts/renderer/helpers/config/utils/buildNavigatorFallback.js +17 -0
  53. package/build/plugins/highcharts/renderer/helpers/config/utils/buildNavigatorFallback.test.d.ts +1 -0
  54. package/build/plugins/highcharts/renderer/helpers/config/utils/buildNavigatorFallback.test.js +28 -0
  55. package/build/plugins/highcharts/renderer/helpers/config/utils/calculatePrecision.d.ts +5 -0
  56. package/build/plugins/highcharts/renderer/helpers/config/utils/calculatePrecision.js +20 -0
  57. package/build/plugins/highcharts/renderer/helpers/config/utils/calculatePrecision.test.d.ts +1 -0
  58. package/build/plugins/highcharts/renderer/helpers/config/utils/calculatePrecision.test.js +27 -0
  59. package/build/plugins/highcharts/renderer/helpers/config/utils/concatStrings.d.ts +1 -0
  60. package/build/plugins/highcharts/renderer/helpers/config/utils/concatStrings.js +1 -0
  61. package/build/plugins/highcharts/renderer/helpers/config/utils/getChartKitFormattedValue.d.ts +2 -0
  62. package/build/plugins/highcharts/renderer/helpers/config/utils/getChartKitFormattedValue.js +15 -0
  63. package/build/plugins/highcharts/renderer/helpers/config/utils/getFormatOptionsFromLine.d.ts +3 -0
  64. package/build/plugins/highcharts/renderer/helpers/config/utils/getFormatOptionsFromLine.js +15 -0
  65. package/build/plugins/highcharts/renderer/helpers/config/utils/getFormatOptionsFromLine.test.d.ts +1 -0
  66. package/build/plugins/highcharts/renderer/helpers/config/utils/getFormatOptionsFromLine.test.js +11 -0
  67. package/build/plugins/highcharts/renderer/helpers/config/utils/getXAxisThresholdValue.d.ts +1 -0
  68. package/build/plugins/highcharts/renderer/helpers/config/utils/getXAxisThresholdValue.js +9 -0
  69. package/build/plugins/highcharts/renderer/helpers/config/utils/getXAxisThresholdValue.test.d.ts +1 -0
  70. package/build/plugins/highcharts/renderer/helpers/config/utils/getXAxisThresholdValue.test.js +20 -0
  71. package/build/plugins/highcharts/renderer/helpers/config/utils/index.d.ts +13 -0
  72. package/build/plugins/highcharts/renderer/helpers/config/utils/index.js +13 -0
  73. package/build/plugins/highcharts/renderer/helpers/config/utils/isNavigatorSeries.d.ts +2 -0
  74. package/build/plugins/highcharts/renderer/helpers/config/utils/isNavigatorSeries.js +3 -0
  75. package/build/plugins/highcharts/renderer/helpers/config/utils/isSafari.d.ts +1 -0
  76. package/build/plugins/highcharts/renderer/helpers/config/utils/isSafari.js +12 -0
  77. package/build/plugins/highcharts/renderer/helpers/config/utils/isTooltipShared.d.ts +1 -0
  78. package/build/plugins/highcharts/renderer/helpers/config/utils/isTooltipShared.js +8 -0
  79. package/build/plugins/highcharts/renderer/helpers/config/utils/isTooltipShared.test.d.ts +1 -0
  80. package/build/plugins/highcharts/renderer/helpers/config/utils/isTooltipShared.test.js +31 -0
  81. package/build/plugins/highcharts/renderer/helpers/config/utils/localStorage.d.ts +5 -0
  82. package/build/plugins/highcharts/renderer/helpers/config/utils/localStorage.js +23 -0
  83. package/build/plugins/highcharts/renderer/helpers/config/utils/mergeArrayWithObject.d.ts +1 -0
  84. package/build/plugins/highcharts/renderer/helpers/config/utils/mergeArrayWithObject.js +10 -0
  85. package/build/plugins/highcharts/renderer/helpers/config/utils/numberFormat.d.ts +2 -0
  86. package/build/plugins/highcharts/renderer/helpers/config/utils/numberFormat.js +19 -0
  87. package/build/plugins/highcharts/renderer/helpers/config/utils/numberFormat.test.d.ts +1 -0
  88. package/build/plugins/highcharts/renderer/helpers/config/utils/numberFormat.test.js +20 -0
  89. package/build/plugins/highcharts/renderer/helpers/config/utils/setNavigatorDefaultPeriod.d.ts +13 -0
  90. package/build/plugins/highcharts/renderer/helpers/config/utils/setNavigatorDefaultPeriod.js +27 -0
  91. package/build/plugins/highcharts/renderer/helpers/config/utils/setNavigatorDefaultPeriod.test.d.ts +1 -0
  92. package/build/plugins/highcharts/renderer/helpers/config/utils/setNavigatorDefaultPeriod.test.js +45 -0
  93. package/build/plugins/highcharts/renderer/helpers/constants.d.ts +28 -0
  94. package/build/plugins/highcharts/renderer/helpers/constants.js +30 -0
  95. package/build/plugins/highcharts/renderer/helpers/graph.css +89 -0
  96. package/build/plugins/highcharts/renderer/helpers/graph.d.ts +552 -0
  97. package/build/plugins/highcharts/renderer/helpers/graph.js +85 -0
  98. package/build/plugins/highcharts/renderer/helpers/highcharts/colors.d.ts +2 -0
  99. package/build/plugins/highcharts/renderer/helpers/highcharts/colors.js +17 -0
  100. package/build/plugins/highcharts/renderer/helpers/highcharts/highcharts.d.ts +4 -0
  101. package/build/plugins/highcharts/renderer/helpers/highcharts/highcharts.js +346 -0
  102. package/build/plugins/highcharts/renderer/helpers/highcharts/utils/calcucalteClosestPointManually.d.ts +1 -0
  103. package/build/plugins/highcharts/renderer/helpers/highcharts/utils/calcucalteClosestPointManually.js +19 -0
  104. package/build/plugins/highcharts/renderer/helpers/highcharts/utils/calculateClosestPointManually.test.d.ts +1 -0
  105. package/build/plugins/highcharts/renderer/helpers/highcharts/utils/calculateClosestPointManually.test.js +42 -0
  106. package/build/plugins/highcharts/renderer/helpers/highcharts/utils/index.d.ts +1 -0
  107. package/build/plugins/highcharts/renderer/helpers/highcharts/utils/index.js +1 -0
  108. package/build/plugins/highcharts/renderer/helpers/init-highcharts-modules.d.ts +1 -0
  109. package/build/plugins/highcharts/renderer/helpers/init-highcharts-modules.js +49 -0
  110. package/build/plugins/highcharts/renderer/helpers/prepare-data.d.ts +1 -0
  111. package/build/plugins/highcharts/renderer/helpers/prepare-data.js +175 -0
  112. package/build/plugins/highcharts/renderer/helpers/tooltip/constants.d.ts +13 -0
  113. package/build/plugins/highcharts/renderer/helpers/tooltip/constants.js +14 -0
  114. package/build/plugins/highcharts/renderer/helpers/tooltip/helpers.d.ts +1 -0
  115. package/build/plugins/highcharts/renderer/helpers/tooltip/helpers.js +5 -0
  116. package/build/plugins/highcharts/renderer/helpers/tooltip/index.d.ts +13 -0
  117. package/build/plugins/highcharts/renderer/helpers/tooltip/index.js +253 -0
  118. package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/index.d.ts +6 -0
  119. package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/index.js +22 -0
  120. package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/template-icons/DashDotLineIcon.d.ts +2 -0
  121. package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/template-icons/DashDotLineIcon.js +20 -0
  122. package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/template-icons/DashLineIcon.d.ts +2 -0
  123. package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/template-icons/DashLineIcon.js +25 -0
  124. package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/template-icons/DotLineIcon.d.ts +2 -0
  125. package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/template-icons/DotLineIcon.js +20 -0
  126. package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/template-icons/LongDashDotDotLineIcon.d.ts +2 -0
  127. package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/template-icons/LongDashDotDotLineIcon.js +18 -0
  128. package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/template-icons/LongDashDotLineIcon.d.ts +2 -0
  129. package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/template-icons/LongDashDotLineIcon.js +18 -0
  130. package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/template-icons/LongDashLineIcon.d.ts +2 -0
  131. package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/template-icons/LongDashLineIcon.js +15 -0
  132. package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/template-icons/ShortDashDotDotLineIcon.d.ts +2 -0
  133. package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/template-icons/ShortDashDotDotLineIcon.js +18 -0
  134. package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/template-icons/ShortDashDotLineIcon.d.ts +2 -0
  135. package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/template-icons/ShortDashDotLineIcon.js +18 -0
  136. package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/template-icons/ShortDashLineIcon.d.ts +2 -0
  137. package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/template-icons/ShortDashLineIcon.js +18 -0
  138. package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/template-icons/ShortDotLineIcon.d.ts +2 -0
  139. package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/template-icons/ShortDotLineIcon.js +20 -0
  140. package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/template-icons/SolidLineIcon.d.ts +2 -0
  141. package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/template-icons/SolidLineIcon.js +13 -0
  142. package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/template-icons/index.d.ts +11 -0
  143. package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/template-icons/index.js +11 -0
  144. package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/types.d.ts +4 -0
  145. package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/types.js +1 -0
  146. package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/utils.d.ts +7 -0
  147. package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/utils.js +5 -0
  148. package/build/plugins/highcharts/renderer/helpers/tooltip/tooltip.css +367 -0
  149. package/build/plugins/highcharts/renderer/helpers/tooltip/types.d.ts +85 -0
  150. package/build/plugins/highcharts/renderer/helpers/tooltip/types.js +1 -0
  151. package/build/plugins/highcharts/renderer/helpers/types.d.ts +22 -0
  152. package/build/plugins/highcharts/renderer/helpers/types.js +1 -0
  153. package/build/plugins/highcharts/types/comments.d.ts +51 -0
  154. package/build/plugins/highcharts/types/comments.js +1 -0
  155. package/build/plugins/highcharts/types/highcharts-extends.d.ts +38 -0
  156. package/build/plugins/highcharts/types/index.d.ts +4 -0
  157. package/build/plugins/highcharts/types/index.js +1 -0
  158. package/build/plugins/highcharts/types/lib.d.ts +1 -0
  159. package/build/plugins/highcharts/types/lib.js +1 -0
  160. package/build/plugins/highcharts/types/misc.d.ts +19 -0
  161. package/build/plugins/highcharts/types/misc.js +1 -0
  162. package/build/plugins/highcharts/types/widget.d.ts +47 -0
  163. package/build/plugins/highcharts/types/widget.js +1 -0
  164. package/build/plugins/index.d.ts +4 -2
  165. package/build/plugins/index.js +1 -0
  166. package/build/plugins/indicator/renderer/IndicatorItem.d.ts +3 -2
  167. package/build/plugins/indicator/renderer/IndicatorWidget.d.ts +10 -2
  168. package/build/plugins/indicator/renderer/IndicatorWidget.js +1 -1
  169. package/build/plugins/indicator/types.d.ts +0 -6
  170. package/build/plugins/shared/format-number/format-number.d.ts +4 -0
  171. package/build/plugins/shared/format-number/format-number.js +88 -0
  172. package/build/plugins/shared/format-number/format-number.test.d.ts +1 -0
  173. package/build/plugins/shared/format-number/format-number.test.js +14 -0
  174. package/build/plugins/shared/format-number/i18n/en.json +17 -0
  175. package/build/plugins/shared/format-number/i18n/i18n.d.ts +5 -0
  176. package/build/plugins/shared/format-number/i18n/i18n.js +8 -0
  177. package/build/plugins/shared/format-number/i18n/ru.json +17 -0
  178. package/build/plugins/shared/format-number/types.d.ts +14 -0
  179. package/build/plugins/shared/format-number/types.js +1 -0
  180. package/build/plugins/shared/index.d.ts +2 -0
  181. package/build/plugins/shared/index.js +1 -0
  182. package/build/plugins/yagr/renderer/YagrWidget.d.ts +11 -3
  183. package/build/plugins/yagr/renderer/YagrWidget.js +2 -1
  184. package/build/plugins/yagr/types.d.ts +0 -7
  185. package/build/types/index.d.ts +1 -2
  186. package/build/types/misc.d.ts +4 -0
  187. package/build/types/misc.js +1 -0
  188. package/build/types/widget.d.ts +17 -0
  189. package/package.json +4 -1
@@ -0,0 +1,1483 @@
1
+ /* eslint new-cap: 0, complexity: 0 */
2
+ import Highcharts from 'highcharts';
3
+ import block from 'bem-cn-lite';
4
+ import merge from 'lodash/merge';
5
+ import mergeWith from 'lodash/mergeWith';
6
+ import get from 'lodash/get';
7
+ import clamp from 'lodash/clamp';
8
+ import isNumber from 'lodash/isNumber';
9
+ import throttle from 'lodash/throttle';
10
+ import pick from 'lodash/pick';
11
+ import debounce from 'lodash/debounce';
12
+ import moment from 'moment';
13
+ import { i18n } from '../../../../../i18n';
14
+ import { formatNumber } from '../../../../shared';
15
+ import { getCommentsOnLine, drawComments, hideComments, drawOnlyRendererComments, } from '../comments/drawing';
16
+ import formatTooltip, { TOOLTIP_ROW_CLASS_NAME, SERIES_NAME_DATA_ATTRIBUTE, TOOLTIP_HEADER_CLASS_NAME, TOOLTIP_LIST_CLASS_NAME, TOOLTIP_FOOTER_CLASS_NAME, TOOLTIP_CONTAINER_CLASS_NAME, TOOLTIP_ROW_NAME_CLASS_NANE, } from '../tooltip';
17
+ import defaultOptions from './options';
18
+ import { calculatePrecision, isTooltipShared, isSafari, mergeArrayWithObject, concatStrings, buildNavigatorFallback, addShowInNavigatorToSeries, setNavigatorDefaultPeriod, numberFormat, getFormatOptionsFromLine, } from './utils';
19
+ import { handleLegendItemClick } from './handleLegendItemClick';
20
+ import { getChartKitFormattedValue } from './utils/getChartKitFormattedValue';
21
+ const b = block('chartkit-tooltip');
22
+ const TOOLTIP_OFFSET_FROM_CURSOR = 15;
23
+ const TOOLTIP_ROOT_CLASS_NAME = 'chartkit-highcharts-tooltip-container';
24
+ const MOBILE_TOOLTIP_OFFSET_FROM_POINTER = 30;
25
+ const CUSTOM_TYPES = {
26
+ stack: {
27
+ type: 'area',
28
+ stacking: 'normal',
29
+ },
30
+ stacked_100p: {
31
+ type: 'area',
32
+ stacking: 'percent',
33
+ },
34
+ stacked_column: {
35
+ type: 'column',
36
+ stacking: 'normal',
37
+ },
38
+ stacked_column_100p: {
39
+ type: 'column',
40
+ stacking: 'percent',
41
+ },
42
+ };
43
+ function formatNumberWrapper(line) {
44
+ return formatNumber(line.originalValue, {
45
+ precision: line.chartKitPrecision,
46
+ prefix: line.chartKitPrefix,
47
+ postfix: line.chartKitPostfix,
48
+ format: line.chartKitFormat,
49
+ showRankDelimiter: line.chartKitShowRankDelimiter,
50
+ unit: line.chartKitUnit,
51
+ });
52
+ }
53
+ function getFormattedValueWithSuffixAndPrefix(item) {
54
+ const prefix = item.valuePrefix || '';
55
+ const suffix = item.valueSuffix || '';
56
+ // eslint-disable-next-line no-nested-ternary
57
+ const formattedNumber = item.chartKitFormatting
58
+ ? formatNumberWrapper(item)
59
+ : item.valueDecimals && typeof item.value === 'number'
60
+ ? item.value.toFixed(item.valueDecimals)
61
+ : item.value;
62
+ return `${prefix}${formattedNumber}${suffix}`;
63
+ }
64
+ function isZoomResetButtonClick(event, chartContainer) {
65
+ let iterationIndex = 0;
66
+ let element = event.path[iterationIndex];
67
+ while (element) {
68
+ if (element === chartContainer) {
69
+ return false;
70
+ }
71
+ else if (element.classList.contains('highcharts-reset-zoom')) {
72
+ return true;
73
+ }
74
+ element = event.path[++iterationIndex];
75
+ }
76
+ return false;
77
+ }
78
+ export function synchronizeTooltipTablesCellsWidth(tooltipContainer, isMobile) {
79
+ const tHeadNode = tooltipContainer.querySelector(`.${TOOLTIP_HEADER_CLASS_NAME}`);
80
+ const tBodyNode = tooltipContainer.querySelector(`.${TOOLTIP_LIST_CLASS_NAME}`);
81
+ if (!tHeadNode || !tHeadNode.children.length) {
82
+ return false;
83
+ }
84
+ const tHeadNodeFirstRow = tHeadNode.children[0];
85
+ for (let j = 0; j < tHeadNodeFirstRow.children.length; j++) {
86
+ const cell = tHeadNodeFirstRow.children[j];
87
+ cell.removeAttribute('style');
88
+ // Insert into cell some content to avoid Safari bad TD's width calculation
89
+ if (tBodyNode.children.length === 1) {
90
+ cell.innerHTML = '&nbsp;';
91
+ }
92
+ }
93
+ const tBodyNodeFirstRow = tBodyNode.children[0];
94
+ for (let j = 0; j < tBodyNodeFirstRow.children.length; j++) {
95
+ const cell = tBodyNodeFirstRow.children[j];
96
+ cell.removeAttribute('style');
97
+ }
98
+ const tHeadRowsWidth = tHeadNode.children[0].getBoundingClientRect().width;
99
+ const tBodyRowsWidth = tBodyNode.children[0].getBoundingClientRect().width;
100
+ const nodeWithWidesRows = tHeadRowsWidth > tBodyRowsWidth ? tHeadNode : tBodyNode;
101
+ const nodeWithWidesRowsCellsWidth = Array.prototype.reduce.call(nodeWithWidesRows.children[0].children, (accum, cellNode) => {
102
+ accum.push(cellNode.getBoundingClientRect().width);
103
+ return accum;
104
+ }, []);
105
+ let tooltipOverflowsViewport = false;
106
+ if (isMobile) {
107
+ const containerWidth = tooltipContainer.getBoundingClientRect().width;
108
+ const viewportWidth = window.screen.availWidth;
109
+ const nameColumnWidth = nodeWithWidesRowsCellsWidth[1];
110
+ if (containerWidth > viewportWidth) {
111
+ tooltipOverflowsViewport = true;
112
+ const diff = containerWidth - viewportWidth;
113
+ const maxWidth = nameColumnWidth - diff;
114
+ nodeWithWidesRowsCellsWidth[1] = maxWidth;
115
+ }
116
+ }
117
+ const nodeToSetCellsWidth = nodeWithWidesRows === tHeadNode ? tBodyNode : tHeadNode;
118
+ const nodeToSetCellsWidthFirstRow = nodeToSetCellsWidth.children[0];
119
+ for (let j = 0; j < nodeToSetCellsWidthFirstRow.children.length; j++) {
120
+ const cell = nodeToSetCellsWidthFirstRow.children[j];
121
+ cell.setAttribute('style', `width: ${nodeWithWidesRowsCellsWidth[j]}px`);
122
+ }
123
+ if (isMobile && tooltipOverflowsViewport) {
124
+ const rowNamesNodes = tooltipContainer.querySelectorAll(`.${TOOLTIP_ROW_NAME_CLASS_NANE}`);
125
+ for (let i = 0; i < rowNamesNodes.length; i++) {
126
+ const node = rowNamesNodes[i];
127
+ node.setAttribute('style', `max-width: ${nodeWithWidesRowsCellsWidth[1]}px`);
128
+ }
129
+ }
130
+ if (tBodyNode.children.length === 1) {
131
+ for (const cell of tHeadNodeFirstRow.children) {
132
+ cell.innerHTML = '';
133
+ }
134
+ }
135
+ }
136
+ const throttledAppendTooltip = throttle((container, tooltipMarkup) => {
137
+ container.innerHTML = tooltipMarkup;
138
+ }, 500);
139
+ export function isNavigatorSerie(serie) {
140
+ return serie.options.className === 'highcharts-navigator-series';
141
+ }
142
+ export function buildLegend(options) {
143
+ // https://api.highcharts.com/highcharts/legend
144
+ const legend = {
145
+ alignColumns: false,
146
+ labelFormatter: function () {
147
+ var _a;
148
+ if ((_a = this.userOptions) === null || _a === void 0 ? void 0 : _a.formattedName) {
149
+ // Other charts
150
+ return this.userOptions.formattedName;
151
+ }
152
+ else if (this.formattedName) {
153
+ // Pie chart
154
+ return this.formattedName;
155
+ }
156
+ else {
157
+ return this.name;
158
+ }
159
+ },
160
+ navigation: {
161
+ activeColor: 'var(--yc-color-base-special)',
162
+ inactiveColor: 'var(--yc-color-base-generic-accent-disabled)',
163
+ style: { color: 'var(--yc-color-text-primary)' },
164
+ },
165
+ };
166
+ if (options.outsideLegend) {
167
+ options.legendPosition = null;
168
+ }
169
+ if (options.legendResetMargin || options.outsideLegend) {
170
+ legend.y = 0;
171
+ legend.x = 0;
172
+ }
173
+ if (typeof options.legendPosition === 'number' &&
174
+ options.legendPosition >= 1 &&
175
+ options.legendPosition <= 12) {
176
+ if (options.type !== 'map') {
177
+ legend.layout = 'vertical';
178
+ }
179
+ legend.verticalAlign = 'middle';
180
+ legend.backgroundColor = 'var(--highcharts-floating-bg)';
181
+ legend.floating = true;
182
+ switch (options.legendPosition) {
183
+ case 1:
184
+ case 2:
185
+ legend.verticalAlign = 'top';
186
+ legend.align = 'right';
187
+ break;
188
+ case 3:
189
+ legend.verticalAlign = 'middle';
190
+ legend.align = 'right';
191
+ break;
192
+ case 4:
193
+ case 5:
194
+ legend.verticalAlign = 'bottom';
195
+ legend.align = 'right';
196
+ break;
197
+ case 6:
198
+ legend.verticalAlign = 'bottom';
199
+ legend.align = 'center';
200
+ break;
201
+ case 7:
202
+ case 8:
203
+ legend.verticalAlign = 'bottom';
204
+ legend.align = 'left';
205
+ break;
206
+ case 9:
207
+ legend.verticalAlign = 'middle';
208
+ legend.align = 'left';
209
+ break;
210
+ case 10:
211
+ case 11:
212
+ legend.verticalAlign = 'top';
213
+ legend.align = 'left';
214
+ break;
215
+ case 12:
216
+ legend.verticalAlign = 'top';
217
+ legend.align = 'center';
218
+ break;
219
+ }
220
+ if (options.legendPosition >= 4 && options.legendPosition <= 8) {
221
+ if (options.highstock) {
222
+ legend.margin = -38;
223
+ legend.y -= 110;
224
+ }
225
+ else {
226
+ legend.y -= 50;
227
+ }
228
+ }
229
+ if (options.legendPosition >= 7 && options.legendPosition <= 11) {
230
+ legend.x = 45;
231
+ }
232
+ if (options.legendPosition === 4 || options.legendPosition === 8) {
233
+ legend.y += -45;
234
+ }
235
+ }
236
+ return legend;
237
+ }
238
+ export function hasChartVisibleSeries(chart) {
239
+ return (chart &&
240
+ Array.isArray(chart.series) &&
241
+ chart.series
242
+ .filter((serie) => serie.options.showInLegend !== false)
243
+ .some((serie) => serie.visible));
244
+ }
245
+ function buildNavigator(params, options) {
246
+ const graphs = params.series;
247
+ const navigatorSettings = options.navigatorSettings;
248
+ const baseSeriesName = options.highstock.base_series_name || '';
249
+ if (!navigatorSettings) {
250
+ buildNavigatorFallback(graphs, baseSeriesName);
251
+ return;
252
+ }
253
+ const linesMode = navigatorSettings.linesMode;
254
+ const selectedLines = navigatorSettings.selectedLines;
255
+ const graphNames = graphs.map((graph) => graph.legendTitle || graph.title || graph.name);
256
+ const filteredSelectedLines = selectedLines.filter((line) => graphNames.includes(line));
257
+ addShowInNavigatorToSeries({
258
+ linesMode,
259
+ selectedLines: filteredSelectedLines,
260
+ params,
261
+ graphs,
262
+ baseSeriesName,
263
+ });
264
+ const periodSettings = navigatorSettings.periodSettings;
265
+ setNavigatorDefaultPeriod({ params, periodSettings });
266
+ params.navigator.series = Object.assign(Object.assign(Object.assign({}, options.highcharts.plotOptions.series), options.highcharts.plotOptions[options.highcharts.chart.type]), { type: options.highcharts.chart.type });
267
+ }
268
+ function prepareZones(options) {
269
+ const plotbands = [];
270
+ const zonesColors = ['#FFD3C9', '#FFFFC9', '#C9FFCA', '#C4C6D4', '#D4C4D2'];
271
+ for (let i = 0; i < options.zones.length; i++) {
272
+ let nowColor = options.zones[i].color;
273
+ if (!nowColor.length) {
274
+ nowColor = zonesColors[i];
275
+ }
276
+ let nowFrom = options.zones[i].from;
277
+ if (nowFrom === 'min') {
278
+ nowFrom = -Infinity;
279
+ }
280
+ let nowTo = options.zones[i].to;
281
+ if (nowTo === 'max') {
282
+ nowTo = Infinity;
283
+ }
284
+ const nowzone = {
285
+ color: nowColor,
286
+ from: nowFrom,
287
+ to: nowTo,
288
+ label: {
289
+ text: options.zones[i].text,
290
+ textAlign: 'left',
291
+ style: {
292
+ color: '#3E576F',
293
+ 'font-size': '8pt',
294
+ },
295
+ },
296
+ };
297
+ plotbands.push(nowzone);
298
+ }
299
+ return plotbands;
300
+ }
301
+ function getTypeParams(data, options) {
302
+ const params = {
303
+ xAxis: { labels: {} },
304
+ yAxis: {},
305
+ };
306
+ if (data.categories_ms) {
307
+ params.xAxis.type = 'datetime';
308
+ params.xAxis.labels.staggerLines = 1;
309
+ }
310
+ else {
311
+ const flag = options.type === 'line' || options.type === 'area';
312
+ params.xAxis.startOnTick = flag;
313
+ params.xAxis.endOnTick = flag;
314
+ if (data.categories) {
315
+ params.xAxis.categories = data.categories;
316
+ }
317
+ }
318
+ if (options.highstock) {
319
+ params.xAxis.events = {};
320
+ params.xAxis.events.afterSetExtremes = (e) => {
321
+ const chart = e.target.chart;
322
+ if (chart.userOptions.isCallbackCalled) {
323
+ hideComments(chart, chart.userOptions._getComments(), chart.userOptions._config);
324
+ drawComments(chart, chart.userOptions._getComments(), chart.userOptions._config);
325
+ }
326
+ };
327
+ }
328
+ if (options.zones) {
329
+ params.yAxis.plotBands = prepareZones(options);
330
+ }
331
+ return params;
332
+ }
333
+ function getPrecision(point) {
334
+ if (point.series.options && isNumber(point.series.options.precision)) {
335
+ return point.series.options.precision;
336
+ }
337
+ else if (point.series.tooltipOptions && isNumber(point.series.tooltipOptions.valueDecimals)) {
338
+ return point.series.tooltipOptions.valueDecimals;
339
+ }
340
+ else if (point.series.tooltipOptions &&
341
+ isNumber(point.series.tooltipOptions.chartKitPrecision)) {
342
+ return point.series.tooltipOptions.chartKitPrecision;
343
+ }
344
+ else {
345
+ return null;
346
+ }
347
+ }
348
+ function callManageTooltipConfig(options, json, chart) {
349
+ const initialTooltipHeaderValue = json.tooltipHeader;
350
+ json.onlyDate = initialTooltipHeaderValue;
351
+ const result = options.manageTooltipConfig(json, chart);
352
+ if (result.onlyDate !== initialTooltipHeaderValue &&
353
+ initialTooltipHeaderValue === result.tooltipHeader) {
354
+ json.tooltipHeader = result.onlyDate;
355
+ }
356
+ delete result.onlyDate;
357
+ return result;
358
+ }
359
+ function validateCellManipulationConfig(tooltipOptions, property, item) {
360
+ const values = Object.values(tooltipOptions[property]);
361
+ const keys = Object.keys(tooltipOptions[property]);
362
+ let errorMessage = `${i18n('chartkit', 'error-incorrect-key-value-intro')} "${property}"`;
363
+ let isIncorrectFormat = false;
364
+ if (keys.some(isNaN)) {
365
+ errorMessage += i18n('chartkit', 'error-incorrect-key');
366
+ isIncorrectFormat = true;
367
+ }
368
+ if (values.some((value) => typeof value !== 'string' && typeof value !== 'function')) {
369
+ errorMessage += i18n('chartkit', 'error-incorrect-value');
370
+ isIncorrectFormat = true;
371
+ }
372
+ if (isIncorrectFormat) {
373
+ console.error(errorMessage);
374
+ }
375
+ else {
376
+ item[property] = tooltipOptions[property];
377
+ }
378
+ }
379
+ function getTooltip(tooltip, options, comments, holidays) {
380
+ var _a, _b, _c, _d, _e, _f, _g, _h;
381
+ const serieType = (this.series && this.series.type) || tooltip.chart.options.chart.type;
382
+ const chart = tooltip.chart;
383
+ const xAxis = chart.xAxis[0];
384
+ const isDatetimeXAxis = xAxis.options.type === 'datetime';
385
+ let json;
386
+ if (['pie', 'funnel', 'solidgauge'].includes(serieType)) {
387
+ const dataSource = this.point || this.points[0].point;
388
+ const precision = isNumber(options.tooltipPercentPrecision)
389
+ ? options.tooltipPercentPrecision
390
+ : 1;
391
+ const percentage = numberFormat(dataSource.percentage, precision);
392
+ const tooltipOptions = ((_a = dataSource.series) === null || _a === void 0 ? void 0 : _a.tooltipOptions) || {};
393
+ json = {
394
+ lines: [
395
+ Object.assign(Object.assign({ value: numberFormat(dataSource.y, isNumber(options.precision) ? options.precision : 1), seriesColor: dataSource.color, seriesName: dataSource.formattedName || dataSource.name, originalValue: dataSource.y }, (options.showPercentInTooltip ? { percentValue: percentage } : null)), pick(tooltipOptions, [
396
+ 'chartKitFormatting',
397
+ 'chartKitPrecision',
398
+ 'chartKitPrefix',
399
+ 'chartKitPostfix',
400
+ 'chartKitFormat',
401
+ 'chartKitShowRankDelimiter',
402
+ 'chartKitUnit',
403
+ 'valuePrefix',
404
+ 'valueSuffix',
405
+ 'valueDecimals',
406
+ ])),
407
+ ],
408
+ count: 1,
409
+ shared: true,
410
+ };
411
+ if (typeof options.manageTooltipConfig === 'function') {
412
+ json = callManageTooltipConfig(options, json, chart);
413
+ }
414
+ const usersPointFormat = get(options.highcharts, 'tooltip.pointFormat');
415
+ if (tooltipOptions.pointFormatter || usersPointFormat) {
416
+ const formatter = tooltipOptions[(dataSource.formatPrefix || 'point') + 'Formatter'] ||
417
+ dataSource.tooltipFormatter;
418
+ const customRender = formatter.call(dataSource, usersPointFormat ||
419
+ tooltipOptions[(dataSource.formatPrefix || 'point') + 'Format'] ||
420
+ '');
421
+ json.lines[0].customRender = customRender;
422
+ }
423
+ if (!json.lines[0].customRender && tooltipOptions.insertCellAt) {
424
+ validateCellManipulationConfig(tooltipOptions, 'insertCellAt', json.lines[0]);
425
+ }
426
+ if (!json.lines[0].customRender && tooltipOptions.replaceCellAt) {
427
+ validateCellManipulationConfig(tooltipOptions, 'replaceCellAt', json.lines[0]);
428
+ }
429
+ json.lines[0].value = getFormattedValueWithSuffixAndPrefix(json.lines[0]);
430
+ json.splitTooltip = options.splitTooltip;
431
+ json.withPercent = (json.lines || []).some((line) => 'percentValue' in line);
432
+ return formatTooltip(json, tooltip);
433
+ }
434
+ let points = [];
435
+ let shared;
436
+ if (this.points) {
437
+ points = this.points;
438
+ shared = true;
439
+ }
440
+ else {
441
+ points.push(Object.assign({}, this.point));
442
+ shared = false;
443
+ }
444
+ const extendedPoint = points.find(({ x }) => x === this.x);
445
+ const pointsCount = points.length;
446
+ json = {
447
+ this: this,
448
+ useCompareFrom: options.useCompareFrom,
449
+ pre_lines: [],
450
+ lines: [],
451
+ count: pointsCount,
452
+ shared,
453
+ withPercent: false,
454
+ tooltipHeader: null,
455
+ unsafe: Boolean(options.unsafe),
456
+ };
457
+ if (isDatetimeXAxis) {
458
+ const items = this.points || Highcharts.splat(this);
459
+ const highchartsScale = chart.userOptions._config.highchartsScale;
460
+ let xDateFormat;
461
+ if (tooltip.options.xDateFormat) {
462
+ xDateFormat = tooltip.options.xDateFormat;
463
+ }
464
+ else if (highchartsScale) {
465
+ xDateFormat = tooltip.options.dateTimeLabelFormats[highchartsScale];
466
+ }
467
+ else {
468
+ xDateFormat = Highcharts.Tooltip.prototype.getXDateFormat.call(tooltip, items[0], tooltip.options, xAxis);
469
+ }
470
+ json.tooltipHeader = chart.time.dateFormat(xDateFormat, this.x);
471
+ }
472
+ else if ((_d = (_c = (_b = extendedPoint.point) === null || _b === void 0 ? void 0 : _b.options) === null || _c === void 0 ? void 0 : _c.xFormatted) !== null && _d !== void 0 ? _d : (extendedPoint.x || extendedPoint.x === 0)) {
473
+ const customTooltipHeaderFormatter = (_e = options === null || options === void 0 ? void 0 : options.highcharts) === null || _e === void 0 ? void 0 : _e.tooltipHeaderFormatter;
474
+ const tooltipHeaderStringValue = String((_h = (_g = (_f = extendedPoint.point) === null || _f === void 0 ? void 0 : _f.options) === null || _g === void 0 ? void 0 : _g.xFormatted) !== null && _h !== void 0 ? _h : extendedPoint.x);
475
+ json.tooltipHeader = customTooltipHeaderFormatter
476
+ ? customTooltipHeaderFormatter(tooltipHeaderStringValue)
477
+ : tooltipHeaderStringValue;
478
+ }
479
+ if (options.scale === 'd' && isDatetimeXAxis) {
480
+ const pointTimestamp = Number(chart.time.dateFormat('%Y%m%d', this.x));
481
+ const region = (options.region || 'TOT').toLowerCase();
482
+ if (region !== 'tot') {
483
+ json.region = region;
484
+ }
485
+ if (holidays.holiday[region][pointTimestamp]) {
486
+ json.holiday = true;
487
+ json.holidayText = holidays.holiday[region][pointTimestamp];
488
+ }
489
+ else if (holidays.weekend[region][pointTimestamp]) {
490
+ json.weekend = true;
491
+ }
492
+ json.dayOfWeek = chart.time.dateFormat('%a', this.x);
493
+ }
494
+ let val = 0;
495
+ let oldVal = 0;
496
+ let maxPrecision = 0;
497
+ let compareIndex;
498
+ let compareValue;
499
+ const legendArr = [];
500
+ const newComments = getCommentsOnLine(this, comments, chart);
501
+ json.xComments = newComments.xComments;
502
+ points.forEach((point) => {
503
+ var _a, _b;
504
+ const tooltipOptions = point.series.tooltipOptions || {};
505
+ const userOptions = point.series.userOptions || {};
506
+ const customTooltipSeriesName = (_a = point.point.custom) === null || _a === void 0 ? void 0 : _a.tooltipPointName;
507
+ const obj = Object.assign({ selectedSeries: point.series.index === chart.userOptions._activeSeries, hideSeriesName: options.highcharts &&
508
+ options.highcharts.tooltip &&
509
+ options.highcharts.tooltip.hideSeriesName, seriesColor: shared
510
+ ? point.point.color || point.point.series.color
511
+ : point.series.color, seriesShape: userOptions === null || userOptions === void 0 ? void 0 : userOptions.dashStyle, seriesName: customTooltipSeriesName ||
512
+ ((_b = point.series.userOptions) === null || _b === void 0 ? void 0 : _b.formattedName) ||
513
+ point.series.name }, pick(tooltipOptions, [
514
+ 'chartKitFormatting',
515
+ 'chartKitPrecision',
516
+ 'chartKitPrefix',
517
+ 'chartKitPostfix',
518
+ 'chartKitFormat',
519
+ 'chartKitShowRankDelimiter',
520
+ 'chartKitUnit',
521
+ 'valuePrefix',
522
+ 'valueSuffix',
523
+ 'valueDecimals',
524
+ ]));
525
+ if (options.useCompareFrom) {
526
+ if (!compareIndex) {
527
+ point.series.data.forEach((item) => {
528
+ if (item.category == options.useCompareFrom) {
529
+ compareIndex = item.index;
530
+ }
531
+ });
532
+ }
533
+ if (compareIndex) {
534
+ compareValue = point.series.data[compareIndex].y;
535
+ const diff = point.y - compareValue;
536
+ obj.diff = numberFormat(diff, 2) !== '0' ? numberFormat(diff, 2) : '';
537
+ }
538
+ }
539
+ const seriesIndex = point.series.index;
540
+ legendArr.push([seriesIndex, seriesIndex]);
541
+ let isVal = false;
542
+ let originalValue;
543
+ if (point.series.options.type === 'arearange') {
544
+ isVal = true;
545
+ obj.value = `${point.point.low} – ${point.point.high}`;
546
+ }
547
+ else if (point.y || point.y === 0) {
548
+ originalValue = point.y;
549
+ isVal = true;
550
+ const precision = getPrecision(point);
551
+ if (options.isPercent) {
552
+ obj.value = numberFormat(originalValue, calculatePrecision(precision || 2, options));
553
+ const isNormalize = options.normalizeDiv || options.normalizeSub;
554
+ obj.value = obj.value + (isNormalize ? '' : ' %');
555
+ }
556
+ else {
557
+ obj.value = numberFormat(originalValue, calculatePrecision(precision, options, originalValue));
558
+ }
559
+ const lastPoint = point.y.toString().split('.');
560
+ if (lastPoint[1]) {
561
+ maxPrecision = Math.max(maxPrecision, calculatePrecision(lastPoint[1].length, options));
562
+ }
563
+ }
564
+ obj.originalValue = originalValue;
565
+ const useInSum = point.series.userOptions.useInSum == undefined
566
+ ? true
567
+ : point.series.userOptions.useInSum;
568
+ if (options.enableSum && useInSum) {
569
+ val += point.y;
570
+ }
571
+ oldVal += point.y;
572
+ const serieId = point.series.userOptions.id || point.series.name;
573
+ if (newComments.xyComments && serieId) {
574
+ const xyComment = newComments.xyComments[serieId];
575
+ if (xyComment) {
576
+ obj.xyCommentText = xyComment.text;
577
+ }
578
+ }
579
+ if (point.series.options.stacking === 'percent' ||
580
+ (point.percentage !== undefined && options.showPercentInTooltip)) {
581
+ const precision = isNumber(options.tooltipPercentPrecision)
582
+ ? options.tooltipPercentPrecision
583
+ : 1;
584
+ obj.percentValue = numberFormat(point.percentage, precision);
585
+ }
586
+ const { type } = point.series.options;
587
+ const usersPointFormat = get(options.highcharts, 'tooltip.pointFormat');
588
+ if (tooltipOptions.headerFormat &&
589
+ obj.selectedSeries &&
590
+ tooltipOptions.headerFormat !==
591
+ defaultOptions.plotOptions.series.tooltip.headerFormat &&
592
+ tooltipOptions.headerFormat !==
593
+ get(defaultOptions.plotOptions[type], 'tooltip.headerFormat')) {
594
+ const headerString = tooltip.tooltipFooterHeaderFormatter(point.point.getLabelConfig());
595
+ json.tooltipHeader = headerString;
596
+ }
597
+ if (tooltipOptions.pointFormatter ||
598
+ usersPointFormat ||
599
+ (tooltipOptions.pointFormat !== defaultOptions.tooltip.pointFormat &&
600
+ tooltipOptions.pointFormat !==
601
+ defaultOptions.plotOptions.series.tooltip.pointFormat &&
602
+ tooltipOptions.pointFormat !==
603
+ get(defaultOptions.plotOptions[type], 'tooltip.pointFormat'))) {
604
+ const formatter = tooltipOptions[(point.point.formatPrefix || 'point') + 'Formatter'] ||
605
+ point.point.tooltipFormatter;
606
+ const customRender = formatter.call(point.point, usersPointFormat ||
607
+ tooltipOptions[(point.point.formatPrefix || 'point') + 'Format'] ||
608
+ '');
609
+ obj.customRender = customRender;
610
+ }
611
+ if (!obj.customRender && tooltipOptions.insertCellAt) {
612
+ validateCellManipulationConfig(tooltipOptions, 'insertCellAt', obj);
613
+ }
614
+ if (!obj.customRender && tooltipOptions.replaceCellAt) {
615
+ validateCellManipulationConfig(tooltipOptions, 'replaceCellAt', obj);
616
+ }
617
+ if (isVal) {
618
+ json.pre_lines.push(obj);
619
+ }
620
+ });
621
+ for (let i = 0; i < legendArr.length; i++) {
622
+ if (json.pre_lines[i]) {
623
+ json.lines.push(json.pre_lines[i]);
624
+ }
625
+ }
626
+ delete json.pre_lines;
627
+ if (json.lines && json.lines.length > 0) {
628
+ if (typeof options.manageTooltipConfig === 'function') {
629
+ json = callManageTooltipConfig(options, json, chart);
630
+ }
631
+ let hiddenRowsSum = 0;
632
+ let maxChartKitPrecision = null;
633
+ for (let i = 0; i < json.lines.length; i++) {
634
+ const item = json.lines[i];
635
+ if (item.chartKitPrecision || item.chartKitPrecision === 0) {
636
+ maxChartKitPrecision = Math.max(maxChartKitPrecision, item.chartKitPrecision);
637
+ }
638
+ item.value = getFormattedValueWithSuffixAndPrefix(item);
639
+ if (tooltip.lastVisibleRowIndex && i > tooltip.lastVisibleRowIndex) {
640
+ if (isNumber(item.originalValue)) {
641
+ hiddenRowsSum = hiddenRowsSum + item.originalValue;
642
+ }
643
+ else {
644
+ console.warn('originalValue is not defined for tooltip row');
645
+ hiddenRowsSum = NaN;
646
+ break;
647
+ }
648
+ }
649
+ }
650
+ maxPrecision = maxChartKitPrecision !== null ? maxChartKitPrecision : maxPrecision;
651
+ if (pointsCount > 1) {
652
+ const formatOptions = getFormatOptionsFromLine(json.lines[0]);
653
+ if (options.enableSum == null && // eslint-disable-line eqeqeq, no-eq-null
654
+ (options.stacking === 'normal' || options.stacking === 'percent' || options.sum)) {
655
+ json.sum = numberFormat(oldVal, maxPrecision, formatOptions);
656
+ }
657
+ else if (options.enableSum) {
658
+ json.sum = numberFormat(val, maxPrecision, formatOptions);
659
+ }
660
+ }
661
+ json.hiddenRowsNumber = json.count - tooltip.lastVisibleRowIndex - 1;
662
+ if (isNaN(hiddenRowsSum)) {
663
+ json.hiddenRowsSum = NaN;
664
+ }
665
+ else {
666
+ let hiddenRowsSumAsString = '';
667
+ if (options.isPercent) {
668
+ hiddenRowsSumAsString = numberFormat(hiddenRowsSum, maxPrecision);
669
+ const isNormalize = options.normalizeDiv || options.normalizeSub;
670
+ hiddenRowsSumAsString = hiddenRowsSumAsString + (isNormalize ? '' : ' %');
671
+ }
672
+ else {
673
+ hiddenRowsSumAsString = numberFormat(hiddenRowsSum, maxPrecision);
674
+ }
675
+ json.hiddenRowsSum = hiddenRowsSumAsString;
676
+ }
677
+ json.withPercent = (json.lines || []).some((line) => 'percentValue' in line);
678
+ json.splitTooltip = options.splitTooltip;
679
+ json.activeRowAlwaysFirstInTooltip = options.activeRowAlwaysFirstInTooltip;
680
+ return formatTooltip(json, tooltip);
681
+ }
682
+ else {
683
+ return false;
684
+ }
685
+ }
686
+ function findXVal(xAxisVal, categoriesMs) {
687
+ let xVal, min, max, leftDiff, rightDiff;
688
+ categoriesMs.forEach((val, pos) => {
689
+ if (pos > 0) {
690
+ max = val - xAxisVal;
691
+ min = xAxisVal - categoriesMs[pos - 1];
692
+ if ((pos == 1 && xAxisVal < categoriesMs[pos]) ||
693
+ (categoriesMs[pos - 1] <= xAxisVal && categoriesMs[pos] > xAxisVal) ||
694
+ (pos == categoriesMs.length - 1 && xAxisVal > categoriesMs[pos])) {
695
+ max = categoriesMs[pos];
696
+ min = categoriesMs[pos - 1];
697
+ leftDiff = xAxisVal - min;
698
+ rightDiff = max - xAxisVal;
699
+ if (leftDiff >= rightDiff) {
700
+ xVal = max;
701
+ }
702
+ else {
703
+ xVal = min;
704
+ }
705
+ }
706
+ }
707
+ });
708
+ return xVal;
709
+ }
710
+ function tooltipDiffClick(xVal, chart, options) {
711
+ if (!xVal) {
712
+ return;
713
+ }
714
+ function unCheck() {
715
+ if (!options.useCompareFrom) {
716
+ return false;
717
+ }
718
+ chart.xAxis[0].removePlotLine(options.useCompareFrom);
719
+ options.useCompareFrom = undefined;
720
+ }
721
+ function check() {
722
+ unCheck();
723
+ const lineConfig = {
724
+ value: xVal,
725
+ width: 1,
726
+ color: '#000000',
727
+ id: xVal,
728
+ zIndex: 20,
729
+ };
730
+ chart.xAxis[0].addPlotLine(lineConfig);
731
+ options.useCompareFrom = xVal;
732
+ }
733
+ if (xVal && xVal !== options.useCompareFrom) {
734
+ check();
735
+ }
736
+ else {
737
+ unCheck();
738
+ }
739
+ }
740
+ function getParamsByCustomType(type = 'line', options) {
741
+ const customType = CUSTOM_TYPES[type];
742
+ if (customType) {
743
+ options.enableSum =
744
+ options.enableSum === undefined || options.enableSum === null || options.enableSum;
745
+ return {
746
+ chart: { type: customType.type },
747
+ plotOptions: {
748
+ [customType.type]: {
749
+ stacking: customType.stacking,
750
+ },
751
+ },
752
+ };
753
+ }
754
+ return { chart: { type } };
755
+ }
756
+ export function handleScroll() {
757
+ if (!this.chart.container || this.isHidden) {
758
+ return false;
759
+ }
760
+ const newTopPosition = this.chart.container.getBoundingClientRect().top;
761
+ const diff = newTopPosition - this.chart.topPosition;
762
+ this.chart.topPosition = newTopPosition;
763
+ const currentTooltipTopPosition = this.now.y;
764
+ const newTooltipTopPosition = currentTooltipTopPosition + diff;
765
+ const tooltipHeight = this.container.getBoundingClientRect().height;
766
+ const newTooltipBottomPosition = newTooltipTopPosition + tooltipHeight + this.options.padding * 2;
767
+ if (newTooltipBottomPosition > window.innerHeight || newTooltipTopPosition < 0) {
768
+ if (this.fixed) {
769
+ this.hideFixedTooltip(this);
770
+ }
771
+ else {
772
+ this.hide();
773
+ }
774
+ return false;
775
+ }
776
+ this.now.y = newTooltipTopPosition;
777
+ this.container.style.top = `${newTooltipTopPosition}px`;
778
+ }
779
+ export function tooltipPositioner(tooltipWidth, tooltipHeight, point) {
780
+ const tooltipPadding = this.options.padding;
781
+ const windowHeight = window.innerHeight / ((window.visualViewport && window.visualViewport.scale) || 1);
782
+ const containerDimensions = this.chart.container.parentElement.getBoundingClientRect();
783
+ const pageScrollTop = document.body.scrollTop || document.documentElement.scrollTop;
784
+ const pageScrollLeft = document.body.scrollLeft || document.documentElement.scrollLeft;
785
+ let cursorXPosition = containerDimensions.left + this.chart.plotLeft + point.plotX + pageScrollLeft;
786
+ const tooltipOffset = TOOLTIP_OFFSET_FROM_CURSOR;
787
+ const cursorYPosition = containerDimensions.top + this.chart.plotTop + point.plotY + pageScrollTop;
788
+ const windowWidthAndScroll = window.innerWidth + pageScrollLeft;
789
+ let tooltipTopPosition = cursorYPosition - tooltipHeight / 2;
790
+ const isTooltipOnLeftNotFit = cursorXPosition - tooltipWidth - tooltipOffset < 0;
791
+ const isTooltipOnRightNotFit = cursorXPosition + tooltipWidth + tooltipOffset + 2 * tooltipPadding >= windowWidthAndScroll;
792
+ const isTooltipAboveCursor = isTooltipOnLeftNotFit && isTooltipOnRightNotFit;
793
+ if (isTooltipAboveCursor) {
794
+ cursorXPosition += tooltipWidth / 2;
795
+ tooltipTopPosition -= tooltipHeight / 2;
796
+ }
797
+ if (tooltipTopPosition - pageScrollTop - tooltipPadding < 0) {
798
+ tooltipTopPosition = pageScrollTop + tooltipPadding;
799
+ }
800
+ const tooltipBottomEdgePosition = tooltipTopPosition + tooltipHeight - pageScrollTop;
801
+ if (tooltipBottomEdgePosition + tooltipPadding > windowHeight) {
802
+ tooltipTopPosition = pageScrollTop + (windowHeight - tooltipHeight - tooltipPadding);
803
+ }
804
+ const tooltipOffsetFromCursor = tooltipOffset * (isTooltipOnRightNotFit ? -1 : 1);
805
+ return {
806
+ x: clamp(cursorXPosition + tooltipOffsetFromCursor - (isTooltipOnRightNotFit ? tooltipWidth : 0), tooltipPadding, window.innerWidth - tooltipWidth - 2 * tooltipPadding),
807
+ y: clamp(tooltipTopPosition, pageScrollTop + tooltipPadding, Infinity),
808
+ };
809
+ }
810
+ export function portraitOrientationTooltipPositioner(tooltipWidth, tooltipHeight, point) {
811
+ const windowWidth = document.body.clientWidth;
812
+ const containerDimensions = this.chart.container.parentElement.getBoundingClientRect();
813
+ const cursorXPosition = containerDimensions.left + this.chart.plotLeft + point.plotX - tooltipWidth / 2;
814
+ const pageScrollTop = document.body.scrollTop || document.documentElement.scrollTop;
815
+ const cursorYPosition = containerDimensions.top +
816
+ this.chart.plotTop +
817
+ pageScrollTop -
818
+ tooltipHeight +
819
+ point.plotY -
820
+ MOBILE_TOOLTIP_OFFSET_FROM_POINTER;
821
+ return {
822
+ x: clamp(cursorXPosition, 0, windowWidth - tooltipWidth),
823
+ y: clamp(cursorYPosition, 0, Infinity),
824
+ };
825
+ }
826
+ export function getTooltipPositioner(isMobile) {
827
+ return isMobile && window.innerHeight > window.innerWidth
828
+ ? portraitOrientationTooltipPositioner
829
+ : tooltipPositioner;
830
+ }
831
+ function handleClickOutside(event) {
832
+ let node = event.target;
833
+ while (this && node && node !== window.document.body) {
834
+ if (node === this.container || (this.tooltip && node === this.tooltip.container)) {
835
+ break;
836
+ }
837
+ else {
838
+ node = node.parentElement;
839
+ }
840
+ }
841
+ if (node === window.document.body) {
842
+ this.tooltip.hideFixedTooltip();
843
+ window.document.removeEventListener('click', this.tooltip.clickOutsideHandler);
844
+ }
845
+ }
846
+ function handleTooltipItemMouseEnter(event) {
847
+ if (event.target.classList.contains(TOOLTIP_ROW_CLASS_NAME)) {
848
+ const seriesName = event.target.getAttribute(SERIES_NAME_DATA_ATTRIBUTE);
849
+ const correspondingSeries = this.series.find((series) => series.name === seriesName);
850
+ const correspondingSeriesIndex = this.series.indexOf(correspondingSeries);
851
+ this.series.forEach((series, index) => {
852
+ if (`${index}-${series.name}` === seriesName) {
853
+ series.setState('hover');
854
+ this.userOptions._activeSeries = correspondingSeriesIndex;
855
+ const mouseLeaveHandler = (leaveHandlerEvent) => {
856
+ this.userOptions._activeSeries = null;
857
+ this.series.forEach((seriesItem) => {
858
+ seriesItem.setState('');
859
+ });
860
+ leaveHandlerEvent.target.removeEventListener('mouseleave', mouseLeaveHandler);
861
+ };
862
+ event.target.addEventListener('mouseleave', mouseLeaveHandler);
863
+ }
864
+ else {
865
+ series.setState('inactive');
866
+ }
867
+ });
868
+ }
869
+ }
870
+ export function hideFixedTooltip(tooltip, isMobile) {
871
+ tooltip.fixed = false;
872
+ tooltip.hide();
873
+ if (Array.isArray(tooltip.pointsOnFixedTooltip)) {
874
+ tooltip.pointsOnFixedTooltip.forEach((point) => {
875
+ point.setState('');
876
+ });
877
+ }
878
+ else {
879
+ tooltip.pointsOnFixedTooltip.setState('');
880
+ }
881
+ tooltip.mouseEnterHandler = null;
882
+ tooltip.pointsOnFixedTooltip = null;
883
+ tooltip.seriesTypeOnFixedTooltip = null;
884
+ const chartType = get(tooltip.chart.userOptions, 'chart.type');
885
+ tooltip.update({
886
+ positioner: chartType === 'timeline'
887
+ ? tooltip.preFixationPositioner
888
+ : getTooltipPositioner(isMobile),
889
+ style: Object.assign(Object.assign({}, tooltip.style), { pointerEvents: 'none' }),
890
+ });
891
+ window.document.removeEventListener('click', tooltip.clickOutsideHandler);
892
+ if (tooltip.mouseEnterHandler) {
893
+ tooltip.container.removeEventListener('mouseenter', tooltip.mouseEnterHandler);
894
+ }
895
+ }
896
+ function fixTooltip(tooltip, options, event) {
897
+ if (options.splitTooltip) {
898
+ return false;
899
+ }
900
+ if (tooltip.fixed) {
901
+ hideFixedTooltip(tooltip);
902
+ const serieType = (tooltip.series && tooltip.series.type) || tooltip.chart.options.chart.type;
903
+ const pointsToRefreshTooltip = serieType === 'sankey' ? tooltip.chart.hoverPoint : tooltip.chart.hoverPoints;
904
+ delete tooltip.preFixationHeight;
905
+ tooltip.refresh(pointsToRefreshTooltip, event);
906
+ }
907
+ else {
908
+ const serieType = (tooltip.series && tooltip.series.type) || tooltip.chart.options.chart.type;
909
+ if (!tooltip.chart.hoverPoints || serieType === 'heatmap') {
910
+ return false;
911
+ }
912
+ const hasInvisibleRows = tooltip.lastVisibleRowIndex &&
913
+ tooltip.chart.hoverPoints.length > tooltip.lastVisibleRowIndex;
914
+ let height = 0;
915
+ let top = 0;
916
+ if (hasInvisibleRows) {
917
+ const tooltipNode = tooltip.container.querySelector(`.${TOOLTIP_CONTAINER_CLASS_NAME}`);
918
+ const tooltipRect = tooltipNode.getBoundingClientRect();
919
+ height = tooltipRect.height;
920
+ top = tooltipRect.top;
921
+ tooltip.preFixationHeight = height;
922
+ }
923
+ tooltip.lastVisibleRowIndex = null;
924
+ tooltip.update({
925
+ style: Object.assign(Object.assign({}, tooltip.style), { pointerEvents: 'auto' }),
926
+ });
927
+ tooltip.seriesTypeOnFixedTooltip = get(tooltip, 'chart.hoverPoints[0].series.options.type');
928
+ const pointsToRefreshTooltip = serieType === 'sankey' ? tooltip.chart.hoverPoint : tooltip.chart.hoverPoints;
929
+ tooltip.refresh(pointsToRefreshTooltip, event, true);
930
+ const { x, y } = tooltip.now;
931
+ tooltip.preFixationPositioner = tooltip.positioner;
932
+ tooltip.update({
933
+ positioner: () => ({ x, y }),
934
+ });
935
+ tooltip.refresh(pointsToRefreshTooltip, event, true);
936
+ tooltip.clickOutsideHandler = handleClickOutside.bind(tooltip.chart);
937
+ if (serieType !== 'timeline') {
938
+ tooltip.mouseEnterHandler = handleTooltipItemMouseEnter.bind(tooltip.chart);
939
+ tooltip.container.addEventListener('mouseenter', tooltip.mouseEnterHandler, true);
940
+ }
941
+ setTimeout(() => {
942
+ window.document.addEventListener('click', tooltip.clickOutsideHandler);
943
+ }, 0);
944
+ tooltip.fixed = true;
945
+ tooltip.pointsOnFixedTooltip = pointsToRefreshTooltip;
946
+ if (hasInvisibleRows) {
947
+ const footerNode = tooltip.container.querySelector(`.${TOOLTIP_FOOTER_CLASS_NAME}`);
948
+ const listNode = tooltip.container.querySelector(`.${TOOLTIP_LIST_CLASS_NAME}`);
949
+ const footerHeight = footerNode.getBoundingClientRect().height;
950
+ const headerHeight = listNode.getBoundingClientRect().top - top;
951
+ listNode.style.maxHeight = `${height - footerHeight - headerHeight - 1}px`;
952
+ tooltip.container.style.maxHeight = `${height + tooltip.options.padding * 2}px`;
953
+ const isScrollAppears = listNode.scrollHeight > listNode.clientHeight;
954
+ if (!isScrollAppears) {
955
+ return false;
956
+ }
957
+ const isScrollExtendContainerWidth = listNode.offsetWidth > listNode.clientWidth;
958
+ if (isScrollExtendContainerWidth) {
959
+ if (isSafari) {
960
+ tooltip.container
961
+ .querySelector(`div.${TOOLTIP_ROOT_CLASS_NAME}`)
962
+ .classList.add('_tooltip-with-scroll-in-safari');
963
+ }
964
+ else {
965
+ tooltip.container
966
+ .querySelector(`div.${TOOLTIP_ROOT_CLASS_NAME}`)
967
+ .classList.add('_tooltip-with-scroll');
968
+ }
969
+ }
970
+ synchronizeTooltipTablesCellsWidth(tooltip.container);
971
+ }
972
+ }
973
+ }
974
+ const drillDownUpHandler = function () {
975
+ if (this.tooltip && this.tooltip.fixed) {
976
+ this.tooltip.hideFixedTooltip();
977
+ }
978
+ if (this.legend) {
979
+ this.legend.destroy();
980
+ }
981
+ };
982
+ export const chartTypesWithoutCrosshair = [
983
+ 'wordcloud',
984
+ 'funnel',
985
+ 'treemap',
986
+ 'variwide',
987
+ 'heatmap',
988
+ 'streamgraph',
989
+ 'xrange',
990
+ 'pie',
991
+ 'map',
992
+ 'sankey',
993
+ ];
994
+ export const chartTypesWithoutYCrosshair = [
995
+ 'line',
996
+ 'area',
997
+ 'arearange',
998
+ 'bar',
999
+ 'boxplot',
1000
+ 'column',
1001
+ 'columnrange',
1002
+ 'waterfall',
1003
+ ];
1004
+ export const chartTypesWithNativeTooltip = [
1005
+ 'scatter',
1006
+ 'bubble',
1007
+ 'sankey',
1008
+ 'heatmap',
1009
+ 'treemap',
1010
+ 'networkgraph',
1011
+ 'variwide',
1012
+ 'waterfall',
1013
+ 'streamgraph',
1014
+ 'wordcloud',
1015
+ 'xrange',
1016
+ 'boxplot',
1017
+ 'timeline',
1018
+ ];
1019
+ function getCrosshairConfig(chartType, isCrosshairForYAxis = false) {
1020
+ if (isCrosshairForYAxis && chartTypesWithoutYCrosshair.indexOf(chartType) !== -1) {
1021
+ return false;
1022
+ }
1023
+ if (chartTypesWithoutCrosshair.indexOf(chartType) !== -1) {
1024
+ return false;
1025
+ }
1026
+ else {
1027
+ return {
1028
+ width: 2,
1029
+ color: '#a63eb2',
1030
+ zIndex: 10,
1031
+ };
1032
+ }
1033
+ }
1034
+ function drillOnClick(event, { options, chartType }) {
1035
+ const drillDownLevel = this.chart.getParams().drillDownLevel || ['0'];
1036
+ let filters = this.chart.getParams().drillDownFilters || [];
1037
+ if (!filters.some(Boolean)) {
1038
+ filters = new Array(options.drillDownData.breadcrumbs.length).fill('');
1039
+ }
1040
+ const isColorDrillDown = this.chart.getParams().isColorDrillDown;
1041
+ const level = Number(drillDownLevel[0]);
1042
+ if (level === options.drillDownData.breadcrumbs.length - 1) {
1043
+ return;
1044
+ }
1045
+ const drillDownFilters = filters.map((filter, index) => {
1046
+ if (level === index) {
1047
+ if (isColorDrillDown) {
1048
+ return event.point.series.name;
1049
+ }
1050
+ let drillDownFilter = event.point.options.drillDownFilterValue ||
1051
+ event.point.category ||
1052
+ event.point.name;
1053
+ const isDateTime = chartType !== 'pie' &&
1054
+ event.point.series.userOptions.type !== 'pie' &&
1055
+ event.point.series.xAxis.options.type === 'datetime';
1056
+ if (isDateTime) {
1057
+ drillDownFilter =
1058
+ chartType === 'scatter' ? drillDownFilter - 180 * 60 * 1000 : drillDownFilter;
1059
+ }
1060
+ return isDateTime ? moment(drillDownFilter).format('YYYY-MM-DD') : drillDownFilter;
1061
+ }
1062
+ return filter;
1063
+ });
1064
+ this.chart.updateParams({
1065
+ drillDownLevel: String(level + 1),
1066
+ drillDownFilters,
1067
+ });
1068
+ }
1069
+ function fixTooltipOnClick(event, { options }) {
1070
+ const customHandler = get(options, 'highcharts.plotOptions.series.events.click') ||
1071
+ get(options, 'highcharts.plotOptions.series.point.events.click');
1072
+ if (customHandler) {
1073
+ return false;
1074
+ }
1075
+ fixTooltip(this.chart.tooltip, options, event);
1076
+ }
1077
+ function adjustDonutFontSize(chart, chartSeries, innerWidth, totals) {
1078
+ if (!totals) {
1079
+ return;
1080
+ }
1081
+ const MIN_ACCEPTABLE_INNER_SIZE = 400;
1082
+ const MAX_ACCEPTABLE_TOTALS_LENGTH = 9;
1083
+ let fontSize = 63;
1084
+ let padding = 35;
1085
+ if (totals.length > MAX_ACCEPTABLE_TOTALS_LENGTH) {
1086
+ fontSize = Math.round(fontSize * MAX_ACCEPTABLE_TOTALS_LENGTH) / totals.length;
1087
+ }
1088
+ if (innerWidth < MIN_ACCEPTABLE_INNER_SIZE) {
1089
+ fontSize = Math.round((innerWidth * fontSize) / MIN_ACCEPTABLE_INNER_SIZE);
1090
+ padding = Math.round((innerWidth * padding) / MIN_ACCEPTABLE_INNER_SIZE);
1091
+ }
1092
+ const x = chart.plotLeft + chartSeries.center[0];
1093
+ const y = chart.plotTop + chartSeries.center[1] + padding;
1094
+ if (chart.pieCenter) {
1095
+ chart.pieCenter.destroy();
1096
+ }
1097
+ chart.pieCenter = chart.renderer
1098
+ .text(totals, x, y, true)
1099
+ .css({
1100
+ 'text-align': 'center',
1101
+ width: innerWidth - 2 * padding,
1102
+ fontSize: fontSize + 'px',
1103
+ })
1104
+ .add();
1105
+ const box = chart.pieCenter.getBBox();
1106
+ chart.pieCenter.attr({
1107
+ x: x - box.width / 2,
1108
+ y: y - box.height / 4,
1109
+ });
1110
+ }
1111
+ function formatDonutTotals(totals, formatSettings) {
1112
+ const parsedTotals = parseFloat(totals);
1113
+ if (isNaN(parsedTotals)) {
1114
+ return '';
1115
+ }
1116
+ if (formatSettings && formatSettings.chartKitFormatting) {
1117
+ const { chartKitPrecision, chartKitPrefix, chartKitPostfix, chartKitUnit, chartKitFormat, chartKitShowRankDelimiter, } = formatSettings;
1118
+ const options = {
1119
+ precision: chartKitPrecision,
1120
+ prefix: chartKitPrefix,
1121
+ postfix: chartKitPostfix,
1122
+ format: chartKitFormat,
1123
+ showRankDelimiter: chartKitShowRankDelimiter,
1124
+ unit: chartKitUnit,
1125
+ };
1126
+ return formatNumber(parsedTotals, options);
1127
+ }
1128
+ return `${parsedTotals}`;
1129
+ }
1130
+ export function prepareConfig(data, options, isMobile, holidays) {
1131
+ var _a, _b, _c;
1132
+ const series = data.graphs || data;
1133
+ const totals = formatDonutTotals(data === null || data === void 0 ? void 0 : data.totals, series[0].tooltip);
1134
+ const hasScatterSeries = series && series.some((item) => item.type === 'scatter');
1135
+ const chartType = get(options, 'highcharts.chart.type') || 'line';
1136
+ const { entryId } = options;
1137
+ const testClassName = `data-qa-chartkit-tooltip-entry-${entryId}`;
1138
+ const debouncedAdjustDonutFontSize = debounce(adjustDonutFontSize, 100);
1139
+ const params = merge(getParamsByCustomType(options.type, options), defaultOptions, Object.assign({ _config: options, chart: {
1140
+ events: Object.assign({ load: function () {
1141
+ var _a;
1142
+ if (chartType === 'column' || chartType === 'bar') {
1143
+ this.series.forEach((seriesItem) => {
1144
+ if (!seriesItem.legendItem) {
1145
+ return;
1146
+ }
1147
+ const color = seriesItem.color;
1148
+ // The update method updates all series, and therefore,
1149
+ // after working out the handleLegendItemMouseOverAndOut,
1150
+ // which updates only one specific series, you can get a bug
1151
+ // of rendering bars when the min/max values are set to greater than 0:
1152
+ // ┌───────────────────┐
1153
+ // │Title1 │▒▒▒▒▒▒▒▒ │
1154
+ // │Title2 │▒▒▒▒▒▒ │
1155
+ // │Title3 │▒▒▒▒ │
1156
+ // │ └────────── │
1157
+ // └───────────────────┘
1158
+ // ● Title1 ● Title2 ● Title3
1159
+ //
1160
+ // When hovering over the legend element Title1, we get the following:
1161
+ // ┌───────────────────┐
1162
+ // │Title1 │▒▒▒▒▒▒▒▒ │
1163
+ // │▒▒▒▒▒▒▒│▒▒▒▒▒▒ │
1164
+ // │▒▒▒▒▒▒▒│▒▒▒▒ │
1165
+ // │ └────────── │
1166
+ // └───────────────────┘
1167
+ // ● Title1 ● Title2 ● Title3
1168
+ seriesItem.update({ color }, false);
1169
+ });
1170
+ // All series have chart property (it is a link on the same object)
1171
+ // https://api.highcharts.com/class-reference/Highcharts.Series%23update#chart
1172
+ // Call the redraw method on the chart, since we updated the series without redrawing
1173
+ // https://api.highcharts.com/class-reference/Highcharts.Series%23update#update
1174
+ (_a = this.series[0]) === null || _a === void 0 ? void 0 : _a.chart.redraw();
1175
+ this.series.forEach((serie) => {
1176
+ if (!serie.legendItem) {
1177
+ return;
1178
+ }
1179
+ const color = serie.color;
1180
+ function handleLegendItemMouseOverAndOut() {
1181
+ serie.update({
1182
+ color: Highcharts.Color(color).brighten(0.1).get('rgb'),
1183
+ });
1184
+ serie.legendItem.on('mouseout', () => {
1185
+ serie.update({
1186
+ color: Highcharts.Color(color).get('rgb'),
1187
+ });
1188
+ serie.legendItem.on('mouseover', handleLegendItemMouseOverAndOut);
1189
+ });
1190
+ }
1191
+ serie.legendItem.on('mouseover', handleLegendItemMouseOverAndOut);
1192
+ });
1193
+ }
1194
+ }, selection: function () {
1195
+ if (this.tooltip.fixed) {
1196
+ hideFixedTooltip(this.tooltip);
1197
+ }
1198
+ }, drilldown: drillDownUpHandler, drillup: drillDownUpHandler, click: options.showTooltipDiff
1199
+ ? function (event) {
1200
+ const xVal = findXVal(event.xAxis[0].value, data.categories_ms);
1201
+ tooltipDiffClick(xVal, this, options);
1202
+ }
1203
+ : function (event) {
1204
+ const customHandler = get(options, 'highcharts.chart.events.click');
1205
+ const chartContainer = this.container;
1206
+ const zoomResetButtonClickHappened = isZoomResetButtonClick(event, chartContainer);
1207
+ if (zoomResetButtonClickHappened || customHandler) {
1208
+ return false;
1209
+ }
1210
+ fixTooltip(this.tooltip, options, event);
1211
+ }, redraw: function () {
1212
+ drawOnlyRendererComments(this, this.userOptions._getComments && this.userOptions._getComments(), this.userOptions._config);
1213
+ } }, (chartType === 'pie' &&
1214
+ totals && {
1215
+ render: function () {
1216
+ const chart = this;
1217
+ const chartSeries = chart.series[0];
1218
+ const innerWidth = chartSeries === null || chartSeries === void 0 ? void 0 : chartSeries.center[3];
1219
+ if (innerWidth) {
1220
+ debouncedAdjustDonutFontSize(chart, chartSeries, innerWidth, totals);
1221
+ }
1222
+ },
1223
+ })),
1224
+ }, title: {
1225
+ text: options.hideTitle ? null : options.title,
1226
+ floating: options.titleFloating,
1227
+ }, subtitle: {
1228
+ text: options.hideTitle ? null : options.subtitle,
1229
+ }, series, legend: options.hideLegend === true || options.showLegend === false
1230
+ ? { enabled: false }
1231
+ : buildLegend(options), tooltip: Object.assign(Object.assign(Object.assign({ shared: isTooltipShared(chartType), splitTooltip: options.splitTooltip, distance: 0, style: {
1232
+ width: 'auto',
1233
+ }, className: concatStrings(testClassName, TOOLTIP_ROOT_CLASS_NAME, 'chartkit-theme_common', `${TOOLTIP_ROOT_CLASS_NAME}_type_${chartType}`), outside: chartType !== 'timeline' }, (chartType !== 'timeline' ? { positioner: getTooltipPositioner(isMobile) } : null)), (options.insertCellAt ? { insertCellAt: options.insertCellAt } : null)), (options.replaceCellAt ? { replaceCellAt: options.replaceCellAt } : null)), plotOptions: {
1234
+ xrange: {
1235
+ stickyTracking: false,
1236
+ },
1237
+ series: {
1238
+ events: {
1239
+ legendItemClick: handleLegendItemClick,
1240
+ mouseOver: function () {
1241
+ this.chart.userOptions._activeSeries = this.index;
1242
+ },
1243
+ mouseOut: function () {
1244
+ this.chart.userOptions._activeSeries = null;
1245
+ },
1246
+ click: function (event) {
1247
+ if (options.drillDownData) {
1248
+ drillOnClick.bind(this)(event, { options, chartType });
1249
+ }
1250
+ else {
1251
+ fixTooltipOnClick.bind(this)(event, { options });
1252
+ }
1253
+ },
1254
+ },
1255
+ point: {
1256
+ events: {
1257
+ click: function (event) {
1258
+ if (event.shiftKey) {
1259
+ this.series.chart.tooltip.hide();
1260
+ this.series.data[this.index].remove();
1261
+ return true;
1262
+ }
1263
+ return false;
1264
+ },
1265
+ },
1266
+ },
1267
+ marker: options.splitTooltip
1268
+ ? {
1269
+ states: {
1270
+ hover: {
1271
+ enabled: false,
1272
+ },
1273
+ select: {
1274
+ enabled: false,
1275
+ },
1276
+ },
1277
+ }
1278
+ : {},
1279
+ },
1280
+ pie: {
1281
+ point: {
1282
+ events: {
1283
+ legendItemClick: handleLegendItemClick,
1284
+ },
1285
+ },
1286
+ },
1287
+ area: series.length === 1
1288
+ ? {
1289
+ trackByArea: false,
1290
+ stickyTracking: true,
1291
+ }
1292
+ : {},
1293
+ }, xAxis: {
1294
+ crosshair: options.splitTooltip
1295
+ ? getCrosshairConfig(hasScatterSeries ? 'scatter' : chartType)
1296
+ : false,
1297
+ labels: {
1298
+ formatter: function () {
1299
+ var _a;
1300
+ const axis = this.axis;
1301
+ const userOptions = this.chart.userOptions;
1302
+ const highchartsScale = userOptions._config.highchartsScale;
1303
+ /*
1304
+ * axesFormatting - custom axis formatting
1305
+ * axesFormatting - has 2 properties: yAxis и xAxis
1306
+ * yAxis/xAxis - ChartKitFormatNumberSettings[]
1307
+ * the position in the array corresponds to the axis index, each axis has an index field starting from 0
1308
+ */
1309
+ const xAxisFormatSettings = (_a = userOptions.axesFormatting) === null || _a === void 0 ? void 0 : _a.xAxis;
1310
+ const currentAxisIndex = this.axis.userOptions.index;
1311
+ if (axis.options.type === 'datetime' && highchartsScale) {
1312
+ const dateTimeLabelFormat = axis.options.dateTimeLabelFormats[highchartsScale];
1313
+ return this.chart.time.dateFormat(dateTimeLabelFormat.main || dateTimeLabelFormat, this.value);
1314
+ }
1315
+ else if (xAxisFormatSettings &&
1316
+ xAxisFormatSettings[currentAxisIndex] &&
1317
+ xAxisFormatSettings[currentAxisIndex].chartKitFormatting) {
1318
+ return getChartKitFormattedValue(xAxisFormatSettings[currentAxisIndex], this.value, this.percentage);
1319
+ }
1320
+ return Highcharts.Axis.prototype.defaultLabelFormatter.call(this);
1321
+ },
1322
+ },
1323
+ }, yAxis: {
1324
+ crosshair: options.splitTooltip
1325
+ ? getCrosshairConfig(hasScatterSeries ? 'scatter' : chartType, true)
1326
+ : false,
1327
+ labels: {
1328
+ formatter: function () {
1329
+ var _a;
1330
+ const userOptions = this.chart.userOptions;
1331
+ const yAxisFormatSettings = (_a = userOptions.axesFormatting) === null || _a === void 0 ? void 0 : _a.yAxis;
1332
+ const currentAxisIndex = this.axis.userOptions.index;
1333
+ if (yAxisFormatSettings &&
1334
+ yAxisFormatSettings[currentAxisIndex] &&
1335
+ yAxisFormatSettings[currentAxisIndex].chartKitFormatting) {
1336
+ return getChartKitFormattedValue(yAxisFormatSettings[currentAxisIndex], this.value, this.percentage);
1337
+ }
1338
+ return Highcharts.Axis.prototype.defaultLabelFormatter.call(this);
1339
+ },
1340
+ },
1341
+ } }, (options.highstock && options.highstock.range_min && options.highstock.range_max
1342
+ ? {
1343
+ navigator: {
1344
+ adaptToUpdatedData: false,
1345
+ },
1346
+ }
1347
+ : null)));
1348
+ if (options.highcharts && options.highcharts.tooltip && options.highcharts.tooltip.formatter) {
1349
+ const formatter = options.highcharts.tooltip.formatter;
1350
+ params.tooltip.formatter = function (tooltip) {
1351
+ return `<div class="${b()}">${formatter.call(this, tooltip)}</div>`;
1352
+ };
1353
+ delete options.highcharts.tooltip.formatter;
1354
+ }
1355
+ else {
1356
+ params.tooltip.formatter = function (tooltip) {
1357
+ const serieType = tooltip.seriesTypeOnFixedTooltip ||
1358
+ get(tooltip, 'chart.hoverPoint.series.options.type') ||
1359
+ (this.series && this.series.type) ||
1360
+ tooltip.chart.options.chart.type;
1361
+ if (!options.manageTooltipConfig &&
1362
+ (chartTypesWithNativeTooltip.includes(serieType) ||
1363
+ tooltip.chart.options.chart.polar ||
1364
+ (this.points &&
1365
+ this.points.some((point) => ['histogram', 'bellcurve', 'ohlc'].includes(point.series.type))))) {
1366
+ const splitTooltip = tooltip.splitTooltip;
1367
+ const defaultFormatter = `<div class="${b({ 'split-tooltip': splitTooltip })}">
1368
+ ${tooltip.defaultFormatter.call(this, tooltip).join('')}
1369
+ </div>`;
1370
+ if (splitTooltip) {
1371
+ throttledAppendTooltip(tooltip.getTooltipContainer(), defaultFormatter);
1372
+ return null;
1373
+ }
1374
+ return defaultFormatter;
1375
+ }
1376
+ const chartComments = tooltip.chart.userOptions._getComments();
1377
+ const tooltipRender = getTooltip.call(this, tooltip, options, chartComments, holidays);
1378
+ if (tooltip.splitTooltip) {
1379
+ throttledAppendTooltip(tooltip.getTooltipContainer(), tooltipRender);
1380
+ return null;
1381
+ }
1382
+ return tooltipRender;
1383
+ };
1384
+ }
1385
+ if (params.legend.enabled === undefined &&
1386
+ ['pie', 'heatmap', 'treemap'].indexOf(options.type) === -1 &&
1387
+ ['pie', 'heatmap', 'treemap'].indexOf(options.highcharts && options.highcharts.chart && options.highcharts.chart.type) === -1) {
1388
+ params.legend.enabled = !options.splitTooltip && params.series.length > 1;
1389
+ }
1390
+ if (options.highstock) {
1391
+ params.useHighStock = true;
1392
+ buildNavigator(params, options);
1393
+ }
1394
+ if (options.hideHolidays && !options.highstock) {
1395
+ params.xAxis.ordinal = true;
1396
+ params.xAxis.startOnTick = true;
1397
+ params.xAxis.endOnTick = true;
1398
+ params.xAxis.showFirstLabel = false;
1399
+ params.xAxis.showLastLabel = false;
1400
+ }
1401
+ if (Array.isArray(options.hide_series)) {
1402
+ params.series.forEach((serie) => {
1403
+ if (options.hide_series.indexOf(serie.name) !== -1) {
1404
+ serie.visible = false;
1405
+ }
1406
+ });
1407
+ }
1408
+ const seriesDataLabelsFormatter = {
1409
+ dataLabels: (_c = (_b = (_a = options.highcharts) === null || _a === void 0 ? void 0 : _a.plotOptions) === null || _b === void 0 ? void 0 : _b.series) === null || _c === void 0 ? void 0 : _c.dataLabels,
1410
+ };
1411
+ // If you set plotOptions.series.dataLabels.formatter, then it will not be applied in any way,
1412
+ // because according to the logic of Highcharts, its priority is lower than that of plotOptions.<chart_type>.dataLabels.formatter.
1413
+ // Therefore, we copy the settings from plotOptions.series into plotOptions.<chart_type>
1414
+ const preparedHighchartsOptions = merge({}, {
1415
+ plotOptions: {
1416
+ area: seriesDataLabelsFormatter,
1417
+ bar: seriesDataLabelsFormatter,
1418
+ column: seriesDataLabelsFormatter,
1419
+ line: seriesDataLabelsFormatter,
1420
+ },
1421
+ }, options.highcharts);
1422
+ mergeWith(params, getTypeParams(data, options), preparedHighchartsOptions, (a, b) => {
1423
+ if (typeof a === 'function' && typeof b === 'function' && a !== b) {
1424
+ return function (event, ...args) {
1425
+ a.call(this, event, ...args);
1426
+ if (!event || event.isTrusted !== false) {
1427
+ return b.call(this, event, ...args);
1428
+ }
1429
+ };
1430
+ }
1431
+ return mergeArrayWithObject(a, b);
1432
+ });
1433
+ // https://github.com/highcharts/highcharts/issues/5671
1434
+ // http://jsfiddle.net/yo12kv0b/
1435
+ if (params.plotOptions.area && params.plotOptions.area.stacking === 'normal') {
1436
+ params.series.forEach((serie, serieIndex) => {
1437
+ if (serie.type === undefined) {
1438
+ let hasNegativeValues = false;
1439
+ let hasPositiveValues = false;
1440
+ serie.data.forEach((value) => {
1441
+ let actualValue = value;
1442
+ if (Array.isArray(value)) {
1443
+ actualValue = value[1];
1444
+ }
1445
+ else if (value && typeof value.y === 'number') {
1446
+ actualValue = value.y;
1447
+ }
1448
+ if (actualValue > 0) {
1449
+ hasPositiveValues = true;
1450
+ }
1451
+ else if (actualValue < 0) {
1452
+ hasNegativeValues = true;
1453
+ }
1454
+ });
1455
+ const serieHasIntersectionWithOthers = params.series.some((serieItem, serieItemIndex) => {
1456
+ if (serieItemIndex === serieIndex) {
1457
+ return false;
1458
+ }
1459
+ else {
1460
+ const serieSet = new Set(serie.data.map((item) => item.x));
1461
+ const serieItemIndexSet = new Set(serieItem.data.map((item) => item.x));
1462
+ for (const item of serieSet) {
1463
+ if (serieItemIndexSet.has(item)) {
1464
+ return true;
1465
+ }
1466
+ }
1467
+ return false;
1468
+ }
1469
+ }, false);
1470
+ if (serieHasIntersectionWithOthers) {
1471
+ if (hasPositiveValues && !hasNegativeValues) {
1472
+ serie.stack = 'positive';
1473
+ }
1474
+ else if (!hasPositiveValues && hasNegativeValues) {
1475
+ serie.stack = 'negative';
1476
+ }
1477
+ }
1478
+ }
1479
+ });
1480
+ }
1481
+ params.xAxis.calcClosestPointManually = Boolean(options.calcClosestPointManually);
1482
+ return params;
1483
+ }