@evergis/charts 3.1.6 → 3.1.8

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 (266) hide show
  1. package/LICENSE +2 -2
  2. package/README.md +10 -0
  3. package/dist/charts/BarChart/draw.d.ts +2 -2
  4. package/dist/charts/BarChart/drawGrid/index.d.ts +2 -2
  5. package/dist/charts/BarChart/drawGrid/types.d.ts +8 -8
  6. package/dist/charts/BarChart/drawLines/index.d.ts +13 -13
  7. package/dist/charts/BarChart/drawLines/types.d.ts +9 -9
  8. package/dist/charts/BarChart/drawTooltip/getLabel.d.ts +2 -2
  9. package/dist/charts/BarChart/drawTooltip/getLabelY.d.ts +2 -2
  10. package/dist/charts/BarChart/drawTooltip/index.d.ts +2 -2
  11. package/dist/charts/BarChart/drawTooltip/types.d.ts +12 -13
  12. package/dist/charts/BarChart/getBars/index.d.ts +3 -3
  13. package/dist/charts/BarChart/getBars/types.d.ts +6 -6
  14. package/dist/charts/BarChart/getDomain.d.ts +5 -5
  15. package/dist/charts/BarChart/hooks/useSelection.d.ts +2 -2
  16. package/dist/charts/BarChart/index.d.ts +3 -3
  17. package/dist/charts/BarChart/marshaling.d.ts +2 -2
  18. package/dist/charts/BarChart/resizeBarWidth/index.d.ts +2 -2
  19. package/dist/charts/BarChart/resizeBarWidth/types.d.ts +5 -5
  20. package/dist/charts/BarChart/styled.d.ts +37 -37
  21. package/dist/charts/BarChart/types.d.ts +148 -148
  22. package/dist/charts/BubbleChart/bubbleChartDefaultProps.d.ts +14 -14
  23. package/dist/charts/BubbleChart/draw.d.ts +2 -2
  24. package/dist/charts/BubbleChart/drawGrid/index.d.ts +2 -2
  25. package/dist/charts/BubbleChart/drawGrid/types.d.ts +8 -8
  26. package/dist/charts/BubbleChart/drawTooltip/index.d.ts +2 -2
  27. package/dist/charts/BubbleChart/drawTooltip/styled.d.ts +1 -1
  28. package/dist/charts/BubbleChart/drawTooltip/types.d.ts +4 -4
  29. package/dist/charts/BubbleChart/index.d.ts +3 -3
  30. package/dist/charts/BubbleChart/styled.d.ts +17 -17
  31. package/dist/charts/BubbleChart/types.d.ts +55 -55
  32. package/dist/charts/BubbleChart/unmount.d.ts +1 -1
  33. package/dist/charts/CalendarChart/draw.d.ts +2 -2
  34. package/dist/charts/CalendarChart/index.d.ts +3 -3
  35. package/dist/charts/CalendarChart/styled.d.ts +18 -18
  36. package/dist/charts/CalendarChart/types.d.ts +22 -22
  37. package/dist/charts/HorizontalBarChart/Bar/index.d.ts +3 -3
  38. package/dist/charts/HorizontalBarChart/Bar/styled.d.ts +1 -1
  39. package/dist/charts/HorizontalBarChart/Bar/types.d.ts +11 -11
  40. package/dist/charts/HorizontalBarChart/Tooltip/index.d.ts +3 -3
  41. package/dist/charts/HorizontalBarChart/Tooltip/types.d.ts +5 -5
  42. package/dist/charts/HorizontalBarChart/XScale/hooks/useScale.d.ts +2 -2
  43. package/dist/charts/HorizontalBarChart/XScale/index.d.ts +3 -3
  44. package/dist/charts/HorizontalBarChart/XScale/styled.d.ts +3 -3
  45. package/dist/charts/HorizontalBarChart/hooks/useMarshaling.d.ts +5 -5
  46. package/dist/charts/HorizontalBarChart/hooks/useStackWrapper.d.ts +12 -12
  47. package/dist/charts/HorizontalBarChart/hooks/useTooltip/index.d.ts +3 -3
  48. package/dist/charts/HorizontalBarChart/hooks/useTooltip/types.d.ts +6 -3
  49. package/dist/charts/HorizontalBarChart/index.d.ts +3 -3
  50. package/dist/charts/HorizontalBarChart/styled.d.ts +30 -30
  51. package/dist/charts/HorizontalBarChart/types.d.ts +41 -41
  52. package/dist/charts/LineChart/draw.d.ts +2 -2
  53. package/dist/charts/LineChart/drawGrid/index.d.ts +2 -2
  54. package/dist/charts/LineChart/drawGrid/types.d.ts +9 -9
  55. package/dist/charts/LineChart/drawLabel/index.d.ts +3 -3
  56. package/dist/charts/LineChart/drawLabel/styled.d.ts +2 -2
  57. package/dist/charts/LineChart/drawLabel/types.d.ts +7 -7
  58. package/dist/charts/LineChart/drawTooltip/index.d.ts +2 -2
  59. package/dist/charts/LineChart/drawTooltip/types.d.ts +9 -9
  60. package/dist/charts/LineChart/index.d.ts +3 -3
  61. package/dist/charts/LineChart/styled.d.ts +27 -27
  62. package/dist/charts/LineChart/types.d.ts +78 -78
  63. package/dist/charts/PieChart/draw.d.ts +2 -2
  64. package/dist/charts/PieChart/drawRadialLabels/helpers.d.ts +3 -3
  65. package/dist/charts/PieChart/drawRadialLabels/index.d.ts +2 -2
  66. package/dist/charts/PieChart/drawRadialLabels/types.d.ts +11 -11
  67. package/dist/charts/PieChart/drawTooltips/index.d.ts +2 -2
  68. package/dist/charts/PieChart/drawTooltips/types.d.ts +8 -8
  69. package/dist/charts/PieChart/index.d.ts +3 -3
  70. package/dist/charts/PieChart/styled.d.ts +18 -18
  71. package/dist/charts/PieChart/types.d.ts +54 -54
  72. package/dist/charts/RadarChart/draw.d.ts +2 -2
  73. package/dist/charts/RadarChart/drawRadialLabels/index.d.ts +2 -2
  74. package/dist/charts/RadarChart/drawRadialLabels/styled.d.ts +2 -2
  75. package/dist/charts/RadarChart/drawRadialLabels/types.d.ts +25 -25
  76. package/dist/charts/RadarChart/helpers.d.ts +2 -2
  77. package/dist/charts/RadarChart/index.d.ts +3 -3
  78. package/dist/charts/RadarChart/styled.d.ts +13 -13
  79. package/dist/charts/RadarChart/types.d.ts +42 -42
  80. package/dist/charts.esm.js +3327 -3297
  81. package/dist/charts.esm.js.map +1 -1
  82. package/dist/common/components/SwipeScroll/animate.d.ts +6 -6
  83. package/dist/common/components/SwipeScroll/hooks/useSwipe.d.ts +2 -2
  84. package/dist/common/components/SwipeScroll/index.d.ts +3 -3
  85. package/dist/common/components/SwipeScroll/styled.d.ts +1 -1
  86. package/dist/common/components/SwipeScroll/types.d.ts +8 -8
  87. package/dist/common/components/Wrapper.d.ts +1 -1
  88. package/dist/common/components/labels/index.d.ts +7 -7
  89. package/dist/common/components/labels/types.d.ts +6 -6
  90. package/dist/common/components/tooltips/index.d.ts +14 -14
  91. package/dist/common/types/interpolator.d.ts +1 -1
  92. package/dist/common/types/margin.d.ts +6 -6
  93. package/dist/helpers/appendSvg.d.ts +2 -2
  94. package/dist/helpers/common.d.ts +2 -2
  95. package/dist/helpers/computeDimensions.d.ts +2 -2
  96. package/dist/helpers/getLegend/index.d.ts +19 -19
  97. package/dist/helpers/getLegend/types.d.ts +15 -15
  98. package/dist/helpers/getTextWidth.d.ts +1 -1
  99. package/dist/helpers/index.d.ts +1 -1
  100. package/dist/helpers/math.d.ts +2 -2
  101. package/dist/helpers/stackedData.d.ts +2 -2
  102. package/dist/helpers/textAlignCenter.d.ts +2 -2
  103. package/dist/helpers/throttle.d.ts +1 -1
  104. package/dist/hooks/index.d.ts +2 -2
  105. package/dist/hooks/useNode.d.ts +2 -2
  106. package/dist/hooks/useResize.d.ts +1 -1
  107. package/dist/index.d.ts +26 -26
  108. package/dist/index.js +3553 -5
  109. package/dist/index.js.map +1 -0
  110. package/package.json +29 -40
  111. package/dist/charts.cjs.development.js +0 -3513
  112. package/dist/charts.cjs.development.js.map +0 -1
  113. package/dist/charts.cjs.production.min.js +0 -2
  114. package/dist/charts.cjs.production.min.js.map +0 -1
  115. package/dist/jest.config.d.ts +0 -14
  116. package/dist/stories/Bar/Examples.stories.d.ts +0 -23
  117. package/dist/stories/Bar/HorizontalBar.stories.d.ts +0 -25
  118. package/dist/stories/Bar/Statistics.stories.d.ts +0 -7
  119. package/dist/stories/Bar/VerticalBar.stories.d.ts +0 -41
  120. package/dist/stories/Bubble/Bubble.stories.d.ts +0 -23
  121. package/dist/stories/Bubble/Examples.stories.d.ts +0 -4
  122. package/dist/stories/Bubble/examples/VEB/InvestBubble.d.ts +0 -5
  123. package/dist/stories/Bubble/examples/VEB/hooks/useCustomize.d.ts +0 -3
  124. package/dist/stories/Bubble/examples/VEB/hooks/useRenderTooltip/index.d.ts +0 -4
  125. package/dist/stories/Bubble/examples/VEB/hooks/useRenderTooltip/styled.d.ts +0 -8
  126. package/dist/stories/Bubble/examples/VEB/styled.d.ts +0 -1
  127. package/dist/stories/Calendar/Calendar.stories.d.ts +0 -23
  128. package/dist/stories/Calendar/ColorScheme.stories.d.ts +0 -7
  129. package/dist/stories/Calendar/Examples.stories.d.ts +0 -11
  130. package/dist/stories/Calendar/Legend.stories.d.ts +0 -30
  131. package/dist/stories/Common/SwipeScroll/SwipeScroll.stories.d.ts +0 -13
  132. package/dist/stories/Common/SwipeScroll/hooks/useSwipe.d.ts +0 -1
  133. package/dist/stories/Line/Examples.stories.d.ts +0 -7
  134. package/dist/stories/Line/Line.stories.d.ts +0 -48
  135. package/dist/stories/Line/examples/Beeline.d.ts +0 -5
  136. package/dist/stories/Line/examples/GeoVeb.d.ts +0 -5
  137. package/dist/stories/Line/examples/GeoVebInterval/data.d.ts +0 -9
  138. package/dist/stories/Line/examples/GeoVebInterval/index.d.ts +0 -5
  139. package/dist/stories/Line/examples/GeoVebInterval/styled.d.ts +0 -4
  140. package/dist/stories/Line/examples/Msp.d.ts +0 -5
  141. package/dist/stories/Pie/ColorScheme.stories.d.ts +0 -7
  142. package/dist/stories/Pie/Examples.stories.d.ts +0 -7
  143. package/dist/stories/Pie/Pie.stories.d.ts +0 -47
  144. package/dist/stories/Radar/Chart.stories.d.ts +0 -38
  145. package/dist/stories/Radar/Github.stories.d.ts +0 -7
  146. package/dist/stories/Radar/Gradient.stories.d.ts +0 -7
  147. package/dist/stories/Radar/Veb.stories.d.ts +0 -7
  148. package/dist/stories/Sankey/Examples.stories.d.ts +0 -4
  149. package/dist/stories/Sankey/examples/RelatedIndustries/data.d.ts +0 -2
  150. package/dist/stories/Sankey/examples/RelatedIndustries/index.d.ts +0 -5
  151. package/dist/stories/__internal__/colors.d.ts +0 -40
  152. package/dist/stories/__internal__/components/BeelineLineChart/hooks/useCustomize.d.ts +0 -11
  153. package/dist/stories/__internal__/components/BeelineLineChart/hooks/useLineRenderTooltip/index.d.ts +0 -5
  154. package/dist/stories/__internal__/components/BeelineLineChart/hooks/useLineRenderTooltip/styled.d.ts +0 -5
  155. package/dist/stories/__internal__/components/BeelineLineChart/index.d.ts +0 -3
  156. package/dist/stories/__internal__/components/BeelineLineChart/styled.d.ts +0 -3
  157. package/dist/stories/__internal__/components/BeelineRangeLineChart/Range/index.d.ts +0 -7
  158. package/dist/stories/__internal__/components/BeelineRangeLineChart/Range/styled.d.ts +0 -3
  159. package/dist/stories/__internal__/components/BeelineRangeLineChart/hooks/useChange.d.ts +0 -8
  160. package/dist/stories/__internal__/components/BeelineRangeLineChart/index.d.ts +0 -2
  161. package/dist/stories/__internal__/components/BeelineRangeLineChart/styled.d.ts +0 -4
  162. package/dist/stories/__internal__/components/BeelineTrafficHorizontalBarChart/data.d.ts +0 -5
  163. package/dist/stories/__internal__/components/BeelineTrafficHorizontalBarChart/hooks/useRenderDataTable.d.ts +0 -2
  164. package/dist/stories/__internal__/components/BeelineTrafficHorizontalBarChart/index.d.ts +0 -2
  165. package/dist/stories/__internal__/components/BeelineTrafficHorizontalBarChart/styled.d.ts +0 -3
  166. package/dist/stories/__internal__/components/Divider.d.ts +0 -6
  167. package/dist/stories/__internal__/components/GeoVebBarCharts.d.ts +0 -2
  168. package/dist/stories/__internal__/components/GeoVebHorizontalBarCharts/data.d.ts +0 -47
  169. package/dist/stories/__internal__/components/GeoVebHorizontalBarCharts/hooks/useRenderTooltip.d.ts +0 -3
  170. package/dist/stories/__internal__/components/GeoVebHorizontalBarCharts/hooks/useSimpleRenderTooltip.d.ts +0 -3
  171. package/dist/stories/__internal__/components/GeoVebHorizontalBarCharts/index.d.ts +0 -4
  172. package/dist/stories/__internal__/components/GeoVebHorizontalBarCharts/styled.d.ts +0 -4
  173. package/dist/stories/__internal__/components/GeoYearsBarChart/index.d.ts +0 -2
  174. package/dist/stories/__internal__/components/GeoYearsBarChart/styled.d.ts +0 -4
  175. package/dist/stories/__internal__/components/MixedTableChart/Chart/index.d.ts +0 -3
  176. package/dist/stories/__internal__/components/MixedTableChart/Chart/styled.d.ts +0 -2
  177. package/dist/stories/__internal__/components/MixedTableChart/index.d.ts +0 -3
  178. package/dist/stories/__internal__/components/MixedTableChart/styled.d.ts +0 -5
  179. package/dist/stories/__internal__/components/MixedTableChart/types.d.ts +0 -21
  180. package/dist/stories/__internal__/components/MspDashboardChart/hooks/useAnimation.d.ts +0 -5
  181. package/dist/stories/__internal__/components/MspDashboardChart/index.d.ts +0 -3
  182. package/dist/stories/__internal__/components/MspDashboardChart/styled.d.ts +0 -5
  183. package/dist/stories/__internal__/components/MspPromSupplyBarChart/hooks/useAnimationAreas.d.ts +0 -6
  184. package/dist/stories/__internal__/components/MspPromSupplyBarChart/hooks/useAnimationBars.d.ts +0 -5
  185. package/dist/stories/__internal__/components/MspPromSupplyBarChart/hooks/useCustomize.d.ts +0 -4
  186. package/dist/stories/__internal__/components/MspPromSupplyBarChart/hooks/useData.d.ts +0 -8
  187. package/dist/stories/__internal__/components/MspPromSupplyBarChart/hooks/useMarshalledMap.d.ts +0 -1
  188. package/dist/stories/__internal__/components/MspPromSupplyBarChart/hooks/useRenderTooltip.d.ts +0 -2
  189. package/dist/stories/__internal__/components/MspPromSupplyBarChart/index.d.ts +0 -9
  190. package/dist/stories/__internal__/components/MspPromSupplyBarChart/styled.d.ts +0 -22
  191. package/dist/stories/__internal__/components/SankeyTriChart/Groups/getCSSProperties.d.ts +0 -4
  192. package/dist/stories/__internal__/components/SankeyTriChart/Groups/helpers.d.ts +0 -1
  193. package/dist/stories/__internal__/components/SankeyTriChart/Groups/index.d.ts +0 -5
  194. package/dist/stories/__internal__/components/SankeyTriChart/Groups/styled.d.ts +0 -1
  195. package/dist/stories/__internal__/components/SankeyTriChart/ItemContent/getCSSProperties.d.ts +0 -3
  196. package/dist/stories/__internal__/components/SankeyTriChart/ItemContent/index.d.ts +0 -5
  197. package/dist/stories/__internal__/components/SankeyTriChart/ItemContent/styled.d.ts +0 -8
  198. package/dist/stories/__internal__/components/SankeyTriChart/draw.d.ts +0 -2
  199. package/dist/stories/__internal__/components/SankeyTriChart/helpers.d.ts +0 -9
  200. package/dist/stories/__internal__/components/SankeyTriChart/index.d.ts +0 -10
  201. package/dist/stories/__internal__/components/SankeyTriChart/marshaling.d.ts +0 -6
  202. package/dist/stories/__internal__/components/SankeyTriChart/styled.d.ts +0 -1
  203. package/dist/stories/__internal__/components/SankeyTriChart/types.d.ts +0 -40
  204. package/dist/stories/__internal__/components/SberBarMixChart/colors.d.ts +0 -3
  205. package/dist/stories/__internal__/components/SberBarMixChart/data.d.ts +0 -8
  206. package/dist/stories/__internal__/components/SberBarMixChart/hooks/styled.d.ts +0 -3
  207. package/dist/stories/__internal__/components/SberBarMixChart/hooks/useRenderTooltip.d.ts +0 -2
  208. package/dist/stories/__internal__/components/SberBarMixChart/index.d.ts +0 -2
  209. package/dist/stories/__internal__/components/SberBarMixChart/styled.d.ts +0 -1
  210. package/dist/stories/__internal__/components/StatisticsBarCharts/NumbersStatistics.d.ts +0 -2
  211. package/dist/stories/__internal__/components/StatisticsBarCharts/StringsStatistics.d.ts +0 -2
  212. package/dist/stories/__internal__/components/StatisticsBarCharts/index.d.ts +0 -2
  213. package/dist/stories/__internal__/components/StatisticsBarCharts/styled.d.ts +0 -1
  214. package/dist/stories/__internal__/components/VebEstimationBarChart/data.d.ts +0 -38
  215. package/dist/stories/__internal__/components/VebEstimationBarChart/hooks/useCustomize.d.ts +0 -5
  216. package/dist/stories/__internal__/components/VebEstimationBarChart/hooks/useDrawBars.d.ts +0 -4
  217. package/dist/stories/__internal__/components/VebEstimationBarChart/hooks/useRenderLabel/index.d.ts +0 -9
  218. package/dist/stories/__internal__/components/VebEstimationBarChart/hooks/useRenderLabel/styled.d.ts +0 -1
  219. package/dist/stories/__internal__/components/VebEstimationBarChart/hooks/useRenderTooltip/index.d.ts +0 -8
  220. package/dist/stories/__internal__/components/VebEstimationBarChart/hooks/useRenderTooltip/styled.d.ts +0 -13
  221. package/dist/stories/__internal__/components/VebEstimationBarChart/index.d.ts +0 -3
  222. package/dist/stories/__internal__/components/VebEstimationBarChart/styled.d.ts +0 -2
  223. package/dist/stories/__internal__/components/VebFilterBarChart/index.d.ts +0 -2
  224. package/dist/stories/__internal__/components/VebGroupHorizontalBarChart/hooks/useRenderSum/index.d.ts +0 -3
  225. package/dist/stories/__internal__/components/VebGroupHorizontalBarChart/hooks/useRenderSum/styled.d.ts +0 -1
  226. package/dist/stories/__internal__/components/VebGroupHorizontalBarChart/hooks/useRenderTooltip/index.d.ts +0 -1
  227. package/dist/stories/__internal__/components/VebGroupHorizontalBarChart/hooks/useRenderTooltip/styled.d.ts +0 -5
  228. package/dist/stories/__internal__/components/VebGroupHorizontalBarChart/index.d.ts +0 -3
  229. package/dist/stories/__internal__/components/VebGroupHorizontalBarChart/styled.d.ts +0 -5
  230. package/dist/stories/__internal__/components/VebGroupHorizontalBarChart/types.d.ts +0 -11
  231. package/dist/stories/__internal__/curves.d.ts +0 -8
  232. package/dist/stories/__internal__/data/msp.d.ts +0 -14
  233. package/dist/stories/__internal__/data/mspDashboard.d.ts +0 -1
  234. package/dist/stories/__internal__/data/mspPromSupply.d.ts +0 -11
  235. package/dist/stories/__internal__/data/population.d.ts +0 -4
  236. package/dist/stories/__internal__/data/veb.d.ts +0 -31
  237. package/dist/stories/__internal__/helpers/Path.d.ts +0 -10
  238. package/dist/stories/__internal__/helpers/Vector.d.ts +0 -9
  239. package/dist/stories/__internal__/helpers/animation.d.ts +0 -15
  240. package/dist/stories/__internal__/helpers/hexToRGB.d.ts +0 -1
  241. package/dist/stories/__internal__/helpers/random.d.ts +0 -1
  242. package/dist/stories/__internal__/helpers/randomData.d.ts +0 -14
  243. package/dist/stories/__internal__/helpers/randomHorizontalBarData.d.ts +0 -5
  244. package/dist/stories/__internal__/helpers/randomIntervalData.d.ts +0 -11
  245. package/dist/stories/__internal__/helpers/randomLineData.d.ts +0 -8
  246. package/dist/stories/__internal__/helpers/randomText.d.ts +0 -1
  247. package/dist/stories/__internal__/helpers/roundedRect.d.ts +0 -10
  248. package/dist/stories/__internal__/helpers/shuffleArray.d.ts +0 -1
  249. package/dist/stories/__internal__/hooks/useBarData.d.ts +0 -10
  250. package/dist/stories/__internal__/hooks/useLegend.d.ts +0 -1
  251. package/dist/stories/__internal__/hooks/useMinMaxValue.d.ts +0 -4
  252. package/dist/stories/__internal__/interpolates.d.ts +0 -23
  253. package/dist/storybook-static/1.05dfd83c.iframe.bundle.d.ts +0 -0
  254. package/dist/storybook-static/189.8c077122866758d3cf20.manager.bundle.d.ts +0 -0
  255. package/dist/storybook-static/190.58050c9beb344d4cefd9.manager.bundle.d.ts +0 -2
  256. package/dist/storybook-static/191.b202c06c72968435b80b.manager.bundle.d.ts +0 -0
  257. package/dist/storybook-static/192.83987c5b15f8a80893c5.manager.bundle.d.ts +0 -0
  258. package/dist/storybook-static/193.8a12aa992b466e778018.manager.bundle.d.ts +0 -2
  259. package/dist/storybook-static/2.0231c7b6.iframe.bundle.d.ts +0 -0
  260. package/dist/storybook-static/6.6185fd0d.iframe.bundle.d.ts +0 -0
  261. package/dist/storybook-static/7.0ede09e9.iframe.bundle.d.ts +0 -0
  262. package/dist/storybook-static/8.6f0230ef.iframe.bundle.d.ts +0 -2
  263. package/dist/storybook-static/main.6b7543c14993fcfcab71.manager.bundle.d.ts +0 -2
  264. package/dist/storybook-static/main.724b5942.iframe.bundle.d.ts +0 -9
  265. package/dist/storybook-static/runtime~main.92273705.iframe.bundle.d.ts +0 -1
  266. package/dist/storybook-static/runtime~main.c89e55a461c11ef29193.manager.bundle.d.ts +0 -1
