@gravity-ui/charts 1.9.0 → 1.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (199) hide show
  1. package/dist/cjs/components/Axis/AxisX.d.ts +2 -1
  2. package/dist/cjs/components/Axis/AxisX.js +147 -143
  3. package/dist/cjs/components/Axis/AxisY.d.ts +2 -1
  4. package/dist/cjs/components/Axis/AxisY.js +113 -91
  5. package/dist/cjs/components/ChartInner/index.js +23 -10
  6. package/dist/cjs/components/ChartInner/useChartInnerHandlers.d.ts +1 -1
  7. package/dist/cjs/components/ChartInner/useChartInnerProps.d.ts +8 -5
  8. package/dist/cjs/components/ChartInner/useChartInnerProps.js +55 -9
  9. package/dist/cjs/components/ChartInner/utils.d.ts +3 -0
  10. package/dist/cjs/components/ChartInner/utils.js +28 -0
  11. package/dist/cjs/components/Legend/index.js +199 -196
  12. package/dist/cjs/components/Tooltip/ChartTooltipContent.d.ts +1 -1
  13. package/dist/cjs/components/Tooltip/DefaultContent.d.ts +1 -1
  14. package/dist/cjs/components/Tooltip/DefaultContent.js +1 -1
  15. package/dist/cjs/components/Tooltip/index.d.ts +1 -1
  16. package/dist/cjs/hooks/hooks-utils/index.d.ts +1 -0
  17. package/dist/cjs/hooks/hooks-utils/index.js +1 -0
  18. package/dist/cjs/hooks/hooks-utils/zoom.d.ts +8 -0
  19. package/dist/cjs/hooks/hooks-utils/zoom.js +81 -0
  20. package/dist/cjs/hooks/useAxisScales/index.d.ts +4 -2
  21. package/dist/cjs/hooks/useAxisScales/index.js +22 -8
  22. package/dist/cjs/hooks/useBrush/index.d.ts +3 -0
  23. package/dist/cjs/hooks/useBrush/index.js +70 -0
  24. package/dist/cjs/hooks/useBrush/styles.css +10 -0
  25. package/dist/cjs/hooks/useBrush/types.d.ts +24 -0
  26. package/dist/cjs/hooks/useBrush/types.js +1 -0
  27. package/dist/cjs/hooks/useChartDimensions/index.d.ts +3 -3
  28. package/dist/cjs/hooks/useChartDimensions/index.js +2 -2
  29. package/dist/cjs/hooks/useChartDimensions/utils.d.ts +2 -2
  30. package/dist/cjs/hooks/useChartOptions/chart.d.ts +2 -1
  31. package/dist/cjs/hooks/useChartOptions/chart.js +80 -1
  32. package/dist/cjs/hooks/useChartOptions/index.js +3 -2
  33. package/dist/cjs/hooks/useChartOptions/types.d.ts +3 -1
  34. package/dist/cjs/hooks/useChartOptions/x-axis.d.ts +3 -3
  35. package/dist/cjs/hooks/useChartOptions/x-axis.js +11 -11
  36. package/dist/cjs/hooks/useChartOptions/y-axis.d.ts +3 -3
  37. package/dist/cjs/hooks/useChartOptions/y-axis.js +22 -18
  38. package/dist/cjs/hooks/useCrosshair/index.d.ts +1 -1
  39. package/dist/cjs/hooks/useCrosshair/index.js +2 -2
  40. package/dist/cjs/hooks/useSeries/index.d.ts +8 -6
  41. package/dist/cjs/hooks/useSeries/index.js +41 -22
  42. package/dist/cjs/hooks/useSeries/prepare-bar-y.d.ts +27 -2
  43. package/dist/cjs/hooks/useSeries/prepare-bar-y.js +5 -5
  44. package/dist/cjs/hooks/useSeries/prepare-legend.d.ts +1 -1
  45. package/dist/cjs/hooks/useSeries/prepare-legend.js +6 -5
  46. package/dist/cjs/hooks/useSeries/prepareSeries.d.ts +1 -1
  47. package/dist/cjs/hooks/useSeries/prepareSeries.js +2 -2
  48. package/dist/cjs/hooks/useShapes/area/index.js +1 -1
  49. package/dist/cjs/hooks/useShapes/area/prepare-data.d.ts +1 -1
  50. package/dist/cjs/hooks/useShapes/area/prepare-data.js +32 -16
  51. package/dist/cjs/hooks/useShapes/area/types.d.ts +1 -0
  52. package/dist/cjs/hooks/useShapes/bar-x/prepare-data.d.ts +1 -1
  53. package/dist/cjs/hooks/useShapes/bar-x/prepare-data.js +17 -13
  54. package/dist/cjs/hooks/useShapes/bar-y/prepare-data.d.ts +1 -1
  55. package/dist/cjs/hooks/useShapes/bar-y/prepare-data.js +6 -6
  56. package/dist/cjs/hooks/useShapes/index.d.ts +1 -1
  57. package/dist/cjs/hooks/useShapes/index.js +40 -31
  58. package/dist/cjs/hooks/useShapes/line/prepare-data.d.ts +1 -1
  59. package/dist/cjs/hooks/useShapes/line/prepare-data.js +14 -11
  60. package/dist/cjs/hooks/useShapes/line/types.d.ts +1 -0
  61. package/dist/cjs/hooks/useShapes/marker.js +2 -2
  62. package/dist/cjs/hooks/useShapes/pie/index.js +3 -3
  63. package/dist/cjs/hooks/useShapes/pie/prepare-data.d.ts +1 -1
  64. package/dist/cjs/hooks/useShapes/pie/prepare-data.js +15 -11
  65. package/dist/cjs/hooks/useShapes/radar/prepare-data.d.ts +1 -1
  66. package/dist/cjs/hooks/useShapes/radar/prepare-data.js +6 -7
  67. package/dist/cjs/hooks/useShapes/radar/types.d.ts +1 -0
  68. package/dist/cjs/hooks/useShapes/scatter/index.js +0 -1
  69. package/dist/cjs/hooks/useShapes/scatter/prepare-data.js +2 -0
  70. package/dist/cjs/hooks/useShapes/scatter/types.d.ts +1 -0
  71. package/dist/cjs/hooks/useShapes/treemap/prepare-data.d.ts +1 -1
  72. package/dist/cjs/hooks/useShapes/treemap/prepare-data.js +19 -16
  73. package/dist/cjs/hooks/useShapes/waterfall/prepare-data.d.ts +1 -1
  74. package/dist/cjs/hooks/useShapes/waterfall/prepare-data.js +8 -7
  75. package/dist/cjs/hooks/useZoom/index.d.ts +18 -0
  76. package/dist/cjs/hooks/useZoom/index.js +54 -0
  77. package/dist/cjs/hooks/useZoom/types.d.ts +19 -0
  78. package/dist/cjs/hooks/useZoom/types.js +1 -0
  79. package/dist/cjs/hooks/useZoom/utils.d.ts +12 -0
  80. package/dist/cjs/hooks/useZoom/utils.js +128 -0
  81. package/dist/cjs/types/chart/chart.d.ts +5 -0
  82. package/dist/cjs/types/chart/pie.d.ts +1 -1
  83. package/dist/cjs/types/chart/tooltip.d.ts +1 -1
  84. package/dist/cjs/types/chart/zoom.d.ts +36 -0
  85. package/dist/cjs/types/chart/zoom.js +1 -0
  86. package/dist/cjs/types/index.d.ts +1 -0
  87. package/dist/cjs/types/index.js +1 -0
  88. package/dist/cjs/types/misc.d.ts +7 -0
  89. package/dist/cjs/utils/chart/axis-generators/bottom.d.ts +1 -1
  90. package/dist/cjs/utils/chart/axis-generators/bottom.js +25 -25
  91. package/dist/cjs/utils/chart/axis.d.ts +1 -1
  92. package/dist/cjs/utils/chart/axis.js +2 -2
  93. package/dist/cjs/utils/chart/get-closest-data.js +1 -1
  94. package/dist/cjs/utils/chart/text.d.ts +7 -7
  95. package/dist/cjs/utils/chart/text.js +37 -29
  96. package/dist/cjs/utils/chart-ui/pie-center-text.d.ts +1 -1
  97. package/dist/cjs/utils/chart-ui/pie-center-text.js +2 -2
  98. package/dist/cjs/validation/index.d.ts +1 -1
  99. package/dist/cjs/validation/index.js +16 -16
  100. package/dist/esm/components/Axis/AxisX.d.ts +2 -1
  101. package/dist/esm/components/Axis/AxisX.js +147 -143
  102. package/dist/esm/components/Axis/AxisY.d.ts +2 -1
  103. package/dist/esm/components/Axis/AxisY.js +113 -91
  104. package/dist/esm/components/ChartInner/index.js +23 -10
  105. package/dist/esm/components/ChartInner/useChartInnerHandlers.d.ts +1 -1
  106. package/dist/esm/components/ChartInner/useChartInnerProps.d.ts +8 -5
  107. package/dist/esm/components/ChartInner/useChartInnerProps.js +55 -9
  108. package/dist/esm/components/ChartInner/utils.d.ts +3 -0
  109. package/dist/esm/components/ChartInner/utils.js +28 -0
  110. package/dist/esm/components/Legend/index.js +199 -196
  111. package/dist/esm/components/Tooltip/ChartTooltipContent.d.ts +1 -1
  112. package/dist/esm/components/Tooltip/DefaultContent.d.ts +1 -1
  113. package/dist/esm/components/Tooltip/DefaultContent.js +1 -1
  114. package/dist/esm/components/Tooltip/index.d.ts +1 -1
  115. package/dist/esm/hooks/hooks-utils/index.d.ts +1 -0
  116. package/dist/esm/hooks/hooks-utils/index.js +1 -0
  117. package/dist/esm/hooks/hooks-utils/zoom.d.ts +8 -0
  118. package/dist/esm/hooks/hooks-utils/zoom.js +81 -0
  119. package/dist/esm/hooks/useAxisScales/index.d.ts +4 -2
  120. package/dist/esm/hooks/useAxisScales/index.js +22 -8
  121. package/dist/esm/hooks/useBrush/index.d.ts +3 -0
  122. package/dist/esm/hooks/useBrush/index.js +70 -0
  123. package/dist/esm/hooks/useBrush/styles.css +10 -0
  124. package/dist/esm/hooks/useBrush/types.d.ts +24 -0
  125. package/dist/esm/hooks/useBrush/types.js +1 -0
  126. package/dist/esm/hooks/useChartDimensions/index.d.ts +3 -3
  127. package/dist/esm/hooks/useChartDimensions/index.js +2 -2
  128. package/dist/esm/hooks/useChartDimensions/utils.d.ts +2 -2
  129. package/dist/esm/hooks/useChartOptions/chart.d.ts +2 -1
  130. package/dist/esm/hooks/useChartOptions/chart.js +80 -1
  131. package/dist/esm/hooks/useChartOptions/index.js +3 -2
  132. package/dist/esm/hooks/useChartOptions/types.d.ts +3 -1
  133. package/dist/esm/hooks/useChartOptions/x-axis.d.ts +3 -3
  134. package/dist/esm/hooks/useChartOptions/x-axis.js +11 -11
  135. package/dist/esm/hooks/useChartOptions/y-axis.d.ts +3 -3
  136. package/dist/esm/hooks/useChartOptions/y-axis.js +22 -18
  137. package/dist/esm/hooks/useCrosshair/index.d.ts +1 -1
  138. package/dist/esm/hooks/useCrosshair/index.js +2 -2
  139. package/dist/esm/hooks/useSeries/index.d.ts +8 -6
  140. package/dist/esm/hooks/useSeries/index.js +41 -22
  141. package/dist/esm/hooks/useSeries/prepare-bar-y.d.ts +27 -2
  142. package/dist/esm/hooks/useSeries/prepare-bar-y.js +5 -5
  143. package/dist/esm/hooks/useSeries/prepare-legend.d.ts +1 -1
  144. package/dist/esm/hooks/useSeries/prepare-legend.js +6 -5
  145. package/dist/esm/hooks/useSeries/prepareSeries.d.ts +1 -1
  146. package/dist/esm/hooks/useSeries/prepareSeries.js +2 -2
  147. package/dist/esm/hooks/useShapes/area/index.js +1 -1
  148. package/dist/esm/hooks/useShapes/area/prepare-data.d.ts +1 -1
  149. package/dist/esm/hooks/useShapes/area/prepare-data.js +32 -16
  150. package/dist/esm/hooks/useShapes/area/types.d.ts +1 -0
  151. package/dist/esm/hooks/useShapes/bar-x/prepare-data.d.ts +1 -1
  152. package/dist/esm/hooks/useShapes/bar-x/prepare-data.js +17 -13
  153. package/dist/esm/hooks/useShapes/bar-y/prepare-data.d.ts +1 -1
  154. package/dist/esm/hooks/useShapes/bar-y/prepare-data.js +6 -6
  155. package/dist/esm/hooks/useShapes/index.d.ts +1 -1
  156. package/dist/esm/hooks/useShapes/index.js +40 -31
  157. package/dist/esm/hooks/useShapes/line/prepare-data.d.ts +1 -1
  158. package/dist/esm/hooks/useShapes/line/prepare-data.js +14 -11
  159. package/dist/esm/hooks/useShapes/line/types.d.ts +1 -0
  160. package/dist/esm/hooks/useShapes/marker.js +2 -2
  161. package/dist/esm/hooks/useShapes/pie/index.js +3 -3
  162. package/dist/esm/hooks/useShapes/pie/prepare-data.d.ts +1 -1
  163. package/dist/esm/hooks/useShapes/pie/prepare-data.js +15 -11
  164. package/dist/esm/hooks/useShapes/radar/prepare-data.d.ts +1 -1
  165. package/dist/esm/hooks/useShapes/radar/prepare-data.js +6 -7
  166. package/dist/esm/hooks/useShapes/radar/types.d.ts +1 -0
  167. package/dist/esm/hooks/useShapes/scatter/index.js +0 -1
  168. package/dist/esm/hooks/useShapes/scatter/prepare-data.js +2 -0
  169. package/dist/esm/hooks/useShapes/scatter/types.d.ts +1 -0
  170. package/dist/esm/hooks/useShapes/treemap/prepare-data.d.ts +1 -1
  171. package/dist/esm/hooks/useShapes/treemap/prepare-data.js +19 -16
  172. package/dist/esm/hooks/useShapes/waterfall/prepare-data.d.ts +1 -1
  173. package/dist/esm/hooks/useShapes/waterfall/prepare-data.js +8 -7
  174. package/dist/esm/hooks/useZoom/index.d.ts +18 -0
  175. package/dist/esm/hooks/useZoom/index.js +54 -0
  176. package/dist/esm/hooks/useZoom/types.d.ts +19 -0
  177. package/dist/esm/hooks/useZoom/types.js +1 -0
  178. package/dist/esm/hooks/useZoom/utils.d.ts +12 -0
  179. package/dist/esm/hooks/useZoom/utils.js +128 -0
  180. package/dist/esm/types/chart/chart.d.ts +5 -0
  181. package/dist/esm/types/chart/pie.d.ts +1 -1
  182. package/dist/esm/types/chart/tooltip.d.ts +1 -1
  183. package/dist/esm/types/chart/zoom.d.ts +36 -0
  184. package/dist/esm/types/chart/zoom.js +1 -0
  185. package/dist/esm/types/index.d.ts +1 -0
  186. package/dist/esm/types/index.js +1 -0
  187. package/dist/esm/types/misc.d.ts +7 -0
  188. package/dist/esm/utils/chart/axis-generators/bottom.d.ts +1 -1
  189. package/dist/esm/utils/chart/axis-generators/bottom.js +25 -25
  190. package/dist/esm/utils/chart/axis.d.ts +1 -1
  191. package/dist/esm/utils/chart/axis.js +2 -2
  192. package/dist/esm/utils/chart/get-closest-data.js +1 -1
  193. package/dist/esm/utils/chart/text.d.ts +7 -7
  194. package/dist/esm/utils/chart/text.js +37 -29
  195. package/dist/esm/utils/chart-ui/pie-center-text.d.ts +1 -1
  196. package/dist/esm/utils/chart-ui/pie-center-text.js +2 -2
  197. package/dist/esm/validation/index.d.ts +1 -1
  198. package/dist/esm/validation/index.js +16 -16
  199. package/package.json +2 -1
