@gravity-ui/charts 1.18.2 → 1.20.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/AxisY/AxisY.js +7 -5
- package/dist/cjs/components/AxisY/prepare-axis-data.js +8 -5
- package/dist/cjs/components/AxisY/types.d.ts +1 -1
- package/dist/cjs/components/AxisY/utils.js +1 -1
- package/dist/cjs/components/ChartInner/index.js +20 -26
- package/dist/cjs/components/ChartInner/useChartInnerProps.d.ts +2 -2
- package/dist/cjs/components/ChartInner/useChartInnerProps.js +57 -31
- package/dist/cjs/components/ChartInner/utils.d.ts +1 -0
- package/dist/cjs/components/ChartInner/utils.js +21 -0
- package/dist/cjs/components/Tooltip/ChartTooltipContent.d.ts +1 -1
- package/dist/cjs/components/Tooltip/ChartTooltipContent.js +3 -2
- package/dist/cjs/components/Tooltip/DefaultTooltipContent/index.js +1 -0
- package/dist/cjs/components/Tooltip/DefaultTooltipContent/utils.js +2 -1
- package/dist/cjs/constants/chart-types.d.ts +1 -0
- package/dist/cjs/constants/chart-types.js +1 -0
- package/dist/cjs/constants/defaults/series-options.js +8 -0
- package/dist/cjs/hooks/useAxisScales/index.js +47 -8
- package/dist/cjs/hooks/useChartOptions/tooltip.js +1 -1
- package/dist/cjs/hooks/useChartOptions/x-axis.d.ts +1 -1
- package/dist/cjs/hooks/useChartOptions/x-axis.js +15 -4
- package/dist/cjs/hooks/useChartOptions/y-axis.js +15 -7
- package/dist/cjs/hooks/useSeries/prepare-heatmap.d.ts +11 -0
- package/dist/cjs/hooks/useSeries/prepare-heatmap.js +37 -0
- package/dist/cjs/hooks/useSeries/prepareSeries.js +9 -0
- package/dist/cjs/hooks/useSeries/types.d.ts +14 -2
- package/dist/cjs/hooks/useShapes/heatmap/index.d.ts +13 -0
- package/dist/cjs/hooks/useShapes/heatmap/index.js +74 -0
- package/dist/cjs/hooks/useShapes/heatmap/prepare-data.d.ts +13 -0
- package/dist/cjs/hooks/useShapes/heatmap/prepare-data.js +97 -0
- package/dist/cjs/hooks/useShapes/heatmap/types.d.ts +24 -0
- package/dist/cjs/hooks/useShapes/heatmap/types.js +1 -0
- package/dist/cjs/hooks/useShapes/index.d.ts +2 -1
- package/dist/cjs/hooks/useShapes/index.js +15 -0
- package/dist/cjs/hooks/useShapes/styles.css +4 -0
- package/dist/cjs/hooks/useTooltip/index.js +11 -1
- package/dist/cjs/hooks/utils/bar-y.d.ts +0 -5
- package/dist/cjs/hooks/utils/bar-y.js +2 -29
- package/dist/cjs/hooks/utils/get-band-size.d.ts +5 -0
- package/dist/cjs/hooks/utils/get-band-size.js +29 -0
- package/dist/cjs/i18n/keysets/en.json +2 -1
- package/dist/cjs/i18n/keysets/ru.json +2 -1
- package/dist/cjs/types/chart/axis.d.ts +3 -1
- package/dist/cjs/types/chart/heatmap.d.ts +47 -0
- package/dist/cjs/types/chart/heatmap.js +1 -0
- package/dist/cjs/types/chart/series.d.ts +19 -2
- package/dist/cjs/types/chart/tooltip.d.ts +7 -1
- package/dist/cjs/types/index.d.ts +1 -0
- package/dist/cjs/types/index.js +1 -0
- package/dist/cjs/utils/chart/color.js +3 -2
- package/dist/cjs/utils/chart/get-closest-data.js +18 -1
- package/dist/cjs/utils/chart/index.js +10 -13
- package/dist/cjs/utils/chart/series/waterfall.d.ts +1 -1
- package/dist/cjs/utils/chart/series/waterfall.js +3 -3
- package/dist/cjs/validation/validate-axes.js +31 -1
- package/dist/esm/components/AxisY/AxisY.js +7 -5
- package/dist/esm/components/AxisY/prepare-axis-data.js +8 -5
- package/dist/esm/components/AxisY/types.d.ts +1 -1
- package/dist/esm/components/AxisY/utils.js +1 -1
- package/dist/esm/components/ChartInner/index.js +20 -26
- package/dist/esm/components/ChartInner/useChartInnerProps.js +57 -31
- package/dist/esm/components/ChartInner/utils.d.ts +1 -0
- package/dist/esm/components/ChartInner/utils.js +21 -0
- package/dist/esm/components/Tooltip/ChartTooltipContent.d.ts +1 -1
- package/dist/esm/components/Tooltip/ChartTooltipContent.js +3 -2
- package/dist/esm/components/Tooltip/DefaultTooltipContent/index.js +1 -0
- package/dist/esm/components/Tooltip/DefaultTooltipContent/utils.js +2 -1
- package/dist/esm/constants/chart-types.d.ts +1 -0
- package/dist/esm/constants/chart-types.js +1 -0
- package/dist/esm/constants/defaults/series-options.js +8 -0
- package/dist/esm/hooks/useAxisScales/index.js +47 -8
- package/dist/esm/hooks/useChartOptions/tooltip.js +1 -1
- package/dist/esm/hooks/useChartOptions/x-axis.d.ts +1 -1
- package/dist/esm/hooks/useChartOptions/x-axis.js +15 -4
- package/dist/esm/hooks/useChartOptions/y-axis.js +15 -7
- package/dist/esm/hooks/useSeries/prepare-heatmap.d.ts +11 -0
- package/dist/esm/hooks/useSeries/prepare-heatmap.js +37 -0
- package/dist/esm/hooks/useSeries/prepareSeries.js +9 -0
- package/dist/esm/hooks/useSeries/types.d.ts +14 -2
- package/dist/esm/hooks/useShapes/heatmap/index.d.ts +13 -0
- package/dist/esm/hooks/useShapes/heatmap/index.js +74 -0
- package/dist/esm/hooks/useShapes/heatmap/prepare-data.d.ts +13 -0
- package/dist/esm/hooks/useShapes/heatmap/prepare-data.js +97 -0
- package/dist/esm/hooks/useShapes/heatmap/types.d.ts +24 -0
- package/dist/esm/hooks/useShapes/heatmap/types.js +1 -0
- package/dist/esm/hooks/useShapes/index.d.ts +2 -1
- package/dist/esm/hooks/useShapes/index.js +15 -0
- package/dist/esm/hooks/useShapes/styles.css +4 -0
- package/dist/esm/hooks/useTooltip/index.js +11 -1
- package/dist/esm/hooks/utils/bar-y.d.ts +0 -5
- package/dist/esm/hooks/utils/bar-y.js +2 -29
- package/dist/esm/hooks/utils/get-band-size.d.ts +5 -0
- package/dist/esm/hooks/utils/get-band-size.js +29 -0
- package/dist/esm/i18n/keysets/en.json +2 -1
- package/dist/esm/i18n/keysets/ru.json +2 -1
- package/dist/esm/types/chart/axis.d.ts +3 -1
- package/dist/esm/types/chart/heatmap.d.ts +47 -0
- package/dist/esm/types/chart/heatmap.js +1 -0
- package/dist/esm/types/chart/series.d.ts +19 -2
- package/dist/esm/types/chart/tooltip.d.ts +7 -1
- package/dist/esm/types/index.d.ts +1 -0
- package/dist/esm/types/index.js +1 -0
- package/dist/esm/utils/chart/color.js +3 -2
- package/dist/esm/utils/chart/get-closest-data.js +18 -1
- package/dist/esm/utils/chart/index.js +10 -13
- package/dist/esm/utils/chart/series/waterfall.d.ts +1 -1
- package/dist/esm/utils/chart/series/waterfall.js +3 -3
- package/dist/esm/validation/validate-axes.js +31 -1
- package/package.json +1 -1
|
@@ -69,7 +69,9 @@ export interface ChartAxis {
|
|
|
69
69
|
min?: number;
|
|
70
70
|
/** The maximum value of the axis. If undefined the max value is automatically calculate. */
|
|
71
71
|
max?: number;
|
|
72
|
-
/** The grid lines settings.
|
|
72
|
+
/** The grid lines settings.
|
|
73
|
+
* Unavailable for some visualizations, such as a heatmap.
|
|
74
|
+
*/
|
|
73
75
|
grid?: {
|
|
74
76
|
/** Enable or disable the grid lines.
|
|
75
77
|
* @default true
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { SeriesType } from '../../constants';
|
|
2
|
+
import type { MeaningfulAny } from '../misc';
|
|
3
|
+
import type { BaseSeries, BaseSeriesData } from './base';
|
|
4
|
+
import type { ChartLegend, RectLegendSymbolOptions } from './legend';
|
|
5
|
+
export interface HeatmapSeriesData<T = MeaningfulAny> extends BaseSeriesData<T> {
|
|
6
|
+
/**
|
|
7
|
+
* The `x` value of the heatmap cell. Depending on the context, it may represents:
|
|
8
|
+
* - numeric value (for `linear` x axis)
|
|
9
|
+
* - timestamp value (for `datetime` x axis)
|
|
10
|
+
* - x axis category value (for `category` x axis). If the type is a string, then it is a category value itself. If the type is a number, then it is the index of an element in the array of categories described in `xAxis.categories`
|
|
11
|
+
*/
|
|
12
|
+
x?: number;
|
|
13
|
+
/**
|
|
14
|
+
* The `y` value of the heatmap cell. Depending on the context, it may represents:
|
|
15
|
+
* - numeric value (for `linear` y axis)
|
|
16
|
+
* - timestamp value (for `datetime` y axis)
|
|
17
|
+
* - y axis category value (for `category` y axis). If the type is a string, then it is a category value itself. If the type is a number, then it is the index of an element in the array of categories described in `yAxis[0].categories`
|
|
18
|
+
*/
|
|
19
|
+
y?: string | number;
|
|
20
|
+
/** Value of the heatmap cell */
|
|
21
|
+
value?: number;
|
|
22
|
+
/** Data label value of the heatmap cell. If not specified, the value is used. */
|
|
23
|
+
label?: string;
|
|
24
|
+
}
|
|
25
|
+
export interface HeatmapSeries<T = MeaningfulAny> extends BaseSeries {
|
|
26
|
+
type: typeof SeriesType.Heatmap;
|
|
27
|
+
data: HeatmapSeriesData<T>[];
|
|
28
|
+
/** The name of the series (used in legend, tooltip etc) */
|
|
29
|
+
name: string;
|
|
30
|
+
/** The main color of the series (hex, rgba) */
|
|
31
|
+
color?: string;
|
|
32
|
+
dataLabels?: BaseSeries['dataLabels'];
|
|
33
|
+
/** Individual series legend options. Has higher priority than legend options in widget data */
|
|
34
|
+
legend?: ChartLegend & {
|
|
35
|
+
symbol?: RectLegendSymbolOptions;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* The width of the border surrounding each cell.
|
|
39
|
+
*
|
|
40
|
+
* @default 0
|
|
41
|
+
*/
|
|
42
|
+
borderWidth?: number;
|
|
43
|
+
/**
|
|
44
|
+
* The color of the border surrounding each cell.
|
|
45
|
+
*/
|
|
46
|
+
borderColor?: string;
|
|
47
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -5,6 +5,7 @@ import type { AreaSeries, AreaSeriesData } from './area';
|
|
|
5
5
|
import type { BarXSeries, BarXSeriesData } from './bar-x';
|
|
6
6
|
import type { BarYSeries, BarYSeriesData } from './bar-y';
|
|
7
7
|
import type { Halo } from './halo';
|
|
8
|
+
import type { HeatmapSeries, HeatmapSeriesData } from './heatmap';
|
|
8
9
|
import type { LineSeries, LineSeriesData } from './line';
|
|
9
10
|
import type { PointMarkerOptions } from './marker';
|
|
10
11
|
import type { PieSeries, PieSeriesData } from './pie';
|
|
@@ -13,8 +14,8 @@ import type { SankeySeries, SankeySeriesData } from './sankey';
|
|
|
13
14
|
import type { ScatterSeries, ScatterSeriesData } from './scatter';
|
|
14
15
|
import type { TreemapSeries, TreemapSeriesData } from './treemap';
|
|
15
16
|
import type { WaterfallSeries, WaterfallSeriesData } from './waterfall';
|
|
16
|
-
export type ChartSeries<T = MeaningfulAny> = ScatterSeries<T> | PieSeries<T> | BarXSeries<T> | BarYSeries<T> | LineSeries<T> | AreaSeries<T> | TreemapSeries<T> | WaterfallSeries<T> | SankeySeries<T> | RadarSeries<T>;
|
|
17
|
-
export type ChartSeriesData<T = MeaningfulAny> = ScatterSeriesData<T> | PieSeriesData<T> | BarXSeriesData<T> | BarYSeriesData<T> | LineSeriesData<T> | AreaSeriesData<T> | TreemapSeriesData<T> | WaterfallSeriesData<T> | SankeySeriesData<T> | RadarSeriesData<T>;
|
|
17
|
+
export type ChartSeries<T = MeaningfulAny> = ScatterSeries<T> | PieSeries<T> | BarXSeries<T> | BarYSeries<T> | LineSeries<T> | AreaSeries<T> | TreemapSeries<T> | WaterfallSeries<T> | SankeySeries<T> | RadarSeries<T> | HeatmapSeries<T>;
|
|
18
|
+
export type ChartSeriesData<T = MeaningfulAny> = ScatterSeriesData<T> | PieSeriesData<T> | BarXSeriesData<T> | BarYSeriesData<T> | LineSeriesData<T> | AreaSeriesData<T> | TreemapSeriesData<T> | WaterfallSeriesData<T> | SankeySeriesData<T> | RadarSeriesData<T> | HeatmapSeriesData<T>;
|
|
18
19
|
export interface DataLabelRendererData<T = MeaningfulAny> {
|
|
19
20
|
data: ChartSeriesData<T>;
|
|
20
21
|
}
|
|
@@ -268,4 +269,20 @@ export interface ChartSeriesOptions {
|
|
|
268
269
|
/** Options for the point markers of radar series */
|
|
269
270
|
marker?: PointMarkerOptions;
|
|
270
271
|
};
|
|
272
|
+
heatmap?: {
|
|
273
|
+
/** Options for the series states that provide additional styling information to the series. */
|
|
274
|
+
states?: {
|
|
275
|
+
hover?: BasicHoverState;
|
|
276
|
+
};
|
|
277
|
+
/**
|
|
278
|
+
* The width of the border surrounding each cell.
|
|
279
|
+
*
|
|
280
|
+
* @default 0
|
|
281
|
+
*/
|
|
282
|
+
borderWidth?: number;
|
|
283
|
+
/**
|
|
284
|
+
* The color of the border surrounding each cell.
|
|
285
|
+
*/
|
|
286
|
+
borderColor?: string;
|
|
287
|
+
};
|
|
271
288
|
}
|
|
@@ -5,6 +5,7 @@ import type { ChartXAxis, ChartYAxis } from './axis';
|
|
|
5
5
|
import type { BarXSeries, BarXSeriesData } from './bar-x';
|
|
6
6
|
import type { BarYSeries, BarYSeriesData } from './bar-y';
|
|
7
7
|
import type { CustomFormat, ValueFormat } from './base';
|
|
8
|
+
import type { HeatmapSeries, HeatmapSeriesData } from './heatmap';
|
|
8
9
|
import type { LineSeries, LineSeriesData } from './line';
|
|
9
10
|
import type { PieSeries, PieSeriesData } from './pie';
|
|
10
11
|
import type { RadarSeries, RadarSeriesCategory, RadarSeriesData } from './radar';
|
|
@@ -72,7 +73,12 @@ export interface TooltipDataChunkRadar<T = MeaningfulAny> {
|
|
|
72
73
|
category?: RadarSeriesCategory;
|
|
73
74
|
closest: boolean;
|
|
74
75
|
}
|
|
75
|
-
export
|
|
76
|
+
export interface TooltipDataChunkHeatmap<T = MeaningfulAny> {
|
|
77
|
+
data: HeatmapSeriesData<T>;
|
|
78
|
+
series: HeatmapSeries<T>;
|
|
79
|
+
closest: boolean;
|
|
80
|
+
}
|
|
81
|
+
export type TooltipDataChunk<T = MeaningfulAny> = (TooltipDataChunkBarX<T> | TooltipDataChunkBarY<T> | TooltipDataChunkPie<T> | TooltipDataChunkScatter<T> | TooltipDataChunkLine<T> | TooltipDataChunkArea<T> | TooltipDataChunkTreemap<T> | TooltipDataChunkSankey<T> | TooltipDataChunkWaterfall<T> | TooltipDataChunkRadar<T> | TooltipDataChunkHeatmap<T>) & {
|
|
76
82
|
closest?: boolean;
|
|
77
83
|
};
|
|
78
84
|
export interface ChartTooltipRendererArgs<T = MeaningfulAny> {
|
|
@@ -28,6 +28,7 @@ export * from './chart/treemap';
|
|
|
28
28
|
export * from './chart/waterfall';
|
|
29
29
|
export * from './chart/sankey';
|
|
30
30
|
export * from './chart/radar';
|
|
31
|
+
export * from './chart/heatmap';
|
|
31
32
|
export interface ChartData<T = MeaningfulAny> {
|
|
32
33
|
/**
|
|
33
34
|
* General options for the chart.
|
package/dist/esm/types/index.js
CHANGED
|
@@ -3,8 +3,9 @@ export function getDomainForContinuousColorScale(args) {
|
|
|
3
3
|
const { series } = args;
|
|
4
4
|
const values = series.reduce((acc, s) => {
|
|
5
5
|
switch (s.type) {
|
|
6
|
-
case 'pie':
|
|
7
|
-
|
|
6
|
+
case 'pie':
|
|
7
|
+
case 'heatmap': {
|
|
8
|
+
acc.push(...s.data.map((d) => Number(d.value)));
|
|
8
9
|
break;
|
|
9
10
|
}
|
|
10
11
|
case 'bar-y': {
|
|
@@ -49,7 +49,7 @@ export function getClosestPoints(args) {
|
|
|
49
49
|
const groups = groupBy(shapesData, getSeriesType);
|
|
50
50
|
// eslint-disable-next-line complexity
|
|
51
51
|
Object.entries(groups).forEach(([seriesType, list]) => {
|
|
52
|
-
var _a, _b, _c;
|
|
52
|
+
var _a, _b, _c, _d;
|
|
53
53
|
switch (seriesType) {
|
|
54
54
|
case 'bar-x': {
|
|
55
55
|
const points = list.map((d) => ({
|
|
@@ -177,6 +177,23 @@ export function getClosestPoints(args) {
|
|
|
177
177
|
}
|
|
178
178
|
break;
|
|
179
179
|
}
|
|
180
|
+
case 'heatmap': {
|
|
181
|
+
const data = list;
|
|
182
|
+
const closestPoint = (_d = data[0]) === null || _d === void 0 ? void 0 : _d.items.find((cell) => {
|
|
183
|
+
return (pointerX >= cell.x &&
|
|
184
|
+
pointerX <= cell.x + cell.width &&
|
|
185
|
+
pointerY >= cell.y &&
|
|
186
|
+
pointerY <= cell.y + cell.height);
|
|
187
|
+
});
|
|
188
|
+
if (closestPoint) {
|
|
189
|
+
result.push({
|
|
190
|
+
data: closestPoint.data,
|
|
191
|
+
series: data[0].series,
|
|
192
|
+
closest: true,
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
break;
|
|
196
|
+
}
|
|
180
197
|
case 'sankey': {
|
|
181
198
|
const [data] = list;
|
|
182
199
|
const closestLink = data.links.find((d) => {
|
|
@@ -2,7 +2,7 @@ import { group, select } from 'd3';
|
|
|
2
2
|
import get from 'lodash/get';
|
|
3
3
|
import isNil from 'lodash/isNil';
|
|
4
4
|
import sortBy from 'lodash/sortBy';
|
|
5
|
-
import { DEFAULT_AXIS_LABEL_FONT_SIZE } from '../../constants';
|
|
5
|
+
import { DEFAULT_AXIS_LABEL_FONT_SIZE, SeriesType } from '../../constants';
|
|
6
6
|
import { getSeriesStackId } from '../../hooks/useSeries/utils';
|
|
7
7
|
import { getWaterfallPointSubtotal } from './series/waterfall';
|
|
8
8
|
export * from './axis';
|
|
@@ -109,19 +109,16 @@ export function getDefaultMinXAxisValue(series) {
|
|
|
109
109
|
}
|
|
110
110
|
export function getDefaultMinYAxisValue(series) {
|
|
111
111
|
if (series === null || series === void 0 ? void 0 : series.some((s) => CHART_SERIES_WITH_VOLUME_ON_Y_AXIS.includes(s.type))) {
|
|
112
|
+
if (series.some((s) => s.type === SeriesType.Waterfall)) {
|
|
113
|
+
const seriesData = series.map((s) => s.data).flat();
|
|
114
|
+
const minSubTotal = seriesData.reduce((res, d) => Math.min(res, getWaterfallPointSubtotal(d, seriesData) || 0), 0);
|
|
115
|
+
return Math.min(0, minSubTotal);
|
|
116
|
+
}
|
|
112
117
|
return series.reduce((minValue, s) => {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
}
|
|
118
|
-
default: {
|
|
119
|
-
// https://github.com/gravity-ui/charts/issues/160
|
|
120
|
-
// @ts-expect-error
|
|
121
|
-
const minYValue = s.data.reduce((res, d) => Math.min(res, get(d, 'y', 0)), 0);
|
|
122
|
-
return Math.min(minValue, minYValue);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
118
|
+
// https://github.com/gravity-ui/charts/issues/160
|
|
119
|
+
// @ts-expect-error
|
|
120
|
+
const minYValue = s.data.reduce((res, d) => Math.min(res, get(d, 'y', 0)), 0);
|
|
121
|
+
return Math.min(minValue, minYValue);
|
|
125
122
|
}, 0);
|
|
126
123
|
}
|
|
127
124
|
return undefined;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { PreparedWaterfallSeries, PreparedWaterfallSeriesData } from '../../../hooks';
|
|
2
2
|
import type { WaterfallSeriesData } from '../../../types';
|
|
3
3
|
export declare function getWaterfallPointColor(point: WaterfallSeriesData, series: PreparedWaterfallSeries): string;
|
|
4
|
-
export declare function getWaterfallPointSubtotal(point: PreparedWaterfallSeriesData,
|
|
4
|
+
export declare function getWaterfallPointSubtotal(point: PreparedWaterfallSeriesData, data: PreparedWaterfallSeriesData[]): number | null;
|
|
@@ -4,12 +4,12 @@ export function getWaterfallPointColor(point, series) {
|
|
|
4
4
|
}
|
|
5
5
|
return series.color;
|
|
6
6
|
}
|
|
7
|
-
export function getWaterfallPointSubtotal(point,
|
|
8
|
-
const pointIndex =
|
|
7
|
+
export function getWaterfallPointSubtotal(point, data) {
|
|
8
|
+
const pointIndex = data.indexOf(point);
|
|
9
9
|
if (pointIndex === -1) {
|
|
10
10
|
return null;
|
|
11
11
|
}
|
|
12
|
-
return
|
|
12
|
+
return data.reduce((sum, d, index) => {
|
|
13
13
|
if (index <= pointIndex) {
|
|
14
14
|
const value = d.total ? 0 : Number(d.y);
|
|
15
15
|
return sum + value;
|
|
@@ -2,6 +2,22 @@ import { AXIS_TYPE } from '../constants';
|
|
|
2
2
|
import { i18n } from '../i18n';
|
|
3
3
|
import { CHART_ERROR_CODE, ChartError } from '../libs';
|
|
4
4
|
const AVAILABLE_AXIS_TYPES = Object.values(AXIS_TYPE);
|
|
5
|
+
function validateDuplicateCategories({ categories, key, axisIndex, }) {
|
|
6
|
+
const seen = new Set();
|
|
7
|
+
categories.forEach((category) => {
|
|
8
|
+
if (seen.has(category)) {
|
|
9
|
+
throw new ChartError({
|
|
10
|
+
code: CHART_ERROR_CODE.INVALID_DATA,
|
|
11
|
+
message: i18n('error', 'label_duplicate-axis-categories', {
|
|
12
|
+
key,
|
|
13
|
+
axisIndex,
|
|
14
|
+
duplicate: category,
|
|
15
|
+
}),
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
seen.add(category);
|
|
19
|
+
});
|
|
20
|
+
}
|
|
5
21
|
function validateAxisType({ axis, key }) {
|
|
6
22
|
if (axis.type && !AVAILABLE_AXIS_TYPES.includes(axis.type)) {
|
|
7
23
|
throw new ChartError({
|
|
@@ -38,9 +54,23 @@ export function validateAxes(args) {
|
|
|
38
54
|
if (xAxis) {
|
|
39
55
|
validateAxisType({ axis: xAxis, key: 'x' });
|
|
40
56
|
validateLabelsHtmlOptions({ axis: xAxis });
|
|
57
|
+
if ((xAxis === null || xAxis === void 0 ? void 0 : xAxis.type) === 'category' && xAxis.categories) {
|
|
58
|
+
validateDuplicateCategories({
|
|
59
|
+
categories: xAxis.categories,
|
|
60
|
+
key: 'x',
|
|
61
|
+
axisIndex: 0,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
41
64
|
}
|
|
42
|
-
yAxis.forEach((axis) => {
|
|
65
|
+
yAxis.forEach((axis, axisIndex) => {
|
|
43
66
|
validateAxisType({ axis, key: 'y' });
|
|
67
|
+
if (axis.type === 'category' && axis.categories) {
|
|
68
|
+
validateDuplicateCategories({
|
|
69
|
+
categories: axis.categories,
|
|
70
|
+
key: 'y',
|
|
71
|
+
axisIndex,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
44
74
|
validateLabelsHtmlOptions({ axis });
|
|
45
75
|
});
|
|
46
76
|
}
|