@gravity-ui/charts 1.38.6 → 1.39.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 (169) hide show
  1. package/dist/cjs/components/AxisX/prepare-axis-data.d.ts +1 -1
  2. package/dist/cjs/components/AxisX/prepare-axis-data.js +10 -10
  3. package/dist/cjs/components/AxisY/prepare-axis-data.d.ts +1 -1
  4. package/dist/cjs/components/AxisY/prepare-axis-data.js +2 -2
  5. package/dist/cjs/components/ChartInner/index.js +25 -8
  6. package/dist/cjs/components/ChartInner/useChartInnerHandlers.d.ts +1 -2
  7. package/dist/cjs/components/ChartInner/useChartInnerHandlers.js +5 -1
  8. package/dist/cjs/components/ChartInner/useChartInnerProps.d.ts +19 -20
  9. package/dist/cjs/components/ChartInner/useChartInnerProps.js +230 -139
  10. package/dist/cjs/components/ChartInner/useChartInnerState.js +2 -1
  11. package/dist/cjs/components/ChartInner/useDefaultState.d.ts +26 -0
  12. package/dist/cjs/components/ChartInner/useDefaultState.js +74 -0
  13. package/dist/cjs/components/ChartInner/utils/axis.d.ts +44 -0
  14. package/dist/cjs/components/ChartInner/utils/axis.js +35 -0
  15. package/dist/cjs/{hooks/useChartOptions → components/ChartInner/utils}/chart.d.ts +2 -2
  16. package/dist/{esm/components/ChartInner/utils.d.ts → cjs/components/ChartInner/utils/common.d.ts} +2 -1
  17. package/dist/cjs/components/ChartInner/utils/index.d.ts +7 -0
  18. package/dist/cjs/components/ChartInner/utils/index.js +7 -0
  19. package/dist/cjs/components/ChartInner/utils/normalized-original-data.d.ts +33 -0
  20. package/dist/cjs/components/ChartInner/utils/normalized-original-data.js +21 -0
  21. package/dist/cjs/{hooks/useChartOptions → components/ChartInner/utils}/title.d.ts +2 -2
  22. package/dist/{esm/hooks/useChartOptions → cjs/components/ChartInner/utils}/title.js +1 -1
  23. package/dist/cjs/components/ChartInner/utils/tooltip.d.ts +8 -0
  24. package/dist/cjs/components/ChartInner/utils/tooltip.js +7 -0
  25. package/dist/cjs/{hooks/useChartOptions → components/ChartInner/utils}/zoom.d.ts +3 -3
  26. package/dist/{esm/hooks/useChartOptions → cjs/components/ChartInner/utils}/zoom.js +1 -1
  27. package/dist/cjs/components/Legend/index.d.ts +1 -1
  28. package/dist/cjs/components/Legend/index.js +1 -1
  29. package/dist/cjs/hooks/index.d.ts +1 -4
  30. package/dist/cjs/hooks/index.js +1 -4
  31. package/dist/cjs/hooks/{useChartOptions/types.d.ts → types.d.ts} +1 -1
  32. package/dist/cjs/hooks/useAxis/index.d.ts +41 -6
  33. package/dist/cjs/hooks/useAxis/index.js +55 -40
  34. package/dist/cjs/hooks/useAxis/types.d.ts +0 -2
  35. package/dist/cjs/hooks/useAxis/y-axis.js +1 -3
  36. package/dist/cjs/hooks/useAxisScales/index.d.ts +4 -0
  37. package/dist/cjs/hooks/useAxisScales/index.js +1 -1
  38. package/dist/cjs/hooks/useAxisScales/x-scale.js +0 -1
  39. package/dist/cjs/hooks/useAxisScales/y-scale.js +0 -1
  40. package/dist/cjs/hooks/useCrosshair/index.d.ts +1 -1
  41. package/dist/cjs/hooks/useRangeSlider/types.d.ts +1 -1
  42. package/dist/cjs/hooks/useRangeSlider/utils.d.ts +1 -1
  43. package/dist/cjs/hooks/useSeries/index.d.ts +10 -14
  44. package/dist/cjs/hooks/useSeries/index.js +8 -80
  45. package/dist/cjs/hooks/useSeries/prepare-area.d.ts +2 -2
  46. package/dist/cjs/hooks/useSeries/prepare-legend.d.ts +1 -1
  47. package/dist/cjs/hooks/useSeries/prepare-line.d.ts +2 -2
  48. package/dist/cjs/hooks/useSeries/prepare-radar.d.ts +1 -1
  49. package/dist/cjs/hooks/useShapes/index.d.ts +4 -0
  50. package/dist/cjs/hooks/useShapes/index.js +209 -189
  51. package/dist/cjs/hooks/useShapes/pie/prepare-data.js +0 -1
  52. package/dist/cjs/hooks/useSplit/index.d.ts +5 -2
  53. package/dist/cjs/hooks/useSplit/index.js +27 -30
  54. package/dist/cjs/hooks/useTooltip/index.d.ts +1 -1
  55. package/dist/cjs/hooks/useZoom/index.d.ts +2 -2
  56. package/dist/cjs/hooks/useZoom/index.js +2 -2
  57. package/dist/cjs/index.d.ts +1 -1
  58. package/dist/cjs/index.js +1 -1
  59. package/dist/cjs/types/index.d.ts +24 -11
  60. package/dist/cjs/utils/chart/axis/common.d.ts +2 -2
  61. package/dist/cjs/utils/chart/axis/common.js +1 -1
  62. package/dist/cjs/utils/chart/chart-dimensions.d.ts +24 -0
  63. package/dist/cjs/{hooks/useChartDimensions/index.js → utils/chart/chart-dimensions.js} +56 -33
  64. package/dist/cjs/utils/chart/common.d.ts +28 -0
  65. package/dist/cjs/utils/chart/common.js +192 -0
  66. package/dist/cjs/utils/chart/get-closest-data.js +0 -1
  67. package/dist/cjs/utils/chart/index.d.ts +2 -28
  68. package/dist/cjs/utils/chart/index.js +2 -192
  69. package/dist/cjs/utils/chart/tooltip.d.ts +6 -0
  70. package/dist/cjs/{hooks/useChartOptions → utils/chart}/tooltip.js +2 -7
  71. package/dist/cjs/utils/chart/zoom.js +0 -2
  72. package/dist/esm/components/AxisX/prepare-axis-data.d.ts +1 -1
  73. package/dist/esm/components/AxisX/prepare-axis-data.js +10 -10
  74. package/dist/esm/components/AxisY/prepare-axis-data.d.ts +1 -1
  75. package/dist/esm/components/AxisY/prepare-axis-data.js +2 -2
  76. package/dist/esm/components/ChartInner/index.js +25 -8
  77. package/dist/esm/components/ChartInner/useChartInnerHandlers.d.ts +1 -2
  78. package/dist/esm/components/ChartInner/useChartInnerHandlers.js +5 -1
  79. package/dist/esm/components/ChartInner/useChartInnerProps.d.ts +19 -20
  80. package/dist/esm/components/ChartInner/useChartInnerProps.js +230 -139
  81. package/dist/esm/components/ChartInner/useChartInnerState.js +2 -1
  82. package/dist/esm/components/ChartInner/useDefaultState.d.ts +26 -0
  83. package/dist/esm/components/ChartInner/useDefaultState.js +74 -0
  84. package/dist/esm/components/ChartInner/utils/axis.d.ts +44 -0
  85. package/dist/esm/components/ChartInner/utils/axis.js +35 -0
  86. package/dist/esm/{hooks/useChartOptions → components/ChartInner/utils}/chart.d.ts +2 -2
  87. package/dist/{cjs/components/ChartInner/utils.d.ts → esm/components/ChartInner/utils/common.d.ts} +2 -1
  88. package/dist/esm/components/ChartInner/utils/index.d.ts +7 -0
  89. package/dist/esm/components/ChartInner/utils/index.js +7 -0
  90. package/dist/esm/components/ChartInner/utils/normalized-original-data.d.ts +33 -0
  91. package/dist/esm/components/ChartInner/utils/normalized-original-data.js +21 -0
  92. package/dist/esm/{hooks/useChartOptions → components/ChartInner/utils}/title.d.ts +2 -2
  93. package/dist/{cjs/hooks/useChartOptions → esm/components/ChartInner/utils}/title.js +1 -1
  94. package/dist/esm/components/ChartInner/utils/tooltip.d.ts +8 -0
  95. package/dist/esm/components/ChartInner/utils/tooltip.js +7 -0
  96. package/dist/esm/{hooks/useChartOptions → components/ChartInner/utils}/zoom.d.ts +3 -3
  97. package/dist/{cjs/hooks/useChartOptions → esm/components/ChartInner/utils}/zoom.js +1 -1
  98. package/dist/esm/components/Legend/index.d.ts +1 -1
  99. package/dist/esm/components/Legend/index.js +1 -1
  100. package/dist/esm/hooks/index.d.ts +1 -4
  101. package/dist/esm/hooks/index.js +1 -4
  102. package/dist/esm/hooks/{useChartOptions/types.d.ts → types.d.ts} +1 -1
  103. package/dist/esm/hooks/useAxis/index.d.ts +41 -6
  104. package/dist/esm/hooks/useAxis/index.js +55 -40
  105. package/dist/esm/hooks/useAxis/types.d.ts +0 -2
  106. package/dist/esm/hooks/useAxis/y-axis.js +1 -3
  107. package/dist/esm/hooks/useAxisScales/index.d.ts +4 -0
  108. package/dist/esm/hooks/useAxisScales/index.js +1 -1
  109. package/dist/esm/hooks/useAxisScales/x-scale.js +0 -1
  110. package/dist/esm/hooks/useAxisScales/y-scale.js +0 -1
  111. package/dist/esm/hooks/useCrosshair/index.d.ts +1 -1
  112. package/dist/esm/hooks/useRangeSlider/types.d.ts +1 -1
  113. package/dist/esm/hooks/useRangeSlider/utils.d.ts +1 -1
  114. package/dist/esm/hooks/useSeries/index.d.ts +10 -14
  115. package/dist/esm/hooks/useSeries/index.js +8 -80
  116. package/dist/esm/hooks/useSeries/prepare-area.d.ts +2 -2
  117. package/dist/esm/hooks/useSeries/prepare-legend.d.ts +1 -1
  118. package/dist/esm/hooks/useSeries/prepare-line.d.ts +2 -2
  119. package/dist/esm/hooks/useSeries/prepare-radar.d.ts +1 -1
  120. package/dist/esm/hooks/useShapes/index.d.ts +4 -0
  121. package/dist/esm/hooks/useShapes/index.js +209 -189
  122. package/dist/esm/hooks/useShapes/pie/prepare-data.js +0 -1
  123. package/dist/esm/hooks/useSplit/index.d.ts +5 -2
  124. package/dist/esm/hooks/useSplit/index.js +27 -30
  125. package/dist/esm/hooks/useTooltip/index.d.ts +1 -1
  126. package/dist/esm/hooks/useZoom/index.d.ts +2 -2
  127. package/dist/esm/hooks/useZoom/index.js +2 -2
  128. package/dist/esm/index.d.ts +1 -1
  129. package/dist/esm/index.js +1 -1
  130. package/dist/esm/types/index.d.ts +24 -11
  131. package/dist/esm/utils/chart/axis/common.d.ts +2 -2
  132. package/dist/esm/utils/chart/axis/common.js +1 -1
  133. package/dist/esm/utils/chart/chart-dimensions.d.ts +24 -0
  134. package/dist/esm/{hooks/useChartDimensions/index.js → utils/chart/chart-dimensions.js} +56 -33
  135. package/dist/esm/utils/chart/common.d.ts +28 -0
  136. package/dist/esm/utils/chart/common.js +192 -0
  137. package/dist/esm/utils/chart/get-closest-data.js +0 -1
  138. package/dist/esm/utils/chart/index.d.ts +2 -28
  139. package/dist/esm/utils/chart/index.js +2 -192
  140. package/dist/esm/utils/chart/tooltip.d.ts +6 -0
  141. package/dist/esm/{hooks/useChartOptions → utils/chart}/tooltip.js +2 -7
  142. package/dist/esm/utils/chart/zoom.js +0 -2
  143. package/package.json +3 -1
  144. package/dist/cjs/components/ChartInner/useLegend.d.ts +0 -14
  145. package/dist/cjs/components/ChartInner/useLegend.js +0 -34
  146. package/dist/cjs/hooks/useChartDimensions/index.d.ts +0 -17
  147. package/dist/cjs/hooks/useChartDimensions/utils.d.ts +0 -10
  148. package/dist/cjs/hooks/useChartDimensions/utils.js +0 -41
  149. package/dist/cjs/hooks/useChartOptions/tooltip.d.ts +0 -13
  150. package/dist/cjs/hooks/useNormalizedOriginalData/index.d.ts +0 -38
  151. package/dist/cjs/hooks/useNormalizedOriginalData/index.js +0 -32
  152. package/dist/cjs/hooks/useYAxisLabelWidth/index.d.ts +0 -11
  153. package/dist/cjs/hooks/useYAxisLabelWidth/index.js +0 -48
  154. package/dist/esm/components/ChartInner/useLegend.d.ts +0 -14
  155. package/dist/esm/components/ChartInner/useLegend.js +0 -34
  156. package/dist/esm/hooks/useChartDimensions/index.d.ts +0 -17
  157. package/dist/esm/hooks/useChartDimensions/utils.d.ts +0 -10
  158. package/dist/esm/hooks/useChartDimensions/utils.js +0 -41
  159. package/dist/esm/hooks/useChartOptions/tooltip.d.ts +0 -13
  160. package/dist/esm/hooks/useNormalizedOriginalData/index.d.ts +0 -38
  161. package/dist/esm/hooks/useNormalizedOriginalData/index.js +0 -32
  162. package/dist/esm/hooks/useYAxisLabelWidth/index.d.ts +0 -11
  163. package/dist/esm/hooks/useYAxisLabelWidth/index.js +0 -48
  164. /package/dist/cjs/{hooks/useChartOptions → components/ChartInner/utils}/chart.js +0 -0
  165. /package/dist/cjs/components/ChartInner/{utils.js → utils/common.js} +0 -0
  166. /package/dist/cjs/hooks/{useChartOptions/types.js → types.js} +0 -0
  167. /package/dist/esm/{hooks/useChartOptions → components/ChartInner/utils}/chart.js +0 -0
  168. /package/dist/esm/components/ChartInner/{utils.js → utils/common.js} +0 -0
  169. /package/dist/esm/hooks/{useChartOptions/types.js → types.js} +0 -0