@@ -49,14 +49,14 @@ function getBandWidth(series, yAxis, yScale) {
49
49
  }
50
50
  return bandWidth;
51
51
  }
52
- function setLabel(prepared) {
52
+ async function setLabel(prepared) {
53
53
  const dataLabels = prepared.series.dataLabels;
54
54
  if (!dataLabels.enabled) {
55
55
  return;
56
56
  }
57
57
  const data = prepared.data;
58
58
  const content = getFormattedValue(Object.assign({ value: data.label || data.x }, dataLabels));
59
- const { maxHeight: height, maxWidth: width } = getLabelsSize({
59
+ const { maxHeight: height, maxWidth: width } = await getLabelsSize({
60
60
  labels: [content],
61
61
  style: dataLabels.style,
62
62
  html: dataLabels.html,
@@ -86,7 +86,7 @@ function setLabel(prepared) {
86
86
  };
87
87
  }
88
88
  }
89
- export const prepareBarYData = (args) => {
89
+ export const prepareBarYData = async (args) => {
90
90
  const { series, seriesOptions, yAxis, xScale, yScale: [yScale], } = args;
91
91
  const xLinearScale = xScale;
92
92
  const plotWidth = xLinearScale(xLinearScale.domain()[1]);
@@ -166,8 +166,8 @@ export const prepareBarYData = (args) => {
166
166
  result.push(...stackItems);
167
167
  });
168
168
  });
169
- result.forEach((d) => {
170
- setLabel(d);
171
- });
169
+ await Promise.all(result.map(async (d) => {
170
+ await setLabel(d);
171
+ }));
172
172
  return result;
173
173
  };
@@ -22,7 +22,7 @@ type Args = {
22
22
  dispatcher: Dispatch<object>;
23
23
  series: PreparedSeries[];
24
24
  seriesOptions: PreparedSeriesOptions;
25
- xAxis: PreparedAxis;
25
+ xAxis: PreparedAxis | null;
26
26
  yAxis: PreparedAxis[];
27
27
  xScale?: ChartScale;
28
28
  yScale?: ChartScale[];
@@ -21,17 +21,21 @@ import { WaterfallSeriesShapes, prepareWaterfallData } from './waterfall';
21
21
  import './styles.css';
22
22
  export const useShapes = (args) => {
23
23
  const { boundsWidth, boundsHeight, dispatcher, series, seriesOptions, xAxis, xScale, yAxis, yScale, split, htmlLayout, } = args;
24
- const shapesComponents = React.useMemo(() => {
24
+ const [shapesElemens, setShapesElements] = React.useState([]);
25
+ const [shapesElemensData, setShapesElemensData] = React.useState([]);
26
+ const setShapes = React.useCallback(async () => {
25
27
  const visibleSeries = getOnlyVisibleSeries(series);
26
28
  const groupedSeries = group(visibleSeries, (item) => item.type);
27
29
  const shapesData = [];
30
+ const shapes = [];
31
+ await Promise.all(
28
32
  // eslint-disable-next-line complexity
29
- const shapes = Array.from(groupedSeries).reduce((acc, item) => {
33
+ Array.from(groupedSeries).map(async (item) => {
30
34
  const [seriesType, chartSeries] = item;
31
35
  switch (seriesType) {
32
36
  case 'bar-x': {
33
- if (xScale && yScale) {
34
- const preparedData = prepareBarXData({
37
+ if (xAxis && xScale && yScale) {
38
+ const preparedData = await prepareBarXData({
35
39
  series: chartSeries,
36
40
  seriesOptions,
37
41
  xAxis,
@@ -40,14 +44,14 @@ export const useShapes = (args) => {
40
44
  yScale,
41
45
  boundsHeight,
42
46
  });
43
- acc.push(React.createElement(BarXSeriesShapes, { key: "bar-x", dispatcher: dispatcher, seriesOptions: seriesOptions, preparedData: preparedData, htmlLayout: htmlLayout }));
47
+ shapes.push(React.createElement(BarXSeriesShapes, { key: "bar-x", dispatcher: dispatcher, seriesOptions: seriesOptions, preparedData: preparedData, htmlLayout: htmlLayout }));
44
48
  shapesData.push(...preparedData);
45
49
  }
46
50
  break;
47
51
  }
48
52
  case 'bar-y': {
49
- if (xScale && yScale) {
50
- const preparedData = prepareBarYData({
53
+ if (xAxis && xScale && yScale) {
54
+ const preparedData = await prepareBarYData({
51
55
  series: chartSeries,
52
56
  seriesOptions,
53
57
  xAxis,
@@ -55,14 +59,14 @@ export const useShapes = (args) => {
55
59
  yAxis,
56
60
  yScale,
57
61
  });
58
- acc.push(React.createElement(BarYSeriesShapes, { key: "bar-y", dispatcher: dispatcher, seriesOptions: seriesOptions, preparedData: preparedData, htmlLayout: htmlLayout }));
62
+ shapes.push(React.createElement(BarYSeriesShapes, { key: "bar-y", dispatcher: dispatcher, seriesOptions: seriesOptions, preparedData: preparedData, htmlLayout: htmlLayout }));
59
63
  shapesData.push(...preparedData);
60
64
  }
61
65
  break;
62
66
  }
63
67
  case 'waterfall': {
64
- if (xScale && yScale) {
65
- const preparedData = prepareWaterfallData({
68
+ if (xAxis && xScale && yScale) {
69
+ const preparedData = await prepareWaterfallData({
66
70
  series: chartSeries,
67
71
  seriesOptions,
68
72
  xAxis,
@@ -70,14 +74,14 @@ export const useShapes = (args) => {
70
74
  yAxis,
71
75
  yScale,
72
76
  });
73
- acc.push(React.createElement(WaterfallSeriesShapes, { key: "waterfall", dispatcher: dispatcher, seriesOptions: seriesOptions, preparedData: preparedData, htmlLayout: htmlLayout }));
77
+ shapes.push(React.createElement(WaterfallSeriesShapes, { key: "waterfall", dispatcher: dispatcher, seriesOptions: seriesOptions, preparedData: preparedData, htmlLayout: htmlLayout }));
74
78
  shapesData.push(...preparedData);
75
79
  }
76
80
  break;
77
81
  }
78
82
  case 'line': {
79
- if (xScale && yScale) {
80
- const preparedData = prepareLineData({
83
+ if (xAxis && xScale && yScale) {
84
+ const preparedData = await prepareLineData({
81
85
  series: chartSeries,
82
86
  xAxis,
83
87
  xScale,
@@ -85,14 +89,14 @@ export const useShapes = (args) => {
85
89
  yScale,
86
90
  split,
87
91
  });
88
- acc.push(React.createElement(LineSeriesShapes, { key: "line", dispatcher: dispatcher, seriesOptions: seriesOptions, preparedData: preparedData, htmlLayout: htmlLayout }));
92
+ shapes.push(React.createElement(LineSeriesShapes, { key: "line", dispatcher: dispatcher, seriesOptions: seriesOptions, preparedData: preparedData, htmlLayout: htmlLayout }));
89
93
  shapesData.push(...preparedData);
90
94
  }
91
95
  break;
92
96
  }
93
97
  case 'area': {
94
- if (xScale && yScale) {
95
- const preparedData = prepareAreaData({
98
+ if (xAxis && xScale && yScale) {
99
+ const preparedData = await prepareAreaData({
96
100
  series: chartSeries,
97
101
  xAxis,
98
102
  xScale,
@@ -100,13 +104,13 @@ export const useShapes = (args) => {
100
104
  yScale,
101
105
  boundsHeight,
102
106
  });
103
- acc.push(React.createElement(AreaSeriesShapes, { key: "area", dispatcher: dispatcher, seriesOptions: seriesOptions, preparedData: preparedData, htmlLayout: htmlLayout }));
107
+ shapes.push(React.createElement(AreaSeriesShapes, { key: "area", dispatcher: dispatcher, seriesOptions: seriesOptions, preparedData: preparedData, htmlLayout: htmlLayout }));
104
108
  shapesData.push(...preparedData);
105
109
  }
106
110
  break;
107
111
  }
108
112
  case 'scatter': {
109
- if (xScale && yScale) {
113
+ if (xAxis && xScale && yScale) {
110
114
  const preparedData = prepareScatterData({
111
115
  series: chartSeries,
112
116
  xAxis,
@@ -114,30 +118,30 @@ export const useShapes = (args) => {
114
118
  yAxis,
115
119
  yScale,
116
120
  });
117
- acc.push(React.createElement(ScatterSeriesShape, { key: "scatter", dispatcher: dispatcher, preparedData: preparedData, seriesOptions: seriesOptions, htmlLayout: htmlLayout }));
121
+ shapes.push(React.createElement(ScatterSeriesShape, { key: "scatter", dispatcher: dispatcher, preparedData: preparedData, seriesOptions: seriesOptions, htmlLayout: htmlLayout }));
118
122
  shapesData.push(...preparedData);
119
123
  }
120
124
  break;
121
125
  }
122
126
  case 'pie': {
123
- const preparedData = preparePieData({
127
+ const preparedData = await preparePieData({
124
128
  series: chartSeries,
125
129
  boundsWidth,
126
130
  boundsHeight,
127
131
  });
128
- acc.push(React.createElement(PieSeriesShapes, { key: "pie", dispatcher: dispatcher, preparedData: preparedData, seriesOptions: seriesOptions, htmlLayout: htmlLayout }));
132
+ shapes.push(React.createElement(PieSeriesShapes, { key: "pie", dispatcher: dispatcher, preparedData: preparedData, seriesOptions: seriesOptions, htmlLayout: htmlLayout }));
129
133
  shapesData.push(...preparedData);
130
134
  break;
131
135
  }
132
136
  case 'treemap': {
133
- const preparedData = prepareTreemapData({
137
+ const preparedData = await prepareTreemapData({
134
138
  // We should have exactly one series with "treemap" type
135
139
  // Otherwise data validation should emit an error
136
140
  series: chartSeries[0],
137
141
  width: boundsWidth,
138
142
  height: boundsHeight,
139
143
  });
140
- acc.push(React.createElement(TreemapSeriesShape, { key: "treemap", dispatcher: dispatcher, preparedData: preparedData, seriesOptions: seriesOptions, htmlLayout: htmlLayout }));
144
+ shapes.push(React.createElement(TreemapSeriesShape, { key: "treemap", dispatcher: dispatcher, preparedData: preparedData, seriesOptions: seriesOptions, htmlLayout: htmlLayout }));
141
145
  shapesData.push(preparedData);
142
146
  break;
143
147
  }
@@ -147,17 +151,17 @@ export const useShapes = (args) => {
147
151
  width: boundsWidth,
148
152
  height: boundsHeight,
149
153
  });
150
- acc.push(React.createElement(SankeySeriesShape, { key: "sankey", dispatcher: dispatcher, preparedData: preparedData, seriesOptions: seriesOptions, htmlLayout: htmlLayout }));
154
+ shapes.push(React.createElement(SankeySeriesShape, { key: "sankey", dispatcher: dispatcher, preparedData: preparedData, seriesOptions: seriesOptions, htmlLayout: htmlLayout }));
151
155
  shapesData.push(preparedData);
152
156
  break;
153
157
  }
154
158
  case 'radar': {
155
- const preparedData = prepareRadarData({
159
+ const preparedData = await prepareRadarData({
156
160
  series: chartSeries,
157
161
  boundsWidth,
158
162
  boundsHeight,
159
163
  });
160
- acc.push(React.createElement(RadarSeriesShapes, { key: "radar", dispatcher: dispatcher, series: preparedData, seriesOptions: seriesOptions, htmlLayout: htmlLayout }));
164
+ shapes.push(React.createElement(RadarSeriesShapes, { key: "radar", dispatcher: dispatcher, series: preparedData, seriesOptions: seriesOptions, htmlLayout: htmlLayout }));
161
165
  shapesData.push(...preparedData);
162
166
  break;
163
167
  }
@@ -167,19 +171,24 @@ export const useShapes = (args) => {
167
171
  });
168
172
  }
169
173
  }
170
- return acc;
171
- }, []);
172
- return { shapes, shapesData };
174
+ }));
175
+ setShapesElements(shapes);
176
+ setShapesElemensData(shapesData);
173
177
  }, [
174
- boundsWidth,
175
178
  boundsHeight,
179
+ boundsWidth,
176
180
  dispatcher,
181
+ htmlLayout,
177
182
  series,
178
183
  seriesOptions,
184
+ split,
179
185
  xAxis,
180
186
  xScale,
181
187
  yAxis,
182
188
  yScale,
183
189
  ]);
184
- return { shapes: shapesComponents.shapes, shapesData: shapesComponents.shapesData };
190
+ React.useEffect(() => {
191
+ setShapes();
192
+ }, [setShapes]);
193
+ return { shapes: shapesElemens, shapesData: shapesElemensData };
185
194
  };
@@ -10,4 +10,4 @@ export declare const prepareLineData: (args: {
10
10
  yAxis: PreparedAxis[];
11
11
  yScale: ChartScale[];
12
12
  split: PreparedSplit;
13
- }) => PreparedLineData[];
13
+ }) => Promise<PreparedLineData[]>;
@@ -1,10 +1,10 @@
1
1
  import { getLabelsSize, getLeftPosition } from '../../../utils';
2
2
  import { getFormattedValue } from '../../../utils/chart/format';
3
3
  import { getXValue, getYValue } from '../utils';
4
- function getLabelData(point, series, xMax) {
4
+ async function getLabelData(point, series, xMax) {
5
5
  const text = getFormattedValue(Object.assign({ value: point.data.label || point.data.y }, series.dataLabels));
6
6
  const style = series.dataLabels.style;
7
- const size = getLabelsSize({ labels: [text], style });
7
+ const size = await getLabelsSize({ labels: [text], style });
8
8
  const labelData = {
9
9
  text,
10
10
  x: point.x,
@@ -27,9 +27,9 @@ function getLabelData(point, series, xMax) {
27
27
  }
28
28
  return labelData;
29
29
  }
30
- function getHtmlLabel(point, series, xMax) {
30
+ async function getHtmlLabel(point, series, xMax) {
31
31
  const content = String(point.data.label || point.data.y);
32
- const size = getLabelsSize({ labels: [content], html: true });
32
+ const size = await getLabelsSize({ labels: [content], html: true });
33
33
  return {
34
34
  x: Math.min(xMax - size.maxWidth, Math.max(0, point.x)),
35
35
  y: Math.max(0, point.y - series.dataLabels.padding - size.maxHeight),
@@ -38,12 +38,14 @@ function getHtmlLabel(point, series, xMax) {
38
38
  style: series.dataLabels.style,
39
39
  };
40
40
  }
41
- export const prepareLineData = (args) => {
41
+ export const prepareLineData = async (args) => {
42
+ var _a;
42
43
  const { series, xAxis, yAxis, xScale, yScale, split } = args;
43
44
  const [_xMin, xRangeMax] = xScale.range();
44
45
  const xMax = xRangeMax / (1 - xAxis.maxPadding);
45
- return series.reduce((acc, s) => {
46
- var _a;
46
+ const acc = [];
47
+ for (let i = 0; i < series.length; i++) {
48
+ const s = series[i];
47
49
  const yAxisIndex = s.yAxis;
48
50
  const seriesYAxis = yAxis[yAxisIndex];
49
51
  const yAxisTop = ((_a = split.plots[seriesYAxis.plotIndex]) === null || _a === void 0 ? void 0 : _a.top) || 0;
@@ -59,10 +61,11 @@ export const prepareLineData = (args) => {
59
61
  let labels = [];
60
62
  if (s.dataLabels.enabled) {
61
63
  if (s.dataLabels.html) {
62
- htmlElements.push(...points.map((p) => getHtmlLabel(p, s, xMax)));
64
+ const list = await Promise.all(points.map((p) => getHtmlLabel(p, s, xMax)));
65
+ htmlElements.push(...list);
63
66
  }
64
67
  else {
65
- labels = points.map((p) => getLabelData(p, s, xMax));
68
+ labels = await Promise.all(points.map((p) => getLabelData(p, s, xMax)));
66
69
  }
67
70
  }
68
71
  let markers = [];
@@ -89,6 +92,6 @@ export const prepareLineData = (args) => {
89
92
  htmlElements,
90
93
  };
91
94
  acc.push(result);
92
- return acc;
93
- }, []);
95
+ }
96
+ return acc;
94
97
  };
@@ -6,6 +6,7 @@ export type PointData = {
6
6
  y: number;
7
7
  data: LineSeriesData;
8
8
  series: PreparedLineSeries;
9
+ color?: string;
9
10
  };
10
11
  export type MarkerData = {
11
12
  point: PointData;
@@ -22,7 +22,7 @@ export function renderMarker(selection) {
22
22
  const haloSize = series.marker.states.hover.halo.size;
23
23
  return getMarkerSymbol(type, radius + haloSize);
24
24
  })
25
- .attr('fill', (d) => d.point.series.color)
25
+ .attr('fill', (d) => { var _a; return (_a = d.point.color) !== null && _a !== void 0 ? _a : d.point.series.color; })
26
26
  .attr('opacity', (d) => d.point.series.marker.states.hover.halo.opacity)
27
27
  .attr('z-index', -1)
28
28
  .attr('visibility', getMarkerHaloVisibility);
@@ -30,7 +30,7 @@ export function renderMarker(selection) {
30
30
  .append('path')
31
31
  .attr('class', symbolClassName)
32
32
  .call(setMarker, 'normal')
33
- .attr('fill', (d) => d.point.series.color);
33
+ .attr('fill', (d) => { var _a; return (_a = d.point.color) !== null && _a !== void 0 ? _a : d.point.series.color; });
34
34
  return markerSelection;
35
35
  }
36
36
  export function getMarkerVisibility(d) {
@@ -98,13 +98,13 @@ export function PieSeriesShapes(args) {
98
98
  .attr('stroke-linecap', 'round')
99
99
  .style('fill', 'none');
100
100
  // Render custom shapes if defined
101
- shapesSelection.each(function (d, index, nodes) {
101
+ shapesSelection.each(async function (d, index, nodes) {
102
102
  var _a, _b;
103
- const customShape = (_b = (_a = d.series).renderCustomShape) === null || _b === void 0 ? void 0 : _b.call(_a, {
103
+ const customShape = await ((_b = (_a = d.series).renderCustomShape) === null || _b === void 0 ? void 0 : _b.call(_a, {
104
104
  series: {
105
105
  innerRadius: d.innerRadius,
106
106
  },
107
- });
107
+ }));
108
108
  if (customShape) {
109
109
  nodes[index].append(customShape);
110
110
  }
@@ -5,5 +5,5 @@ type Args = {
5
5
  boundsWidth: number;
6
6
  boundsHeight: number;
7
7
  };
8
- export declare function preparePieData(args: Args): PreparedPieData[];
8
+ export declare function preparePieData(args: Args): Promise<PreparedPieData[]>;
9
9
  export {};
@@ -77,18 +77,20 @@ export function preparePieData(args) {
77
77
  data.segments = pieGenerator(segments);
78
78
  return data;
79
79
  };
80
- const getLabels = ({ series }) => {
80
+ const getLabels = async ({ series }) => {
81
81
  const { dataLabels } = series[0];
82
82
  if (!dataLabels.enabled) {
83
83
  return {};
84
84
  }
85
85
  const getTextSize = getTextSizeFn({ style: dataLabelsStyle });
86
- return series.reduce((acc, d) => {
86
+ const acc = {};
87
+ for (let i = 0; i < series.length; i++) {
88
+ const d = series[i];
87
89
  const text = getFormattedValue(Object.assign({ value: d.data.label || d.data.value }, d.dataLabels));
88
90
  let labelWidth = 0;
89
91
  let labelHeight = 0;
90
92
  if (dataLabels.html) {
91
- const size = getLabelsSize({
93
+ const size = await getLabelsSize({
92
94
  labels: [text],
93
95
  style: dataLabelsStyle,
94
96
  html: true,
@@ -97,7 +99,7 @@ export function preparePieData(args) {
97
99
  labelHeight = size.maxHeight;
98
100
  }
99
101
  else {
100
- const size = getTextSize(text);
102
+ const size = await getTextSize(text);
101
103
  labelWidth = size.width;
102
104
  labelHeight = size.height;
103
105
  }
@@ -106,8 +108,8 @@ export function preparePieData(args) {
106
108
  size: { width: labelWidth, height: labelHeight },
107
109
  };
108
110
  acc[d.id] = label;
109
- return acc;
110
- }, {});
111
+ }
112
+ return acc;
111
113
  };
112
114
  const prepareLabels = (prepareLabelsArgs) => {
113
115
  const { data, series, labels: labelsData, allowOverlow = true } = prepareLabelsArgs;
@@ -272,9 +274,9 @@ export function preparePieData(args) {
272
274
  connectors,
273
275
  };
274
276
  };
275
- return Array.from(groupedPieSeries).map(([stackId, items]) => {
277
+ return Promise.all(Array.from(groupedPieSeries).map(async ([stackId, items]) => {
276
278
  var _a;
277
- const seriesLabels = getLabels({ series: items });
279
+ const seriesLabels = await getLabels({ series: items });
278
280
  const data = prepareItem({ stackId, items, labels: seriesLabels });
279
281
  const preparedLabels = prepareLabels({
280
282
  data,
@@ -293,7 +295,8 @@ export function preparePieData(args) {
293
295
  freeSpace = boundsWidth / 2 - (left + label.size.width);
294
296
  }
295
297
  maxLeftRightFreeSpace = Math.max(0, Math.min(maxLeftRightFreeSpace, freeSpace));
296
- labelsOverflow = freeSpace < 0 ? Math.max(labelsOverflow, -freeSpace) : labelsOverflow;
298
+ labelsOverflow =
299
+ freeSpace < 0 ? Math.max(labelsOverflow, -freeSpace) : labelsOverflow;
297
300
  });
298
301
  preparedLabels.htmlLabels.forEach((label) => {
299
302
  let freeSpace = 0;
@@ -304,7 +307,8 @@ export function preparePieData(args) {
304
307
  freeSpace = boundsWidth - label.x - label.size.width;
305
308
  }
306
309
  maxLeftRightFreeSpace = Math.max(0, Math.min(maxLeftRightFreeSpace, freeSpace));
307
- labelsOverflow = freeSpace < 0 ? Math.max(labelsOverflow, -freeSpace) : labelsOverflow;
310
+ labelsOverflow =
311
+ freeSpace < 0 ? Math.max(labelsOverflow, -freeSpace) : labelsOverflow;
308
312
  });
309
313
  const segmentMaxRadius = Math.max(...data.segments.map((s) => s.data.radius));
310
314
  if (labelsOverflow) {
@@ -369,5 +373,5 @@ export function preparePieData(args) {
369
373
  data.htmlLabels = htmlLabels;
370
374
  data.connectors = connectors;
371
375
  return data;
372
- });
376
+ }));
373
377
  }
@@ -5,5 +5,5 @@ type Args = {
5
5
  boundsWidth: number;
6
6
  boundsHeight: number;
7
7
  };
8
- export declare function prepareRadarData(args: Args): PreparedRadarData[];
8
+ export declare function prepareRadarData(args: Args): Promise<PreparedRadarData[]>;
9
9
  export {};
@@ -1,7 +1,7 @@
1
1
  import { curveLinearClosed, line, range, scaleLinear } from 'd3';
2
2
  import { getLabelsSize } from '../../../utils';
3
3
  import { getFormattedValue } from '../../../utils/chart/format';
4
- export function prepareRadarData(args) {
4
+ export async function prepareRadarData(args) {
5
5
  const { series: preparedSeries, boundsWidth, boundsHeight } = args;
6
6
  const maxRadius = Math.min(boundsWidth, boundsHeight) / 2;
7
7
  const center = [boundsWidth / 2, boundsHeight / 2];
@@ -62,7 +62,7 @@ export function prepareRadarData(args) {
62
62
  data.grid.push(gridLines);
63
63
  });
64
64
  const radarAreaLine = line().curve(curveLinearClosed);
65
- preparedSeries.forEach((series) => {
65
+ await Promise.all(preparedSeries.map(async (series) => {
66
66
  var _a;
67
67
  const { dataLabels } = series;
68
68
  const markers = [];
@@ -112,9 +112,9 @@ export function prepareRadarData(args) {
112
112
  if (dataLabels.enabled) {
113
113
  const { style } = dataLabels;
114
114
  const shouldUseHtml = dataLabels.html;
115
- data.labels = categories.map((category, index) => {
115
+ data.labels = await Promise.all(categories.map(async (category, index) => {
116
116
  const text = getFormattedValue(Object.assign({ value: category.key }, dataLabels));
117
- const labelSize = getLabelsSize({ labels: [text], style });
117
+ const labelSize = await getLabelsSize({ labels: [text], style });
118
118
  const angle = index * angleStep - Math.PI / 2;
119
119
  // Position label slightly outside the point
120
120
  const labelRadius = data.radius + 10;
@@ -138,7 +138,7 @@ export function prepareRadarData(args) {
138
138
  textAnchor: angle > Math.PI / 2 && angle < (3 * Math.PI) / 2 ? 'end' : 'start',
139
139
  series: { id: series.id },
140
140
  };
141
- });
141
+ }));
142
142
  // Create HTML labels if needed
143
143
  if (dataLabels.html) {
144
144
  data.htmlLabels = data.labels.map((label) => ({
@@ -150,8 +150,7 @@ export function prepareRadarData(args) {
150
150
  }));
151
151
  }
152
152
  }
153
- return data;
154
- });
153
+ }));
155
154
  result.push(data);
156
155
  return result;
157
156
  }
@@ -20,6 +20,7 @@ export type PointData = {
20
20
  y: number;
21
21
  data: RadarSeriesData;
22
22
  series: PreparedRadarSeries;
23
+ color?: string;
23
24
  };
24
25
  export type RadarMarkerData = {
25
26
  point: PointData;
@@ -24,7 +24,6 @@ export function ScatterSeriesShape(props) {
24
24
  .data(preparedData, shapeKey)
25
25
  .join('g')
26
26
  .call(renderMarker)
27
- .attr('fill', (d) => d.point.data.color || d.point.series.color || '')
28
27
  .attr('opacity', (d) => d.point.opacity)
29
28
  .attr('cursor', (d) => d.point.series.cursor);
30
29
  const hoverEnabled = hoverOptions === null || hoverOptions === void 0 ? void 0 : hoverOptions.enabled;
@@ -13,6 +13,7 @@ export const prepareScatterData = (args) => {
13
13
  ? s.data
14
14
  : getFilteredLinearScatterData(s.data);
15
15
  filteredData.forEach((d) => {
16
+ var _a;
16
17
  acc.push({
17
18
  point: {
18
19
  data: d,
@@ -20,6 +21,7 @@ export const prepareScatterData = (args) => {
20
21
  x: getXValue({ point: d, xAxis, xScale }),
21
22
  y: getYValue({ point: d, yAxis: seriesYAxis, yScale: seriesYScale }),
22
23
  opacity: get(d, 'opacity', null),
24
+ color: (_a = d.color) !== null && _a !== void 0 ? _a : s.color,
23
25
  },
24
26
  hovered: false,
25
27
  active: true,
@@ -6,6 +6,7 @@ type PointData = {
6
6
  opacity: number | null;
7
7
  data: ScatterSeriesData;
8
8
  series: PreparedScatterSeries;
9
+ color: string;
9
10
  };
10
11
  export type MarkerData = {
11
12
  point: PointData;
@@ -4,4 +4,4 @@ export declare function prepareTreemapData(args: {
4
4
  series: PreparedTreemapSeries;
5
5
  width: number;
6
6
  height: number;
7
- }): PreparedTreemapData;
7
+ }): Promise<PreparedTreemapData>;