@gravity-ui/charts 1.1.0 → 1.3.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.
- package/dist/cjs/components/Axis/AxisX.js +42 -5
- package/dist/cjs/components/Axis/AxisY.d.ts +1 -1
- package/dist/cjs/components/Axis/AxisY.js +48 -5
- package/dist/cjs/components/ChartInner/index.js +1 -1
- package/dist/cjs/components/ChartInner/styles.css +2 -0
- package/dist/cjs/components/ChartInner/useChartInnerProps.js +3 -3
- package/dist/cjs/components/Legend/index.js +22 -10
- package/dist/cjs/components/Title/index.js +1 -1
- package/dist/cjs/constants/defaults/legend.d.ts +1 -0
- package/dist/cjs/constants/defaults/legend.js +1 -0
- package/dist/cjs/hooks/useChartOptions/types.d.ts +5 -3
- package/dist/cjs/hooks/useChartOptions/x-axis.js +7 -0
- package/dist/cjs/hooks/useChartOptions/y-axis.js +12 -1
- package/dist/cjs/hooks/useSeries/prepare-legend.js +1 -0
- package/dist/cjs/hooks/useShapes/HtmlLayer.js +2 -1
- package/dist/cjs/hooks/useShapes/area/prepare-data.js +1 -0
- package/dist/cjs/hooks/useShapes/bar-x/prepare-data.js +1 -0
- package/dist/cjs/hooks/useShapes/bar-y/prepare-data.js +1 -0
- package/dist/cjs/hooks/useShapes/line/prepare-data.js +1 -0
- package/dist/cjs/hooks/useShapes/pie/index.js +1 -1
- package/dist/cjs/hooks/useShapes/pie/prepare-data.js +11 -6
- package/dist/cjs/hooks/useShapes/radar/prepare-data.js +1 -0
- package/dist/cjs/hooks/useShapes/treemap/index.js +1 -1
- package/dist/cjs/hooks/useShapes/treemap/prepare-data.js +14 -8
- package/dist/cjs/i18n/keysets/en.json +3 -1
- package/dist/cjs/i18n/keysets/ru.json +3 -1
- package/dist/cjs/libs/chart-error/index.d.ts +1 -0
- package/dist/cjs/libs/chart-error/index.js +1 -0
- package/dist/cjs/types/chart/axis.d.ts +30 -7
- package/dist/cjs/types/chart/legend.d.ts +6 -0
- package/dist/cjs/types/chart-ui.d.ts +1 -0
- package/dist/cjs/utils/chart/axis.d.ts +12 -1
- package/dist/cjs/utils/chart/axis.js +35 -0
- package/dist/cjs/utils/chart/index.d.ts +2 -1
- package/dist/cjs/utils/chart/types.d.ts +1 -0
- package/dist/cjs/utils/chart/types.js +1 -0
- package/dist/cjs/validation/index.js +144 -0
- package/dist/esm/components/Axis/AxisX.js +42 -5
- package/dist/esm/components/Axis/AxisY.d.ts +1 -1
- package/dist/esm/components/Axis/AxisY.js +48 -5
- package/dist/esm/components/ChartInner/index.js +1 -1
- package/dist/esm/components/ChartInner/styles.css +2 -0
- package/dist/esm/components/ChartInner/useChartInnerProps.js +3 -3
- package/dist/esm/components/Legend/index.js +22 -10
- package/dist/esm/components/Title/index.js +1 -1
- package/dist/esm/constants/defaults/legend.d.ts +1 -0
- package/dist/esm/constants/defaults/legend.js +1 -0
- package/dist/esm/hooks/useChartOptions/types.d.ts +5 -3
- package/dist/esm/hooks/useChartOptions/x-axis.js +7 -0
- package/dist/esm/hooks/useChartOptions/y-axis.js +12 -1
- package/dist/esm/hooks/useSeries/prepare-legend.js +1 -0
- package/dist/esm/hooks/useShapes/HtmlLayer.js +2 -1
- package/dist/esm/hooks/useShapes/area/prepare-data.js +1 -0
- package/dist/esm/hooks/useShapes/bar-x/prepare-data.js +1 -0
- package/dist/esm/hooks/useShapes/bar-y/prepare-data.js +1 -0
- package/dist/esm/hooks/useShapes/line/prepare-data.js +1 -0
- package/dist/esm/hooks/useShapes/pie/index.js +1 -1
- package/dist/esm/hooks/useShapes/pie/prepare-data.js +11 -6
- package/dist/esm/hooks/useShapes/radar/prepare-data.js +1 -0
- package/dist/esm/hooks/useShapes/treemap/index.js +1 -1
- package/dist/esm/hooks/useShapes/treemap/prepare-data.js +14 -8
- package/dist/esm/i18n/keysets/en.json +3 -1
- package/dist/esm/i18n/keysets/ru.json +3 -1
- package/dist/esm/libs/chart-error/index.d.ts +1 -0
- package/dist/esm/libs/chart-error/index.js +1 -0
- package/dist/esm/types/chart/axis.d.ts +30 -7
- package/dist/esm/types/chart/legend.d.ts +6 -0
- package/dist/esm/types/chart-ui.d.ts +1 -0
- package/dist/esm/utils/chart/axis.d.ts +12 -1
- package/dist/esm/utils/chart/axis.js +35 -0
- package/dist/esm/utils/chart/index.d.ts +2 -1
- package/dist/esm/utils/chart/types.d.ts +1 -0
- package/dist/esm/utils/chart/types.js +1 -0
- package/dist/esm/validation/index.js +144 -0
- package/package.json +1 -1
|
@@ -95,6 +95,148 @@ const validateXYSeries = (args) => {
|
|
|
95
95
|
}
|
|
96
96
|
});
|
|
97
97
|
};
|
|
98
|
+
const validateAxisPlotValues = (args) => {
|
|
99
|
+
const { series, xAxis, yAxis = [] } = args;
|
|
100
|
+
const yAxisIndex = get(series, 'yAxis', 0);
|
|
101
|
+
const seriesYAxis = yAxis[yAxisIndex];
|
|
102
|
+
if (yAxisIndex !== 0 && typeof seriesYAxis === 'undefined') {
|
|
103
|
+
throw new ChartError({
|
|
104
|
+
code: CHART_ERROR_CODE.INVALID_DATA,
|
|
105
|
+
message: i18n('error', 'label_invalid-y-axis-index', {
|
|
106
|
+
index: yAxisIndex,
|
|
107
|
+
}),
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
const xPlotBands = get(xAxis, 'plotBands', []);
|
|
111
|
+
const yPlotBands = get(yAxis, 'plotBands', []);
|
|
112
|
+
if (!xPlotBands.length && !yPlotBands.length) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
const xType = get(xAxis, 'type', DEFAULT_AXIS_TYPE);
|
|
116
|
+
const yType = get(seriesYAxis, 'type', DEFAULT_AXIS_TYPE);
|
|
117
|
+
xPlotBands.forEach(({ from = 0, to = 0 }) => {
|
|
118
|
+
const fromNotEqualTo = typeof to !== typeof from;
|
|
119
|
+
if (fromNotEqualTo) {
|
|
120
|
+
throw new ChartError({
|
|
121
|
+
code: CHART_ERROR_CODE.INVALID_OPTION_TYPE,
|
|
122
|
+
message: i18n('error', 'label_axis-plot-band-options-not-equal', {
|
|
123
|
+
axis: 'x',
|
|
124
|
+
option: 'from',
|
|
125
|
+
}),
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
switch (xType) {
|
|
129
|
+
case 'category': {
|
|
130
|
+
const invalidFrom = typeof from !== 'string' && typeof from !== 'number';
|
|
131
|
+
const invalidTo = typeof to !== 'string' && typeof to !== 'number';
|
|
132
|
+
if (invalidFrom) {
|
|
133
|
+
throw new ChartError({
|
|
134
|
+
code: CHART_ERROR_CODE.INVALID_OPTION_TYPE,
|
|
135
|
+
message: i18n('error', 'label_invalid-axis-plot-band-option', {
|
|
136
|
+
axis: 'x',
|
|
137
|
+
option: 'from',
|
|
138
|
+
}),
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
if (invalidTo) {
|
|
142
|
+
throw new ChartError({
|
|
143
|
+
code: CHART_ERROR_CODE.INVALID_OPTION_TYPE,
|
|
144
|
+
message: i18n('error', 'label_invalid-axis-plot-band-option', {
|
|
145
|
+
axis: 'x',
|
|
146
|
+
option: 'to',
|
|
147
|
+
}),
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
break;
|
|
151
|
+
}
|
|
152
|
+
case 'linear':
|
|
153
|
+
case 'datetime': {
|
|
154
|
+
const invalidFrom = typeof from !== 'number';
|
|
155
|
+
const invalidTo = typeof to !== 'number';
|
|
156
|
+
if (invalidFrom) {
|
|
157
|
+
throw new ChartError({
|
|
158
|
+
code: CHART_ERROR_CODE.INVALID_OPTION_TYPE,
|
|
159
|
+
message: i18n('error', 'label_invalid-axis-plot-band-option', {
|
|
160
|
+
axis: 'x',
|
|
161
|
+
option: 'from',
|
|
162
|
+
}),
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
if (invalidTo) {
|
|
166
|
+
throw new ChartError({
|
|
167
|
+
code: CHART_ERROR_CODE.INVALID_OPTION_TYPE,
|
|
168
|
+
message: i18n('error', 'label_invalid-axis-plot-band-option', {
|
|
169
|
+
axis: 'x',
|
|
170
|
+
option: 'to',
|
|
171
|
+
}),
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
break;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
yPlotBands.forEach(({ from = 0, to = 0 }) => {
|
|
179
|
+
const fromNotEqualTo = typeof to !== typeof from;
|
|
180
|
+
if (fromNotEqualTo) {
|
|
181
|
+
throw new ChartError({
|
|
182
|
+
code: CHART_ERROR_CODE.INVALID_OPTION_TYPE,
|
|
183
|
+
message: i18n('error', 'label_axis-plot-band-options-not-equal', {
|
|
184
|
+
axis: 'x',
|
|
185
|
+
option: 'from',
|
|
186
|
+
}),
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
switch (yType) {
|
|
190
|
+
case 'category': {
|
|
191
|
+
const invalidFrom = typeof from !== 'string' && typeof from !== 'number';
|
|
192
|
+
const invalidTo = typeof to !== 'string' && typeof to !== 'number';
|
|
193
|
+
if (invalidFrom) {
|
|
194
|
+
throw new ChartError({
|
|
195
|
+
code: CHART_ERROR_CODE.INVALID_OPTION_TYPE,
|
|
196
|
+
message: i18n('error', 'label_invalid-axis-plot-band-option', {
|
|
197
|
+
axis: 'y',
|
|
198
|
+
option: 'from',
|
|
199
|
+
}),
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
if (invalidTo) {
|
|
203
|
+
throw new ChartError({
|
|
204
|
+
code: CHART_ERROR_CODE.INVALID_OPTION_TYPE,
|
|
205
|
+
message: i18n('error', 'label_invalid-axis-plot-band-option', {
|
|
206
|
+
axis: 'y',
|
|
207
|
+
option: 'to',
|
|
208
|
+
}),
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
break;
|
|
212
|
+
}
|
|
213
|
+
case 'linear':
|
|
214
|
+
case 'datetime': {
|
|
215
|
+
const invalidFrom = typeof from !== 'number';
|
|
216
|
+
const invalidTo = typeof to !== 'number';
|
|
217
|
+
if (invalidFrom) {
|
|
218
|
+
throw new ChartError({
|
|
219
|
+
code: CHART_ERROR_CODE.INVALID_OPTION_TYPE,
|
|
220
|
+
message: i18n('error', 'label_invalid-axis-plot-band-option', {
|
|
221
|
+
axis: 'y',
|
|
222
|
+
option: 'from',
|
|
223
|
+
}),
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
if (invalidTo) {
|
|
227
|
+
throw new ChartError({
|
|
228
|
+
code: CHART_ERROR_CODE.INVALID_OPTION_TYPE,
|
|
229
|
+
message: i18n('error', 'label_invalid-axis-plot-band-option', {
|
|
230
|
+
axis: 'y',
|
|
231
|
+
option: 'to',
|
|
232
|
+
}),
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
break;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
};
|
|
98
240
|
const validatePieSeries = ({ series }) => {
|
|
99
241
|
series.data.forEach(({ value }) => {
|
|
100
242
|
if (typeof value !== 'number') {
|
|
@@ -163,12 +305,14 @@ const validateSeries = (args) => {
|
|
|
163
305
|
case 'area':
|
|
164
306
|
case 'bar-y':
|
|
165
307
|
case 'bar-x': {
|
|
308
|
+
validateAxisPlotValues({ series, xAxis, yAxis });
|
|
166
309
|
validateXYSeries({ series, xAxis, yAxis });
|
|
167
310
|
validateStacking({ series });
|
|
168
311
|
break;
|
|
169
312
|
}
|
|
170
313
|
case 'line':
|
|
171
314
|
case 'scatter': {
|
|
315
|
+
validateAxisPlotValues({ series, xAxis, yAxis });
|
|
172
316
|
validateXYSeries({ series, xAxis, yAxis });
|
|
173
317
|
break;
|
|
174
318
|
}
|