@gravity-ui/charts 1.38.6 → 1.38.7
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.
- package/dist/cjs/components/AxisX/prepare-axis-data.d.ts +1 -1
- package/dist/cjs/components/AxisX/prepare-axis-data.js +10 -9
- package/dist/cjs/components/AxisY/prepare-axis-data.d.ts +1 -1
- package/dist/cjs/components/AxisY/prepare-axis-data.js +2 -2
- package/dist/cjs/components/ChartInner/index.js +8 -3
- package/dist/cjs/components/ChartInner/useChartInnerProps.d.ts +18 -19
- package/dist/cjs/components/ChartInner/useChartInnerProps.js +232 -138
- package/dist/cjs/components/ChartInner/useChartInnerState.js +2 -1
- package/dist/cjs/components/Legend/index.d.ts +1 -1
- package/dist/cjs/components/Legend/index.js +1 -1
- package/dist/cjs/hooks/useAxis/index.d.ts +40 -5
- package/dist/cjs/hooks/useAxis/index.js +54 -39
- package/dist/cjs/hooks/useAxis/types.d.ts +0 -2
- package/dist/cjs/hooks/useAxisScales/index.d.ts +4 -0
- package/dist/cjs/hooks/useAxisScales/index.js +1 -1
- package/dist/cjs/hooks/useChartDimensions/index.d.ts +1 -1
- package/dist/cjs/hooks/useChartDimensions/index.js +14 -29
- package/dist/cjs/hooks/useCrosshair/index.d.ts +1 -1
- package/dist/cjs/hooks/useNormalizedOriginalData/index.d.ts +29 -34
- package/dist/cjs/hooks/useNormalizedOriginalData/index.js +19 -30
- package/dist/cjs/hooks/useSeries/index.d.ts +10 -14
- package/dist/cjs/hooks/useSeries/index.js +8 -80
- package/dist/cjs/hooks/useShapes/index.d.ts +4 -0
- package/dist/cjs/hooks/useShapes/index.js +194 -189
- package/dist/cjs/hooks/useSplit/index.d.ts +5 -2
- package/dist/cjs/hooks/useSplit/index.js +27 -30
- package/dist/cjs/hooks/useYAxisLabelWidth/index.d.ts +39 -6
- package/dist/cjs/hooks/useYAxisLabelWidth/index.js +30 -43
- package/dist/cjs/hooks/useZoom/index.d.ts +1 -1
- package/dist/cjs/hooks/useZoom/index.js +2 -2
- package/dist/cjs/utils/chart/axis/common.d.ts +1 -1
- package/dist/cjs/utils/chart/axis/common.js +1 -1
- package/dist/esm/components/AxisX/prepare-axis-data.d.ts +1 -1
- package/dist/esm/components/AxisX/prepare-axis-data.js +10 -9
- package/dist/esm/components/AxisY/prepare-axis-data.d.ts +1 -1
- package/dist/esm/components/AxisY/prepare-axis-data.js +2 -2
- package/dist/esm/components/ChartInner/index.js +8 -3
- package/dist/esm/components/ChartInner/useChartInnerProps.d.ts +18 -19
- package/dist/esm/components/ChartInner/useChartInnerProps.js +232 -138
- package/dist/esm/components/ChartInner/useChartInnerState.js +2 -1
- package/dist/esm/components/Legend/index.d.ts +1 -1
- package/dist/esm/components/Legend/index.js +1 -1
- package/dist/esm/hooks/useAxis/index.d.ts +40 -5
- package/dist/esm/hooks/useAxis/index.js +54 -39
- package/dist/esm/hooks/useAxis/types.d.ts +0 -2
- package/dist/esm/hooks/useAxisScales/index.d.ts +4 -0
- package/dist/esm/hooks/useAxisScales/index.js +1 -1
- package/dist/esm/hooks/useChartDimensions/index.d.ts +1 -1
- package/dist/esm/hooks/useChartDimensions/index.js +14 -29
- package/dist/esm/hooks/useCrosshair/index.d.ts +1 -1
- package/dist/esm/hooks/useNormalizedOriginalData/index.d.ts +29 -34
- package/dist/esm/hooks/useNormalizedOriginalData/index.js +19 -30
- package/dist/esm/hooks/useSeries/index.d.ts +10 -14
- package/dist/esm/hooks/useSeries/index.js +8 -80
- package/dist/esm/hooks/useShapes/index.d.ts +4 -0
- package/dist/esm/hooks/useShapes/index.js +194 -189
- package/dist/esm/hooks/useSplit/index.d.ts +5 -2
- package/dist/esm/hooks/useSplit/index.js +27 -30
- package/dist/esm/hooks/useYAxisLabelWidth/index.d.ts +39 -6
- package/dist/esm/hooks/useYAxisLabelWidth/index.js +30 -43
- package/dist/esm/hooks/useZoom/index.d.ts +1 -1
- package/dist/esm/hooks/useZoom/index.js +2 -2
- package/dist/esm/utils/chart/axis/common.d.ts +1 -1
- package/dist/esm/utils/chart/axis/common.js +1 -1
- package/package.json +1 -1
- package/dist/cjs/components/ChartInner/useLegend.d.ts +0 -14
- package/dist/cjs/components/ChartInner/useLegend.js +0 -34
- package/dist/esm/components/ChartInner/useLegend.d.ts +0 -14
- package/dist/esm/components/ChartInner/useLegend.js +0 -34
|
@@ -30,6 +30,199 @@ 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(
|
|
40
|
+
// eslint-disable-next-line complexity
|
|
41
|
+
Array.from(groupedSeries).map(async (item, index) => {
|
|
42
|
+
const [seriesType, chartSeries] = item;
|
|
43
|
+
switch (seriesType) {
|
|
44
|
+
case SERIES_TYPE.BarX: {
|
|
45
|
+
if (xAxis && xScale && (yScale === null || yScale === void 0 ? void 0 : yScale.length)) {
|
|
46
|
+
const preparedData = await prepareBarXData({
|
|
47
|
+
series: chartSeries,
|
|
48
|
+
seriesOptions,
|
|
49
|
+
xAxis,
|
|
50
|
+
xScale,
|
|
51
|
+
yAxis,
|
|
52
|
+
yScale,
|
|
53
|
+
boundsHeight,
|
|
54
|
+
split,
|
|
55
|
+
isRangeSlider,
|
|
56
|
+
});
|
|
57
|
+
shapes[index] = (React.createElement(BarXSeriesShapes, { key: SERIES_TYPE.BarX, dispatcher: dispatcher, seriesOptions: seriesOptions, preparedData: preparedData, htmlLayout: htmlLayout, clipPathId: clipPathId }));
|
|
58
|
+
shapesData.splice(index, 0, ...preparedData);
|
|
59
|
+
}
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
case SERIES_TYPE.BarY: {
|
|
63
|
+
if (xAxis && xScale && (yScale === null || yScale === void 0 ? void 0 : yScale.length)) {
|
|
64
|
+
const preparedData = await prepareBarYData({
|
|
65
|
+
boundsHeight,
|
|
66
|
+
boundsWidth,
|
|
67
|
+
series: chartSeries,
|
|
68
|
+
seriesOptions,
|
|
69
|
+
xAxis,
|
|
70
|
+
xScale,
|
|
71
|
+
yAxis,
|
|
72
|
+
yScale,
|
|
73
|
+
});
|
|
74
|
+
shapes[index] = (React.createElement(BarYSeriesShapes, { key: SERIES_TYPE.BarY, dispatcher: dispatcher, seriesOptions: seriesOptions, preparedData: preparedData, htmlLayout: htmlLayout, clipPathId: clipPathId }));
|
|
75
|
+
shapesData.splice(index, 0, ...preparedData.shapes);
|
|
76
|
+
}
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
case SERIES_TYPE.Waterfall: {
|
|
80
|
+
if (xAxis && xScale && (yScale === null || yScale === void 0 ? void 0 : yScale.length)) {
|
|
81
|
+
const preparedData = await prepareWaterfallData({
|
|
82
|
+
series: chartSeries,
|
|
83
|
+
seriesOptions,
|
|
84
|
+
xAxis,
|
|
85
|
+
xScale,
|
|
86
|
+
yAxis,
|
|
87
|
+
yScale,
|
|
88
|
+
});
|
|
89
|
+
shapes[index] = (React.createElement(WaterfallSeriesShapes, { key: SERIES_TYPE.Waterfall, dispatcher: dispatcher, seriesOptions: seriesOptions, preparedData: preparedData, htmlLayout: htmlLayout, clipPathId: clipPathId }));
|
|
90
|
+
shapesData.splice(index, 0, ...preparedData);
|
|
91
|
+
}
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
case SERIES_TYPE.Line: {
|
|
95
|
+
if (xAxis && xScale && (yScale === null || yScale === void 0 ? void 0 : yScale.length)) {
|
|
96
|
+
const preparedData = await prepareLineData({
|
|
97
|
+
series: chartSeries,
|
|
98
|
+
xAxis,
|
|
99
|
+
xScale,
|
|
100
|
+
yAxis,
|
|
101
|
+
yScale,
|
|
102
|
+
split,
|
|
103
|
+
isOutsideBounds,
|
|
104
|
+
isRangeSlider,
|
|
105
|
+
});
|
|
106
|
+
const resultClipPathId = getSeriesClipPathId({
|
|
107
|
+
clipPathId,
|
|
108
|
+
yAxis,
|
|
109
|
+
zoomState,
|
|
110
|
+
});
|
|
111
|
+
shapes[index] = (React.createElement(LineSeriesShapes, { key: SERIES_TYPE.Line, dispatcher: dispatcher, seriesOptions: seriesOptions, preparedData: preparedData, htmlLayout: htmlLayout, clipPathId: resultClipPathId }));
|
|
112
|
+
shapesData.splice(index, 0, ...preparedData);
|
|
113
|
+
}
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
case SERIES_TYPE.Area: {
|
|
117
|
+
if (xAxis && xScale && (yScale === null || yScale === void 0 ? void 0 : yScale.length)) {
|
|
118
|
+
const preparedData = await prepareAreaData({
|
|
119
|
+
series: chartSeries,
|
|
120
|
+
xAxis,
|
|
121
|
+
xScale,
|
|
122
|
+
yAxis,
|
|
123
|
+
yScale,
|
|
124
|
+
boundsHeight,
|
|
125
|
+
split,
|
|
126
|
+
isOutsideBounds,
|
|
127
|
+
isRangeSlider,
|
|
128
|
+
});
|
|
129
|
+
shapes[index] = (React.createElement(AreaSeriesShapes, { key: SERIES_TYPE.Area, dispatcher: dispatcher, seriesOptions: seriesOptions, preparedData: preparedData, htmlLayout: htmlLayout, clipPathId: clipPathId }));
|
|
130
|
+
shapesData.splice(index, 0, ...preparedData);
|
|
131
|
+
}
|
|
132
|
+
break;
|
|
133
|
+
}
|
|
134
|
+
case SERIES_TYPE.Scatter: {
|
|
135
|
+
if (xAxis && xScale && (yScale === null || yScale === void 0 ? void 0 : yScale.length)) {
|
|
136
|
+
const preparedData = prepareScatterData({
|
|
137
|
+
series: chartSeries,
|
|
138
|
+
xAxis,
|
|
139
|
+
xScale,
|
|
140
|
+
yAxis,
|
|
141
|
+
yScale,
|
|
142
|
+
isOutsideBounds,
|
|
143
|
+
});
|
|
144
|
+
shapes[index] = (React.createElement(ScatterSeriesShape, { key: SERIES_TYPE.Scatter, clipPathId: shouldUseClipPathId(SERIES_TYPE.Scatter, clipPathBySeriesType)
|
|
145
|
+
? clipPathId
|
|
146
|
+
: undefined, dispatcher: dispatcher, preparedData: preparedData, seriesOptions: seriesOptions, htmlLayout: htmlLayout }));
|
|
147
|
+
shapesData.splice(index, 0, ...preparedData);
|
|
148
|
+
}
|
|
149
|
+
break;
|
|
150
|
+
}
|
|
151
|
+
case SERIES_TYPE.Pie: {
|
|
152
|
+
const preparedData = await preparePieData({
|
|
153
|
+
series: chartSeries,
|
|
154
|
+
boundsWidth,
|
|
155
|
+
boundsHeight,
|
|
156
|
+
});
|
|
157
|
+
shapes[index] = (React.createElement(PieSeriesShapes, { key: SERIES_TYPE.Pie, dispatcher: dispatcher, preparedData: preparedData, seriesOptions: seriesOptions, htmlLayout: htmlLayout }));
|
|
158
|
+
shapesData.splice(index, 0, ...preparedData);
|
|
159
|
+
break;
|
|
160
|
+
}
|
|
161
|
+
case SERIES_TYPE.Treemap: {
|
|
162
|
+
const preparedData = await prepareTreemapData({
|
|
163
|
+
// We should have exactly one series with "treemap" type
|
|
164
|
+
// Otherwise data validation should emit an error
|
|
165
|
+
series: chartSeries[0],
|
|
166
|
+
width: boundsWidth,
|
|
167
|
+
height: boundsHeight,
|
|
168
|
+
});
|
|
169
|
+
shapes[index] = (React.createElement(TreemapSeriesShape, { key: SERIES_TYPE.Treemap, dispatcher: dispatcher, preparedData: preparedData, seriesOptions: seriesOptions, htmlLayout: htmlLayout }));
|
|
170
|
+
shapesData.splice(index, 0, preparedData);
|
|
171
|
+
break;
|
|
172
|
+
}
|
|
173
|
+
case SERIES_TYPE.Sankey: {
|
|
174
|
+
const preparedData = prepareSankeyData({
|
|
175
|
+
series: chartSeries[0],
|
|
176
|
+
width: boundsWidth,
|
|
177
|
+
height: boundsHeight,
|
|
178
|
+
});
|
|
179
|
+
shapes[index] = (React.createElement(SankeySeriesShape, { key: SERIES_TYPE.Sankey, dispatcher: dispatcher, preparedData: preparedData, seriesOptions: seriesOptions, htmlLayout: htmlLayout }));
|
|
180
|
+
shapesData.splice(index, 0, preparedData);
|
|
181
|
+
break;
|
|
182
|
+
}
|
|
183
|
+
case SERIES_TYPE.Radar: {
|
|
184
|
+
const preparedData = await prepareRadarData({
|
|
185
|
+
series: chartSeries,
|
|
186
|
+
boundsWidth,
|
|
187
|
+
boundsHeight,
|
|
188
|
+
});
|
|
189
|
+
shapes[index] = (React.createElement(RadarSeriesShapes, { key: SERIES_TYPE.Radar, dispatcher: dispatcher, series: preparedData, seriesOptions: seriesOptions, htmlLayout: htmlLayout }));
|
|
190
|
+
shapesData.splice(index, 0, ...preparedData);
|
|
191
|
+
break;
|
|
192
|
+
}
|
|
193
|
+
case SERIES_TYPE.Heatmap: {
|
|
194
|
+
if (xAxis && xScale && (yScale === null || yScale === void 0 ? void 0 : yScale[0])) {
|
|
195
|
+
const preparedData = await prepareHeatmapData({
|
|
196
|
+
series: chartSeries[0],
|
|
197
|
+
xAxis,
|
|
198
|
+
xScale,
|
|
199
|
+
yAxis: yAxis[0],
|
|
200
|
+
yScale: yScale[0],
|
|
201
|
+
});
|
|
202
|
+
shapes[index] = (React.createElement(HeatmapSeriesShapes, { key: SERIES_TYPE.Heatmap, dispatcher: dispatcher, preparedData: preparedData, seriesOptions: seriesOptions, htmlLayout: htmlLayout }));
|
|
203
|
+
shapesData.splice(index, 0, preparedData);
|
|
204
|
+
}
|
|
205
|
+
break;
|
|
206
|
+
}
|
|
207
|
+
case 'funnel': {
|
|
208
|
+
const preparedData = await prepareFunnelData({
|
|
209
|
+
series: chartSeries,
|
|
210
|
+
boundsWidth,
|
|
211
|
+
boundsHeight,
|
|
212
|
+
});
|
|
213
|
+
shapes[index] = (React.createElement(FunnelSeriesShapes, { key: "funnel", dispatcher: dispatcher, preparedData: preparedData, seriesOptions: seriesOptions, htmlLayout: htmlLayout }));
|
|
214
|
+
shapesData.splice(index, 0, preparedData);
|
|
215
|
+
break;
|
|
216
|
+
}
|
|
217
|
+
default: {
|
|
218
|
+
throw new ChartError({
|
|
219
|
+
message: `The display method is not defined for a series with type "${seriesType}"`,
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}));
|
|
224
|
+
return { shapes, shapesData };
|
|
225
|
+
}
|
|
33
226
|
export const useShapes = (args) => {
|
|
34
227
|
const { boundsWidth, boundsHeight, clipPathId, clipPathBySeriesType, dispatcher, htmlLayout, isOutsideBounds = IS_OUTSIDE_BOUNDS, isRangeSlider, series, seriesOptions, split, xAxis, xScale, yAxis, yScale, zoomState, } = args;
|
|
35
228
|
const [shapesElemens, setShapesElements] = React.useState([]);
|
|
@@ -43,195 +236,7 @@ export const useShapes = (args) => {
|
|
|
43
236
|
}
|
|
44
237
|
(async () => {
|
|
45
238
|
const currentRun = countedRef.current;
|
|
46
|
-
const
|
|
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
|
-
}));
|
|
239
|
+
const { shapes, shapesData } = await getShapes(args);
|
|
235
240
|
if (countedRef.current === currentRun) {
|
|
236
241
|
shapesReadyRef.current = true;
|
|
237
242
|
setShapesElements(shapes);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ChartSplit } from '../../types';
|
|
2
|
-
import type {
|
|
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
|
|
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
|
|
34
|
+
export function getSplit(args) {
|
|
35
|
+
var _a, _b;
|
|
36
36
|
const { split, boundsHeight, chartWidth } = args;
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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,11 +1,44 @@
|
|
|
1
|
-
import type { PreparedYAxis
|
|
1
|
+
import type { PreparedYAxis } from '../useAxis/types';
|
|
2
2
|
import type { ChartScale } from '../useAxisScales/types';
|
|
3
3
|
import type { PreparedSeries } from '../useSeries/types';
|
|
4
|
-
|
|
4
|
+
export declare function recalculateYAxisLabelsWidth(props: {
|
|
5
5
|
seriesData: PreparedSeries[];
|
|
6
|
-
setAxes: SetAxes;
|
|
7
6
|
yAxis: PreparedYAxis[];
|
|
8
7
|
yScale?: (ChartScale | undefined)[];
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
}): Promise<(Omit<import("../..").ChartAxis, "type" | "labels" | "plotLines" | "plotBands"> & {
|
|
9
|
+
type: import("../..").ChartAxisType;
|
|
10
|
+
labels: Omit<import("../..").ChartAxisLabels, "enabled" | "style" | "padding" | "autoRotation"> & Required<Pick<import("../..").ChartAxisLabels, "margin" | "html" | "enabled" | "rotation" | "padding">> & {
|
|
11
|
+
style: import("../..").BaseTextStyle;
|
|
12
|
+
rotation: number;
|
|
13
|
+
height: number;
|
|
14
|
+
width: number;
|
|
15
|
+
lineHeight: number;
|
|
16
|
+
maxWidth: number;
|
|
17
|
+
};
|
|
18
|
+
title: {
|
|
19
|
+
height: number;
|
|
20
|
+
width: number;
|
|
21
|
+
text: string;
|
|
22
|
+
margin: number;
|
|
23
|
+
style: import("../..").BaseTextStyle;
|
|
24
|
+
align: import("../..").ChartAxisTitleAlignment;
|
|
25
|
+
maxRowCount: number;
|
|
26
|
+
rotation: number;
|
|
27
|
+
maxWidth: number;
|
|
28
|
+
html: boolean;
|
|
29
|
+
};
|
|
30
|
+
min?: number;
|
|
31
|
+
grid: {
|
|
32
|
+
enabled: boolean;
|
|
33
|
+
};
|
|
34
|
+
maxPadding: number;
|
|
35
|
+
ticks: {
|
|
36
|
+
pixelInterval?: number;
|
|
37
|
+
};
|
|
38
|
+
tickMarks: import("..").PreparedAxisTickMarks;
|
|
39
|
+
position: "left" | "right" | "top" | "bottom";
|
|
40
|
+
plotIndex: number;
|
|
41
|
+
plotLines: import("..").PreparedAxisPlotLine[];
|
|
42
|
+
plotBands: import("..").PreparedAxisPlotBand[];
|
|
43
|
+
crosshair: Required<import("../..").AxisCrosshair>;
|
|
44
|
+
})[]>;
|
|
@@ -1,48 +1,35 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
1
|
import get from 'lodash/get';
|
|
3
2
|
import { getYAxisLabelMaxWidth } from '../useAxis/y-axis';
|
|
4
|
-
export function
|
|
5
|
-
const { seriesData,
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
if (axis.startOnTick || axis.endOnTick) {
|
|
19
|
-
const axisSeriesData = seriesData.filter((s) => get(s, 'yAxis', 0) === i && s.visible);
|
|
20
|
-
if (axisSeriesData.length === 0) {
|
|
21
|
-
continue;
|
|
22
|
-
}
|
|
23
|
-
const res = await getYAxisLabelMaxWidth({
|
|
24
|
-
axis,
|
|
25
|
-
seriesData: axisSeriesData,
|
|
26
|
-
scale,
|
|
27
|
-
});
|
|
28
|
-
if (res.width > axis.labels.width) {
|
|
29
|
-
axisIndexesToRecalculateMap.set(i, res.width);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
3
|
+
export async function recalculateYAxisLabelsWidth(props) {
|
|
4
|
+
const { seriesData, yAxis, yScale } = props;
|
|
5
|
+
const axisIndexesToRecalculateMap = new Map();
|
|
6
|
+
for (let i = 0; i < yAxis.length; i++) {
|
|
7
|
+
const axis = yAxis[i];
|
|
8
|
+
const scale = yScale === null || yScale === void 0 ? void 0 : yScale[i];
|
|
9
|
+
if (!scale) {
|
|
10
|
+
continue;
|
|
11
|
+
}
|
|
12
|
+
if (axis.startOnTick || axis.endOnTick) {
|
|
13
|
+
const axisSeriesData = seriesData.filter((s) => get(s, 'yAxis', 0) === i && s.visible);
|
|
14
|
+
if (axisSeriesData.length === 0) {
|
|
15
|
+
continue;
|
|
32
16
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
return axis;
|
|
42
|
-
});
|
|
43
|
-
return Object.assign(Object.assign({}, prevState), { yAxis: newYAxis });
|
|
44
|
-
});
|
|
17
|
+
const res = await getYAxisLabelMaxWidth({
|
|
18
|
+
axis,
|
|
19
|
+
seriesData: axisSeriesData,
|
|
20
|
+
scale,
|
|
21
|
+
});
|
|
22
|
+
if (res.width > axis.labels.width) {
|
|
23
|
+
axisIndexesToRecalculateMap.set(i, res.width);
|
|
45
24
|
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return yAxis.map((axis, i) => {
|
|
28
|
+
const width = axisIndexesToRecalculateMap.get(i);
|
|
29
|
+
if (width) {
|
|
30
|
+
const axisWithRecalculatedLabels = Object.assign(Object.assign({}, axis), { labels: Object.assign(Object.assign({}, axis.labels), { width }) });
|
|
31
|
+
return axisWithRecalculatedLabels;
|
|
32
|
+
}
|
|
33
|
+
return axis;
|
|
34
|
+
});
|
|
48
35
|
}
|
|
@@ -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
|
|
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({
|
|
@@ -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
|
}
|