package/dist/index.js CHANGED
@@ -1,8 +1,3556 @@
1
+ 'use strict';
1
2
 
2
- 'use strict'
3
+ var styled = require('styled-components');
4
+ var react = require('react');
5
+ var d3 = require('d3');
6
+ var jsxRuntime = require('react/jsx-runtime');
7
+ var ReactDOMServer = require('react-dom/server');
8
+ var lodash = require('lodash');
9
+ var reactDom = require('react-dom');
3
10
 
4
- if (process.env.NODE_ENV === 'production') {
5
- module.exports = require('./charts.cjs.production.min.js')
6
- } else {
7
- module.exports = require('./charts.cjs.development.js')
11
+ function _interopNamespaceDefault(e) {
12
+ var n = Object.create(null);
13
+ if (e) {
14
+ Object.keys(e).forEach(function (k) {
15
+ if (k !== 'default') {
16
+ var d = Object.getOwnPropertyDescriptor(e, k);
17
+ Object.defineProperty(n, k, d.get ? d : {
18
+ enumerable: true,
19
+ get: function () { return e[k]; }
20
+ });
21
+ }
22
+ });
23
+ }
24
+ n.default = e;
25
+ return Object.freeze(n);
8
26
  }
27
+
28
+ var d3__namespace = /*#__PURE__*/_interopNamespaceDefault(d3);
29
+
30
+ const Wrapper = styled.div `
31
+ position: relative;
32
+ width: 100%;
33
+ box-sizing: border-box;
34
+ `;
35
+
36
+ function useNode() {
37
+ const [node, onSetNode] = react.useState(null);
38
+ const ref = react.useCallback(onSetNode, [onSetNode]);
39
+ return [ref, node];
40
+ }
41
+
42
+ function throttle(fn, wait) {
43
+ let isCalled = false;
44
+ return function (...args) {
45
+ if (!isCalled) {
46
+ fn(...args);
47
+ isCalled = true;
48
+ setTimeout(function () {
49
+ isCalled = false;
50
+ }, wait);
51
+ }
52
+ };
53
+ }
54
+
55
+ const THROTTLE_DELAY = 44;
56
+ const useResize = (width, callback, delay) => {
57
+ const throttledCallback = react.useMemo(() => {
58
+ return callback ? throttle(callback, delay || THROTTLE_DELAY) : undefined;
59
+ }, [callback, delay]);
60
+ react.useEffect(() => {
61
+ throttledCallback &&
62
+ typeof width !== "number" &&
63
+ window.addEventListener("resize", throttledCallback);
64
+ return () => throttledCallback &&
65
+ window.removeEventListener("resize", throttledCallback);
66
+ }, [width, throttledCallback]);
67
+ };
68
+
69
+ const appendSvg = (node, width, height) => {
70
+ d3__namespace.select(node)
71
+ .select('svg')
72
+ .remove();
73
+ const svg = d3__namespace
74
+ .select(node)
75
+ .append('svg')
76
+ .attr('width', width)
77
+ .attr('height', height);
78
+ return svg;
79
+ };
80
+
81
+ const SwipeScrollContainer = styled.div `
82
+ width: 100%;
83
+ overflow: hidden;
84
+ user-select: none;
85
+ `;
86
+
87
+ function animate({ duration, timing, draw, }) {
88
+ const start = performance.now();
89
+ let requestId;
90
+ requestAnimationFrame(function requestAnimate(time) {
91
+ let timeFraction = (time - start) / duration;
92
+ if (timeFraction < 1) {
93
+ requestId = requestAnimationFrame(requestAnimate);
94
+ }
95
+ if (timeFraction > 1)
96
+ cancelAnimationFrame(requestId);
97
+ const progress = timing(timeFraction);
98
+ draw(progress, requestId);
99
+ });
100
+ }
101
+ const easeOutQuad = (time) => time * (2 - time);
102
+
103
+ const range = (num, min, max) => Math.min(Math.max(num, min), max);
104
+ const defaultRefs = {
105
+ animation: 0,
106
+ speed: 0,
107
+ timestamp: 0,
108
+ startX: 0,
109
+ currentX: 0,
110
+ };
111
+ const useSwipe = (node, { width, duration, animationFunc, onSwipe }) => {
112
+ const container = d3__namespace.select(node);
113
+ const body = d3__namespace.select('body');
114
+ const documentSelect = d3__namespace.select(document);
115
+ const refs = react.useRef(defaultRefs);
116
+ react.useEffect(() => {
117
+ if (width && refs.current.animation) {
118
+ cancelAnimationFrame(refs.current.animation);
119
+ refs.current = defaultRefs;
120
+ }
121
+ }, [width]);
122
+ const onMove = react.useCallback((event) => {
123
+ const { width: nodeWidth } = node
124
+ ? node.getBoundingClientRect()
125
+ : { width: 0 };
126
+ const [x] = d3__namespace.pointer(event.type.includes('touch') ? event.touches[0] : event);
127
+ const newX = x - refs.current.startX;
128
+ const maxX = width - nodeWidth;
129
+ const translateX = range(newX, -maxX, 0);
130
+ container.style('transform', `translateX(${translateX}px)`);
131
+ if (refs.current.currentX) {
132
+ const hundred = 100;
133
+ const now = Date.now();
134
+ const dt = now - refs.current.timestamp;
135
+ const dx = translateX - refs.current.currentX;
136
+ const speedX = Math.round((dx / dt) * hundred);
137
+ refs.current.speed = speedX;
138
+ refs.current.timestamp = now;
139
+ }
140
+ refs.current.currentX = translateX;
141
+ onSwipe && onSwipe(translateX, container);
142
+ }, [onSwipe, width, node, container]);
143
+ const onEnd = react.useCallback(() => {
144
+ const { width: nodeWidth } = node
145
+ ? node.getBoundingClientRect()
146
+ : { width: 0 };
147
+ documentSelect.on('mousemove.swipe touchmove.swipe mouseup.swipe touchend.swipe', null);
148
+ body.style('cursor', null);
149
+ if (width > nodeWidth) {
150
+ container.style('cursor', 'grab');
151
+ }
152
+ else {
153
+ container.style('cursor', null);
154
+ }
155
+ const dt = Date.now() - refs.current.timestamp;
156
+ const dtEnd = 44;
157
+ if (dt < dtEnd) {
158
+ animate({
159
+ duration: duration,
160
+ timing: animationFunc || easeOutQuad,
161
+ draw: (progress, requestId) => {
162
+ refs.current.animation = requestId;
163
+ const px = Math.round(refs.current.speed * 2 * progress);
164
+ const currX = refs.current.currentX + px;
165
+ const maxX = width - nodeWidth;
166
+ const translateX = range(currX, -maxX, 0);
167
+ const transX = Math.max(Math.min(currX, maxX), 0);
168
+ if (refs.current.currentX !== transX) {
169
+ container.style('transform', `translateX(${translateX}px)`);
170
+ onSwipe && onSwipe(translateX, container);
171
+ }
172
+ },
173
+ });
174
+ }
175
+ }, [
176
+ body,
177
+ animationFunc,
178
+ onSwipe,
179
+ container,
180
+ duration,
181
+ node,
182
+ width,
183
+ documentSelect,
184
+ ]);
185
+ const onStart = react.useCallback((event) => {
186
+ const isTouch = event.type.includes('touch');
187
+ const [x] = d3__namespace.pointer(isTouch ? event.touches[0] : event, node);
188
+ const { left } = node && node.parentElement
189
+ ? node.parentElement.getBoundingClientRect()
190
+ : { left: 0 };
191
+ body.style('cursor', 'grabbing');
192
+ container.style('cursor', 'grabbing');
193
+ if (refs.current.animation) {
194
+ cancelAnimationFrame(refs.current.animation);
195
+ refs.current = defaultRefs;
196
+ }
197
+ refs.current.startX = Math.max(x + left, 0);
198
+ documentSelect.on('mousemove.swipe touchmove.swipe', onMove);
199
+ documentSelect.on('mouseup.swipe touchend.swipe', onEnd);
200
+ }, [container, body, node, onEnd, onMove, documentSelect]);
201
+ react.useEffect(() => {
202
+ if (node) {
203
+ const { width: nodeWidth } = node.getBoundingClientRect();
204
+ if (width > nodeWidth) {
205
+ container.style('cursor', 'grab');
206
+ container.on('mousedown.swipe touchstart.swipe', onStart);
207
+ }
208
+ }
209
+ }, [container, onStart, node, width]);
210
+ };
211
+
212
+ const SwipeScroll = ({ children, width, onSwipe, ...props }) => {
213
+ const [ref, draggingNode] = useNode();
214
+ useSwipe(draggingNode, { width, onSwipe, ...props });
215
+ return (jsxRuntime.jsx(SwipeScrollContainer, { ...props, children: jsxRuntime.jsx("div", { ref: ref, children: children }) }));
216
+ };
217
+ SwipeScroll.defaultProps = {
218
+ duration: 1400,
219
+ };
220
+
221
+ const getTranslate$1 = ({ anchor, index, translateX, translateY, }) => {
222
+ if (index === 0 && anchor === "middle") {
223
+ return `translate(calc(-50% + ${translateX}px), calc(-100% + ${translateY}px))`;
224
+ }
225
+ else if (anchor === "middle") {
226
+ return `translate(calc(-50% + ${translateX}px), calc(${translateY}px))`;
227
+ }
228
+ else if (anchor === "start") {
229
+ return `translate(calc(${translateX}px), calc(-50% + ${translateY}px))`;
230
+ }
231
+ else if (anchor === "end") {
232
+ return `translate(calc(-100% + ${translateX}px), calc(-50% + ${translateY}px))`;
233
+ }
234
+ return `translate(${translateX}px, ${translateY}px)`;
235
+ };
236
+ const Label$2 = styled.div `
237
+ display: flex;
238
+ align-items: center;
239
+ font-size: 12px;
240
+ `;
241
+ const Name$1 = styled.div `
242
+ text-align: center;
243
+ max-width: 120px;
244
+ `;
245
+ const middleBadgeStyles = styled.css `
246
+ position: absolute;
247
+ top: 50%;
248
+ right: 0;
249
+ transform: translate(calc(100% + 6px), -50%);
250
+ `;
251
+ const DefaultBadge = styled.div `
252
+ display: flex;
253
+ align-items: center;
254
+ padding: 2px 4px;
255
+ border-radius: 4px;
256
+ color: rgb(255, 255, 255);
257
+ background-color: rgb(144, 197, 61);
258
+ margin-left: 8px;
259
+ `;
260
+ const MiddleBadge = styled(DefaultBadge) `
261
+ ${middleBadgeStyles}
262
+ `;
263
+ const BadgePrefix = styled.div `
264
+ margin-left: 4px;
265
+ font-size: 10px;
266
+ color: rgba(255, 255, 255, 0.54);
267
+ `;
268
+
269
+ const radarChartclassNames = {
270
+ radar: 'radar',
271
+ radarAxis: 'radarAxis',
272
+ radarAxisTextGlobal: 'radarAxisTextGlobal',
273
+ radarAxisText: 'radarAxisText',
274
+ radarPolygon: 'radarPolygon',
275
+ radarLabel: 'radarLabel',
276
+ radarLabelName: 'radarLabelName',
277
+ radarLabelBadge: 'radarLabelBadge',
278
+ radarLabelBadgePrefix: 'radarLabelBadgePrefix',
279
+ radarCircle: 'radarCircle',
280
+ };
281
+ const SvgWrapper$5 = styled(Wrapper) `
282
+ .${radarChartclassNames.radarAxis} {
283
+ path,
284
+ line,
285
+ circle {
286
+ fill: none;
287
+ stroke-width: 1px;
288
+ stroke: rgba(149, 149, 149, 0.18);
289
+ }
290
+ }
291
+ .${radarChartclassNames.radarAxisText} {
292
+ font-size: 12px;
293
+ fill-opacity: 0.56;
294
+ }
295
+ .${radarChartclassNames.radarPolygon} {
296
+ fill-opacity: 0.06;
297
+ stroke-width: 2px;
298
+ fill: rgb(144, 197, 61);
299
+ stroke: rgb(144, 197, 61);
300
+ }
301
+ .${radarChartclassNames.radarCircle} {
302
+ fill: rgb(144, 197, 61);
303
+ }
304
+ `;
305
+
306
+ const getTranslate = ({ anchor, index, translateX, translateY, }) => {
307
+ if (index === 0 && anchor === 'middle') {
308
+ return `translate(calc(-50% + ${translateX}px), calc(-100% + ${translateY}px))`;
309
+ }
310
+ else if (anchor === 'middle') {
311
+ return `translate(calc(-50% + ${translateX}px), calc(${translateY}px))`;
312
+ }
313
+ else if (anchor === 'start') {
314
+ return `translate(calc(${translateX}px), calc(-50% + ${translateY}px))`;
315
+ }
316
+ else if (anchor === 'end') {
317
+ return `translate(calc(-100% + ${translateX}px), calc(-50% + ${translateY}px))`;
318
+ }
319
+ return `translate(${translateX}px, ${translateY}px)`;
320
+ };
321
+ const LabelContainer$1 = styled.div.attrs(props => ({
322
+ style: {
323
+ transform: getTranslate(props),
324
+ },
325
+ })) `
326
+ position: absolute;
327
+ `;
328
+
329
+ const degByIndex = (index, count) => {
330
+ const degs = 360;
331
+ const deg = (degs / count) * index;
332
+ return deg;
333
+ };
334
+ const getTextAnchor = (index, length) => {
335
+ const deg = degByIndex(index, length);
336
+ const halfAngle = 180;
337
+ if ([0, halfAngle].includes(deg)) {
338
+ return 'middle';
339
+ }
340
+ if (deg < halfAngle) {
341
+ return 'start';
342
+ }
343
+ return 'end';
344
+ };
345
+
346
+ const labelClassName$1 = "d3-chart-label";
347
+ const drawRadialLabels$1 = ({ node, dataLength, radiusScale, maxValue, angleSlice, radius, xOffset, yOffset, translateX, translateY, renderLabel, selectLabel, }) => {
348
+ const d3container = d3__namespace.select(node);
349
+ d3container.selectAll(`.${labelClassName$1}`).remove();
350
+ const pxToValue = (value) => (maxValue / radius) * value;
351
+ const axisX = (i) => radiusScale(maxValue + pxToValue(xOffset || 0)) *
352
+ Math.cos(angleSlice * i - Math.PI / 2);
353
+ const axisY = (i) => radiusScale((maxValue + pxToValue(yOffset || 0)) *
354
+ Math.sin(angleSlice * i - Math.PI / 2));
355
+ const labels = Array.from({ length: dataLength }, (_, index) => ({
356
+ x: Math.ceil(axisX(index)),
357
+ y: Math.ceil(axisY(index)),
358
+ }));
359
+ labels.forEach(({ x, y }, index) => {
360
+ const anchor = getTextAnchor(index, dataLength);
361
+ const html = ReactDOMServer.renderToString(jsxRuntime.jsx(LabelContainer$1, { anchor: anchor, translateX: translateX || 0, translateY: translateY || 0, index: index, style: {
362
+ left: x,
363
+ top: y,
364
+ }, children: typeof renderLabel === "function"
365
+ ? renderLabel(anchor, index)
366
+ : renderLabel }));
367
+ const label = d3container
368
+ .append("div")
369
+ .attr("class", labelClassName$1)
370
+ .html(html);
371
+ selectLabel(label, anchor, index);
372
+ });
373
+ };
374
+
375
+ const draw$5 = (node, props) => {
376
+ const { data, curve, polar, formatValue, badgePrefix, labelOffset, circleRadius, svgElements, renderLabel, customize, formatAxisValue, radarStyles, labelIndex, selectLabel, } = props;
377
+ if (node !== null && data.length) {
378
+ const defaultBleedLength = 10;
379
+ const bleedLength = typeof props.bleedLength === "number"
380
+ ? props.bleedLength
381
+ : defaultBleedLength;
382
+ const { width: nodeWidth } = node.getBoundingClientRect();
383
+ const width = props.width || nodeWidth;
384
+ const defaultHeight = 400;
385
+ const height = props.height || defaultHeight;
386
+ const minValue = props.minValue ||
387
+ Math.min(0, d3__namespace.min(data, i => d3__namespace.min(i.map(({ value }) => value))));
388
+ const maxValue = (props.maxValue ||
389
+ Math.max(0, d3__namespace.max(data, i => d3__namespace.max(i.map(({ value }) => value))))) - minValue;
390
+ const paddingX = props.paddingX || 0;
391
+ const paddingY = props.paddingY || 0;
392
+ const radius = Math.min((width - paddingX * 2 - bleedLength * 2) / 2, (height - paddingY * 2 - bleedLength * 2) / 2);
393
+ const defaultLevels = 4;
394
+ const ticks = d3__namespace
395
+ .scaleLinear()
396
+ .domain([0, maxValue || 1])
397
+ .range([])
398
+ .ticks(props.levels || defaultLevels);
399
+ const lastTick = ticks[ticks.length - 1];
400
+ const newLastTick = lastTick + (ticks[1] - ticks[0]);
401
+ if (lastTick < maxValue) {
402
+ ticks.push(newLastTick);
403
+ }
404
+ const levels = props.levels || ticks.length - 1;
405
+ const newMaxValue = ticks[ticks.length - 1];
406
+ const angleSlice = (Math.PI * 2) / data[0].length;
407
+ const radiusScale = d3__namespace
408
+ .scaleLinear()
409
+ .range([0, radius])
410
+ .domain([0, newMaxValue]);
411
+ const radarLine = d3__namespace
412
+ .lineRadial()
413
+ .curve(d3__namespace.curveLinearClosed)
414
+ // @ts-ignore
415
+ .radius(({ value }) => radiusScale(value))
416
+ .angle((_, i) => i * angleSlice);
417
+ const radarValue = d3__namespace
418
+ .lineRadial()
419
+ .curve(curve || d3__namespace.curveLinearClosed)
420
+ // @ts-ignore
421
+ .radius(({ value }) => radiusScale(value))
422
+ .angle((_, i) => i * angleSlice);
423
+ const svg = appendSvg(node, width, height);
424
+ const globalCenter = svg.append("g");
425
+ const levelsGrid = d3__namespace.range(1, levels + 1).reverse();
426
+ const axisGridY = (value) => (-value * radius) / levels;
427
+ const getAxisValue = (value) => (newMaxValue * value) / levels;
428
+ const gridGlobal = globalCenter
429
+ .append("g")
430
+ .attr("class", radarChartclassNames.radarAxis)
431
+ .selectAll()
432
+ .data([data[0]])
433
+ .enter();
434
+ const radarGlobal = globalCenter
435
+ .append("g")
436
+ .attr("class", radarChartclassNames.radar);
437
+ const axis = gridGlobal
438
+ .selectAll()
439
+ .data(data[0].map(({ name }) => name))
440
+ .enter();
441
+ let maxGridHeight = 0;
442
+ if (polar) {
443
+ levelsGrid.forEach(value => {
444
+ const path = gridGlobal
445
+ .append("circle")
446
+ .attr("cx", 0)
447
+ .attr("cy", 0)
448
+ .attr("r", () => (radius / levels) * value);
449
+ const circleNode = path.node();
450
+ const circleHeight = circleNode.getBoundingClientRect().height;
451
+ maxGridHeight = Math.max(maxGridHeight, circleHeight);
452
+ });
453
+ }
454
+ else {
455
+ levelsGrid.map(getAxisValue).forEach(value => {
456
+ const path = gridGlobal.append("path").attr("d", () =>
457
+ // @ts-ignore
458
+ radarLine(Array.from({ length: data[0].length }, () => ({ value }))));
459
+ const pathNode = path.node();
460
+ const pathHeight = pathNode.getBoundingClientRect().height;
461
+ maxGridHeight = Math.max(maxGridHeight, pathHeight);
462
+ });
463
+ }
464
+ const radiusByMaxValue = radiusScale(newMaxValue) + bleedLength;
465
+ axis
466
+ .append("line")
467
+ .attr("x1", 0)
468
+ .attr("y1", 0)
469
+ .attr("x2", (_, i) => Math.round(radiusByMaxValue * Math.cos(angleSlice * i - Math.PI / 2)))
470
+ .attr("y2", (_, i) => Math.round(radiusByMaxValue * Math.sin(angleSlice * i - Math.PI / 2)));
471
+ radarGlobal
472
+ .selectAll("path")
473
+ .data(data)
474
+ .join("path")
475
+ .attr("class", radarChartclassNames.radarPolygon)
476
+ .attr("style", (_, index) => radarStyles?.[index] || "")
477
+ .attr("d", d => radarValue(
478
+ // @ts-ignore
479
+ d.map(dataItem => ({
480
+ ...dataItem,
481
+ value: dataItem.value - minValue,
482
+ }))));
483
+ const format = d3__namespace.format(",");
484
+ const axisTextGlobal = globalCenter
485
+ .append("g")
486
+ .attr("class", radarChartclassNames.radarAxisTextGlobal);
487
+ axisTextGlobal
488
+ .selectAll("text")
489
+ .data(levelsGrid)
490
+ .enter()
491
+ .append("text")
492
+ .attr("class", radarChartclassNames.radarAxisText)
493
+ .attr("x", "4")
494
+ .attr("y", axisGridY)
495
+ .attr("dy", 0)
496
+ .attr("dominant-baseline", "central")
497
+ .text((value, index) => {
498
+ const axisValue = getAxisValue(value) + minValue;
499
+ return formatAxisValue
500
+ ? formatAxisValue(axisValue, index)
501
+ : format(axisValue);
502
+ });
503
+ circleRadius &&
504
+ data.forEach(item => {
505
+ const circleGlobal = globalCenter
506
+ .append("g")
507
+ .attr("class", radarChartclassNames.radarCircle);
508
+ item.forEach(({ value }, i) => {
509
+ circleGlobal
510
+ .append("circle")
511
+ .attr("cx", Math.round(radiusScale(value) *
512
+ Math.cos(angleSlice * i - Math.PI / 2)))
513
+ .attr("cy", Math.round(radiusScale(value * Math.sin(angleSlice * i - Math.PI / 2))))
514
+ .attr("r", circleRadius);
515
+ });
516
+ });
517
+ const defaultLabelOffset = 8;
518
+ const heightInner = height - bleedLength - paddingY;
519
+ const translateX = width / 2;
520
+ const translateY = heightInner / 2 + (heightInner - maxGridHeight) / 2;
521
+ const offset = bleedLength + (labelOffset || defaultLabelOffset);
522
+ globalCenter.attr("transform", `translate(${translateX},${translateY})`);
523
+ drawRadialLabels$1({
524
+ node,
525
+ maxValue: newMaxValue,
526
+ translateX,
527
+ translateY,
528
+ dataLength: data[labelIndex || 0].length,
529
+ angleSlice,
530
+ radius,
531
+ radiusScale,
532
+ xOffset: offset,
533
+ yOffset: offset,
534
+ renderLabel: (anchor, index) => {
535
+ const items = data.map(item => item[index]);
536
+ const Badge = anchor === "middle" ? MiddleBadge : DefaultBadge;
537
+ const item = data[labelIndex || 0][index];
538
+ const { name, value } = item;
539
+ return renderLabel ? (renderLabel({ item, items, anchor, index })) : (jsxRuntime.jsxs(Label$2, { className: radarChartclassNames.radarLabel, children: [jsxRuntime.jsx(Name$1, { className: radarChartclassNames.radarLabelName, children: name }), jsxRuntime.jsxs(Badge, { className: radarChartclassNames.radarLabelBadge, children: [formatValue ? formatValue(value, index) : format(value), badgePrefix && (jsxRuntime.jsx(BadgePrefix, { className: radarChartclassNames.radarLabelBadgePrefix, children: badgePrefix }))] })] }));
540
+ },
541
+ selectLabel: (label, anchor, index) => {
542
+ if (selectLabel) {
543
+ const items = data.map(item => item[index]);
544
+ const item = data[labelIndex || 0][index];
545
+ selectLabel(label, { index, item, items, anchor });
546
+ }
547
+ },
548
+ });
549
+ if (svgElements) {
550
+ const html = ReactDOMServer.renderToString(svgElements);
551
+ svg.append("g").html(html);
552
+ }
553
+ customize && customize(svg);
554
+ }
555
+ };
556
+
557
+ const RadarChart = (props) => {
558
+ const { className, style } = props;
559
+ const [ref, node] = useNode();
560
+ react.useEffect(() => {
561
+ node && draw$5(node, props);
562
+ }, [node, props]);
563
+ const onDraw = () => draw$5(node, props);
564
+ useResize(props.width, onDraw);
565
+ return (jsxRuntime.jsx("div", { className: className, style: style, children: jsxRuntime.jsx(SvgWrapper$5, { ref: ref }) }));
566
+ };
567
+ RadarChart.defaultProps = {
568
+ height: 400,
569
+ data: [],
570
+ curve: d3__namespace.curveLinearClosed,
571
+ };
572
+
573
+ function radiansToDegrees(radians) {
574
+ const flatAngle = 180;
575
+ return (radians * flatAngle) / Math.PI;
576
+ }
577
+ function degreesToRadians(degrees) {
578
+ const flatAngle = 180;
579
+ return degrees * (Math.PI / flatAngle);
580
+ }
581
+
582
+ const pieChartclassNames = {
583
+ pieGlobal: 'pieGlobal',
584
+ pieSlice: 'pieSlice',
585
+ pieSliceLabel: 'pieSliceLabel',
586
+ pieSliceLabelValue: 'pieSliceLabelValue',
587
+ pieSliceLabelName: 'pieSliceLabelName',
588
+ pieRadialLabel: 'pieRadialLabel',
589
+ pieRadialLink: 'pieRadialLink',
590
+ pieTooltipContainer: 'pieTooltipContainer',
591
+ pieTooltipFlex: 'pieTooltipFlex',
592
+ pieTooltip: 'pieTooltip',
593
+ pieTooltipItem: 'pieTooltipItem',
594
+ pieTooltipName: 'pieTooltipName',
595
+ pieTooltipValue: 'pieTooltipValue',
596
+ pieTooltipColorBox: 'pieTooltipColorBox',
597
+ pieFullChartTooltipCircle: 'pieFullChartTooltipCircle',
598
+ };
599
+ const SvgWrapper$4 = styled(Wrapper) `
600
+ .${pieChartclassNames.pieSliceLabel} {
601
+ fill: #4a4a4a;
602
+ }
603
+ .${pieChartclassNames.pieRadialLabel} {
604
+ position: absolute;
605
+ max-width: 128px;
606
+ }
607
+ .${pieChartclassNames.pieRadialLink} {
608
+ stroke: #000;
609
+ }
610
+ .${pieChartclassNames.pieFullChartTooltipCircle} {
611
+ fill: transparent;
612
+ cursor: pointer;
613
+ }
614
+ `;
615
+
616
+ const getMidFactor = (d) => d.startAngle + (d.endAngle - d.startAngle) / 2 < Math.PI ? 1 : -1;
617
+ const getAlign = (d) => {
618
+ const midangle = d.startAngle + (d.endAngle - d.startAngle) / 2;
619
+ return midangle < Math.PI ? 'start' : 'end';
620
+ };
621
+
622
+ const drawRadialLabels = ({ arc, enableRadialLabels, global, node, radius, dataReady, radialLabelsLinkHorizontalLength, formatRadialLabel, radialLabelsTextXOffset, translateX, translateY, radialLabelYOffset, radialAngleXOffset, }) => {
623
+ const d3container = d3__namespace.select(node);
624
+ d3container.selectAll(`.${pieChartclassNames.pieRadialLabel}`).remove();
625
+ if (enableRadialLabels) {
626
+ const defaultRadialLabelsLinkHorizontalLength = 4;
627
+ const outerArc = d3__namespace
628
+ .arc()
629
+ .innerRadius(radius)
630
+ .outerRadius(radius);
631
+ global
632
+ .selectAll("allPolylines")
633
+ .data(dataReady)
634
+ .enter()
635
+ .append("polyline")
636
+ .attr("class", pieChartclassNames.pieRadialLink)
637
+ .style("fill", "none")
638
+ .attr("points", (d) => {
639
+ const midFactor = getMidFactor(d);
640
+ const posA = arc.centroid(d);
641
+ const posB = outerArc.centroid(d);
642
+ const posC = outerArc.centroid(d);
643
+ const posCPi = [
644
+ (radius +
645
+ (radialLabelsLinkHorizontalLength ||
646
+ defaultRadialLabelsLinkHorizontalLength)) *
647
+ midFactor,
648
+ posC[1],
649
+ ];
650
+ return [
651
+ [posA[0], posA[1]],
652
+ [
653
+ posB[0] + (radialAngleXOffset || 0) * midFactor,
654
+ posB[1] - (radialLabelYOffset || 0) * d.index,
655
+ ],
656
+ [posCPi[0], posCPi[1] - (radialLabelYOffset || 0) * d.index],
657
+ ];
658
+ });
659
+ const getPosition = (d) => {
660
+ const pos = outerArc.centroid(d);
661
+ return [
662
+ (radius +
663
+ (radialLabelsLinkHorizontalLength ||
664
+ defaultRadialLabelsLinkHorizontalLength)) *
665
+ getMidFactor(d),
666
+ pos[1],
667
+ ];
668
+ };
669
+ const defaultRadialLabelsTextXOffset = 4;
670
+ d3container
671
+ .selectAll("allLabels")
672
+ .data(dataReady)
673
+ .enter()
674
+ .append("div")
675
+ // @ts-ignore
676
+ .html((d) => {
677
+ const html = ReactDOMServer.renderToString(
678
+ // @ts-ignore
679
+ formatRadialLabel ? formatRadialLabel(d) : d.data.name);
680
+ return html;
681
+ })
682
+ .attr("class", pieChartclassNames.pieRadialLabel)
683
+ // @ts-ignore
684
+ .style("transform", (d) => getTranslate$1({
685
+ anchor: getAlign(d),
686
+ index: d.index,
687
+ translateX,
688
+ translateY: translateY - (radialLabelYOffset || 0) * d.index,
689
+ }))
690
+ // @ts-ignore
691
+ .style("left",
692
+ // @ts-ignore
693
+ (d) => `${getPosition(d)[0] -
694
+ (getAlign(d) === "start"
695
+ ? -(radialLabelsTextXOffset || defaultRadialLabelsTextXOffset)
696
+ : radialLabelsTextXOffset || defaultRadialLabelsTextXOffset)}px`)
697
+ // @ts-ignore
698
+ .style("top", (d) => `${getPosition(d)[1]}px`)
699
+ // @ts-ignore
700
+ .style("text-align", getAlign);
701
+ }
702
+ };
703
+
704
+ const TooltipFlex$1 = styled.div `
705
+ width: 0;
706
+ height: 0;
707
+ display: flex;
708
+ align-items: flex-end;
709
+ justify-content: center;
710
+ pointer-events: none;
711
+ white-space: nowrap;
712
+ `;
713
+ const LabelFlex = styled(TooltipFlex$1) ``;
714
+ const LabelFlexCenter = styled(LabelFlex) `
715
+ align-items: center;
716
+ `;
717
+ const TooltipContainer = styled.div `
718
+ position: relative;
719
+ font-size: 11px;
720
+ color: #fff;
721
+ margin-bottom: 8px;
722
+ padding: 4px 6px;
723
+ background-color: rgba(48, 69, 79, 1);
724
+ border-radius: 4px;
725
+ box-shadow: 0 0.1875rem 0.5rem rgba(48, 69, 79, 0.06);
726
+
727
+ :before {
728
+ content: '';
729
+ position: absolute;
730
+ bottom: 0;
731
+ left: 50%;
732
+ transform: translate(-50%, 100%);
733
+ width: 0;
734
+ height: 0;
735
+ border-style: solid;
736
+ border-width: 4px 3px 0 3px;
737
+ border-color: rgba(48, 69, 79, 1) transparent transparent transparent;
738
+ }
739
+ `;
740
+ const TooltipGroupName = styled.div `
741
+ font-size: 14px;
742
+ margin-bottom: 6px;
743
+ `;
744
+ const TooltipItem = styled.div `
745
+ display: flex;
746
+ align-items: center;
747
+ margin-bottom: 0.25rem;
748
+
749
+ &:last-of-type {
750
+ margin-bottom: 0;
751
+ }
752
+ `;
753
+ const ColFlex = styled.div `
754
+ display: flex;
755
+ align-items: center;
756
+ margin-right: 4px;
757
+ `;
758
+ const ColorBox = styled.div `
759
+ margin-right: 4px;
760
+ width: 10px;
761
+ height: 10px;
762
+ border-radius: 2px;
763
+ `;
764
+ const ColorLine = styled(ColorBox) `
765
+ height: 2px;
766
+ border-radius: 0;
767
+ `;
768
+ const Name = styled.div `
769
+ margin-right: 4px;
770
+ `;
771
+ const Value = styled.div `
772
+ text-align: right;
773
+ flex-shrink: 0;
774
+ flex-grow: 1;
775
+ `;
776
+ const Label$1 = styled.div `
777
+ position: relative;
778
+ font-size: 11px;
779
+ color: #fff;
780
+ font-weight: bold;
781
+ letter-spacing: 0.52px;
782
+ `;
783
+ const LabelTop = styled(Label$1) `
784
+ top: 6px;
785
+ `;
786
+ const LabelBottom = styled(Label$1) `
787
+ bottom: 6px;
788
+ `;
789
+
790
+ const drawTooltip$3 = ({ fullChartTooltip, global, tooltipRoot, data, tooltipClassName, tooltipBind, renderTooltip, arc, allSlices, tooltipStyle, width, height, radius, }) => {
791
+ const container = tooltipRoot || document.querySelector("body");
792
+ const format = d3__namespace.format(",");
793
+ const pieTooltipContainer = d3__namespace.select(container).select(`.${pieChartclassNames.pieTooltipContainer}`);
794
+ const isEmpty = pieTooltipContainer.empty();
795
+ const tooltipContainer = isEmpty
796
+ ? d3__namespace
797
+ .select(container)
798
+ .append("div")
799
+ .attr("class", `${pieChartclassNames.pieTooltipContainer} ${tooltipClassName || ""}`)
800
+ .style("position", "absolute")
801
+ .style("opacity", "0")
802
+ .style("z-index", "103")
803
+ : pieTooltipContainer;
804
+ if (tooltipStyle) {
805
+ Object.entries(tooltipStyle).forEach(([prop, val]) => tooltipContainer.style(prop, val));
806
+ }
807
+ tooltipContainer.html("");
808
+ let isVisible = false;
809
+ const setVisible = (visible) => {
810
+ isVisible = Boolean(visible);
811
+ const opacity = isVisible ? "1" : "0";
812
+ tooltipContainer.style("opacity", opacity);
813
+ };
814
+ const setPosition = (event, pieChartDatum) => {
815
+ let [x, y] = d3__namespace.pointer(event, document);
816
+ if (!tooltipBind && fullChartTooltip) {
817
+ const [itemX, itemY] = d3__namespace.pointer(event, event.target);
818
+ x = x - itemX;
819
+ y = y - itemY;
820
+ }
821
+ else if (!tooltipBind) {
822
+ const globalNode = global.node();
823
+ const { x: itemX, y: itemY, width: itemWidth, height: itemHeight, } = globalNode
824
+ ? globalNode.getBoundingClientRect()
825
+ : { x: 0, y: 0, width: 0, height: 0 };
826
+ const [arcX, arcY] = arc.centroid(pieChartDatum);
827
+ x = itemX + itemWidth / 2 + arcX;
828
+ y = itemY + itemHeight / 2 + arcY;
829
+ }
830
+ tooltipContainer.style("left", x + "px").style("top", y + "px");
831
+ };
832
+ const setTooltip = (event, pieChartDatum) => {
833
+ setVisible(true);
834
+ setPosition(event, pieChartDatum);
835
+ const pieChartData = pieChartDatum ? [pieChartDatum.data] : data;
836
+ tooltipContainer.html(() => {
837
+ const html = ReactDOMServer.renderToString(jsxRuntime.jsx(TooltipFlex$1, { className: pieChartclassNames.pieTooltipFlex, children: jsxRuntime.jsx(TooltipContainer, { className: pieChartclassNames.pieTooltip, children: renderTooltip ? (renderTooltip(pieChartData)) : (jsxRuntime.jsx(jsxRuntime.Fragment, { children: pieChartData.map(({ color, name, value }, index) => (jsxRuntime.jsxs(TooltipItem, { className: pieChartclassNames.pieTooltipItem, children: [color && (jsxRuntime.jsx(ColorBox, { className: pieChartclassNames.pieTooltipColorBox, style: { backgroundColor: color } })), name && (jsxRuntime.jsx(Name, { className: pieChartclassNames.pieTooltipName, children: name })), jsxRuntime.jsx(Value, { className: pieChartclassNames.pieTooltipValue, children: format(value) })] }, `${name}-${index}`))) })) }) }));
838
+ return html;
839
+ });
840
+ };
841
+ if (fullChartTooltip) {
842
+ global.on("mouseover.fulltooltip", event => setTooltip(event));
843
+ global.on("mouseout.fulltooltip", () => {
844
+ tooltipContainer.html("");
845
+ setVisible();
846
+ });
847
+ if (width && height) {
848
+ global
849
+ .append("circle")
850
+ .attr("class", pieChartclassNames.pieFullChartTooltipCircle)
851
+ .attr("r", radius)
852
+ .attr("cx", 0)
853
+ .attr("cy", 0);
854
+ }
855
+ if (!tooltipBind) {
856
+ global.on("touchmove.tooltipBind mousemove.tooltipBind", event => setPosition(event));
857
+ }
858
+ }
859
+ else {
860
+ allSlices.on("mouseover.slice", setTooltip);
861
+ if (!tooltipBind) {
862
+ allSlices.on("touchmove.slice mousemove.slice", setPosition);
863
+ }
864
+ allSlices.on("mouseout.slice", () => {
865
+ tooltipContainer.html("");
866
+ setVisible();
867
+ });
868
+ }
869
+ };
870
+
871
+ const draw$4 = (node, props) => {
872
+ const { data, padAngle, onClick, outerRadius, startAngle, endAngle, cornerRadius, margin, enableSlicesLabels, formatSliceLabel, slicesLabelsSkipAngle, enableSlicesLabelsName, formatSliceLabelName, borderWidth, borderColor, enableRadialLabels, backgroundColor, radialLabelsLinkHorizontalLength, radialLabelsTextXOffset, formatRadialLabel, radialLabelYOffset, svgElements, formatSliceTitle, radialAngleXOffset, withTooltip, fullChartTooltip, tooltipClassName, tooltipBind, renderTooltip, tooltipStyle, } = props;
873
+ if (node !== null && data.length) {
874
+ const marginTop = margin ? margin.top : 0;
875
+ const marginRight = margin ? margin.right : 0;
876
+ const marginBottom = margin ? margin.bottom : 0;
877
+ const marginLeft = margin ? margin.left : 0;
878
+ const { width: nodeWidth } = node.getBoundingClientRect();
879
+ const width = props.width || nodeWidth;
880
+ const defaultHeight = 240;
881
+ const height = props.height || defaultHeight;
882
+ const radius = (Math.min(width, height) -
883
+ (borderWidth || 0) * 2 -
884
+ (width > height
885
+ ? marginTop + marginBottom
886
+ : marginRight + marginLeft)) /
887
+ 2;
888
+ const svg = appendSvg(node, width, height);
889
+ const global = svg
890
+ .append("g")
891
+ .attr("class", pieChartclassNames.pieGlobal)
892
+ .attr("transform", `translate(${(width - (marginLeft + marginRight)) / 2 +
893
+ marginLeft},${(height - (marginBottom + marginTop)) / 2 + marginTop})`);
894
+ const maxPadAngle = 45;
895
+ const dividerPadAngle = 100;
896
+ const fullAngle = 360;
897
+ const pie = d3__namespace
898
+ .pie()
899
+ .startAngle(-degreesToRadians(startAngle || 0))
900
+ .endAngle(degreesToRadians(endAngle || fullAngle))
901
+ .padAngle(padAngle
902
+ ? Math.max(Math.min(padAngle / dividerPadAngle, maxPadAngle), 0)
903
+ : 0)
904
+ .sort(null)
905
+ // @ts-ignore
906
+ .value(({ value }) => value);
907
+ // @ts-ignore
908
+ const dataReady = pie(data);
909
+ const maxOuterRadius = 0.95;
910
+ const arc = d3__namespace
911
+ .arc()
912
+ .cornerRadius(cornerRadius || 0)
913
+ .innerRadius(radius)
914
+ .outerRadius(radius * Math.min(Math.max(outerRadius || 0, 0), maxOuterRadius));
915
+ if (typeof backgroundColor === "string") {
916
+ global
917
+ .append("path")
918
+ .attr("fill", backgroundColor)
919
+ .attr("d", () =>
920
+ // @ts-ignore
921
+ arc({
922
+ startAngle: degreesToRadians(0),
923
+ endAngle: degreesToRadians(fullAngle),
924
+ }));
925
+ }
926
+ const format = d3__namespace.format(",");
927
+ const allSlices = global
928
+ .selectAll("allSlices")
929
+ .data(dataReady)
930
+ .enter()
931
+ .append("path")
932
+ // @ts-ignore
933
+ .attr("d", arc);
934
+ allSlices
935
+ .attr("class", pieChartclassNames.pieSlice)
936
+ .attr("fill", ({ index }) => data[index].color || "")
937
+ .attr("stroke", borderColor || "")
938
+ .attr("stroke-width", borderWidth || 0)
939
+ .attr("style", onClick ? "cursor: pointer" : "")
940
+ .on("click",
941
+ // @ts-ignore
942
+ (_, d) => onClick && onClick(data[d.index]))
943
+ .append("svg:title")
944
+ .text(d => formatSliceTitle
945
+ ? // @ts-ignore
946
+ formatSliceTitle(d)
947
+ : fullChartTooltip || withTooltip
948
+ ? ""
949
+ : `${data[d.index].name || ""} (${format(data[d.index].value)})`);
950
+ if (enableSlicesLabels) {
951
+ const text = global
952
+ .selectAll("allSlices")
953
+ .data(dataReady)
954
+ .enter()
955
+ .append("text")
956
+ .attr("class", pieChartclassNames.pieSliceLabel)
957
+ .attr("text-anchor", "middle")
958
+ .attr("dominant-baseline", "central")
959
+ .attr("transform",
960
+ // @ts-ignore
961
+ (d) => "translate(" + arc.centroid(d) + ")");
962
+ text
963
+ .append("tspan")
964
+ .attr("class", pieChartclassNames.pieSliceLabelValue)
965
+ // @ts-ignore
966
+ .text((d) => {
967
+ const deg = radiansToDegrees(d.endAngle - d.startAngle);
968
+ if (!slicesLabelsSkipAngle || deg > slicesLabelsSkipAngle) {
969
+ return formatSliceLabel ? formatSliceLabel(d) : d.value;
970
+ }
971
+ });
972
+ if (enableSlicesLabelsName) {
973
+ text
974
+ .append("tspan")
975
+ .attr("class", pieChartclassNames.pieSliceLabelName)
976
+ // @ts-ignore
977
+ .text((d) => formatSliceLabelName ? formatSliceLabelName(d) : d.data.name)
978
+ .attr("x", "0")
979
+ .attr("dy", "1.2em");
980
+ }
981
+ }
982
+ drawRadialLabels({
983
+ arc,
984
+ enableRadialLabels,
985
+ global,
986
+ radius,
987
+ node,
988
+ dataReady,
989
+ translateX: (width - (marginLeft - marginRight)) / 2,
990
+ translateY: (height + (marginTop - marginBottom)) / 2,
991
+ radialLabelsLinkHorizontalLength,
992
+ radialLabelsTextXOffset,
993
+ formatRadialLabel,
994
+ radialLabelYOffset,
995
+ radialAngleXOffset,
996
+ });
997
+ if (withTooltip || fullChartTooltip) {
998
+ drawTooltip$3({
999
+ fullChartTooltip,
1000
+ global,
1001
+ data,
1002
+ tooltipClassName,
1003
+ tooltipBind,
1004
+ renderTooltip,
1005
+ allSlices,
1006
+ arc,
1007
+ tooltipStyle,
1008
+ width,
1009
+ height,
1010
+ radius,
1011
+ });
1012
+ }
1013
+ if (svgElements) {
1014
+ const html = ReactDOMServer.renderToString(svgElements);
1015
+ svg.append("g").html(html);
1016
+ }
1017
+ }
1018
+ };
1019
+
1020
+ const PieChart = (props) => {
1021
+ const { className, style, children } = props;
1022
+ const [ref, node] = useNode();
1023
+ react.useEffect(() => {
1024
+ node && draw$4(node, props);
1025
+ }, [node, props]);
1026
+ const onDraw = () => draw$4(node, props);
1027
+ useResize(props.width, onDraw);
1028
+ return (jsxRuntime.jsx("div", { className: className, style: style, children: jsxRuntime.jsx(SvgWrapper$4, { ref: ref, children: children }) }));
1029
+ };
1030
+ PieChart.defaultProps = {
1031
+ data: [],
1032
+ startAngle: 0,
1033
+ endAngle: 360,
1034
+ slicesLabelsSkipAngle: 0,
1035
+ radialLabelYOffset: 16,
1036
+ radialAngleXOffset: 8,
1037
+ };
1038
+
1039
+ const defaultN = 256;
1040
+ const legendClassNames = {
1041
+ legendContainer: 'd3-legend-container',
1042
+ legendTitle: 'd3-legend-title',
1043
+ legendTick: 'd3-legend-tick',
1044
+ legendTickLine: 'd3-legend-tick-line',
1045
+ legendTickText: 'd3-legend-tick-text',
1046
+ };
1047
+ function ramp(color, n = defaultN) {
1048
+ const canvas = document.createElement('canvas');
1049
+ canvas.width = n;
1050
+ canvas.height = 1;
1051
+ const context = canvas.getContext('2d');
1052
+ for (let i = 0; i < n; ++i) {
1053
+ context.fillStyle = color(i / (n - 1));
1054
+ context.fillRect(i, 0, 1, 1);
1055
+ }
1056
+ return canvas;
1057
+ }
1058
+ const legendDefaultParams = {
1059
+ tickSize: 6,
1060
+ height: 44,
1061
+ width: 320,
1062
+ marginTop: 18,
1063
+ marginBottom: 16,
1064
+ ticksDivier: 64,
1065
+ titleMarginBottom: 6,
1066
+ };
1067
+ const getLegend = ({ color, title, tickSize = legendDefaultParams.tickSize, width = legendDefaultParams.width, height = legendDefaultParams.height + tickSize, marginTop = legendDefaultParams.marginTop, marginRight = 0, marginBottom = legendDefaultParams.marginBottom + tickSize, marginLeft = 0, ticks = legendDefaultParams.width / legendDefaultParams.ticksDivier, tickFormat, tickValues, titleMarginBottom, }) => {
1068
+ const svg = d3__namespace
1069
+ .create('svg')
1070
+ .attr('width', width)
1071
+ .attr('height', height)
1072
+ // @ts-ignore
1073
+ .attr('viewBox', [0, 0, width, height])
1074
+ .style('overflow', 'visible')
1075
+ .style('display', 'block');
1076
+ let tickAdjust = (g) => {
1077
+ const tick = g.selectAll('.tick');
1078
+ tick
1079
+ .selectAll('.tick line')
1080
+ .attr('y1', marginTop + marginBottom - height)
1081
+ .attr('class', legendClassNames.legendTickLine);
1082
+ tick.selectAll('.tick text').attr('class', legendClassNames.legendTickText);
1083
+ tick.attr('class', legendClassNames.legendTick);
1084
+ return tick;
1085
+ };
1086
+ let x;
1087
+ // Continuous
1088
+ if (color.interpolate) {
1089
+ const n = Math.min(color.domain().length, color.range().length);
1090
+ x = color
1091
+ .copy()
1092
+ .rangeRound(d3__namespace.quantize(d3__namespace.interpolate(marginLeft, width - marginRight), n));
1093
+ svg
1094
+ .append('image')
1095
+ .attr('x', marginLeft)
1096
+ .attr('y', marginTop)
1097
+ .attr('class', legendClassNames.legendContainer)
1098
+ .attr('width', width - marginLeft - marginRight)
1099
+ .attr('height', height - marginTop - marginBottom)
1100
+ .attr('preserveAspectRatio', 'none')
1101
+ .attr('xlink:href', ramp(color.copy().domain(d3__namespace.quantize(d3__namespace.interpolate(0, 1), n))).toDataURL());
1102
+ }
1103
+ // Sequential
1104
+ else if (color.interpolator) {
1105
+ x = Object.assign(color
1106
+ .copy()
1107
+ .interpolator(d3__namespace.interpolateRound(marginLeft, width - marginRight)), {
1108
+ range() {
1109
+ return [marginLeft, width - marginRight];
1110
+ },
1111
+ });
1112
+ svg
1113
+ .append('image')
1114
+ .attr('x', marginLeft)
1115
+ .attr('y', marginTop)
1116
+ .attr('width', width - marginLeft - marginRight)
1117
+ .attr('height', height - marginTop - marginBottom)
1118
+ .attr('preserveAspectRatio', 'none')
1119
+ .attr('xlink:href', ramp(color.interpolator()).toDataURL());
1120
+ // scaleSequentialQuantile doesn’t implement ticks or tickFormat.
1121
+ if (!x.ticks) {
1122
+ if (tickValues === undefined) {
1123
+ const n = Math.round(ticks + 1);
1124
+ tickValues = d3__namespace
1125
+ .range(n)
1126
+ .map(i => d3__namespace.quantile(color.domain(), i / (n - 1)));
1127
+ }
1128
+ if (typeof tickFormat !== 'function') {
1129
+ tickFormat = d3__namespace.format(tickFormat === undefined ? ',f' : tickFormat);
1130
+ }
1131
+ }
1132
+ }
1133
+ svg
1134
+ .append('g')
1135
+ .attr('transform', `translate(0,${height - marginBottom})`)
1136
+ // @ts-ignore
1137
+ .call(d3__namespace
1138
+ .axisBottom(x)
1139
+ .ticks(ticks, typeof tickFormat === 'string' ? tickFormat : undefined)
1140
+ // @ts-ignore
1141
+ .tickFormat(typeof tickFormat === 'function' ? tickFormat : undefined)
1142
+ .tickSize(tickSize)
1143
+ // @ts-ignore
1144
+ .tickValues(tickValues))
1145
+ .call(tickAdjust)
1146
+ .call(g => g.select('.domain').remove())
1147
+ .call(g => g
1148
+ .append('text')
1149
+ .attr('x', marginLeft)
1150
+ .attr('class', legendClassNames.legendTitle)
1151
+ .attr('y', marginTop +
1152
+ marginBottom -
1153
+ height -
1154
+ (titleMarginBottom || legendDefaultParams.titleMarginBottom))
1155
+ .attr('fill', 'currentColor')
1156
+ .attr('text-anchor', 'start')
1157
+ .attr('font-weight', 'bold')
1158
+ .text(title));
1159
+ return svg;
1160
+ };
1161
+
1162
+ const calendarChartClassNames = {
1163
+ calendarChart: "calendarChart",
1164
+ calendarYear: "calendarYear",
1165
+ calendarAxis: "calendarAxis",
1166
+ calendarBody: "calendarBody",
1167
+ calendarHeader: "calendarHeader",
1168
+ calendarYearTitle: "calendarYearTitle",
1169
+ calendarWeekDay: "calendarWeekDay",
1170
+ calendarMonth: "calendarMonth",
1171
+ calendarDays: "calendarDays",
1172
+ calendarDay: "calendarDay",
1173
+ ...legendClassNames,
1174
+ };
1175
+ const headerHeight = "20px";
1176
+ const SvgWrapper$3 = styled(Wrapper) `
1177
+ .${calendarChartClassNames.calendarYear} {
1178
+ display: flex;
1179
+ margin-bottom: 16px;
1180
+ }
1181
+
1182
+ .${calendarChartClassNames.calendarYearTitle} {
1183
+ display: inline-flex;
1184
+ align-items: flex-end;
1185
+ height: ${headerHeight};
1186
+ margin-bottom: 4px;
1187
+ font-weight: bold;
1188
+ }
1189
+
1190
+ .${calendarChartClassNames.calendarHeader} {
1191
+ height: ${headerHeight};
1192
+ margin-bottom: 4px;
1193
+ position: relative;
1194
+ display: flex;
1195
+ }
1196
+
1197
+ .${calendarChartClassNames.calendarMonth} {
1198
+ font-size: 14px;
1199
+ bottom: 0;
1200
+ position: absolute;
1201
+ }
1202
+
1203
+ .${calendarChartClassNames.calendarAxis} {
1204
+ display: flex;
1205
+ flex-direction: column;
1206
+ margin-right: 10px;
1207
+ }
1208
+
1209
+ .${calendarChartClassNames.calendarWeekDay} {
1210
+ font-size: 12px;
1211
+ display: inline-flex;
1212
+ align-items: center;
1213
+ justify-content: flex-end;
1214
+ }
1215
+
1216
+ .${calendarChartClassNames.calendarDays} {
1217
+ position: relative;
1218
+ }
1219
+
1220
+ .${calendarChartClassNames.calendarDay} {
1221
+ position: absolute;
1222
+ }
1223
+ `;
1224
+
1225
+ const draw$3 = (node, props) => {
1226
+ const { data, startSunday, weekdays, interpolator, monthSpacing, onEachDay, colorRange, legendProps, } = props;
1227
+ if (node !== null && data.length) {
1228
+ const years = d3__namespace.group(data, d => d.date.getUTCFullYear());
1229
+ const cellOffset = typeof props.cellOffset === 'number' ? props.cellOffset : 0;
1230
+ const weekDays = 7;
1231
+ const defaultCellSize = 18;
1232
+ const cellSize = props.cellSize || defaultCellSize;
1233
+ const countDay = (i) => startSunday ? i : (i + (weekDays - 1)) % weekDays;
1234
+ const days = weekdays || ['вс', 'пн', 'вт', 'ср', 'чт', 'пт', 'сб'];
1235
+ const sundayIndex = 6;
1236
+ const formatDay = (i) => startSunday ? days[i] : i === sundayIndex ? days[0] : days[i + 1];
1237
+ const formatDate = d3__namespace.utcFormat('%x');
1238
+ const timeWeek = startSunday ? d3__namespace.utcSunday : d3__namespace.utcMonday;
1239
+ const getTimeWeekCount = (from, to) => timeWeek.count(d3__namespace.utcYear(from), to);
1240
+ const getMonthSpacing = (date) => date.getUTCMonth() * (monthSpacing || 0);
1241
+ const formatMonth = d3__namespace.utcFormat('%b');
1242
+ const max = d3__namespace.max(data.map(({ value }) => value));
1243
+ const min = d3__namespace.min(data.map(({ value }) => value));
1244
+ const color = colorRange
1245
+ ? d3__namespace
1246
+ .scaleLinear()
1247
+ .domain([min, max])
1248
+ // @ts-ignore
1249
+ .range(colorRange)
1250
+ : d3__namespace
1251
+ .scaleSequential(interpolator || d3__namespace.interpolateGreens)
1252
+ .domain([min, +max]);
1253
+ let chartWidth = 0;
1254
+ years.forEach((values, year) => {
1255
+ const min = new Date(year, 1);
1256
+ const max = d3__namespace.max(values.map(d => d.date));
1257
+ const months = max.getUTCMonth() - min.getUTCMonth();
1258
+ const weekCount = getTimeWeekCount(min, max) + 1;
1259
+ const width = weekCount * (cellSize + cellOffset) + (monthSpacing || 0) * months;
1260
+ chartWidth = Math.max(chartWidth, width);
1261
+ });
1262
+ d3__namespace.select(node)
1263
+ .select(`.${calendarChartClassNames.calendarChart}`)
1264
+ .remove();
1265
+ const container = d3__namespace
1266
+ .select(node)
1267
+ .append('div')
1268
+ .attr('class', calendarChartClassNames.calendarChart);
1269
+ const year = container
1270
+ .selectAll('div')
1271
+ // @ts-ignore
1272
+ .data(years)
1273
+ .join('div')
1274
+ .attr('class', calendarChartClassNames.calendarYear);
1275
+ const calendarWeekdays = year
1276
+ .append('div')
1277
+ .attr('class', calendarChartClassNames.calendarAxis);
1278
+ calendarWeekdays
1279
+ .append('div')
1280
+ .attr('class', calendarChartClassNames.calendarYearTitle)
1281
+ // @ts-ignore
1282
+ .text(([key]) => key);
1283
+ calendarWeekdays
1284
+ .selectAll('span')
1285
+ .data(d3__namespace.range(weekDays))
1286
+ .join('div')
1287
+ .attr('class', calendarChartClassNames.calendarWeekDay)
1288
+ .style('height', cellSize + 'px')
1289
+ .style('margin-bottom', cellOffset + 'px')
1290
+ .text(formatDay);
1291
+ const body = year
1292
+ .append('div')
1293
+ .attr('class', calendarChartClassNames.calendarBody);
1294
+ const header = body
1295
+ .append('div')
1296
+ .attr('class', calendarChartClassNames.calendarHeader);
1297
+ header
1298
+ .selectAll('div')
1299
+ // @ts-ignore
1300
+ .data(([_, values]) => {
1301
+ const fullYearlastMonth = 12;
1302
+ const fullYearlastDate = 31;
1303
+ return d3__namespace.utcMonths(d3__namespace.utcMonth(new Date(values[0].date.getUTCFullYear(), 1, 1)), d3__namespace.utcMonth(new Date(values[0].date.getUTCFullYear(), fullYearlastMonth, fullYearlastDate)));
1304
+ })
1305
+ .join('div')
1306
+ .attr('class', calendarChartClassNames.calendarMonth)
1307
+ .style('left', (d) => getTimeWeekCount(d, timeWeek.ceil(d)) * (cellSize + cellOffset) +
1308
+ getMonthSpacing(d) +
1309
+ 'px')
1310
+ // @ts-ignore
1311
+ .text(formatMonth);
1312
+ // @ts-ignore
1313
+ body
1314
+ .append('div')
1315
+ .attr('class', calendarChartClassNames.calendarDays)
1316
+ .style('height', (cellSize + cellOffset) * weekDays + 'px')
1317
+ .style('width', chartWidth + 'px')
1318
+ .selectAll('div')
1319
+ // @ts-ignore
1320
+ .data(([, values]) => values)
1321
+ .join('div')
1322
+ // @ts-ignore
1323
+ .each((data, index, elements) => {
1324
+ if (onEachDay) {
1325
+ const element = elements[index];
1326
+ const currColor = color(data.value);
1327
+ onEachDay(data, element, currColor);
1328
+ }
1329
+ })
1330
+ .attr('class', calendarChartClassNames.calendarDay)
1331
+ .style('width', cellSize + 'px')
1332
+ .style('height', cellSize + 'px')
1333
+ // @ts-ignore
1334
+ .style('left', (d) => getTimeWeekCount(d.date, d.date) * (cellSize + cellOffset) +
1335
+ getMonthSpacing(d.date) +
1336
+ 'px')
1337
+ .style('top',
1338
+ // @ts-ignore
1339
+ d => countDay(d.date.getUTCDay()) * (cellSize + cellOffset) + 'px')
1340
+ // @ts-ignore
1341
+ .style('background-color', d => color(d.value))
1342
+ // @ts-ignore
1343
+ .attr('title', d => `${formatDate(d.date)} - ${d.value}`);
1344
+ if (typeof legendProps === 'object') {
1345
+ const legend = getLegend({
1346
+ color: color,
1347
+ ...legendProps,
1348
+ });
1349
+ const containerNode = container.node();
1350
+ const legendSvg = legend.node();
1351
+ containerNode.appendChild(legendSvg);
1352
+ }
1353
+ }
1354
+ };
1355
+
1356
+ const CalendarChart = (props) => {
1357
+ const { className, style, children, data, startSunday, weekdays, cellOffset, cellSize, interpolator, monthSpacing, colorRange, legendProps, } = props;
1358
+ const [ref, node] = useNode();
1359
+ react.useEffect(() => {
1360
+ node && draw$3(node, props);
1361
+ // eslint-disable-next-line
1362
+ }, [
1363
+ node,
1364
+ data,
1365
+ startSunday,
1366
+ weekdays,
1367
+ cellOffset,
1368
+ cellSize,
1369
+ interpolator,
1370
+ monthSpacing,
1371
+ colorRange,
1372
+ legendProps,
1373
+ ]);
1374
+ return (jsxRuntime.jsx(SvgWrapper$3, { ref: ref, className: className, style: style, children: children }));
1375
+ };
1376
+ CalendarChart.defaultProps = {
1377
+ data: [],
1378
+ };
1379
+
1380
+ function computeDimensions(selection) {
1381
+ let dimensions;
1382
+ const node = selection.node();
1383
+ if (node instanceof SVGGraphicsElement) {
1384
+ // check if node is svg element
1385
+ dimensions = node.getBBox();
1386
+ }
1387
+ else {
1388
+ // else is html element
1389
+ dimensions = node.getBoundingClientRect();
1390
+ }
1391
+ return dimensions;
1392
+ }
1393
+
1394
+ function none() {
1395
+ return;
1396
+ }
1397
+ function isVoid(value) {
1398
+ return value === undefined || value === null || Number.isNaN(value);
1399
+ }
1400
+
1401
+ const stackedData = (data) => {
1402
+ const stacks = {};
1403
+ return data.map((item, index) => {
1404
+ stacks[index] = {};
1405
+ if (index > 0) {
1406
+ return {
1407
+ ...item,
1408
+ values: item.values.map((value, valuesIndex) => {
1409
+ const prevValue = stacks[index - 1][valuesIndex];
1410
+ stacks[index][valuesIndex] = Number((typeof prevValue !== 'number' ? 0 : Math.abs(prevValue)) +
1411
+ (typeof value !== 'number' ? 0 : Math.abs(value)));
1412
+ return stacks[index][valuesIndex];
1413
+ }),
1414
+ };
1415
+ }
1416
+ else {
1417
+ item.values.forEach((value, valuesIndex) => {
1418
+ stacks[index][valuesIndex] = Number(value);
1419
+ });
1420
+ }
1421
+ return item;
1422
+ });
1423
+ };
1424
+
1425
+ const lineChartClassNames = {
1426
+ lineChartYScaleGlobal: "lineChartYScaleGlobal",
1427
+ lineChartYScaleRight: "lineChartYScaleRight",
1428
+ lineChartXScaleGlobal: "lineChartXScaleGlobal",
1429
+ lineChartLinesGlobal: "lineChartLinesGlobal",
1430
+ lineChartLine: "lineChartLine",
1431
+ lineChartAreasGlobal: "lineChartAreasGlobal",
1432
+ lineChartArea: "lineChartArea",
1433
+ lineChartDotsGlobalContainer: "lineChartDotsGlobalContainer",
1434
+ lineChartDotsGlobal: "lineChartDotsGlobal",
1435
+ lineChartDot: "lineChartDot",
1436
+ lineChartGridGlobal: "lineChartGridGlobal",
1437
+ lineChartGridLineX: "lineChartGridLineX",
1438
+ lineChartGridLineY: "lineChartGridLineY",
1439
+ lineChartLabelContainer: "lineChartLabelContainer",
1440
+ lineChartLabelFlex: "lineChartLabelFlex",
1441
+ lineChartLabel: "lineChartLabel",
1442
+ lineChartMouseGlobal: "lineChartMouseGlobal",
1443
+ lineChartMouseLine: "lineChartMouseLine",
1444
+ lineChartMouseRect: "lineChartMouseRect",
1445
+ lineChartMouseCircle: "lineChartMouseCircle",
1446
+ lineChartMouseLabelContainer: "lineChartMouseLabelContainer",
1447
+ lineChartMouseLabel: "lineChartMouseLabel",
1448
+ };
1449
+ const SvgWrapper$2 = styled(Wrapper) `
1450
+ .${lineChartClassNames.lineChartYScaleGlobal},
1451
+ .${lineChartClassNames.lineChartXScaleGlobal},
1452
+ .${lineChartClassNames.lineChartGridGlobal} {
1453
+ shape-rendering: crispEdges;
1454
+ }
1455
+
1456
+ .${lineChartClassNames.lineChartLinesGlobal} {
1457
+ fill: none;
1458
+ stroke: steelblue;
1459
+ stroke-width: 1.5px;
1460
+ stroke-linejoin: round;
1461
+ stroke-linecap: round;
1462
+ }
1463
+
1464
+ .${lineChartClassNames.lineChartArea} {
1465
+ fill-opacity: 0.24;
1466
+ }
1467
+
1468
+ .${lineChartClassNames.lineChartGridLineX},
1469
+ .${lineChartClassNames.lineChartGridLineY},
1470
+ .${lineChartClassNames.lineChartMouseLine} {
1471
+ stroke: rgba(149, 149, 149, 0.24);
1472
+ }
1473
+
1474
+ .${lineChartClassNames.lineChartMouseLine},
1475
+ .${lineChartClassNames.lineChartMouseCircle} {
1476
+ transition: opacity linear 200ms;
1477
+ pointer-events: none;
1478
+ stroke-width: 1px;
1479
+ }
1480
+
1481
+ .${lineChartClassNames.lineChartDot} {
1482
+ stroke: #fff;
1483
+ stroke-width: 2px;
1484
+ }
1485
+
1486
+ .${lineChartClassNames.lineChartMouseLine} {
1487
+ shape-rendering: crispEdges;
1488
+ }
1489
+
1490
+ .${lineChartClassNames.lineChartMouseRect} {
1491
+ fill: none;
1492
+ pointer-events: all;
1493
+ }
1494
+ `;
1495
+ const TooltipStyles$2 = styled.createGlobalStyle `
1496
+ .${lineChartClassNames.lineChartMouseLabel} {
1497
+ transition: opacity linear 200ms;
1498
+ z-index: 100;
1499
+
1500
+ .${lineChartClassNames.lineChartLabelFlex} {
1501
+ justify-content: flex-start;
1502
+ align-items: center;
1503
+ pointer-events: none;
1504
+ }
1505
+
1506
+ .${lineChartClassNames.lineChartLabel} {
1507
+ margin: 0 0 0 10px;
1508
+ }
1509
+ }
1510
+ `;
1511
+
1512
+ const drawGrid$2 = ({ svg, yScale, xScale, yTicksCount, lastIndex, drawGridX, drawGridY, }) => {
1513
+ if (!drawGridY && !drawGridX)
1514
+ return;
1515
+ const global = svg
1516
+ .append('g')
1517
+ .attr('class', lineChartClassNames.lineChartGridGlobal);
1518
+ const yTicks = yScale.ticks(yTicksCount);
1519
+ if (drawGridX) {
1520
+ global
1521
+ .append('g')
1522
+ .selectAll('line')
1523
+ .data(yTicks)
1524
+ .join('line')
1525
+ .attr('class', lineChartClassNames.lineChartGridLineX)
1526
+ .attr('x1', () => xScale(0))
1527
+ .attr('x2', () => xScale(lastIndex))
1528
+ .attr('y1', (d) => Math.round(yScale(d)))
1529
+ .attr('y2', (d) => Math.round(yScale(d)));
1530
+ }
1531
+ if (drawGridY) {
1532
+ global
1533
+ .append('g')
1534
+ .selectAll('line')
1535
+ .data(Array.from({ length: lastIndex + 1 }, (_, index) => index))
1536
+ .join('line')
1537
+ .attr('class', lineChartClassNames.lineChartGridLineY)
1538
+ .attr('x1', (_, index) => Math.round(xScale(index)))
1539
+ .attr('x2', (_, index) => Math.round(xScale(index)))
1540
+ .attr('y1', () => Math.round(yScale(yTicks[0])))
1541
+ .attr('y2', () => Math.round(yScale(yTicks[yTicks.length - 1])));
1542
+ }
1543
+ };
1544
+
1545
+ const LabelContainer = styled.div `
1546
+ width: 0;
1547
+ height: 0;
1548
+ display: flex;
1549
+ align-items: flex-end;
1550
+ justify-content: center;
1551
+ font-size: 12px;
1552
+ white-space: nowrap;
1553
+ `;
1554
+ const Label = styled.div `
1555
+ margin-bottom: 4px;
1556
+ `;
1557
+
1558
+ const labelClassName = "d3-chart-label";
1559
+ const drawLabel = ({ node, data, yScale, xScale, formatLabel, eachLabel, }) => {
1560
+ const labelsDiv = d3__namespace
1561
+ .select(node)
1562
+ .append("div")
1563
+ .attr("class", labelClassName);
1564
+ const format = d3__namespace.format(",");
1565
+ // @ts-ignore
1566
+ data.forEach(({ values }) => {
1567
+ labelsDiv
1568
+ .append("div")
1569
+ .selectAll("div")
1570
+ .data(values)
1571
+ .join("div")
1572
+ .attr("class", lineChartClassNames.lineChartLabelContainer)
1573
+ .style("position", "absolute")
1574
+ .style("left", (_, index) => xScale(index) + "px")
1575
+ .style("top", d => yScale(d) + "px")
1576
+ .html((d, index, elements) => {
1577
+ const html = ReactDOMServer.renderToString(jsxRuntime.jsx(LabelContainer, { className: lineChartClassNames.lineChartLabelFlex, children: jsxRuntime.jsx(Label, { className: lineChartClassNames.lineChartLabel, children: formatLabel ? formatLabel(d, index, elements) : format(d) }) }));
1578
+ return html;
1579
+ })
1580
+ // @ts-ignore
1581
+ .each(eachLabel ? eachLabel : none);
1582
+ });
1583
+ };
1584
+
1585
+ const drawTooltip$2 = ({ svg, node, data: argData, xScale, yScale, dynamicCircleRadius, formatDynamicTooltip, renderTooltip, stackedTooltipIndex, stackedTooltip, tooltipLineTop, tooltipRoot, tooltipClassName, dotSnapping, lastIndex, }) => {
1586
+ const container = tooltipRoot || document.querySelector("body");
1587
+ const format = d3__namespace.format(",");
1588
+ const chartData = argData.filter(({ tooltipOff }) => !tooltipOff);
1589
+ const data = typeof stackedTooltipIndex === "number"
1590
+ ? [chartData[stackedTooltipIndex]]
1591
+ : stackedTooltip
1592
+ ? [chartData[0]]
1593
+ : chartData;
1594
+ const [x1, x2] = xScale.range();
1595
+ const [y1, y2] = yScale.range();
1596
+ const mouseGlobal = svg
1597
+ .append("g")
1598
+ .attr("class", lineChartClassNames.lineChartMouseGlobal);
1599
+ const mouseRect = mouseGlobal
1600
+ .append("rect")
1601
+ .attr("width", x2 - x1)
1602
+ .attr("height", Math.abs(y1 - y2))
1603
+ .attr("class", lineChartClassNames.lineChartMouseRect)
1604
+ .attr("transform", `translate(${x1}, ${y2})`);
1605
+ const mouseLine = mouseGlobal
1606
+ .append("path")
1607
+ .attr("class", lineChartClassNames.lineChartMouseLine)
1608
+ .style("opacity", "0");
1609
+ const lines = svg
1610
+ .selectAll(`.${lineChartClassNames.lineChartLine}`)
1611
+ .nodes();
1612
+ const circles = mouseGlobal
1613
+ .selectAll("circle")
1614
+ .data(chartData.filter(({ dynamicDotOff }) => !dynamicDotOff))
1615
+ .join("circle")
1616
+ .attr("class", lineChartClassNames.lineChartMouseCircle)
1617
+ .attr("r", dynamicCircleRadius)
1618
+ .attr("fill", ({ stroke }) => stroke || "none")
1619
+ .attr("stroke", ({ stroke }) => stroke || "none")
1620
+ .style("opacity", "0");
1621
+ let labelContainer = d3__namespace.select(`.${lineChartClassNames.lineChartMouseLabelContainer}`);
1622
+ if (labelContainer.size() === 0) {
1623
+ labelContainer = d3__namespace
1624
+ .select(container)
1625
+ .append("div")
1626
+ .attr("class", lineChartClassNames.lineChartMouseLabelContainer);
1627
+ }
1628
+ let labels = null;
1629
+ let isVisible = false;
1630
+ const setVisible = (visible) => {
1631
+ isVisible = Boolean(visible);
1632
+ const opacity = isVisible ? "1" : "0";
1633
+ mouseLine.style("opacity", opacity);
1634
+ circles.style("opacity", opacity);
1635
+ labels && labels.style("opacity", opacity);
1636
+ };
1637
+ const mouseMove = (event) => {
1638
+ const [docX, docY] = d3__namespace.pointer(event, document);
1639
+ const [rectrX] = d3__namespace.pointer(event, mouseRect);
1640
+ const [nodeX, nodeY] = d3__namespace.pointer(event, node);
1641
+ const x = rectrX - (rectrX - nodeX);
1642
+ const left = nodeX + (docX - nodeX);
1643
+ const currIndex = Math.abs(xScale.invert(x));
1644
+ const positions = {};
1645
+ const getValue = (values) => {
1646
+ // The returning result is fixed for the task: https://jr.everpoint.ru/browse/PUB-5648
1647
+ // Before the task it was like this (and I don't know why):
1648
+ /* return !isVoid(values[Math.floor(currIndex + 1)])
1649
+ ? values[Math.floor(currIndex)]
1650
+ : null;*/
1651
+ return values[Math.floor(currIndex)];
1652
+ };
1653
+ lines.forEach((line, index) => {
1654
+ let pos = {
1655
+ x: 0,
1656
+ y: 0,
1657
+ };
1658
+ if (!line.hasAttribute("d") || argData[index].tooltipOff) {
1659
+ positions[index] = pos;
1660
+ return;
1661
+ }
1662
+ if (!dotSnapping) {
1663
+ let beginning = 0;
1664
+ let end = line.getTotalLength();
1665
+ let target = null;
1666
+ while (true) {
1667
+ target = Math.floor((beginning + end) / 2);
1668
+ pos = line.getPointAtLength(target);
1669
+ if ((target === end || target === beginning) && pos.x !== x) {
1670
+ break;
1671
+ }
1672
+ if (pos.x > x) {
1673
+ end = target;
1674
+ }
1675
+ else if (pos.x < x) {
1676
+ beginning = target;
1677
+ }
1678
+ else {
1679
+ break;
1680
+ }
1681
+ }
1682
+ positions[index] = pos;
1683
+ }
1684
+ else {
1685
+ const [x1, x2] = xScale.range();
1686
+ const chartWidth = x2 - x1;
1687
+ const step = chartWidth / lastIndex;
1688
+ positions[index] = {
1689
+ x: x1 + Math.round(currIndex) * step,
1690
+ y: typeof argData[index].values[Math.round(currIndex)] === "number"
1691
+ ? yScale(argData[index].values[Math.round(currIndex)])
1692
+ : 0,
1693
+ };
1694
+ }
1695
+ });
1696
+ circles
1697
+ .attr("transform", (lineChartData, index) => {
1698
+ const value = getValue(lineChartData.values);
1699
+ return positions[index] && value
1700
+ ? "translate(" + (!dotSnapping ? x : positions[index].x) + "," + positions[index].y + ")"
1701
+ : "translate(-9999, -9999)";
1702
+ })
1703
+ .attr("style", ({ dynamicDotStyle }) => dynamicDotStyle || "");
1704
+ const datas = chartData.map(({ values, ...rest }, i) => ({
1705
+ ...rest,
1706
+ value: getValue(values),
1707
+ invertValue: positions[i] ? yScale.invert(positions[i].y) : 0,
1708
+ }));
1709
+ const noHasData = datas.every(({ value }) => isVoid(value));
1710
+ if (noHasData && isVisible) {
1711
+ setVisible();
1712
+ }
1713
+ else if (!isVisible && !noHasData) {
1714
+ setVisible(true);
1715
+ }
1716
+ const topIndex = Object.keys(positions).reduce((acc, key, index) => {
1717
+ const prevValue = datas[Number(acc)]?.value;
1718
+ const value = datas[Number(key)]?.value;
1719
+ const dynamicDotOff = argData?.[index].dynamicDotOff;
1720
+ return index === 0 || isVoid(value) || dynamicDotOff
1721
+ ? acc
1722
+ : isVoid(prevValue) || positions[acc].y > positions[key].y
1723
+ ? key
1724
+ : acc;
1725
+ }, "0");
1726
+ const labelTexts = labels &&
1727
+ labels
1728
+ .style("left", (_, i) => {
1729
+ return !dotSnapping ? `${left}px` : `${positions[i]?.x ?? 0}px`;
1730
+ })
1731
+ .style("top", (_, i) => {
1732
+ const index = typeof stackedTooltipIndex === "number"
1733
+ ? stackedTooltipIndex
1734
+ : stackedTooltip
1735
+ ? topIndex
1736
+ : i;
1737
+ return `${(positions[index]?.y ?? 0) + (docY - nodeY)}px`;
1738
+ })
1739
+ .select(`.${lineChartClassNames.lineChartLabel}`);
1740
+ if (renderTooltip && labels) {
1741
+ labels.html((_, index) => {
1742
+ return ReactDOMServer.renderToString(jsxRuntime.jsx(LabelContainer, { className: lineChartClassNames.lineChartLabelFlex, children: renderTooltip(datas, {
1743
+ indexX: Math.round(currIndex),
1744
+ indexY: index,
1745
+ svg,
1746
+ event,
1747
+ }) }));
1748
+ });
1749
+ }
1750
+ else {
1751
+ labelTexts &&
1752
+ labelTexts.text((_, i) => {
1753
+ const value = datas[i].value;
1754
+ const invertValue = datas[i].invertValue;
1755
+ return formatDynamicTooltip
1756
+ ? formatDynamicTooltip(invertValue, value)
1757
+ : format(invertValue);
1758
+ });
1759
+ }
1760
+ mouseLine.attr("d", () => {
1761
+ let d = "M" + x + "," + y1;
1762
+ d += " " + x + "," + (tooltipLineTop ? y2 : positions[topIndex]?.y || 0);
1763
+ return d;
1764
+ });
1765
+ };
1766
+ mouseRect.on("mouseover.tooltip", event => {
1767
+ labels = labelContainer
1768
+ .selectAll("div")
1769
+ .data(data)
1770
+ .join("div")
1771
+ .attr("class", `${lineChartClassNames.lineChartMouseLabel} ${tooltipClassName || ""}`)
1772
+ .style("opacity", "0")
1773
+ .style("position", "absolute")
1774
+ .html(() => {
1775
+ const html = ReactDOMServer.renderToString(jsxRuntime.jsx(LabelContainer, { className: lineChartClassNames.lineChartLabelFlex, children: jsxRuntime.jsx(Label, { className: lineChartClassNames.lineChartLabel }) }));
1776
+ return html;
1777
+ });
1778
+ mouseMove(event);
1779
+ });
1780
+ mouseRect.on("mouseout.tooltip", () => {
1781
+ d3__namespace.select(`.${lineChartClassNames.lineChartMouseLabelContainer}`)
1782
+ .selectAll("*")
1783
+ .remove();
1784
+ setVisible();
1785
+ });
1786
+ mouseRect.on("touchmove.tooltip mousemove.tooltip", mouseMove);
1787
+ };
1788
+
1789
+ const draw$2 = (node, props) => {
1790
+ const { data: chartData, labels, margin, customYAxisSelection, customXAxisSelection, customYAxis, customXAxis, curve, yAxisPadding, xAxisPadding, drawGridY, drawGridX, withLabels, formatLabel, eachLabel, stacked, dynamicTooltipEnable, dynamicCircleRadius, formatDynamicTooltip, renderTooltip, stackedTooltip, stackedTooltipIndex, tooltipLineTop, customize, customYScale, customLine, tooltipClassName, xScaleItemWidth, areaCurve, dotSnapping, rightAxis, } = props;
1791
+ if (node !== null && chartData.length) {
1792
+ const data = stacked ? stackedData(chartData) : chartData;
1793
+ const marginTop = margin ? margin.top : 0;
1794
+ const marginRight = margin ? margin.right : 0;
1795
+ const marginBottom = margin ? margin.bottom : 0;
1796
+ const marginLeft = margin ? margin.left : 0;
1797
+ const { width: nodeWidth } = node.getBoundingClientRect();
1798
+ const width = props.width || nodeWidth;
1799
+ const height = props.height || 0;
1800
+ const min = typeof props.min === 'number'
1801
+ ? props.min
1802
+ : d3__namespace.min(data, ({ values }) => d3__namespace.min(values));
1803
+ const max = typeof props.max === 'number'
1804
+ ? props.max
1805
+ : d3__namespace.max(data, ({ values }) => d3__namespace.max(values));
1806
+ const svg = appendSvg(node, width, height || 0);
1807
+ const yRange = [
1808
+ height - marginTop - marginBottom - (xAxisPadding || 0),
1809
+ marginTop,
1810
+ ];
1811
+ const yScale = d3__namespace
1812
+ .scaleLinear()
1813
+ .domain([min || 0, max || 0])
1814
+ .range(yRange)
1815
+ .nice();
1816
+ customYScale && customYScale(yScale);
1817
+ const yTicksCountDefault = 8;
1818
+ const yAxisLeft = d3__namespace.axisLeft(yScale).ticks(yTicksCountDefault);
1819
+ customYAxis && customYAxis(yAxisLeft);
1820
+ const yTicksCount = yAxisLeft.tickArguments()[0];
1821
+ const yAxis = svg
1822
+ .append('g')
1823
+ .attr('class', lineChartClassNames.lineChartYScaleGlobal)
1824
+ .call(yAxisLeft)
1825
+ .call(customYAxisSelection ? customYAxisSelection : none);
1826
+ const { width: yAxisWidth } = computeDimensions(yAxis);
1827
+ yAxis.attr('transform', `translate(${marginLeft + yAxisWidth}, 0)`);
1828
+ let yAxisRightWidth = 0;
1829
+ if (rightAxis) {
1830
+ const rightAxisMin = d3__namespace.min(rightAxis);
1831
+ const rightAxisMax = d3__namespace.max(rightAxis);
1832
+ const yRightScale = d3__namespace
1833
+ .scaleLinear()
1834
+ .domain([rightAxisMin || 0, rightAxisMax || 0])
1835
+ .range(yRange)
1836
+ .nice();
1837
+ const yAxisRightTicks = d3__namespace.axisRight(yRightScale).ticks(yTicksCountDefault);
1838
+ const yAxisRight = svg
1839
+ .append('g')
1840
+ .attr('class', `${lineChartClassNames.lineChartYScaleGlobal} ${lineChartClassNames.lineChartYScaleRight}`)
1841
+ .call(yAxisRightTicks)
1842
+ .call(customYAxisSelection ? customYAxisSelection : none);
1843
+ ({ width: yAxisRightWidth } = computeDimensions(yAxisRight));
1844
+ yAxisRight.attr('transform', `translate(${width - yAxisRightWidth}, 0)`);
1845
+ }
1846
+ /** xScale **/
1847
+ const lastIndex = labels && labels.length
1848
+ ? labels.length - 1
1849
+ : data.reduce((acc, { values }) => Math.max(acc, values.length), 0) - 1;
1850
+ const xScale = d3__namespace
1851
+ .scaleLinear()
1852
+ .domain([0, lastIndex])
1853
+ .range([
1854
+ marginLeft + yAxisWidth + (yAxisPadding || 0),
1855
+ width - yAxisRightWidth - marginRight,
1856
+ ]);
1857
+ const xAxisBottom = d3__namespace
1858
+ .axisBottom(xScale)
1859
+ .tickFormat((value) =>
1860
+ // @ts-ignore
1861
+ labels && labels.length > 0 ? labels[value] : 0)
1862
+ .ticks(lastIndex);
1863
+ if (typeof xScaleItemWidth === 'number') {
1864
+ const [x1, x2] = xScale.range();
1865
+ const chartWidth = x2 - x1;
1866
+ xAxisBottom
1867
+ .ticks(Math.round(chartWidth / xScaleItemWidth))
1868
+ .tickSizeOuter(0);
1869
+ }
1870
+ customXAxis && customXAxis(xAxisBottom);
1871
+ drawGrid$2({
1872
+ svg,
1873
+ yScale,
1874
+ xScale,
1875
+ yTicksCount,
1876
+ lastIndex,
1877
+ drawGridY,
1878
+ drawGridX,
1879
+ });
1880
+ if (Array.isArray(labels) && labels.length > 0) {
1881
+ const xAxis = svg
1882
+ .append('g')
1883
+ .call(customXAxisSelection ? customXAxisSelection : none)
1884
+ .attr('class', lineChartClassNames.lineChartXScaleGlobal)
1885
+ .call(xAxisBottom);
1886
+ const { height: xAxisHeight } = computeDimensions(xAxis);
1887
+ xAxis.attr('transform', `translate(0, ${height - Math.ceil(xAxisHeight) - marginBottom})`);
1888
+ }
1889
+ const line = d3__namespace
1890
+ .line()
1891
+ .defined(d => d !== null)
1892
+ .x((_, index) => xScale(index))
1893
+ .y((d) => yScale(d))
1894
+ .curve(curve || d3__namespace.curveLinear);
1895
+ customLine && customLine(line);
1896
+ const withAreas = data.some(({ fill }) => fill);
1897
+ if (withAreas) {
1898
+ let dataIndex = -2;
1899
+ const getArea = (d) => {
1900
+ const { minAreaValues } = d;
1901
+ const minTick = yScale.ticks()[0];
1902
+ return d3__namespace
1903
+ .area()
1904
+ .defined(d => d !== null)
1905
+ .x((_, index) => xScale(index))
1906
+ .y0((value, index) => {
1907
+ if (index === 0) {
1908
+ dataIndex = dataIndex + 1;
1909
+ }
1910
+ let minValue = minTick;
1911
+ if (minAreaValues && typeof minAreaValues[index] === 'number') {
1912
+ minValue = minAreaValues[index] || minValue;
1913
+ }
1914
+ else if (minAreaValues) {
1915
+ minValue = yScale((minValue - value));
1916
+ }
1917
+ const currData = data[dataIndex];
1918
+ return stacked
1919
+ ? dataIndex > -1
1920
+ ? yScale(typeof currData.values[index] !== 'number'
1921
+ ? 0
1922
+ : currData.values[index])
1923
+ : yScale(minValue)
1924
+ : yScale(minValue);
1925
+ })
1926
+ .y1((d) => yScale(d))
1927
+ .curve(areaCurve || curve || d3__namespace.curveLinear);
1928
+ };
1929
+ svg
1930
+ .append('g')
1931
+ .attr('class', lineChartClassNames.lineChartAreasGlobal)
1932
+ .selectAll('path')
1933
+ .data(data.filter(({ fill }) => Boolean(fill)))
1934
+ .join('path')
1935
+ .attr('class', lineChartClassNames.lineChartArea)
1936
+ .attr('d', (d) => {
1937
+ const area = getArea(d);
1938
+ return area(d.values);
1939
+ })
1940
+ .attr('fill', ({ fill }) => fill || 'none')
1941
+ .attr('style', ({ areaStyle }) => areaStyle || '');
1942
+ }
1943
+ svg
1944
+ .append('g')
1945
+ .attr('class', lineChartClassNames.lineChartLinesGlobal)
1946
+ .selectAll('path')
1947
+ .data(data)
1948
+ .join('path')
1949
+ .attr('class', lineChartClassNames.lineChartLine)
1950
+ .attr('d', (d) => line(d.values))
1951
+ .attr('stroke', ({ stroke }) => stroke || 'steelblue')
1952
+ .attr('style', ({ style }) => style || '');
1953
+ const dots = data.filter(({ dot }) => dot);
1954
+ if (dots.length > 0) {
1955
+ const dotsGlobal = svg
1956
+ .append('g')
1957
+ .attr('class', lineChartClassNames.lineChartDotsGlobalContainer);
1958
+ dots.forEach(item => {
1959
+ const { values, dot } = item;
1960
+ const { radius, style, filter } = dot;
1961
+ const dotsGroup = dotsGlobal
1962
+ .append('g')
1963
+ .attr('class', lineChartClassNames.lineChartDotsGlobal);
1964
+ dotsGroup
1965
+ .selectAll('circle')
1966
+ .data(values)
1967
+ .join('circle')
1968
+ .attr('cx', (_, index) => xScale(index))
1969
+ .attr('class', lineChartClassNames.lineChartDot)
1970
+ .attr('cy', d => yScale(d))
1971
+ .attr('r', radius || 0)
1972
+ .attr('style', style || '');
1973
+ if (filter) {
1974
+ dotsGroup
1975
+ .selectAll('circle')
1976
+ .select((_, i, g) => (filter(item, i, g) ? g[i] : null))
1977
+ .remove();
1978
+ }
1979
+ });
1980
+ }
1981
+ d3__namespace.select(node)
1982
+ .select(`.${labelClassName}`)
1983
+ .remove();
1984
+ withLabels &&
1985
+ drawLabel({ node, eachLabel, data, yScale, xScale, formatLabel });
1986
+ if (dynamicTooltipEnable) {
1987
+ drawTooltip$2({
1988
+ tooltipLineTop,
1989
+ stackedTooltip,
1990
+ renderTooltip,
1991
+ stackedTooltipIndex,
1992
+ formatDynamicTooltip,
1993
+ node,
1994
+ svg,
1995
+ data,
1996
+ xScale,
1997
+ yScale,
1998
+ dynamicCircleRadius,
1999
+ tooltipClassName,
2000
+ dotSnapping,
2001
+ lastIndex,
2002
+ });
2003
+ }
2004
+ customize && customize({ svg, yScale, xScale });
2005
+ }
2006
+ };
2007
+
2008
+ const LineChart = (props) => {
2009
+ const { className, style, children } = props;
2010
+ const [ref, node] = useNode();
2011
+ react.useEffect(() => {
2012
+ node && draw$2(node, props);
2013
+ }, [node, props]);
2014
+ const onDraw = () => draw$2(node, props);
2015
+ useResize(props.width, onDraw);
2016
+ return (jsxRuntime.jsxs("div", { className: className, style: style, children: [jsxRuntime.jsx(TooltipStyles$2, {}), jsxRuntime.jsx(SvgWrapper$2, { ref: ref, children: children })] }));
2017
+ };
2018
+ LineChart.defaultProps = {
2019
+ data: [],
2020
+ labels: [],
2021
+ height: 240,
2022
+ yAxisPadding: 10,
2023
+ xAxisPadding: 20,
2024
+ margin: {
2025
+ top: 10,
2026
+ right: 10,
2027
+ bottom: 10,
2028
+ left: 0,
2029
+ },
2030
+ dynamicCircleRadius: 4,
2031
+ stackedTooltip: false,
2032
+ };
2033
+
2034
+ const barChartLinesClassNames = {
2035
+ barChartLinesGlobal: 'barChartLinesGlobal',
2036
+ barChartLine: 'barChartLine',
2037
+ barChartAreasGlobal: 'barChartAreasGlobal',
2038
+ barChartArea: 'barChartArea',
2039
+ };
2040
+ const drawLines = ({ svg, lineData, min, yScale, xScale, curve, stackedLine, }) => {
2041
+ let linesSelection = null;
2042
+ let areasSelection = null;
2043
+ let area = null;
2044
+ const line = d3__namespace
2045
+ .line()
2046
+ .defined(d => d !== null)
2047
+ .x((_, index) => xScale(index) + bandwidth / 2)
2048
+ // @ts-ignore
2049
+ .y((d) => yScale(d))
2050
+ .curve(curve || d3__namespace.curveLinear);
2051
+ const bandwidth = xScale.bandwidth();
2052
+ const linesData = lineData.filter(({ lineType }) => lineType === 'line');
2053
+ const areasData = lineData.filter(({ lineType }) => lineType === 'area');
2054
+ if (linesData.length > 0) {
2055
+ linesSelection = svg
2056
+ .append('g')
2057
+ .attr('class', barChartLinesClassNames.barChartLinesGlobal)
2058
+ .selectAll('path')
2059
+ .data(linesData)
2060
+ .join('path')
2061
+ .attr('class', barChartLinesClassNames.barChartLine)
2062
+ .attr('d', (d) => line(d.values))
2063
+ .attr('stroke', ({ stroke }) => stroke || '')
2064
+ .attr('fill', ({ fill }) => fill || 'none');
2065
+ }
2066
+ if (areasData.length > 0) {
2067
+ let dataIndex = -2;
2068
+ area = d3__namespace
2069
+ .area()
2070
+ .x((_, index) => xScale(index) + bandwidth / 2)
2071
+ .y0((_, index) => {
2072
+ if (index === 0) {
2073
+ dataIndex = dataIndex + 1;
2074
+ }
2075
+ return stackedLine
2076
+ ? dataIndex > -1
2077
+ ? yScale(typeof lineData[dataIndex].values[index] !== 'number'
2078
+ ? 0
2079
+ : lineData[dataIndex].values[index])
2080
+ : yScale(min)
2081
+ : yScale(min);
2082
+ })
2083
+ // @ts-ignore
2084
+ .y1(d => yScale(d))
2085
+ .curve(curve || d3__namespace.curveLinear);
2086
+ areasSelection = svg
2087
+ .append('g')
2088
+ .attr('class', barChartLinesClassNames.barChartAreasGlobal)
2089
+ .selectAll('path')
2090
+ .data(areasData)
2091
+ .join('path')
2092
+ .attr('class', barChartLinesClassNames.barChartArea)
2093
+ .attr('d', (d) => area && area(d.values))
2094
+ .attr('fill', ({ fill }) => fill || 'none');
2095
+ }
2096
+ return {
2097
+ areasSelection,
2098
+ linesSelection,
2099
+ area,
2100
+ };
2101
+ };
2102
+
2103
+ const tooltipClassnames = {
2104
+ barChartMouseRect: 'barChartMouseRect',
2105
+ barChartMouseContainer: 'barChartMouseContainer',
2106
+ barChartTooltipFlex: 'barChartTooltipFlex',
2107
+ barChartMouseTooltip: 'barChartMouseTooltip',
2108
+ barChartTooltip: 'barChartTooltip',
2109
+ barChartTooltipItem: 'barChartTooltipItem',
2110
+ barChartTooltipColFlex: 'barChartTooltipColFlex',
2111
+ barChartTooltipGroupName: 'barChartTooltipGroupName',
2112
+ barChartColorBox: 'barChartColorBox',
2113
+ barChartColorLine: 'barChartColorLine',
2114
+ barChartTooltipName: 'barChartTooltipName',
2115
+ barChartTooltipValue: 'barChartTooltipValue',
2116
+ };
2117
+ const labelClassnames = {
2118
+ barChartLabelContainer: 'barChartLabelContainer',
2119
+ barChartLabelFlex: 'barChartLabelFlex',
2120
+ barChartLabel: 'barChartLabel',
2121
+ };
2122
+ const barChartClassNames = {
2123
+ barChartBarGlobal: 'barChartBarGlobal',
2124
+ barChartYScaleGlobal: 'barChartYScaleGlobal',
2125
+ barChartYAxis: 'barChartYAxis',
2126
+ barChartXAxis: 'barChartXAxis',
2127
+ barChartYAxisZeroTick: 'barChartYAxisZeroTick',
2128
+ barChartGridGlobal: 'barChartGridGlobal',
2129
+ barChartGridLineX: 'barChartGridLineX',
2130
+ barChartGridLineXZero: 'barChartGridLineXZero',
2131
+ barChartGridLineYZero: 'barChartGridLineYZero',
2132
+ barChartGridLineY: 'barChartGridLineY',
2133
+ barChartSelection: 'barChartSelection',
2134
+ ...tooltipClassnames,
2135
+ ...labelClassnames,
2136
+ ...barChartLinesClassNames,
2137
+ };
2138
+ const SvgWrapper$1 = styled(Wrapper) `
2139
+ display: ${({ selectable }) => selectable && "inline-block"};
2140
+ user-select: ${({ selectable }) => selectable && "none"};
2141
+ width: ${({ selectable }) => selectable && "auto"};
2142
+
2143
+ line {
2144
+ stroke-width: 1px;
2145
+ shape-rendering: crispEdges;
2146
+ }
2147
+
2148
+ .${barChartClassNames.barChartGridLineX},
2149
+ .${barChartClassNames.barChartGridLineY} {
2150
+ stroke: rgba(48, 69, 79, 0.06);
2151
+ }
2152
+
2153
+ .${barChartClassNames.barChartMouseRect} {
2154
+ }
2155
+
2156
+ .${barChartClassNames.barChartMouseRect} {
2157
+ fill: none;
2158
+ pointer-events: all;
2159
+ }
2160
+
2161
+ .${barChartClassNames.barChartLinesGlobal} {
2162
+ stroke-width: 1.5px;
2163
+ stroke-linejoin: round;
2164
+ stroke-linecap: round;
2165
+ }
2166
+
2167
+ .${barChartClassNames.barChartLine} {
2168
+ shape-rendering: auto;
2169
+ }
2170
+
2171
+ .${barChartClassNames.barChartArea} {
2172
+ fill-opacity: 0.24;
2173
+ }
2174
+
2175
+ .${barChartClassNames.barChartSelection} {
2176
+ position: absolute;
2177
+ top: 0;
2178
+ width: 0;
2179
+ background: rgba(0, 170, 255, 0.06);
2180
+ box-shadow: 1px 0 0 #00AAFF, -1px 0 0 #00AAFF;
2181
+ pointer-events: none;
2182
+ }
2183
+ `;
2184
+ const TooltipStyles$1 = styled.createGlobalStyle `
2185
+ .${barChartClassNames.barChartMouseTooltip} {
2186
+ z-index: 100;
2187
+ transition: all linear 144ms;
2188
+
2189
+ .${barChartClassNames.barChartTooltipItem} {
2190
+ margin-bottom: 4px;
2191
+ :last-of-type {
2192
+ margin-bottom: 0;
2193
+ }
2194
+ }
2195
+ }
2196
+ `;
2197
+
2198
+ const useSelection = (node, props) => {
2199
+ const drawing = react.useRef(false);
2200
+ const startX = react.useRef(0);
2201
+ const selection = react.useRef();
2202
+ const clearSelection = react.useCallback(() => {
2203
+ if (node && selection.current) {
2204
+ drawing.current = false;
2205
+ node.removeChild(selection.current);
2206
+ selection.current = undefined;
2207
+ }
2208
+ }, [node]);
2209
+ const onStartDrawing = react.useCallback((e) => {
2210
+ const isTouch = Boolean(e.touches);
2211
+ e.stopPropagation();
2212
+ if (node && e.which !== 3) {
2213
+ clearSelection();
2214
+ selection.current = document.createElement("div");
2215
+ selection.current.setAttribute("class", barChartClassNames.barChartSelection);
2216
+ selection.current.setAttribute("style", `height: calc(100% - ${props.margin?.bottom ?? 0}px)`);
2217
+ node.appendChild(selection.current);
2218
+ drawing.current = true;
2219
+ startX.current = isTouch
2220
+ ? (e.touches[0]?.pageX - node.firstChild.getBoundingClientRect().left)
2221
+ : e.offsetX;
2222
+ selection.current.style.display = "block";
2223
+ selection.current.style.width = "0px";
2224
+ selection.current.style.left = `${startX.current}px`;
2225
+ }
2226
+ }, [node]);
2227
+ const onDraw = react.useCallback((e) => {
2228
+ const isTouch = Boolean(e.touches);
2229
+ e.stopPropagation();
2230
+ if (node && drawing.current && selection.current) {
2231
+ const nodeWidth = node.firstChild.getBoundingClientRect().width;
2232
+ const offsetX = isTouch
2233
+ ? (e.touches[0]?.pageX - node.firstChild.getBoundingClientRect().left)
2234
+ : e.offsetX;
2235
+ const newWidth = offsetX - startX.current;
2236
+ if (offsetX >= 0) {
2237
+ if (newWidth > 0) {
2238
+ selection.current.style.marginLeft = "0px";
2239
+ selection.current.style.width = offsetX <= nodeWidth ? `${newWidth}px` : `${nodeWidth - startX.current}px`;
2240
+ }
2241
+ else {
2242
+ selection.current.style.right = `${nodeWidth - startX.current}px`;
2243
+ selection.current.style.width = `${Math.abs(newWidth)}px`;
2244
+ selection.current.style.marginLeft = `${newWidth}px`;
2245
+ }
2246
+ }
2247
+ if (isTouch) {
2248
+ if (node.offsetLeft > e.touches[0].pageX) {
2249
+ selection.current.style.right = `${nodeWidth - startX.current}px`;
2250
+ selection.current.style.width = `${startX.current}px`;
2251
+ selection.current.style.marginLeft = `-${startX.current}px`;
2252
+ }
2253
+ }
2254
+ }
2255
+ }, [node]);
2256
+ const onMouseLeave = react.useCallback((e) => {
2257
+ if (drawing.current && node && selection.current) {
2258
+ if (node.offsetLeft > e.pageX) {
2259
+ const nodeWidth = node.firstChild.getBoundingClientRect().width;
2260
+ selection.current.style.right = `${nodeWidth - startX.current}px`;
2261
+ selection.current.style.width = `${startX.current}px`;
2262
+ selection.current.style.marginLeft = `-${startX.current}px`;
2263
+ }
2264
+ if (node.offsetLeft + node.offsetWidth < e.pageX) {
2265
+ const nodeWidth = node.firstChild.getBoundingClientRect().width;
2266
+ selection.current.style.left = `${startX.current}px`;
2267
+ selection.current.style.width = `${nodeWidth - startX.current}px`;
2268
+ selection.current.style.marginLeft = "0px";
2269
+ }
2270
+ }
2271
+ }, [node]);
2272
+ const onStopDrawing = react.useCallback(() => {
2273
+ if (node && selection.current) {
2274
+ const nodeWidth = node.firstChild.getBoundingClientRect().width;
2275
+ const selectionMinX = selection.current.offsetLeft >= 0
2276
+ ? selection.current.offsetLeft <= nodeWidth ? selection.current.offsetLeft : nodeWidth
2277
+ : 0;
2278
+ const selectionWidth = selection.current.getBoundingClientRect().right - selection.current.getBoundingClientRect().left;
2279
+ const selectionMaxX = selection.current.offsetLeft + selectionWidth <= nodeWidth
2280
+ ? selection.current.offsetLeft + selectionWidth >= 0 ? selection.current.offsetLeft + selectionWidth : 0
2281
+ : nodeWidth;
2282
+ const min = Math.round(selectionMinX);
2283
+ const max = Math.round(selectionMaxX);
2284
+ if (max - min > 0 && props.onSelect) {
2285
+ props.onSelect([min, max]);
2286
+ }
2287
+ }
2288
+ clearSelection();
2289
+ }, [node, clearSelection]);
2290
+ react.useEffect(() => {
2291
+ if (node) {
2292
+ node.childNodes.forEach((child) => {
2293
+ child.style.userSelect = "none";
2294
+ });
2295
+ node.addEventListener("mousedown", onStartDrawing);
2296
+ node.addEventListener("touchstart", onStartDrawing);
2297
+ node.addEventListener("mousemove", onDraw);
2298
+ node.addEventListener("touchmove", onDraw);
2299
+ node.addEventListener("mouseleave", onMouseLeave);
2300
+ node.addEventListener("mouseup", onStopDrawing);
2301
+ node.addEventListener("touchend", onStopDrawing);
2302
+ document.addEventListener("mouseup", onStopDrawing);
2303
+ }
2304
+ return () => {
2305
+ node?.removeEventListener("mousedown", onStartDrawing);
2306
+ node?.removeEventListener("touchstart", onStartDrawing);
2307
+ node?.removeEventListener("mousemove", onDraw);
2308
+ node?.removeEventListener("touchmove", onDraw);
2309
+ node?.removeEventListener("mouseleave", onMouseLeave);
2310
+ node?.removeEventListener("mouseup", onStopDrawing);
2311
+ node?.removeEventListener("touchend", onStopDrawing);
2312
+ document.removeEventListener("mouseup", onStopDrawing);
2313
+ };
2314
+ }, [node]);
2315
+ };
2316
+
2317
+ const drawGrid$1 = ({ svg, yScale, xScale, yTicksCount, drawGridX, drawGridY, }) => {
2318
+ if (!drawGridY && !drawGridX)
2319
+ return;
2320
+ const global = svg
2321
+ .append('g')
2322
+ .attr('class', barChartClassNames.barChartGridGlobal);
2323
+ const yTicks = yScale.ticks(yTicksCount);
2324
+ const range = xScale.range();
2325
+ const domain = xScale.domain();
2326
+ if (drawGridX) {
2327
+ global
2328
+ .append('g')
2329
+ .selectAll('line')
2330
+ .data(yTicks)
2331
+ .join('line')
2332
+ .attr('class', d => d === 0
2333
+ ? `${barChartClassNames.barChartGridLineX} ${barChartClassNames.barChartGridLineXZero}`
2334
+ : barChartClassNames.barChartGridLineX)
2335
+ .attr('x1', () => range[0])
2336
+ .attr('x2', () => range[1])
2337
+ .attr('y1', (d) => Math.round(yScale(d)))
2338
+ .attr('y2', (d) => Math.round(yScale(d)));
2339
+ }
2340
+ if (drawGridY) {
2341
+ const getX = (index) => domain[index] !== void 0
2342
+ ? index === 0
2343
+ ? range[0]
2344
+ : Math.round(xScale.step() * index +
2345
+ range[0] -
2346
+ (xScale.step() / 2) * xScale.padding())
2347
+ : range[1];
2348
+ global
2349
+ .append('g')
2350
+ .selectAll('line')
2351
+ .data(Array.from({ length: domain.length + 1 }, (_, index) => index))
2352
+ .join('line')
2353
+ .attr('class', d => d === 0
2354
+ ? `${barChartClassNames.barChartGridLineY} ${barChartClassNames.barChartGridLineYZero}`
2355
+ : barChartClassNames.barChartGridLineY)
2356
+ .attr('x1', getX)
2357
+ .attr('x2', getX)
2358
+ .attr('y1', () => Math.round(yScale(yTicks[0])))
2359
+ .attr('y2', () => Math.round(yScale(yTicks[yTicks.length - 1])));
2360
+ }
2361
+ };
2362
+
2363
+ const getDomain = ({ data, minDomainValue, maxDomainValue, }) => {
2364
+ let MIN = Number.POSITIVE_INFINITY;
2365
+ let MAX = Number.NEGATIVE_INFINITY;
2366
+ data.forEach(({ groupName, ...groups }) => {
2367
+ let groupMax = 0;
2368
+ let groupMin = 0;
2369
+ Object.keys(groups).forEach(key => {
2370
+ const group = groups[key];
2371
+ let stackMax = 0;
2372
+ let stackMin = 0;
2373
+ Object.keys(group).forEach(groupKey => {
2374
+ const value = group[groupKey];
2375
+ if (value > 0) {
2376
+ stackMax += value;
2377
+ }
2378
+ else {
2379
+ stackMin += value;
2380
+ }
2381
+ });
2382
+ groupMax = Math.min(groupMax, stackMin);
2383
+ groupMin = Math.max(groupMin, stackMax);
2384
+ });
2385
+ MIN = Math.min(MIN, groupMax);
2386
+ MAX = Math.max(MAX, groupMin);
2387
+ });
2388
+ if (MIN === 0 && MAX === 0) {
2389
+ return {
2390
+ min: typeof minDomainValue === 'number' ? minDomainValue : 0,
2391
+ max: typeof maxDomainValue === 'number' ? maxDomainValue : 1,
2392
+ };
2393
+ }
2394
+ return {
2395
+ min: typeof minDomainValue === 'number' ? minDomainValue : MIN,
2396
+ max: typeof maxDomainValue === 'number' ? maxDomainValue : MAX,
2397
+ };
2398
+ };
2399
+
2400
+ const marshaling = ({ data, yScale, xScale, barWidth, barPadding, colors, marginTop, }) => data.map(({ groupName, ...groups }, groupIndex) => {
2401
+ const marshalledGroup = [];
2402
+ const hundred = 100;
2403
+ const bandwidth = xScale.bandwidth();
2404
+ const groupsKeys = Object.keys(groups);
2405
+ groupsKeys.forEach((key, stackIndex) => {
2406
+ const group = groups[key];
2407
+ const groupKeys = Object.keys(group);
2408
+ const barGroupWidth = (barWidth + barPadding) * groupsKeys.length -
2409
+ (groupKeys.length > 1 ? barPadding : 0);
2410
+ let stackMax = 0;
2411
+ let stackMin = 0;
2412
+ groupKeys.forEach(groupKey => {
2413
+ const value = group[groupKey];
2414
+ const color = colors[groupKey];
2415
+ const x = (barWidth + barPadding) * stackIndex +
2416
+ bandwidth / 2 -
2417
+ barGroupWidth / 2;
2418
+ const isPositiveValue = value > 0;
2419
+ const height = isPositiveValue
2420
+ ? Math.abs(((yScale(stackMax - value) - yScale(stackMax) + Number.EPSILON) *
2421
+ hundred) /
2422
+ hundred)
2423
+ : Math.abs(((yScale(stackMin - value) - yScale(stackMin) + Number.EPSILON) *
2424
+ hundred) /
2425
+ hundred);
2426
+ if (isPositiveValue) {
2427
+ stackMax += value;
2428
+ }
2429
+ const y = isPositiveValue
2430
+ ? ((yScale(stackMax) + Number.EPSILON) * hundred) / hundred
2431
+ : yScale(stackMin) - yScale(0) + yScale(0);
2432
+ marshalledGroup.push({
2433
+ x,
2434
+ y: y + (marginTop || 0),
2435
+ height,
2436
+ color,
2437
+ value,
2438
+ groupName: groupName,
2439
+ name: groupKey,
2440
+ stackIndex,
2441
+ groupIndex,
2442
+ });
2443
+ if (!isPositiveValue) {
2444
+ stackMin += value;
2445
+ }
2446
+ });
2447
+ });
2448
+ return marshalledGroup;
2449
+ });
2450
+
2451
+ const getLabelY = (labelPosition, y2, item) => {
2452
+ switch (labelPosition) {
2453
+ case 'center':
2454
+ return item.y + item.height / 2 - y2;
2455
+ case 'bottom':
2456
+ return item.y + item.height - y2;
2457
+ default:
2458
+ return item.y;
2459
+ }
2460
+ };
2461
+
2462
+ const getLabel = (labelPosition) => {
2463
+ switch (labelPosition) {
2464
+ case 'top':
2465
+ return LabelTop;
2466
+ case 'bottom':
2467
+ return LabelBottom;
2468
+ default:
2469
+ return Label$1;
2470
+ }
2471
+ };
2472
+
2473
+ const drawTooltip$1 = ({ svg, node, data, marshalledData, xScale, yScale, renderTooltip, labelPosition, marginTop, renderLabel, barWidth, barPadding, dynamicTooltipEnable, hideTooltipGroupName, tooltipY, tooltipBind, lineData, formatTooltipValue, formatTooltipName, tooltipYDomain, setTooltipPosition, onLabelItem, isBarTooltip, bars, tooltipRoot, tooltipClassName, onBarClick, onBarHover, }) => {
2474
+ d3__namespace.select(node)
2475
+ .select(`.${barChartClassNames.barChartMouseContainer}`)
2476
+ .remove();
2477
+ const xScaleBandDomain = xScale.domain();
2478
+ const [x1, x2] = xScale.range();
2479
+ const [y1, y2] = yScale.range();
2480
+ const bandwidth = xScale.bandwidth();
2481
+ const format = d3__namespace.format(",");
2482
+ const getX = (index) => xScaleBandDomain[index] !== void 0
2483
+ ? index === 0
2484
+ ? x1
2485
+ : Math.round(xScale.step() * index + x1 - (xScale.step() / 2) * xScale.padding())
2486
+ : x2;
2487
+ const groups = xScaleBandDomain.map(value => getX(Number(value) + 1));
2488
+ const topYDomain = tooltipYDomain
2489
+ ? tooltipYDomain({ data: marshalledData, lineData, yScale })
2490
+ : marshalledData.reduce((acc, curr, index) => {
2491
+ const lineMin = d3__namespace.min(lineData, ({ values }) => typeof values[index] === "number"
2492
+ ? yScale((values[index] || 0) - y2)
2493
+ : Number.POSITIVE_INFINITY) || Number.POSITIVE_INFINITY;
2494
+ acc.push(curr.reduce((acc, { y }) => Math.min(acc, y, lineMin), Number.POSITIVE_INFINITY));
2495
+ return acc;
2496
+ }, []);
2497
+ const mouseGlobal = svg.append("g").attr("class", "lineChartMouseGlobal");
2498
+ const mouseRect = mouseGlobal
2499
+ .append("rect")
2500
+ .attr("width", x2 - x1)
2501
+ .attr("height", Math.abs(y1 - y2))
2502
+ .attr("class", barChartClassNames.barChartMouseRect)
2503
+ .attr("transform", `translate(${x1}, ${y2})`);
2504
+ if (dynamicTooltipEnable) {
2505
+ const tooltipContainer = tooltipRoot || document.querySelector("body");
2506
+ let tooltip = d3__namespace.select(`.${barChartClassNames.barChartMouseTooltip}`);
2507
+ if (tooltip.size() === 0) {
2508
+ tooltip = d3__namespace
2509
+ .select(tooltipContainer)
2510
+ .append("div")
2511
+ .attr("class", barChartClassNames.barChartMouseTooltip)
2512
+ .style("opacity", "0")
2513
+ .style("position", "absolute")
2514
+ .html(() => {
2515
+ const html = ReactDOMServer.renderToString(jsxRuntime.jsx(TooltipFlex$1, { className: barChartClassNames.barChartTooltipFlex }));
2516
+ return html;
2517
+ });
2518
+ }
2519
+ const barChartTootipFlex = tooltip.select(`.${barChartClassNames.barChartTooltipFlex}`);
2520
+ let isVisible = false;
2521
+ let flagCurrIndex = null;
2522
+ const setVisible = (visible) => {
2523
+ isVisible = Boolean(visible);
2524
+ const opacity = isVisible ? "1" : "0";
2525
+ tooltip.style("opacity", opacity);
2526
+ if (!isVisible) {
2527
+ tooltip.attr("class", barChartClassNames.barChartMouseTooltip);
2528
+ flagCurrIndex = null;
2529
+ tooltip.style("transition", "none");
2530
+ tooltip.style("top", null);
2531
+ tooltip.style("left", null);
2532
+ }
2533
+ else {
2534
+ tooltip.attr("class", `${barChartClassNames.barChartMouseTooltip} ${tooltipClassName || ""}`);
2535
+ tooltip.style("transition", null);
2536
+ }
2537
+ };
2538
+ mouseRect.on("mouseout.tooltip", () => setVisible());
2539
+ mouseRect.on("touchmove.tooltip mousemove.tooltip", event => {
2540
+ const [docX, docY] = d3__namespace.pointer(event, document);
2541
+ const [rectrX] = d3__namespace.pointer(event, mouseRect);
2542
+ const [nodeX, nodeY] = d3__namespace.pointer(event, node);
2543
+ const x = rectrX - (rectrX - nodeX);
2544
+ const offsetX = docX - nodeX;
2545
+ const offsetY = docY - nodeY;
2546
+ const currIndex = groups.findIndex(value => x <= value);
2547
+ if (isBarTooltip) {
2548
+ const containts = document.elementsFromPoint(event.clientX, event.clientY);
2549
+ const currBars = d3__namespace
2550
+ .select(bars.nodes()[currIndex])
2551
+ .selectAll("rect")
2552
+ .nodes();
2553
+ const isContains = containts.some(item => currBars.includes(item));
2554
+ if (!isContains) {
2555
+ if (isVisible) {
2556
+ setVisible(false);
2557
+ }
2558
+ mouseRect.style("cursor", "default");
2559
+ return;
2560
+ }
2561
+ else {
2562
+ mouseRect.style("cursor", "pointer");
2563
+ }
2564
+ }
2565
+ const top = (typeof tooltipY === "number"
2566
+ ? tooltipY
2567
+ : topYDomain[currIndex] - y2) + offsetY;
2568
+ const left = (tooltipBind
2569
+ ? (xScale(currIndex) || 0) + bandwidth / 2
2570
+ : x) + offsetX;
2571
+ if (tooltipBind && flagCurrIndex === currIndex) {
2572
+ return;
2573
+ }
2574
+ let currData = marshalledData[currIndex];
2575
+ if (Array.isArray(currData) && currData.length === 0) {
2576
+ return;
2577
+ }
2578
+ if (lineData) {
2579
+ const currLineData = lineData.map(({ values, ...rest }) => ({
2580
+ ...rest,
2581
+ value: values[currIndex],
2582
+ groupName: data[currIndex] && data[currIndex].groupName,
2583
+ }));
2584
+ if (Array.isArray(currLineData) && Array.isArray(currData)) {
2585
+ currData = currData.concat(currLineData);
2586
+ }
2587
+ }
2588
+ const svgWidth = svg.node().getBoundingClientRect()
2589
+ .width;
2590
+ if (typeof setTooltipPosition === "function") {
2591
+ setTooltipPosition({
2592
+ left,
2593
+ top,
2594
+ tooltip,
2595
+ svgWidth,
2596
+ });
2597
+ }
2598
+ else if (!setTooltipPosition) {
2599
+ tooltip.style("left", `${left}px`).style("top", `${top}px`);
2600
+ }
2601
+ if (renderTooltip) {
2602
+ barChartTootipFlex.html(() => {
2603
+ const html = ReactDOMServer.renderToString(jsxRuntime.jsx(jsxRuntime.Fragment, { children: renderTooltip(currData, setTooltipPosition
2604
+ ? {
2605
+ left,
2606
+ top,
2607
+ tooltip,
2608
+ svgWidth,
2609
+ }
2610
+ : undefined, barWidth) }));
2611
+ return html;
2612
+ });
2613
+ }
2614
+ else {
2615
+ if (!isVisible) {
2616
+ setVisible(true);
2617
+ }
2618
+ barChartTootipFlex.html(() => {
2619
+ const html = ReactDOMServer.renderToString(jsxRuntime.jsxs(TooltipContainer, { className: barChartClassNames.barChartTooltip, children: [currData && currData[0] && !hideTooltipGroupName && (jsxRuntime.jsx(TooltipGroupName, { className: barChartClassNames.barChartTooltipGroupName, children: currData[0].groupName })), currData &&
2620
+ currData.map(({ name, value, stroke, fill, color, lineType }) => (jsxRuntime.jsxs(TooltipItem, { className: barChartClassNames.barChartTooltipItem, children: [jsxRuntime.jsxs(ColFlex, { className: barChartClassNames.barChartTooltipColFlex, children: [lineType ? (jsxRuntime.jsx(ColorLine, { className: barChartClassNames.barChartColorLine, style: { backgroundColor: stroke || fill } })) : (jsxRuntime.jsx(ColorBox, { className: barChartClassNames.barChartColorBox, style: { backgroundColor: color } })), jsxRuntime.jsx(Name, { className: barChartClassNames.barChartTooltipName, children: formatTooltipName ? formatTooltipName(name) : name })] }), jsxRuntime.jsx(Value, { className: barChartClassNames.barChartTooltipValue, children: formatTooltipValue
2621
+ ? formatTooltipValue(value, name)
2622
+ : format(value) })] }, name)))] }));
2623
+ return html;
2624
+ });
2625
+ }
2626
+ flagCurrIndex = currIndex;
2627
+ if (!isVisible) {
2628
+ setVisible(true);
2629
+ }
2630
+ });
2631
+ }
2632
+ const container = d3__namespace
2633
+ .select(node)
2634
+ .append("div")
2635
+ .attr("class", barChartClassNames.barChartMouseContainer);
2636
+ const labelContainer = container
2637
+ .append("div")
2638
+ .attr("class", barChartClassNames.barChartLabelContainer)
2639
+ .style("position", "absolute")
2640
+ .style("top", `${y2}px`);
2641
+ const isMouseWithin = (e, callback) => {
2642
+ const [rectrX, rectrY] = d3__namespace.pointer(e, mouseRect);
2643
+ const [nodeX, nodeY] = d3__namespace.pointer(e, node);
2644
+ const x = rectrX - (rectrX - nodeX);
2645
+ const y = rectrY - nodeY;
2646
+ const currIndex = groups.findIndex(value => x <= value);
2647
+ const dataItem = marshalledData[currIndex][0];
2648
+ if (dataItem.height >= y1 - y) {
2649
+ callback(dataItem);
2650
+ }
2651
+ };
2652
+ mouseGlobal
2653
+ .on("click", e => isMouseWithin(e, (dataItem) => onBarClick && onBarClick(dataItem)))
2654
+ .on("mousemove", e => isMouseWithin(e, (dataItem) => onBarHover && onBarHover(dataItem)))
2655
+ .on("mouseleave", () => onBarHover && onBarHover(undefined));
2656
+ if (labelPosition) {
2657
+ const concatedData = lineData
2658
+ ? marshalledData.map((stack, index) => stack.concat(lineData.map(({ values, name, stroke }) => {
2659
+ const { stacksCount } = stack.reduce((acc, { stackIndex }) => {
2660
+ const { indexFlag, stacksCount } = acc;
2661
+ if (stackIndex !== indexFlag) {
2662
+ return {
2663
+ indexFlag: stackIndex,
2664
+ stacksCount: stacksCount + 1,
2665
+ };
2666
+ }
2667
+ return acc;
2668
+ }, {
2669
+ indexFlag: -1,
2670
+ stacksCount: 0,
2671
+ });
2672
+ const barsWidth = (barWidth * stacksCount +
2673
+ (barPadding || 0) * (stacksCount - 1)) /
2674
+ 2;
2675
+ return {
2676
+ x: stack[0].x - barWidth / 2 + barsWidth,
2677
+ y: yScale(values[index]) + marginTop,
2678
+ height: 0,
2679
+ color: stroke,
2680
+ value: values[index],
2681
+ groupName: stack[0].groupName,
2682
+ name,
2683
+ stackIndex: 0,
2684
+ groupIndex: index,
2685
+ };
2686
+ })))
2687
+ : marshalledData;
2688
+ const groups = labelContainer
2689
+ .selectAll("div")
2690
+ .data(concatedData)
2691
+ .enter()
2692
+ .append("div")
2693
+ .style("position", "absolute")
2694
+ .style("transform", (_, index) => `translate(${Math.round(xScale(index))}px,${-(marginTop || 0)}px)`);
2695
+ const LabelFlexStyled = labelPosition === "center" ? LabelFlexCenter : LabelFlex;
2696
+ const LabelStyle = getLabel(labelPosition);
2697
+ groups
2698
+ .selectAll("span")
2699
+ .data((item) => onLabelItem ? onLabelItem(item) : item)
2700
+ .join("div")
2701
+ .style("left", item => `${Math.round(item.x + barWidth / 2)}px`)
2702
+ .style("top", (item) => `${getLabelY(labelPosition, y2, item)}px`)
2703
+ .style("position", "absolute")
2704
+ .html((item) => ReactDOMServer.renderToString(jsxRuntime.jsx(LabelFlexStyled, { className: barChartClassNames.barChartLabelFlex, children: renderLabel ? (renderLabel({ ...item, barWidth })) : (jsxRuntime.jsx(LabelStyle, { className: barChartClassNames.barChartLabel, children: format(item.value) })) })));
2705
+ }
2706
+ };
2707
+
2708
+ const resizeBarWidth = ({ data, range, barWidth, barPadding, sectionPadding, }) => {
2709
+ const groupPadding = typeof sectionPadding === 'number' ? sectionPadding : 0;
2710
+ const chartWidth = range[1] - range[0];
2711
+ const barsWidth = data.reduce((acc, { groupName, ...curr }) => {
2712
+ return (acc +
2713
+ Object.keys(curr).reduce((acc, _key, index) => index > 0
2714
+ ? acc + (barWidth || 0) + (barPadding || 0)
2715
+ : acc + barWidth, 0) +
2716
+ groupPadding);
2717
+ }, groupPadding);
2718
+ if (chartWidth < barsWidth) {
2719
+ return Math.floor(barWidth * (chartWidth / barsWidth));
2720
+ }
2721
+ return barWidth;
2722
+ };
2723
+
2724
+ const MIN_BAR_HEIGHT$1 = 2;
2725
+ const getBars = ({ groups, barWidth }) => {
2726
+ return groups
2727
+ .selectAll('rect')
2728
+ .data((item) => item)
2729
+ .join('rect')
2730
+ .attr('x', (item) => item.x)
2731
+ .attr('y', (item) => item.y)
2732
+ .attr('width', barWidth)
2733
+ .attr('height', (item) => item.value === null ? 0 : Math.max(item.height, MIN_BAR_HEIGHT$1))
2734
+ .style('fill', (item) => item.color);
2735
+ };
2736
+
2737
+ const MIN_BAR_HEIGHT = 2;
2738
+ const draw$1 = (node, props) => {
2739
+ const { data, lineData = [], markers = [], barWidth: barWidthProp, barPadding, colors, margin, xAxisPadding, yAxisPadding, drawGridY, drawGridX, customYScale, customXScale, customYAxisLeft, customXAxisBottom, customYAxis, customXAxis, customBars, customize, dynamicTooltipEnable, hideTooltipGroupName, renderTooltip, labelPosition, renderLabel, tooltipY, tooltipBind, stackedLine, curve, formatTooltipValue, formatTooltipName, sectionPadding, minValuesLine, tooltipYDomain, marshalledMap, minValue, maxValue, minDomainValue, maxDomainValue, drawBars, setTooltipPosition, onLabelItem, isBarTooltip, xScaleItemWidth, tooltipRoot, tooltipClassName, onBarClick, onBarHover, } = props;
2740
+ if (node !== null && data.length) {
2741
+ const marginTop = margin ? margin.top : 0;
2742
+ const marginRight = margin ? margin.right : 0;
2743
+ const marginBottom = margin ? margin.bottom : 0;
2744
+ const marginLeft = margin ? margin.left : 0;
2745
+ const defaultBarWidth = 12;
2746
+ const { width: nodeWidth } = node.getBoundingClientRect();
2747
+ const width = props.width || nodeWidth;
2748
+ const height = props.height || 0;
2749
+ const barDomain = getDomain({
2750
+ data,
2751
+ minDomainValue,
2752
+ maxDomainValue,
2753
+ });
2754
+ const min = typeof minValue === 'number'
2755
+ ? minValue
2756
+ : Math.min(d3__namespace.min(lineData, ({ values }) => d3__namespace.min(values)) ||
2757
+ Number.POSITIVE_INFINITY, barDomain.min || 0);
2758
+ const max = typeof maxValue === 'number'
2759
+ ? maxValue
2760
+ : Math.max(d3__namespace.max(lineData, ({ values }) => d3__namespace.max(values)) ||
2761
+ Number.NEGATIVE_INFINITY, barDomain.max);
2762
+ const svg = appendSvg(node, width, height || 0);
2763
+ const yTicksCountDefault = 6;
2764
+ const labels = data.map((item) => item.groupName);
2765
+ let barWidth = barWidthProp || defaultBarWidth;
2766
+ const yScale = d3__namespace
2767
+ .scaleLinear()
2768
+ .domain([min, max])
2769
+ .range([
2770
+ height - marginTop - marginBottom - (xAxisPadding || 0),
2771
+ marginTop,
2772
+ ])
2773
+ .nice();
2774
+ customYScale && customYScale(yScale);
2775
+ const yTicks = yScale.ticks();
2776
+ const yAxisLeft = d3__namespace.axisLeft(yScale).ticks(yTicksCountDefault);
2777
+ customYAxisLeft && customYAxisLeft(yAxisLeft);
2778
+ const yTicksCount = yAxisLeft.tickArguments()[0];
2779
+ const yAxis = svg
2780
+ .append('g')
2781
+ .attr('class', barChartClassNames.barChartYAxis)
2782
+ .call(yAxisLeft);
2783
+ yAxis.selectAll('.tick').attr('class', value => {
2784
+ return value === 0 ? `tick ${barChartClassNames.barChartYAxisZeroTick}` : 'tick';
2785
+ });
2786
+ customYAxis && customYAxis(yAxis);
2787
+ const { width: yAxisWidth } = computeDimensions(yAxis);
2788
+ const range = [
2789
+ marginLeft + yAxisWidth + (yAxisPadding || 0),
2790
+ width - marginRight,
2791
+ ];
2792
+ const xScale = d3__namespace
2793
+ .scaleBand()
2794
+ .domain(d3__namespace.range(data.length))
2795
+ .range(range);
2796
+ barWidth = resizeBarWidth({
2797
+ data,
2798
+ sectionPadding,
2799
+ range,
2800
+ barWidth,
2801
+ barPadding,
2802
+ });
2803
+ customXScale && customXScale(xScale);
2804
+ const [x1, x2] = xScale.range();
2805
+ const xAxisBottom = d3__namespace
2806
+ .axisBottom(xScale)
2807
+ .tickFormat(value => labels[Number(value)]);
2808
+ if (typeof xScaleItemWidth === 'number') {
2809
+ xAxisBottom
2810
+ .tickValues(xScale.domain().filter((_, i, array) => {
2811
+ const chartWidth = x2 - x1;
2812
+ const ticks = Math.round(chartWidth / xScaleItemWidth);
2813
+ const length = array.length;
2814
+ const divider = Math.round(length / ticks);
2815
+ return !(i % divider);
2816
+ }))
2817
+ .tickSizeOuter(0);
2818
+ }
2819
+ customXAxisBottom && customXAxisBottom(xAxisBottom, { node, labels });
2820
+ const xAxis = svg
2821
+ .append('g')
2822
+ .call(xAxisBottom)
2823
+ .attr('class', barChartClassNames.barChartXAxis);
2824
+ customXAxis && customXAxis(xAxis);
2825
+ const marshalled = marshaling({
2826
+ data,
2827
+ yScale,
2828
+ xScale,
2829
+ barWidth,
2830
+ barPadding: typeof barPadding === 'number' ? barPadding : 0,
2831
+ colors,
2832
+ marginTop,
2833
+ });
2834
+ const marshalledData = marshalledMap
2835
+ ? marshalledMap(marshalled)
2836
+ : marshalled;
2837
+ yAxis.attr('transform', `translate( ${marginLeft + yAxisWidth}, 0)`);
2838
+ drawGrid$1({
2839
+ svg,
2840
+ yScale,
2841
+ xScale,
2842
+ yTicksCount,
2843
+ drawGridY,
2844
+ drawGridX,
2845
+ });
2846
+ xAxis.attr('transform', `translate(0, ${yScale(yTicks[0]) + (xAxisPadding || 0)})`);
2847
+ const maskId = `height-limit-mask-${lodash.uniqueId()}`;
2848
+ svg.append('defs')
2849
+ .append('mask')
2850
+ .attr('id', maskId)
2851
+ .append('rect')
2852
+ .attr('width', '100%')
2853
+ .attr('height', height - marginBottom + MIN_BAR_HEIGHT)
2854
+ .attr('fill', 'white');
2855
+ const gSvg = svg.append('g')
2856
+ .attr('class', barChartClassNames.barChartBarGlobal)
2857
+ .attr('mask', `url(#${maskId})`);
2858
+ const groups = gSvg
2859
+ .selectAll('g')
2860
+ .data(marshalledData)
2861
+ .enter()
2862
+ .append('g')
2863
+ .attr('transform', (_, i) => `translate(${Math.round(xScale(i))},${-(marginTop || 0)})`);
2864
+ const bars = drawBars
2865
+ ? drawBars({ groups, yScale, marshalledData, barWidth })
2866
+ : getBars({ groups, barWidth });
2867
+ markers.forEach((marker) => {
2868
+ if (!marker) {
2869
+ return;
2870
+ }
2871
+ if (marker.horizontal) {
2872
+ if (marker.line) {
2873
+ svg.append('line')
2874
+ .style("stroke", marker.lineColor || marker.color || "inherit")
2875
+ .style("stroke-width", 1)
2876
+ .style("stroke-dasharray", ("5, 3"))
2877
+ .attr("x1", marginLeft + yAxisWidth)
2878
+ .attr("y1", yScale(marker.value) + 1)
2879
+ .attr("x2", width)
2880
+ .attr("y2", yScale(marker.value) + 1);
2881
+ }
2882
+ svg.append("text")
2883
+ .attr("y", yScale(marker.value) + 1)
2884
+ .attr("x", marginLeft + yAxisWidth)
2885
+ .attr('text-anchor', 'middle')
2886
+ .attr("class", ["marker", marker.className].filter(Boolean).join(" "))
2887
+ .style("fill", marker?.color || "inherit")
2888
+ .text(marker.label);
2889
+ return;
2890
+ }
2891
+ if (marker.line) {
2892
+ svg.append('line')
2893
+ .style("stroke", marker.lineColor || marker.color || "inherit")
2894
+ .style("stroke-width", 1)
2895
+ .style("stroke-dasharray", ("5, 3"))
2896
+ .attr("x1", width / data.length * marker.value + 1)
2897
+ .attr("y1", 0)
2898
+ .attr("x2", width / data.length * marker.value + 1)
2899
+ .attr("y2", (height - marginTop - marginBottom + 8));
2900
+ }
2901
+ svg.append("text")
2902
+ .attr("y", height - 2)
2903
+ .attr("x", width / data.length * marker.value + 1)
2904
+ .attr('text-anchor', marker.align === 'right' ? 'end' : marker.align === 'left' ? 'start' : 'middle')
2905
+ .attr("class", ["marker", marker.className].filter(Boolean).join(" "))
2906
+ .style("fill", marker?.color || "inherit")
2907
+ .text(marker.label);
2908
+ });
2909
+ let lines = null;
2910
+ if (Array.isArray(lineData) && lineData.length > 0) {
2911
+ lines = drawLines({
2912
+ svg,
2913
+ lineData,
2914
+ xScale,
2915
+ yScale,
2916
+ min: typeof minValuesLine === 'number' ? minValuesLine : min,
2917
+ stackedLine,
2918
+ curve,
2919
+ });
2920
+ }
2921
+ customBars && customBars({ bars, yScale, lines, marshalledData, lineData });
2922
+ if (dynamicTooltipEnable || labelPosition) {
2923
+ drawTooltip$1({
2924
+ svg,
2925
+ node,
2926
+ xScale,
2927
+ yScale,
2928
+ marshalledData,
2929
+ data,
2930
+ lineData,
2931
+ renderTooltip,
2932
+ labelPosition,
2933
+ marginTop,
2934
+ renderLabel,
2935
+ barWidth,
2936
+ barPadding,
2937
+ dynamicTooltipEnable,
2938
+ hideTooltipGroupName,
2939
+ tooltipY,
2940
+ tooltipBind,
2941
+ formatTooltipValue,
2942
+ formatTooltipName,
2943
+ tooltipYDomain,
2944
+ setTooltipPosition,
2945
+ onLabelItem,
2946
+ isBarTooltip,
2947
+ bars: groups,
2948
+ tooltipRoot,
2949
+ tooltipClassName,
2950
+ onBarClick,
2951
+ onBarHover,
2952
+ });
2953
+ }
2954
+ customize && customize({ svg, marshalledData, yScale, xScale, lineData });
2955
+ }
2956
+ };
2957
+
2958
+ const BarChart = (props) => {
2959
+ const { className, style, children, selectable } = props;
2960
+ const [ref, node] = useNode();
2961
+ react.useEffect(() => {
2962
+ node && draw$1(node, props);
2963
+ }, [node, props]);
2964
+ const onDraw = () => draw$1(node, props);
2965
+ useResize(props.width, onDraw);
2966
+ useSelection(selectable ? node : null, props);
2967
+ return (jsxRuntime.jsxs("div", { className: className, style: style, children: [jsxRuntime.jsx(TooltipStyles$1, {}), jsxRuntime.jsx(SvgWrapper$1, { ref: ref, selectable: selectable, children: children })] }));
2968
+ };
2969
+ BarChart.defaultProps = {
2970
+ data: [],
2971
+ colors: {},
2972
+ margin: {
2973
+ top: 10,
2974
+ right: 10,
2975
+ bottom: 10,
2976
+ left: 0,
2977
+ },
2978
+ barWidth: 12,
2979
+ barPadding: 0,
2980
+ height: 320,
2981
+ yAxisPadding: 0,
2982
+ xAxisPadding: 0,
2983
+ tooltipBind: true,
2984
+ sectionPadding: 1,
2985
+ };
2986
+
2987
+ const hundred$1 = 100;
2988
+ const useMarshaling = ({ data, fullExtent, maxValue, labels, }) => {
2989
+ return react.useMemo(() => {
2990
+ const fullMax = d3__namespace.max(data, item => d3__namespace.sum(item, ({ value }) => value));
2991
+ const scaleLinear = d3__namespace
2992
+ .scaleLinear()
2993
+ .domain([
2994
+ 0,
2995
+ typeof maxValue === 'number' ? maxValue : fullMax,
2996
+ ])
2997
+ .range([0, hundred$1]);
2998
+ return {
2999
+ fullMax,
3000
+ data: data.map((item, index) => {
3001
+ if (!fullExtent) {
3002
+ scaleLinear.domain([
3003
+ 0,
3004
+ typeof maxValue === 'number'
3005
+ ? maxValue
3006
+ : d3__namespace.sum(item, ({ value }) => value),
3007
+ ]);
3008
+ }
3009
+ return item.map(({ value, ...rest }) => ({
3010
+ ...rest,
3011
+ value,
3012
+ width: scaleLinear(value),
3013
+ groupName: labels ? labels[index] : '',
3014
+ }));
3015
+ }),
3016
+ };
3017
+ }, [data, fullExtent, maxValue, labels]);
3018
+ };
3019
+
3020
+ const horizontalBarChartClassNames = {
3021
+ horizontalBarChartButtonTd: "horizontalBarChartButtonTd",
3022
+ horizontalBarChartLabelTd: "horizontalBarChartLabelTd",
3023
+ horizontalBarChartLabelCell: "horizontalBarChartLabelCell",
3024
+ horizontalBarChartBarTd: "horizontalBarChartBarTd",
3025
+ horizontalBarChartBarFlex: "horizontalBarChartBarFlex",
3026
+ horizontalBarChartBar: "horizontalBarChartBar",
3027
+ horizontalBarChartBarFirst: "horizontalBarChartBarFirst",
3028
+ horizontalBarChartBarLast: "horizontalBarChartBarLast",
3029
+ horizontalBarChartBarOnly: "horizontalBarChartBarOnly",
3030
+ horizontalBarChartTooltipFlex: "horizontalBarChartTooltipFlex",
3031
+ horizontalBarChartStackWrapper: "horizontalBarChartStackWrapper",
3032
+ horizontalBarChartTooltipContainer: "horizontalBarChartTooltipContainer",
3033
+ horizontalBarChartStackSumContainer: "horizontalBarChartStackSumContainer",
3034
+ horizontalBarChartStackSum: "horizontalBarChartStackSum",
3035
+ horizontalBarChartXScaleTd: "horizontalBarChartXScaleTd",
3036
+ horizontalBarChartXScaleTicks: "horizontalBarChartXScaleTicks",
3037
+ horizontalBarChartXScaleTick: "horizontalBarChartXScaleTick",
3038
+ horizontalBarChartTooltipItem: "horizontalBarChartTooltipItem",
3039
+ horizontalBarChartTooltipName: "horizontalBarChartTooltipName",
3040
+ horizontalBarChartTooltipValue: "horizontalBarChartTooltipValue",
3041
+ };
3042
+ const Table = styled.table `
3043
+ width: 100%;
3044
+ `;
3045
+ const LabelCell = styled.div `
3046
+ text-align: right;
3047
+ `;
3048
+ const BarFlex = styled.div `
3049
+ width: 100%;
3050
+ display: flex;
3051
+ height: 1rem;
3052
+ `;
3053
+ const BarsTd = styled.td `
3054
+ width: 100%;
3055
+ position: relative;
3056
+ vertical-align: middle;
3057
+ `;
3058
+ const TooltipFlex = styled(TooltipFlex$1) `
3059
+ position: absolute;
3060
+ top: 0;
3061
+ left: 50%;
3062
+ transform: translate(-50%, -50%);
3063
+ will-change: left, top;
3064
+ `;
3065
+ const StackSumContainer = styled.div `
3066
+ position: relative;
3067
+ `;
3068
+ const StackSum = styled.div `
3069
+ white-space: nowrap;
3070
+ position: absolute;
3071
+ top: 50%;
3072
+ left: 50%;
3073
+ transform: translate(0, -50%);
3074
+ `;
3075
+ const StackWrapper = styled.div `
3076
+ position: absolute;
3077
+ top: 0;
3078
+ display: flex;
3079
+ justify-content: flex-start;
3080
+ height: 100%;
3081
+ `;
3082
+
3083
+ const Tooltip$1 = ({ renderTooltip, bars, style, className, }) => {
3084
+ const format = d3__namespace.format(",");
3085
+ return (jsxRuntime.jsx(TooltipFlex, { className: `${horizontalBarChartClassNames.horizontalBarChartTooltipFlex} ${className ||
3086
+ ""}`, style: style, children: jsxRuntime.jsx(TooltipContainer, { className: horizontalBarChartClassNames.horizontalBarChartTooltipContainer, children: renderTooltip
3087
+ ? renderTooltip(bars)
3088
+ : bars.map(({ color, name, value, groupName }, index) => (jsxRuntime.jsxs(TooltipItem, { className: horizontalBarChartClassNames.horizontalBarChartTooltipItem, children: [color && jsxRuntime.jsx(ColorBox, { style: { backgroundColor: color } }), name && (jsxRuntime.jsx(Name, { className: horizontalBarChartClassNames.horizontalBarChartTooltipName, children: name })), jsxRuntime.jsx(Value, { className: horizontalBarChartClassNames.horizontalBarChartTooltipValue, children: format(value) })] }, `${name || ""}-${index}-${groupName}`))) }) }));
3089
+ };
3090
+
3091
+ const rootElement = document.createElement('div');
3092
+ const useTooltip = ({ renderTooltip, tooltipBind, tooltipStyle, tooltipRoot, tooltipClassName, hideTooltip, }) => {
3093
+ react.useEffect(() => {
3094
+ const container = tooltipRoot || document.querySelector('body');
3095
+ container && container.appendChild(rootElement);
3096
+ return () => {
3097
+ reactDom.unmountComponentAtNode(rootElement);
3098
+ };
3099
+ }, [tooltipRoot]);
3100
+ const onMouseMove = react.useCallback((event, bars) => {
3101
+ let [x, y] = d3__namespace.pointer(event, document);
3102
+ if (!tooltipBind && 'getBoundingClientRect' in event.target) {
3103
+ const { width, height, } = event.target.getBoundingClientRect();
3104
+ const [barX, barY] = d3__namespace.pointer(event, event.target);
3105
+ x = x - barX + width / 2;
3106
+ y = y - barY + height / 2;
3107
+ }
3108
+ if (rootElement) {
3109
+ rootElement.style.visibility = 'visible';
3110
+ }
3111
+ reactDom.render(jsxRuntime.jsx(Tooltip$1, { style: {
3112
+ left: x,
3113
+ top: y,
3114
+ ...tooltipStyle,
3115
+ }, bars: bars, renderTooltip: renderTooltip, className: tooltipClassName }), rootElement);
3116
+ }, [tooltipClassName, tooltipStyle, renderTooltip, tooltipBind]);
3117
+ const onMouseLeave = react.useCallback(() => {
3118
+ if (rootElement) {
3119
+ rootElement.style.visibility = 'hidden';
3120
+ hideTooltip && hideTooltip();
3121
+ }
3122
+ }, [hideTooltip]);
3123
+ return [onMouseMove, onMouseLeave];
3124
+ };
3125
+
3126
+ const useStackWrapper = (stackedTooltip) => {
3127
+ return react.useMemo(() => stackedTooltip
3128
+ ? ({ item, mouseMove, mouseLeave, tooltipBind, ...props }) => (jsxRuntime.jsx(StackWrapper, { className: horizontalBarChartClassNames.horizontalBarChartStackWrapper, onMouseOver: event => mouseMove(event, item), onMouseMove: tooltipBind ? event => mouseMove(event, item) : void 0, onMouseOut: mouseLeave, ...props }))
3129
+ : ({ children }) => (jsxRuntime.jsx(react.Fragment, { children: children })), [stackedTooltip]);
3130
+ };
3131
+
3132
+ const BarStyled = styled.div `
3133
+ position: relative;
3134
+ display: inline-flex;
3135
+ height: 100%;
3136
+ `;
3137
+
3138
+ const Bar = ({ withTooltip, bar, formatNativeTitle, tooltipBind, mouseMove, mouseLeave, pointerEventsNone, isFirstChild, isLastChild, isOnlyChild, }) => {
3139
+ const { color, width } = bar;
3140
+ const ceiledWidth = Math.abs(width);
3141
+ const onMouseMove = withTooltip
3142
+ ? (event) => mouseMove(event, [bar])
3143
+ : void 0;
3144
+ const onMouseLeave = withTooltip ? () => mouseLeave() : void 0;
3145
+ return (jsxRuntime.jsx(BarStyled, { className: `${horizontalBarChartClassNames.horizontalBarChartBar} ${isFirstChild ? horizontalBarChartClassNames.horizontalBarChartBarFirst : ""} ${isLastChild ? horizontalBarChartClassNames.horizontalBarChartBarLast : ""} ${isOnlyChild ? horizontalBarChartClassNames.horizontalBarChartBarOnly : ""}`, style: {
3146
+ width: `${ceiledWidth}%`,
3147
+ backgroundColor: color,
3148
+ pointerEvents: pointerEventsNone ? "none" : "auto",
3149
+ }, title: formatNativeTitle ? formatNativeTitle(bar) : "", onMouseOver: onMouseMove, onMouseMove: tooltipBind ? onMouseMove : void 0, onMouseOut: onMouseLeave }));
3150
+ };
3151
+
3152
+ const TickTd = styled.td `
3153
+ position: relative;
3154
+ `;
3155
+ const Ticks = styled.div `
3156
+ position: relative;
3157
+ height: 1rem;
3158
+ `;
3159
+ const Tick = styled.div `
3160
+ white-space: nowrap;
3161
+ width: 0;
3162
+ height: 0;
3163
+ position: absolute;
3164
+ top: 50%;
3165
+ transform: translateY(-50%);
3166
+ display: flex;
3167
+ align-items: center;
3168
+ justify-content: center;
3169
+ `;
3170
+
3171
+ const hundred = 100;
3172
+ const useScale = ({ maxValue, scaleTicks, scaleDomain, }) => {
3173
+ return react.useMemo(() => {
3174
+ const scaleLinear = d3__namespace
3175
+ .scaleLinear()
3176
+ .domain([0, maxValue])
3177
+ .range([0, hundred]);
3178
+ const ticks = scaleLinear.ticks(scaleTicks);
3179
+ return (scaleDomain || ticks).map((value) => ({
3180
+ value,
3181
+ x: scaleLinear(value),
3182
+ }));
3183
+ }, [maxValue, scaleTicks, scaleDomain]);
3184
+ };
3185
+
3186
+ const XScale = ({ maxValue, scaleTicks, renderTicks, scaleDomain, }) => {
3187
+ const range = useScale({ maxValue, scaleTicks, scaleDomain });
3188
+ const format = d3__namespace.format(",");
3189
+ return (jsxRuntime.jsxs("tr", { children: [jsxRuntime.jsx("td", {}), jsxRuntime.jsx(TickTd, { className: horizontalBarChartClassNames.horizontalBarChartXScaleTd, children: jsxRuntime.jsx(Ticks, { className: horizontalBarChartClassNames.horizontalBarChartXScaleTicks, children: range.map((tick, index, ticks) => {
3190
+ const { value, x } = tick;
3191
+ return (jsxRuntime.jsx(Tick, { className: horizontalBarChartClassNames.horizontalBarChartXScaleTick, style: {
3192
+ left: `${x}%`,
3193
+ justifyContent: index === 0
3194
+ ? "flex-start"
3195
+ : index === ticks.length - 1
3196
+ ? "flex-end"
3197
+ : "",
3198
+ }, children: renderTicks ? renderTicks(tick) : format(value) }, value));
3199
+ }) }) })] }));
3200
+ };
3201
+
3202
+ const HorizontalBarChart = ({ data, className, style, children, labels, fullExtent, maxValue, formatNativeTitle, renderTooltip, withTooltip, withStackSum, tooltipBind, scaleTicks, renderTicks, renderButton, tooltipStyle, tooltipClassName, scaleDomain, renderDataTable, thead, withoutXScale, stackedTooltip, fullChartTooltip, hideTooltip, }) => {
3203
+ const { fullMax, data: marshalingData } = useMarshaling({
3204
+ data,
3205
+ fullExtent,
3206
+ maxValue,
3207
+ labels,
3208
+ });
3209
+ const [mouseMove, mouseLeave] = useTooltip({
3210
+ renderTooltip,
3211
+ tooltipBind,
3212
+ tooltipStyle,
3213
+ tooltipClassName,
3214
+ hideTooltip,
3215
+ });
3216
+ const Stack = useStackWrapper(stackedTooltip);
3217
+ return (jsxRuntime.jsxs(Table, { className: className, style: style, onMouseOver: fullChartTooltip
3218
+ ? event => mouseMove(event, marshalingData.flat())
3219
+ : void 0, onMouseMove: fullChartTooltip
3220
+ ? event => mouseMove(event, marshalingData.flat())
3221
+ : void 0, onMouseOut: fullChartTooltip ? mouseLeave : void 0, children: [thead, jsxRuntime.jsxs("tbody", { children: [marshalingData.map((item, rowIndex) => {
3222
+ const stackSum = (withStackSum || renderDataTable) &&
3223
+ d3__namespace.sum(item, ({ value }) => value);
3224
+ const sumWidth = d3__namespace.sum(item, ({ width }) => width);
3225
+ return (jsxRuntime.jsxs("tr", { children: [typeof renderButton === "function" && (jsxRuntime.jsx("td", { className: horizontalBarChartClassNames.horizontalBarChartButtonTd, children: renderButton(item, rowIndex) })), jsxRuntime.jsx("td", { className: horizontalBarChartClassNames.horizontalBarChartLabelTd, children: labels && labels[rowIndex] && (jsxRuntime.jsx(LabelCell, { className: horizontalBarChartClassNames.horizontalBarChartLabelCell, children: labels[rowIndex] })) }), jsxRuntime.jsx(BarsTd, { className: horizontalBarChartClassNames.horizontalBarChartBarTd, style: { pointerEvents: fullChartTooltip ? "none" : "auto" }, children: jsxRuntime.jsxs(BarFlex, { className: horizontalBarChartClassNames.horizontalBarChartBarFlex, style: { pointerEvents: fullChartTooltip ? "none" : "auto" }, children: [jsxRuntime.jsx(Stack, { style: stackedTooltip ? { width: `${sumWidth}%` } : void 0, item: item, tooltipBind: tooltipBind, mouseMove: mouseMove, mouseLeave: mouseLeave }), item.map((bar, barIndex, array) => bar.value !== 0 && (jsxRuntime.jsx(Bar, { formatNativeTitle: formatNativeTitle, bar: bar, tooltipBind: tooltipBind, pointerEventsNone: stackedTooltip || fullChartTooltip, withTooltip: withTooltip && !stackedTooltip, mouseMove: mouseMove, mouseLeave: mouseLeave, isOnlyChild: array.length === 1, isFirstChild: barIndex === 0 && array.length > 1, isLastChild: array.length - 1 === barIndex && array.length > 1 }, `bar-${bar.name || ""}-${barIndex}`))), withStackSum && (jsxRuntime.jsx(StackSumContainer, { className: horizontalBarChartClassNames.horizontalBarChartStackSumContainer, children: jsxRuntime.jsx(StackSum, { className: horizontalBarChartClassNames.horizontalBarChartStackSum, children: stackSum }) }))] }) }), renderDataTable &&
3226
+ renderDataTable(item, stackSum, rowIndex)] }, `row-${rowIndex}`));
3227
+ }), !withoutXScale && (jsxRuntime.jsx(XScale, { maxValue: typeof maxValue === "number" ? maxValue : fullMax, scaleTicks: scaleTicks, renderTicks: renderTicks, scaleDomain: scaleDomain })), children] })] }));
3228
+ };
3229
+ HorizontalBarChart.defaultProps = {
3230
+ fullExtent: true,
3231
+ withTooltip: false,
3232
+ withStackSum: false,
3233
+ tooltipBind: false,
3234
+ scaleTicks: 4,
3235
+ withoutXScale: false,
3236
+ };
3237
+
3238
+ const bubbleChartDefaultProps = {
3239
+ height: 280,
3240
+ minSize: 6,
3241
+ maxSize: 30,
3242
+ margin: {
3243
+ top: 10,
3244
+ right: 15,
3245
+ bottom: 10,
3246
+ left: 0,
3247
+ },
3248
+ yAxisPadding: 10,
3249
+ xAxisPadding: 10,
3250
+ yScaleLabelPadding: 10,
3251
+ };
3252
+
3253
+ const bubbleChartClassNames = {
3254
+ bubbleChartYAxis: "bubbleChartYAxis",
3255
+ bubbleChartYAxisZeroTick: "bubbleChartYAxisZeroTick",
3256
+ bubbleChartXAxis: "bubbleChartXAxis",
3257
+ bubbleChartGridGlobal: "bubbleChartGridGlobal",
3258
+ bubbleChartGridLineX: "bubbleChartGridLineX",
3259
+ bubbleChartGridLineY: "bubbleChartGridLineY",
3260
+ bubbleChartCircle: "bubbleChartCircle",
3261
+ bubbleChartYScaleLabel: "bubbleChartYScaleLabel",
3262
+ bubbleChartTooltip: "bubbleChartTooltip",
3263
+ bubbleChartTooltipContainer: "bubbleChartTooltipContainer",
3264
+ bubbleChartTooltipFlex: "bubbleChartTooltipFlex",
3265
+ bubbleChartTip: "bubbleChartTip",
3266
+ };
3267
+ const SvgWrapper = styled(Wrapper) `
3268
+ .${bubbleChartClassNames.bubbleChartYAxis},
3269
+ .${bubbleChartClassNames.bubbleChartXAxis},
3270
+ .${bubbleChartClassNames.bubbleChartGridGlobal} {
3271
+ shape-rendering: crispEdges;
3272
+ }
3273
+
3274
+ .${bubbleChartClassNames.bubbleChartGridLineX},
3275
+ .${bubbleChartClassNames.bubbleChartGridLineY} {
3276
+ stroke: rgba(149, 149, 149, 0.24);
3277
+ }
3278
+
3279
+ .${bubbleChartClassNames.bubbleChartYScaleLabel} {
3280
+ font-size: 10px;
3281
+ }
3282
+ `;
3283
+ const TooltipStyles = styled.createGlobalStyle `
3284
+ .${bubbleChartClassNames.bubbleChartTooltipContainer} {
3285
+ position: absolute;
3286
+ transition: opacity 150ms cubic-bezier(0.2, 1, 0.6, 1);
3287
+ pointer-events: none;
3288
+ z-index: 1;
3289
+ }
3290
+ `;
3291
+
3292
+ const drawGrid = ({ svg, yScale, xScale, yTicksCount, drawGridX, drawGridY, }) => {
3293
+ if (!drawGridY && !drawGridX)
3294
+ return;
3295
+ const [min, max] = xScale.domain();
3296
+ const global = svg
3297
+ .append('g')
3298
+ .attr('class', bubbleChartClassNames.bubbleChartGridGlobal);
3299
+ const yTicks = yScale.ticks(yTicksCount);
3300
+ if (drawGridX) {
3301
+ global
3302
+ .append('g')
3303
+ .selectAll('line')
3304
+ .data(yTicks)
3305
+ .join('line')
3306
+ .attr('class', bubbleChartClassNames.bubbleChartGridLineX)
3307
+ .attr('x1', () => xScale(min))
3308
+ .attr('x2', () => xScale(max))
3309
+ .attr('y1', (d) => Math.round(yScale(d)))
3310
+ .attr('y2', (d) => Math.round(yScale(d)));
3311
+ }
3312
+ if (drawGridY) {
3313
+ global
3314
+ .append('g')
3315
+ .selectAll('line')
3316
+ .data(xScale.ticks(yTicksCount))
3317
+ .join('line')
3318
+ .attr('class', bubbleChartClassNames.bubbleChartGridLineY)
3319
+ .attr('x1', (d) => Math.round(xScale(d)))
3320
+ .attr('x2', (d) => Math.round(xScale(d)))
3321
+ .attr('y1', () => Math.round(yScale(yTicks[0])))
3322
+ .attr('y2', () => Math.round(yScale(yTicks[yTicks.length - 1])));
3323
+ }
3324
+ };
3325
+
3326
+ const Tooltip = styled.div `
3327
+ width: 0;
3328
+ height: 0;
3329
+ display: flex;
3330
+ align-items: flex-end;
3331
+ justify-content: center;
3332
+ font-size: 12px;
3333
+ white-space: nowrap;
3334
+ `;
3335
+
3336
+ const drawTooltip = ({ bubbles, tooltipRoot, tooltipClassName, renderTooltip, }) => {
3337
+ const root = tooltipRoot || document.querySelector("body");
3338
+ const format = d3__namespace.format(",");
3339
+ let container = d3__namespace
3340
+ .select(root)
3341
+ .select(`.${bubbleChartClassNames.bubbleChartTooltip}`);
3342
+ if (container.node() === null) {
3343
+ container = d3__namespace
3344
+ .select(root)
3345
+ .append("div")
3346
+ .attr("class", bubbleChartClassNames.bubbleChartTooltip);
3347
+ }
3348
+ let tooltip = container
3349
+ .append("div")
3350
+ .attr("class", `${bubbleChartClassNames.bubbleChartTooltipContainer} ${tooltipClassName || ""}`)
3351
+ .style("opacity", "0");
3352
+ bubbles.on("mouseover.tooltip", (event, data) => {
3353
+ const { sizeValue } = data;
3354
+ const circle = event.currentTarget;
3355
+ const { x, y, width } = circle.getBoundingClientRect();
3356
+ const left = window.pageXOffset + x + width / 2;
3357
+ const top = window.pageYOffset + y;
3358
+ tooltip
3359
+ .style("left", `${left}px`)
3360
+ .style("top", `${top}px`)
3361
+ .html(() => {
3362
+ const html = ReactDOMServer.renderToString(jsxRuntime.jsx(Tooltip, { className: bubbleChartClassNames.bubbleChartTooltipFlex, children: jsxRuntime.jsx(TooltipContainer, { className: bubbleChartClassNames.bubbleChartTip, children: format(sizeValue) }) }));
3363
+ return html;
3364
+ });
3365
+ renderTooltip && renderTooltip({ tooltip, data, circle });
3366
+ tooltip.style("opacity", "1");
3367
+ });
3368
+ bubbles.on("mouseout.tooltip", () => {
3369
+ tooltip.style("opacity", "0");
3370
+ });
3371
+ };
3372
+
3373
+ const draw = (node, props) => {
3374
+ const { data, margin, xAxisPadding, yAxisPadding, customYScale, customYAxis, customXScale, customXAxis, minSize, maxSize, minYValue, maxYValue, drawGridY, drawGridX, scaleLog, xScaleItemWidth, bubbleStyle, customize, yScaleLabel, yScaleLabelPadding, enableTooltip, tooltipRoot, tooltipClassName, renderTooltip, } = props;
3375
+ if (node !== null && data.length) {
3376
+ const marginTop = margin ? margin.top : 0;
3377
+ const marginRight = margin ? margin.right : 0;
3378
+ const marginBottom = margin ? margin.bottom : 0;
3379
+ const marginLeft = margin ? margin.left : 0;
3380
+ const { width: nodeWidth } = node.getBoundingClientRect();
3381
+ const width = props.width || nodeWidth;
3382
+ const height = props.height || 0;
3383
+ const yTicksCountDefault = 6;
3384
+ const minY = typeof minYValue === 'number'
3385
+ ? minYValue
3386
+ : d3__namespace.min(data, ({ yValue }) => yValue);
3387
+ const maxY = typeof maxYValue === 'number'
3388
+ ? maxYValue
3389
+ : d3__namespace.max(data, ({ yValue }) => yValue);
3390
+ const svg = appendSvg(node, width, height || 0);
3391
+ const sizeScale = scaleLog
3392
+ ? d3__namespace
3393
+ .scaleLog()
3394
+ .domain([
3395
+ d3__namespace.min(data, ({ sizeValue }) => sizeValue) || 0.1,
3396
+ d3__namespace.max(data, ({ sizeValue }) => sizeValue) || 0.1,
3397
+ ])
3398
+ .range([
3399
+ minSize || bubbleChartDefaultProps.minSize || 0.1,
3400
+ maxSize || bubbleChartDefaultProps.maxSize || 0.1,
3401
+ ])
3402
+ : d3__namespace
3403
+ .scaleLinear()
3404
+ .domain([
3405
+ d3__namespace.min(data, ({ sizeValue }) => sizeValue),
3406
+ d3__namespace.max(data, ({ sizeValue }) => sizeValue),
3407
+ ])
3408
+ .range([
3409
+ minSize || bubbleChartDefaultProps.minSize,
3410
+ maxSize || bubbleChartDefaultProps.maxSize,
3411
+ ]);
3412
+ const yRange1 = height - marginTop - marginBottom - (xAxisPadding || 0);
3413
+ const yScale = scaleLog
3414
+ ? d3__namespace
3415
+ .scaleLog()
3416
+ .domain([minY || 0.1, maxY || 0.1])
3417
+ .range([yRange1 || 0.1, marginTop || 0.1])
3418
+ .nice()
3419
+ : d3__namespace
3420
+ .scaleLinear()
3421
+ .domain([minY, maxY])
3422
+ .range([yRange1, marginTop])
3423
+ .nice();
3424
+ customYScale && customYScale(yScale);
3425
+ const yTicks = yScale.ticks();
3426
+ const yAxisLeft = d3__namespace.axisLeft(yScale).ticks(yTicksCountDefault);
3427
+ const yTicksCount = yAxisLeft.tickArguments()[0];
3428
+ const yAxis = svg
3429
+ .append('g')
3430
+ .attr('class', bubbleChartClassNames.bubbleChartYAxis)
3431
+ .call(yAxisLeft);
3432
+ let yScaleLabelHeight = yScaleLabelPadding || 0;
3433
+ if (yScaleLabel) {
3434
+ const label = svg
3435
+ .append('text')
3436
+ .text(yScaleLabel)
3437
+ .attr('class', bubbleChartClassNames.bubbleChartYScaleLabel);
3438
+ const { width, height } = computeDimensions(label);
3439
+ yScaleLabelHeight = yScaleLabelHeight + height;
3440
+ label.attr('transform', `rotate(-90) translate(-${(yRange1 + marginBottom + width) /
3441
+ 2}, ${height})`);
3442
+ }
3443
+ yAxis.selectAll('.tick').attr('class', value => {
3444
+ return value === 0
3445
+ ? `tick ${bubbleChartClassNames.bubbleChartYAxisZeroTick}`
3446
+ : 'tick';
3447
+ });
3448
+ customYAxis && customYAxis(yAxis);
3449
+ const { width: yAxisWidth } = computeDimensions(yAxis);
3450
+ const xScale = scaleLog
3451
+ ? d3__namespace
3452
+ .scaleLog()
3453
+ .domain([
3454
+ d3__namespace.min(data, ({ xValue }) => xValue) || 0.1,
3455
+ d3__namespace.max(data, ({ xValue }) => xValue) || 0.1,
3456
+ ])
3457
+ .range([
3458
+ (marginLeft + yAxisWidth + (yAxisPadding || 0) + yScaleLabelHeight) || 0.1,
3459
+ (width - marginRight) || 0.1,
3460
+ ])
3461
+ : d3__namespace
3462
+ .scaleLinear()
3463
+ .domain([
3464
+ d3__namespace.min(data, ({ xValue }) => xValue),
3465
+ d3__namespace.max(data, ({ xValue }) => xValue),
3466
+ ])
3467
+ .range([
3468
+ marginLeft + yAxisWidth + (yAxisPadding || 0) + yScaleLabelHeight,
3469
+ width - marginRight,
3470
+ ]);
3471
+ customXScale && customXScale(xScale);
3472
+ const xAxisBottom = d3__namespace.axisBottom(xScale);
3473
+ if (typeof xScaleItemWidth === 'number') {
3474
+ const [x1, x2] = xScale.range();
3475
+ const chartWidth = x2 - x1;
3476
+ xAxisBottom
3477
+ .ticks(Math.round(chartWidth / xScaleItemWidth))
3478
+ .tickSizeOuter(0);
3479
+ }
3480
+ const xAxis = svg
3481
+ .append('g')
3482
+ .call(xAxisBottom)
3483
+ .attr('class', bubbleChartClassNames.bubbleChartXAxis);
3484
+ customXAxis && customXAxis(xAxis);
3485
+ yAxis.attr('transform', `translate(${marginLeft + yAxisWidth + yScaleLabelHeight}, 0)`);
3486
+ drawGrid({
3487
+ svg,
3488
+ yScale,
3489
+ xScale,
3490
+ yTicksCount,
3491
+ drawGridY,
3492
+ drawGridX,
3493
+ });
3494
+ xAxis.attr('transform', `translate(0, ${yScale(yTicks[0]) + (xAxisPadding || 0)})`);
3495
+ const bubbles = svg
3496
+ .append('g')
3497
+ .selectAll('dot')
3498
+ .data(data)
3499
+ .enter()
3500
+ .append('circle')
3501
+ .attr('class', bubbleChartClassNames.bubbleChartCircle)
3502
+ .attr('cx', ({ xValue }) => xScale(xValue))
3503
+ .attr('cy', ({ yValue }) => yScale(yValue))
3504
+ .attr('r', ({ sizeValue }) => sizeScale(sizeValue) / 2)
3505
+ .attr('fill', ({ color }) => color || 'rgba(0, 176, 113, 0.6)')
3506
+ .attr('stroke', ({ stroke }) => stroke || 'transparent')
3507
+ .attr('style', ({ style }) => style || bubbleStyle || '');
3508
+ if (enableTooltip) {
3509
+ drawTooltip({ bubbles, tooltipRoot, tooltipClassName, renderTooltip });
3510
+ }
3511
+ customize && customize({ svg, bubbles, yScale, xScale, sizeScale });
3512
+ }
3513
+ };
3514
+
3515
+ const unmount = (tooltipRoot) => {
3516
+ const root = tooltipRoot || document.querySelector('body');
3517
+ d3__namespace.select(root)
3518
+ .select(`.${bubbleChartClassNames.bubbleChartTooltip}`)
3519
+ .remove();
3520
+ };
3521
+
3522
+ const BubbleChart = (props) => {
3523
+ const { className, style, children, tooltipRoot } = props;
3524
+ const [ref, node] = useNode();
3525
+ react.useEffect(() => {
3526
+ node && draw(node, props);
3527
+ }, [node, props]);
3528
+ react.useEffect(() => {
3529
+ return () => unmount(tooltipRoot);
3530
+ }, [tooltipRoot]);
3531
+ const onDraw = () => draw(node, props);
3532
+ useResize(props.width, onDraw);
3533
+ return (jsxRuntime.jsxs("div", { className: className, style: style, children: [jsxRuntime.jsx(TooltipStyles, {}), jsxRuntime.jsx(SvgWrapper, { ref: ref, children: children })] }));
3534
+ };
3535
+ BubbleChart.defaultProps = bubbleChartDefaultProps;
3536
+
3537
+ exports.BarChart = BarChart;
3538
+ exports.BubbleChart = BubbleChart;
3539
+ exports.CalendarChart = CalendarChart;
3540
+ exports.ChartWrapper = Wrapper;
3541
+ exports.HorizontalBarChart = HorizontalBarChart;
3542
+ exports.LineChart = LineChart;
3543
+ exports.PieChart = PieChart;
3544
+ exports.RadarChart = RadarChart;
3545
+ exports.SwipeScroll = SwipeScroll;
3546
+ exports.appendSvg = appendSvg;
3547
+ exports.barChartClassNames = barChartClassNames;
3548
+ exports.bubbleChartClassNames = bubbleChartClassNames;
3549
+ exports.calendarChartClassNames = calendarChartClassNames;
3550
+ exports.horizontalBarChartClassNames = horizontalBarChartClassNames;
3551
+ exports.lineChartClassNames = lineChartClassNames;
3552
+ exports.pieChartclassNames = pieChartclassNames;
3553
+ exports.radarChartclassNames = radarChartclassNames;
3554
+ exports.useNode = useNode;
3555
+ exports.useResize = useResize;
3556
+ //# sourceMappingURL=index.js.map