@@ -40,6 +40,10 @@ type Args = {
40
40
  yScale?: (ChartScale | undefined)[];
41
41
  zoomState?: Partial<ZoomState>;
42
42
  };
43
+ export declare function getShapes(args: Args): Promise<{
44
+ shapes: React.ReactElement<any, string | React.JSXElementConstructor<any>>[];
45
+ shapesData: ShapeData[];
46
+ }>;
43
47
  export declare const useShapes: (args: Args) => {
44
48
  shapes: React.ReactElement<any, string | React.JSXElementConstructor<any>>[];
45
49
  shapesData: ShapeData[];
@@ -30,6 +30,197 @@ function shouldUseClipPathId(seriesType, clipPathBySeriesType) {
30
30
  var _a;
31
31
  return (_a = clipPathBySeriesType === null || clipPathBySeriesType === void 0 ? void 0 : clipPathBySeriesType[seriesType]) !== null && _a !== void 0 ? _a : true;
32
32
  }
33
+ export async function getShapes(args) {
34
+ const { boundsWidth, boundsHeight, clipPathId, clipPathBySeriesType, dispatcher, htmlLayout, isOutsideBounds = IS_OUTSIDE_BOUNDS, isRangeSlider, series, seriesOptions, split, xAxis, xScale, yAxis, yScale, zoomState, } = args;
35
+ const visibleSeries = getOnlyVisibleSeries(series);
36
+ const groupedSeries = group(visibleSeries, (item) => item.type);
37
+ const shapesData = [];
38
+ const shapes = [];
39
+ await Promise.all(Array.from(groupedSeries).map(async (item, index) => {
40
+ const [seriesType, chartSeries] = item;
41
+ switch (seriesType) {
42
+ case SERIES_TYPE.BarX: {
43
+ if (xAxis && xScale && (yScale === null || yScale === void 0 ? void 0 : yScale.length)) {
44
+ const preparedData = await prepareBarXData({
45
+ series: chartSeries,
46
+ seriesOptions,
47
+ xAxis,
48
+ xScale,
49
+ yAxis,
50
+ yScale,
51
+ boundsHeight,
52
+ split,
53
+ isRangeSlider,
54
+ });
55
+ shapes[index] = (React.createElement(BarXSeriesShapes, { key: SERIES_TYPE.BarX, dispatcher: dispatcher, seriesOptions: seriesOptions, preparedData: preparedData, htmlLayout: htmlLayout, clipPathId: clipPathId }));
56
+ shapesData.splice(index, 0, ...preparedData);
57
+ }
58
+ break;
59
+ }
60
+ case SERIES_TYPE.BarY: {
61
+ if (xAxis && xScale && (yScale === null || yScale === void 0 ? void 0 : yScale.length)) {
62
+ const preparedData = await prepareBarYData({
63
+ boundsHeight,
64
+ boundsWidth,
65
+ series: chartSeries,
66
+ seriesOptions,
67
+ xAxis,
68
+ xScale,
69
+ yAxis,
70
+ yScale,
71
+ });
72
+ shapes[index] = (React.createElement(BarYSeriesShapes, { key: SERIES_TYPE.BarY, dispatcher: dispatcher, seriesOptions: seriesOptions, preparedData: preparedData, htmlLayout: htmlLayout, clipPathId: clipPathId }));
73
+ shapesData.splice(index, 0, ...preparedData.shapes);
74
+ }
75
+ break;
76
+ }
77
+ case SERIES_TYPE.Waterfall: {
78
+ if (xAxis && xScale && (yScale === null || yScale === void 0 ? void 0 : yScale.length)) {
79
+ const preparedData = await prepareWaterfallData({
80
+ series: chartSeries,
81
+ seriesOptions,
82
+ xAxis,
83
+ xScale,
84
+ yAxis,
85
+ yScale,
86
+ });
87
+ shapes[index] = (React.createElement(WaterfallSeriesShapes, { key: SERIES_TYPE.Waterfall, dispatcher: dispatcher, seriesOptions: seriesOptions, preparedData: preparedData, htmlLayout: htmlLayout, clipPathId: clipPathId }));
88
+ shapesData.splice(index, 0, ...preparedData);
89
+ }
90
+ break;
91
+ }
92
+ case SERIES_TYPE.Line: {
93
+ if (xAxis && xScale && (yScale === null || yScale === void 0 ? void 0 : yScale.length)) {
94
+ const preparedData = await prepareLineData({
95
+ series: chartSeries,
96
+ xAxis,
97
+ xScale,
98
+ yAxis,
99
+ yScale,
100
+ split,
101
+ isOutsideBounds,
102
+ isRangeSlider,
103
+ });
104
+ const resultClipPathId = getSeriesClipPathId({
105
+ clipPathId,
106
+ yAxis,
107
+ zoomState,
108
+ });
109
+ shapes[index] = (React.createElement(LineSeriesShapes, { key: SERIES_TYPE.Line, dispatcher: dispatcher, seriesOptions: seriesOptions, preparedData: preparedData, htmlLayout: htmlLayout, clipPathId: resultClipPathId }));
110
+ shapesData.splice(index, 0, ...preparedData);
111
+ }
112
+ break;
113
+ }
114
+ case SERIES_TYPE.Area: {
115
+ if (xAxis && xScale && (yScale === null || yScale === void 0 ? void 0 : yScale.length)) {
116
+ const preparedData = await prepareAreaData({
117
+ series: chartSeries,
118
+ xAxis,
119
+ xScale,
120
+ yAxis,
121
+ yScale,
122
+ boundsHeight,
123
+ split,
124
+ isOutsideBounds,
125
+ isRangeSlider,
126
+ });
127
+ shapes[index] = (React.createElement(AreaSeriesShapes, { key: SERIES_TYPE.Area, dispatcher: dispatcher, seriesOptions: seriesOptions, preparedData: preparedData, htmlLayout: htmlLayout, clipPathId: clipPathId }));
128
+ shapesData.splice(index, 0, ...preparedData);
129
+ }
130
+ break;
131
+ }
132
+ case SERIES_TYPE.Scatter: {
133
+ if (xAxis && xScale && (yScale === null || yScale === void 0 ? void 0 : yScale.length)) {
134
+ const preparedData = prepareScatterData({
135
+ series: chartSeries,
136
+ xAxis,
137
+ xScale,
138
+ yAxis,
139
+ yScale,
140
+ isOutsideBounds,
141
+ });
142
+ shapes[index] = (React.createElement(ScatterSeriesShape, { key: SERIES_TYPE.Scatter, clipPathId: shouldUseClipPathId(SERIES_TYPE.Scatter, clipPathBySeriesType)
143
+ ? clipPathId
144
+ : undefined, dispatcher: dispatcher, preparedData: preparedData, seriesOptions: seriesOptions, htmlLayout: htmlLayout }));
145
+ shapesData.splice(index, 0, ...preparedData);
146
+ }
147
+ break;
148
+ }
149
+ case SERIES_TYPE.Pie: {
150
+ const preparedData = await preparePieData({
151
+ series: chartSeries,
152
+ boundsWidth,
153
+ boundsHeight,
154
+ });
155
+ shapes[index] = (React.createElement(PieSeriesShapes, { key: SERIES_TYPE.Pie, dispatcher: dispatcher, preparedData: preparedData, seriesOptions: seriesOptions, htmlLayout: htmlLayout }));
156
+ shapesData.splice(index, 0, ...preparedData);
157
+ break;
158
+ }
159
+ case SERIES_TYPE.Treemap: {
160
+ const preparedData = await prepareTreemapData({
161
+ // We should have exactly one series with "treemap" type
162
+ // Otherwise data validation should emit an error
163
+ series: chartSeries[0],
164
+ width: boundsWidth,
165
+ height: boundsHeight,
166
+ });
167
+ shapes[index] = (React.createElement(TreemapSeriesShape, { key: SERIES_TYPE.Treemap, dispatcher: dispatcher, preparedData: preparedData, seriesOptions: seriesOptions, htmlLayout: htmlLayout }));
168
+ shapesData.splice(index, 0, preparedData);
169
+ break;
170
+ }
171
+ case SERIES_TYPE.Sankey: {
172
+ const preparedData = prepareSankeyData({
173
+ series: chartSeries[0],
174
+ width: boundsWidth,
175
+ height: boundsHeight,
176
+ });
177
+ shapes[index] = (React.createElement(SankeySeriesShape, { key: SERIES_TYPE.Sankey, dispatcher: dispatcher, preparedData: preparedData, seriesOptions: seriesOptions, htmlLayout: htmlLayout }));
178
+ shapesData.splice(index, 0, preparedData);
179
+ break;
180
+ }
181
+ case SERIES_TYPE.Radar: {
182
+ const preparedData = await prepareRadarData({
183
+ series: chartSeries,
184
+ boundsWidth,
185
+ boundsHeight,
186
+ });
187
+ shapes[index] = (React.createElement(RadarSeriesShapes, { key: SERIES_TYPE.Radar, dispatcher: dispatcher, series: preparedData, seriesOptions: seriesOptions, htmlLayout: htmlLayout }));
188
+ shapesData.splice(index, 0, ...preparedData);
189
+ break;
190
+ }
191
+ case SERIES_TYPE.Heatmap: {
192
+ if (xAxis && xScale && (yScale === null || yScale === void 0 ? void 0 : yScale[0])) {
193
+ const preparedData = await prepareHeatmapData({
194
+ series: chartSeries[0],
195
+ xAxis,
196
+ xScale,
197
+ yAxis: yAxis[0],
198
+ yScale: yScale[0],
199
+ });
200
+ shapes[index] = (React.createElement(HeatmapSeriesShapes, { key: SERIES_TYPE.Heatmap, dispatcher: dispatcher, preparedData: preparedData, seriesOptions: seriesOptions, htmlLayout: htmlLayout }));
201
+ shapesData.splice(index, 0, preparedData);
202
+ }
203
+ break;
204
+ }
205
+ case 'funnel': {
206
+ const preparedData = await prepareFunnelData({
207
+ series: chartSeries,
208
+ boundsWidth,
209
+ boundsHeight,
210
+ });
211
+ shapes[index] = (React.createElement(FunnelSeriesShapes, { key: "funnel", dispatcher: dispatcher, preparedData: preparedData, seriesOptions: seriesOptions, htmlLayout: htmlLayout }));
212
+ shapesData.splice(index, 0, preparedData);
213
+ break;
214
+ }
215
+ default: {
216
+ throw new ChartError({
217
+ message: `The display method is not defined for a series with type "${seriesType}"`,
218
+ });
219
+ }
220
+ }
221
+ }));
222
+ return { shapes, shapesData };
223
+ }
33
224
  export const useShapes = (args) => {
34
225
  const { boundsWidth, boundsHeight, clipPathId, clipPathBySeriesType, dispatcher, htmlLayout, isOutsideBounds = IS_OUTSIDE_BOUNDS, isRangeSlider, series, seriesOptions, split, xAxis, xScale, yAxis, yScale, zoomState, } = args;
35
226
  const [shapesElemens, setShapesElements] = React.useState([]);
@@ -43,195 +234,24 @@ export const useShapes = (args) => {
43
234
  }
44
235
  (async () => {
45
236
  const currentRun = countedRef.current;
46
- const visibleSeries = getOnlyVisibleSeries(series);
47
- const groupedSeries = group(visibleSeries, (item) => item.type);
48
- const shapesData = [];
49
- const shapes = [];
50
- await Promise.all(
51
- // eslint-disable-next-line complexity
52
- Array.from(groupedSeries).map(async (item, index) => {
53
- const [seriesType, chartSeries] = item;
54
- switch (seriesType) {
55
- case SERIES_TYPE.BarX: {
56
- if (xAxis && xScale && (yScale === null || yScale === void 0 ? void 0 : yScale.length)) {
57
- const preparedData = await prepareBarXData({
58
- series: chartSeries,
59
- seriesOptions,
60
- xAxis,
61
- xScale,
62
- yAxis,
63
- yScale,
64
- boundsHeight,
65
- split,
66
- isRangeSlider,
67
- });
68
- shapes[index] = (React.createElement(BarXSeriesShapes, { key: SERIES_TYPE.BarX, dispatcher: dispatcher, seriesOptions: seriesOptions, preparedData: preparedData, htmlLayout: htmlLayout, clipPathId: clipPathId }));
69
- shapesData.splice(index, 0, ...preparedData);
70
- }
71
- break;
72
- }
73
- case SERIES_TYPE.BarY: {
74
- if (xAxis && xScale && (yScale === null || yScale === void 0 ? void 0 : yScale.length)) {
75
- const preparedData = await prepareBarYData({
76
- boundsHeight,
77
- boundsWidth,
78
- series: chartSeries,
79
- seriesOptions,
80
- xAxis,
81
- xScale,
82
- yAxis,
83
- yScale,
84
- });
85
- shapes[index] = (React.createElement(BarYSeriesShapes, { key: SERIES_TYPE.BarY, dispatcher: dispatcher, seriesOptions: seriesOptions, preparedData: preparedData, htmlLayout: htmlLayout, clipPathId: clipPathId }));
86
- shapesData.splice(index, 0, ...preparedData.shapes);
87
- }
88
- break;
89
- }
90
- case SERIES_TYPE.Waterfall: {
91
- if (xAxis && xScale && (yScale === null || yScale === void 0 ? void 0 : yScale.length)) {
92
- const preparedData = await prepareWaterfallData({
93
- series: chartSeries,
94
- seriesOptions,
95
- xAxis,
96
- xScale,
97
- yAxis,
98
- yScale,
99
- });
100
- shapes[index] = (React.createElement(WaterfallSeriesShapes, { key: SERIES_TYPE.Waterfall, dispatcher: dispatcher, seriesOptions: seriesOptions, preparedData: preparedData, htmlLayout: htmlLayout, clipPathId: clipPathId }));
101
- shapesData.splice(index, 0, ...preparedData);
102
- }
103
- break;
104
- }
105
- case SERIES_TYPE.Line: {
106
- if (xAxis && xScale && (yScale === null || yScale === void 0 ? void 0 : yScale.length)) {
107
- const preparedData = await prepareLineData({
108
- series: chartSeries,
109
- xAxis,
110
- xScale,
111
- yAxis,
112
- yScale,
113
- split,
114
- isOutsideBounds,
115
- isRangeSlider,
116
- });
117
- const resultClipPathId = getSeriesClipPathId({
118
- clipPathId,
119
- yAxis,
120
- zoomState,
121
- });
122
- shapes[index] = (React.createElement(LineSeriesShapes, { key: SERIES_TYPE.Line, dispatcher: dispatcher, seriesOptions: seriesOptions, preparedData: preparedData, htmlLayout: htmlLayout, clipPathId: resultClipPathId }));
123
- shapesData.splice(index, 0, ...preparedData);
124
- }
125
- break;
126
- }
127
- case SERIES_TYPE.Area: {
128
- if (xAxis && xScale && (yScale === null || yScale === void 0 ? void 0 : yScale.length)) {
129
- const preparedData = await prepareAreaData({
130
- series: chartSeries,
131
- xAxis,
132
- xScale,
133
- yAxis,
134
- yScale,
135
- boundsHeight,
136
- split,
137
- isOutsideBounds,
138
- isRangeSlider,
139
- });
140
- shapes[index] = (React.createElement(AreaSeriesShapes, { key: SERIES_TYPE.Area, dispatcher: dispatcher, seriesOptions: seriesOptions, preparedData: preparedData, htmlLayout: htmlLayout, clipPathId: clipPathId }));
141
- shapesData.splice(index, 0, ...preparedData);
142
- }
143
- break;
144
- }
145
- case SERIES_TYPE.Scatter: {
146
- if (xAxis && xScale && (yScale === null || yScale === void 0 ? void 0 : yScale.length)) {
147
- const preparedData = prepareScatterData({
148
- series: chartSeries,
149
- xAxis,
150
- xScale,
151
- yAxis,
152
- yScale,
153
- isOutsideBounds,
154
- });
155
- shapes[index] = (React.createElement(ScatterSeriesShape, { key: SERIES_TYPE.Scatter, clipPathId: shouldUseClipPathId(SERIES_TYPE.Scatter, clipPathBySeriesType)
156
- ? clipPathId
157
- : undefined, dispatcher: dispatcher, preparedData: preparedData, seriesOptions: seriesOptions, htmlLayout: htmlLayout }));
158
- shapesData.splice(index, 0, ...preparedData);
159
- }
160
- break;
161
- }
162
- case SERIES_TYPE.Pie: {
163
- const preparedData = await preparePieData({
164
- series: chartSeries,
165
- boundsWidth,
166
- boundsHeight,
167
- });
168
- shapes[index] = (React.createElement(PieSeriesShapes, { key: SERIES_TYPE.Pie, dispatcher: dispatcher, preparedData: preparedData, seriesOptions: seriesOptions, htmlLayout: htmlLayout }));
169
- shapesData.splice(index, 0, ...preparedData);
170
- break;
171
- }
172
- case SERIES_TYPE.Treemap: {
173
- const preparedData = await prepareTreemapData({
174
- // We should have exactly one series with "treemap" type
175
- // Otherwise data validation should emit an error
176
- series: chartSeries[0],
177
- width: boundsWidth,
178
- height: boundsHeight,
179
- });
180
- shapes[index] = (React.createElement(TreemapSeriesShape, { key: SERIES_TYPE.Treemap, dispatcher: dispatcher, preparedData: preparedData, seriesOptions: seriesOptions, htmlLayout: htmlLayout }));
181
- shapesData.splice(index, 0, preparedData);
182
- break;
183
- }
184
- case SERIES_TYPE.Sankey: {
185
- const preparedData = prepareSankeyData({
186
- series: chartSeries[0],
187
- width: boundsWidth,
188
- height: boundsHeight,
189
- });
190
- shapes[index] = (React.createElement(SankeySeriesShape, { key: SERIES_TYPE.Sankey, dispatcher: dispatcher, preparedData: preparedData, seriesOptions: seriesOptions, htmlLayout: htmlLayout }));
191
- shapesData.splice(index, 0, preparedData);
192
- break;
193
- }
194
- case SERIES_TYPE.Radar: {
195
- const preparedData = await prepareRadarData({
196
- series: chartSeries,
197
- boundsWidth,
198
- boundsHeight,
199
- });
200
- shapes[index] = (React.createElement(RadarSeriesShapes, { key: SERIES_TYPE.Radar, dispatcher: dispatcher, series: preparedData, seriesOptions: seriesOptions, htmlLayout: htmlLayout }));
201
- shapesData.splice(index, 0, ...preparedData);
202
- break;
203
- }
204
- case SERIES_TYPE.Heatmap: {
205
- if (xAxis && xScale && (yScale === null || yScale === void 0 ? void 0 : yScale[0])) {
206
- const preparedData = await prepareHeatmapData({
207
- series: chartSeries[0],
208
- xAxis,
209
- xScale,
210
- yAxis: yAxis[0],
211
- yScale: yScale[0],
212
- });
213
- shapes[index] = (React.createElement(HeatmapSeriesShapes, { key: SERIES_TYPE.Heatmap, dispatcher: dispatcher, preparedData: preparedData, seriesOptions: seriesOptions, htmlLayout: htmlLayout }));
214
- shapesData.splice(index, 0, preparedData);
215
- }
216
- break;
217
- }
218
- case 'funnel': {
219
- const preparedData = await prepareFunnelData({
220
- series: chartSeries,
221
- boundsWidth,
222
- boundsHeight,
223
- });
224
- shapes[index] = (React.createElement(FunnelSeriesShapes, { key: "funnel", dispatcher: dispatcher, preparedData: preparedData, seriesOptions: seriesOptions, htmlLayout: htmlLayout }));
225
- shapesData.splice(index, 0, preparedData);
226
- break;
227
- }
228
- default: {
229
- throw new ChartError({
230
- message: `The display method is not defined for a series with type "${seriesType}"`,
231
- });
232
- }
233
- }
234
- }));
237
+ const { shapes, shapesData } = await getShapes({
238
+ boundsHeight,
239
+ boundsWidth,
240
+ clipPathId,
241
+ clipPathBySeriesType,
242
+ dispatcher,
243
+ htmlLayout,
244
+ isOutsideBounds,
245
+ isRangeSlider,
246
+ series,
247
+ seriesOptions,
248
+ split,
249
+ xAxis,
250
+ xScale,
251
+ yAxis,
252
+ yScale,
253
+ zoomState,
254
+ });
235
255
  if (countedRef.current === currentRun) {
236
256
  shapesReadyRef.current = true;
237
257
  setShapesElements(shapes);
@@ -145,7 +145,6 @@ export function preparePieData(args) {
145
145
  .innerRadius((d) => d.data.radius + distance + connectorPadding)
146
146
  .outerRadius((d) => d.data.radius + distance + connectorPadding);
147
147
  let shouldStopLabelPlacement = false;
148
- // eslint-disable-next-line complexity
149
148
  series.forEach((d, index) => {
150
149
  var _a, _b;
151
150
  const prevLabel = labels[labels.length - 1];
@@ -1,5 +1,5 @@
1
1
  import type { ChartSplit } from '../../types';
2
- import type { PreparedSplit } from './types';
2
+ import type { PreparedPlot } from './types';
3
3
  type UseSplitArgs = {
4
4
  split?: ChartSplit;
5
5
  boundsHeight: number;
@@ -10,5 +10,8 @@ export declare function getPlotHeight(args: {
10
10
  boundsHeight: number;
11
11
  gap: number;
12
12
  }): number;
13
- export declare const useSplit: (args: UseSplitArgs) => PreparedSplit;
13
+ export declare function getSplit(args: UseSplitArgs): {
14
+ plots: PreparedPlot[];
15
+ gap: number;
16
+ };
14
17
  export {};
@@ -1,4 +1,3 @@
1
- import React from 'react';
2
1
  import get from 'lodash/get';
3
2
  import isEmpty from 'lodash/isEmpty';
4
3
  import { calculateNumericProperty, getHorizontalSvgTextHeight } from '../../utils';
@@ -32,33 +31,31 @@ export function getPlotHeight(args) {
32
31
  }
33
32
  return boundsHeight;
34
33
  }
35
- export const useSplit = (args) => {
34
+ export function getSplit(args) {
35
+ var _a, _b;
36
36
  const { split, boundsHeight, chartWidth } = args;
37
- return React.useMemo(() => {
38
- var _a, _b;
39
- const splitGap = (_a = calculateNumericProperty({ value: split === null || split === void 0 ? void 0 : split.gap, base: boundsHeight })) !== null && _a !== void 0 ? _a : 0;
40
- const plotHeight = getPlotHeight({ split: split, boundsHeight, gap: splitGap });
41
- const plots = (_b = split === null || split === void 0 ? void 0 : split.plots) !== null && _b !== void 0 ? _b : [];
42
- if (isEmpty(plots)) {
43
- plots.push({});
44
- }
45
- return {
46
- plots: plots.map((p, index) => {
47
- const title = preparePlotTitle({
48
- title: p.title,
49
- plotIndex: index,
50
- gap: splitGap,
51
- plotHeight,
52
- chartWidth,
53
- });
54
- const top = index * (plotHeight + splitGap);
55
- return {
56
- top: top + title.height,
57
- height: plotHeight - title.height,
58
- title,
59
- };
60
- }),
61
- gap: splitGap,
62
- };
63
- }, [split, boundsHeight, chartWidth]);
64
- };
37
+ const splitGap = (_a = calculateNumericProperty({ value: split === null || split === void 0 ? void 0 : split.gap, base: boundsHeight })) !== null && _a !== void 0 ? _a : 0;
38
+ const plotHeight = getPlotHeight({ split: split, boundsHeight, gap: splitGap });
39
+ const plots = (_b = split === null || split === void 0 ? void 0 : split.plots) !== null && _b !== void 0 ? _b : [];
40
+ if (isEmpty(plots)) {
41
+ plots.push({});
42
+ }
43
+ return {
44
+ plots: plots.map((p, index) => {
45
+ const title = preparePlotTitle({
46
+ title: p.title,
47
+ plotIndex: index,
48
+ gap: splitGap,
49
+ plotHeight,
50
+ chartWidth,
51
+ });
52
+ const top = index * (plotHeight + splitGap);
53
+ return {
54
+ top: top + title.height,
55
+ height: plotHeight - title.height,
56
+ title,
57
+ };
58
+ }),
59
+ gap: splitGap,
60
+ };
61
+ }
@@ -1,6 +1,6 @@
1
1
  import type { Dispatch } from 'd3';
2
2
  import type { AxisPlotBand, AxisPlotLine, PointPosition, TooltipDataChunk } from '../../types';
3
- import type { PreparedTooltip } from '../useChartOptions/types';
3
+ import type { PreparedTooltip } from '../types';
4
4
  type Args = {
5
5
  dispatcher: Dispatch<object>;
6
6
  tooltip: PreparedTooltip;
@@ -1,6 +1,6 @@
1
+ import type { PreparedZoom } from '../types';
1
2
  import type { PreparedXAxis, PreparedYAxis } from '../useAxis/types';
2
3
  import type { ChartScale } from '../useAxisScales/types';
3
- import type { PreparedZoom } from '../useChartOptions/types';
4
4
  import type { PreparedSplit } from '../useSplit/types';
5
5
  import type { ZoomState } from './types';
6
6
  interface UseZoomProps {
@@ -8,7 +8,7 @@ interface UseZoomProps {
8
8
  onUpdate: (zoomState: Partial<ZoomState>) => void;
9
9
  plotContainerHeight: number;
10
10
  plotContainerWidth: number;
11
- preparedSplit: PreparedSplit;
11
+ preparedSplit: PreparedSplit | undefined;
12
12
  preparedZoom: PreparedZoom | null;
13
13
  rangeSliderDomain?: [number, number];
14
14
  xAxis: PreparedXAxis | null;
@@ -10,7 +10,7 @@ export function useZoom(props) {
10
10
  if (!preparedZoom) {
11
11
  return result;
12
12
  }
13
- if (preparedSplit.plots.length > 1) {
13
+ if (preparedSplit && preparedSplit.plots.length > 1) {
14
14
  preparedSplit.plots.forEach((plot) => {
15
15
  result.push({
16
16
  extent: [
@@ -29,7 +29,7 @@ export function useZoom(props) {
29
29
  });
30
30
  }
31
31
  return result;
32
- }, [plotContainerHeight, plotContainerWidth, preparedSplit.plots, preparedZoom]);
32
+ }, [plotContainerHeight, plotContainerWidth, preparedSplit, preparedZoom]);
33
33
  const handleChartBrushEnd = React.useCallback(function (brushInstance, selection) {
34
34
  if (selection && yScale && xAxis && yAxis && xScale && (preparedZoom === null || preparedZoom === void 0 ? void 0 : preparedZoom.type)) {
35
35
  const nextZoomState = selectionToZoomBounds({
@@ -1,4 +1,4 @@
1
1
  export { CustomShapeRenderer, getFormattedValue } from './utils';
2
- export { getDefaultTooltipHeaderFormat } from './hooks/useChartOptions/tooltip';
2
+ export { getDefaultTooltipHeaderFormat } from './utils/chart/tooltip';
3
3
  export * from './components';
4
4
  export * from './types';
package/dist/esm/index.js CHANGED
@@ -1,4 +1,4 @@
1
1
  export { CustomShapeRenderer, getFormattedValue } from './utils';
2
- export { getDefaultTooltipHeaderFormat } from './hooks/useChartOptions/tooltip';
2
+ export { getDefaultTooltipHeaderFormat } from './utils/chart/tooltip';
3
3
  export * from './components';
4
4
  export * from './types';
@@ -36,6 +36,25 @@ export interface ChartData<T = MeaningfulAny> {
36
36
  * General options for the chart.
37
37
  */
38
38
  chart?: ChartOptions;
39
+ /**
40
+ * The color list of palette.
41
+ * If no color is set in series, the colors would be adopted sequentially and circularly from this list as the colors of series.
42
+ * @default ['#4DA2F1', '#FF3D64', '#8AD554', '#FFC636', '#FFB9DD', '#84D1EE', '#FF91A1', '#54A520', '#DB9100', '#BA74B3', '#1F68A9', '#ED65A9', '#0FA08D', '#FF7E00', '#E8B0A4', '#52A6C5', '#BE2443', '#70C1AF', '#FFB46C', '#DCA3D7']
43
+ */
44
+ colors?: string[];
45
+ /**
46
+ * Default state applied on first render.
47
+ */
48
+ defaultState?: {
49
+ /**
50
+ * Position within the plot area to trigger hover on first render.
51
+ * Values can be absolute pixels (`number` or `"100px"`) or percentages (`"50%"`).
52
+ */
53
+ hoveredPosition?: {
54
+ x: number | string;
55
+ y: number | string;
56
+ };
57
+ };
39
58
  /**
40
59
  * The legend displays a labeled box for each data element in the chart.
41
60
  * It shows a distinctive symbol paired with a name for every series.
@@ -54,6 +73,11 @@ export interface ChartData<T = MeaningfulAny> {
54
73
  */
55
74
  options?: ChartSeriesOptions;
56
75
  };
76
+ /**
77
+ * Setting for displaying charts on different plots.
78
+ * It can be used to visualize related information on multiple charts.
79
+ */
80
+ split?: ChartSplit;
57
81
  /**
58
82
  * The main title of the chart.
59
83
  */
@@ -70,15 +94,4 @@ export interface ChartData<T = MeaningfulAny> {
70
94
  * Options for the the Y axis or multiple Y axes.
71
95
  */
72
96
  yAxis?: ChartYAxis[];
73
- /**
74
- * Setting for displaying charts on different plots.
75
- * It can be used to visualize related information on multiple charts.
76
- */
77
- split?: ChartSplit;
78
- /**
79
- * The color list of palette.
80
- * If no color is set in series, the colors would be adopted sequentially and circularly from this list as the colors of series.
81
- * @default ['#4DA2F1', '#FF3D64', '#8AD554', '#FFC636', '#FFB9DD', '#84D1EE', '#FF91A1', '#54A520', '#DB9100', '#BA74B3', '#1F68A9', '#ED65A9', '#0FA08D', '#FF7E00', '#E8B0A4', '#52A6C5', '#BE2443', '#70C1AF', '#FFB46C', '#DCA3D7']
82
- */
83
- colors?: string[];
84
97
  }
@@ -17,7 +17,7 @@ export declare function getAxisItems({ scale, count, maxCount, }: {
17
17
  scale: ChartScale | AxisScale<AxisDomain>;
18
18
  count?: number;
19
19
  maxCount?: number;
20
- }): number[] | string[] | Date[];
20
+ }): string[] | number[] | Date[];
21
21
  export declare function getAxisHeight(args: {
22
22
  split: PreparedSplit;
23
23
  boundsHeight: number;
@@ -27,7 +27,7 @@ interface GetBandsPositionArgs {
27
27
  axisScale: AxisScale<AxisDomain>;
28
28
  axis: AxisDirection;
29
29
  }
30
- export declare const getAxisPlotsPosition: (axis: PreparedAxis, split: PreparedSplit, width?: number) => number[];
30
+ export declare const getAxisPlotsPosition: (axis: PreparedAxis, split: PreparedSplit | undefined, width?: number) => number[];
31
31
  export declare function getBandsPosition(args: GetBandsPositionArgs): {
32
32
  from: number;
33
33
  to: number;
@@ -50,7 +50,7 @@ export function getAxisHeight(args) {
50
50
  }
51
51
  export const getAxisPlotsPosition = (axis, split, width = 0) => {
52
52
  var _a;
53
- const top = ((_a = split.plots[axis.plotIndex]) === null || _a === void 0 ? void 0 : _a.top) || 0;
53
+ const top = ((_a = split === null || split === void 0 ? void 0 : split.plots[axis.plotIndex]) === null || _a === void 0 ? void 0 : _a.top) || 0;
54
54
  if (axis.position === 'left') {
55
55
  return [0, top];
56
56
  }