@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.
Files changed (75) hide show
  1. package/dist/cjs/components/Axis/AxisX.js +42 -5
  2. package/dist/cjs/components/Axis/AxisY.d.ts +1 -1
  3. package/dist/cjs/components/Axis/AxisY.js +48 -5
  4. package/dist/cjs/components/ChartInner/index.js +1 -1
  5. package/dist/cjs/components/ChartInner/styles.css +2 -0
  6. package/dist/cjs/components/ChartInner/useChartInnerProps.js +3 -3
  7. package/dist/cjs/components/Legend/index.js +22 -10
  8. package/dist/cjs/components/Title/index.js +1 -1
  9. package/dist/cjs/constants/defaults/legend.d.ts +1 -0
  10. package/dist/cjs/constants/defaults/legend.js +1 -0
  11. package/dist/cjs/hooks/useChartOptions/types.d.ts +5 -3
  12. package/dist/cjs/hooks/useChartOptions/x-axis.js +7 -0
  13. package/dist/cjs/hooks/useChartOptions/y-axis.js +12 -1
  14. package/dist/cjs/hooks/useSeries/prepare-legend.js +1 -0
  15. package/dist/cjs/hooks/useShapes/HtmlLayer.js +2 -1
  16. package/dist/cjs/hooks/useShapes/area/prepare-data.js +1 -0
  17. package/dist/cjs/hooks/useShapes/bar-x/prepare-data.js +1 -0
  18. package/dist/cjs/hooks/useShapes/bar-y/prepare-data.js +1 -0
  19. package/dist/cjs/hooks/useShapes/line/prepare-data.js +1 -0
  20. package/dist/cjs/hooks/useShapes/pie/index.js +1 -1
  21. package/dist/cjs/hooks/useShapes/pie/prepare-data.js +11 -6
  22. package/dist/cjs/hooks/useShapes/radar/prepare-data.js +1 -0
  23. package/dist/cjs/hooks/useShapes/treemap/index.js +1 -1
  24. package/dist/cjs/hooks/useShapes/treemap/prepare-data.js +14 -8
  25. package/dist/cjs/i18n/keysets/en.json +3 -1
  26. package/dist/cjs/i18n/keysets/ru.json +3 -1
  27. package/dist/cjs/libs/chart-error/index.d.ts +1 -0
  28. package/dist/cjs/libs/chart-error/index.js +1 -0
  29. package/dist/cjs/types/chart/axis.d.ts +30 -7
  30. package/dist/cjs/types/chart/legend.d.ts +6 -0
  31. package/dist/cjs/types/chart-ui.d.ts +1 -0
  32. package/dist/cjs/utils/chart/axis.d.ts +12 -1
  33. package/dist/cjs/utils/chart/axis.js +35 -0
  34. package/dist/cjs/utils/chart/index.d.ts +2 -1
  35. package/dist/cjs/utils/chart/types.d.ts +1 -0
  36. package/dist/cjs/utils/chart/types.js +1 -0
  37. package/dist/cjs/validation/index.js +144 -0
  38. package/dist/esm/components/Axis/AxisX.js +42 -5
  39. package/dist/esm/components/Axis/AxisY.d.ts +1 -1
  40. package/dist/esm/components/Axis/AxisY.js +48 -5
  41. package/dist/esm/components/ChartInner/index.js +1 -1
  42. package/dist/esm/components/ChartInner/styles.css +2 -0
  43. package/dist/esm/components/ChartInner/useChartInnerProps.js +3 -3
  44. package/dist/esm/components/Legend/index.js +22 -10
  45. package/dist/esm/components/Title/index.js +1 -1
  46. package/dist/esm/constants/defaults/legend.d.ts +1 -0
  47. package/dist/esm/constants/defaults/legend.js +1 -0
  48. package/dist/esm/hooks/useChartOptions/types.d.ts +5 -3
  49. package/dist/esm/hooks/useChartOptions/x-axis.js +7 -0
  50. package/dist/esm/hooks/useChartOptions/y-axis.js +12 -1
  51. package/dist/esm/hooks/useSeries/prepare-legend.js +1 -0
  52. package/dist/esm/hooks/useShapes/HtmlLayer.js +2 -1
  53. package/dist/esm/hooks/useShapes/area/prepare-data.js +1 -0
  54. package/dist/esm/hooks/useShapes/bar-x/prepare-data.js +1 -0
  55. package/dist/esm/hooks/useShapes/bar-y/prepare-data.js +1 -0
  56. package/dist/esm/hooks/useShapes/line/prepare-data.js +1 -0
  57. package/dist/esm/hooks/useShapes/pie/index.js +1 -1
  58. package/dist/esm/hooks/useShapes/pie/prepare-data.js +11 -6
  59. package/dist/esm/hooks/useShapes/radar/prepare-data.js +1 -0
  60. package/dist/esm/hooks/useShapes/treemap/index.js +1 -1
  61. package/dist/esm/hooks/useShapes/treemap/prepare-data.js +14 -8
  62. package/dist/esm/i18n/keysets/en.json +3 -1
  63. package/dist/esm/i18n/keysets/ru.json +3 -1
  64. package/dist/esm/libs/chart-error/index.d.ts +1 -0
  65. package/dist/esm/libs/chart-error/index.js +1 -0
  66. package/dist/esm/types/chart/axis.d.ts +30 -7
  67. package/dist/esm/types/chart/legend.d.ts +6 -0
  68. package/dist/esm/types/chart-ui.d.ts +1 -0
  69. package/dist/esm/utils/chart/axis.d.ts +12 -1
  70. package/dist/esm/utils/chart/axis.js +35 -0
  71. package/dist/esm/utils/chart/index.d.ts +2 -1
  72. package/dist/esm/utils/chart/types.d.ts +1 -0
  73. package/dist/esm/utils/chart/types.js +1 -0
  74. package/dist/esm/validation/index.js +144 -0
  75. 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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/charts",
3
- "version": "1.1.0",
3
+ "version": "1.3.0",
4
4
  "description": "React component used to render charts",
5
5
  "license": "MIT",
6
6
  "main": "dist/cjs/index.js",