@gravity-ui/chartkit 5.5.0 → 5.7.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 (61) hide show
  1. package/build/i18n/keysets/en.json +2 -1
  2. package/build/i18n/keysets/ru.json +2 -4
  3. package/build/plugins/d3/examples/area/NegativeValues.d.ts +2 -0
  4. package/build/plugins/d3/examples/area/NegativeValues.js +24 -0
  5. package/build/plugins/d3/examples/area/TwoYAxis.d.ts +2 -0
  6. package/build/plugins/d3/examples/area/TwoYAxis.js +58 -0
  7. package/build/plugins/d3/examples/bar-x/NegativeValues.d.ts +2 -0
  8. package/build/plugins/d3/examples/bar-x/NegativeValues.js +41 -0
  9. package/build/plugins/d3/examples/bar-x/TwoYAxis.d.ts +2 -0
  10. package/build/plugins/d3/examples/bar-x/TwoYAxis.js +58 -0
  11. package/build/plugins/d3/examples/bar-y/NegativeValues.d.ts +2 -0
  12. package/build/plugins/d3/examples/bar-y/NegativeValues.js +40 -0
  13. package/build/plugins/d3/examples/line/TwoYAxis.d.ts +2 -0
  14. package/build/plugins/d3/examples/line/TwoYAxis.js +58 -0
  15. package/build/plugins/d3/examples/mars-weather.d.ts +13 -0
  16. package/build/plugins/d3/examples/mars-weather.js +1203 -0
  17. package/build/plugins/d3/examples/scatter/TwoYAxis.d.ts +2 -0
  18. package/build/plugins/d3/examples/scatter/TwoYAxis.js +58 -0
  19. package/build/plugins/d3/renderer/components/AxisY.d.ts +1 -1
  20. package/build/plugins/d3/renderer/components/AxisY.js +112 -79
  21. package/build/plugins/d3/renderer/components/Chart.js +4 -3
  22. package/build/plugins/d3/renderer/hooks/useAxisScales/index.d.ts +1 -1
  23. package/build/plugins/d3/renderer/hooks/useAxisScales/index.js +19 -6
  24. package/build/plugins/d3/renderer/hooks/useChartDimensions/utils.d.ts +1 -0
  25. package/build/plugins/d3/renderer/hooks/useChartDimensions/utils.js +11 -10
  26. package/build/plugins/d3/renderer/hooks/useChartOptions/types.d.ts +1 -0
  27. package/build/plugins/d3/renderer/hooks/useChartOptions/x-axis.js +1 -0
  28. package/build/plugins/d3/renderer/hooks/useChartOptions/y-axis.js +61 -54
  29. package/build/plugins/d3/renderer/hooks/useSeries/prepare-area.d.ts +1 -1
  30. package/build/plugins/d3/renderer/hooks/useSeries/prepare-area.js +1 -0
  31. package/build/plugins/d3/renderer/hooks/useSeries/prepare-bar-x.js +1 -0
  32. package/build/plugins/d3/renderer/hooks/useSeries/prepare-legend.js +3 -3
  33. package/build/plugins/d3/renderer/hooks/useSeries/prepare-line.d.ts +1 -1
  34. package/build/plugins/d3/renderer/hooks/useSeries/prepare-line.js +1 -0
  35. package/build/plugins/d3/renderer/hooks/useSeries/prepare-scatter.js +1 -0
  36. package/build/plugins/d3/renderer/hooks/useSeries/types.d.ts +4 -0
  37. package/build/plugins/d3/renderer/hooks/useShapes/area/prepare-data.d.ts +2 -1
  38. package/build/plugins/d3/renderer/hooks/useShapes/area/prepare-data.js +21 -10
  39. package/build/plugins/d3/renderer/hooks/useShapes/bar-x/prepare-data.d.ts +2 -1
  40. package/build/plugins/d3/renderer/hooks/useShapes/bar-x/prepare-data.js +8 -6
  41. package/build/plugins/d3/renderer/hooks/useShapes/bar-y/prepare-data.d.ts +1 -1
  42. package/build/plugins/d3/renderer/hooks/useShapes/bar-y/prepare-data.js +6 -4
  43. package/build/plugins/d3/renderer/hooks/useShapes/index.d.ts +1 -1
  44. package/build/plugins/d3/renderer/hooks/useShapes/index.js +3 -1
  45. package/build/plugins/d3/renderer/hooks/useShapes/line/prepare-data.d.ts +1 -1
  46. package/build/plugins/d3/renderer/hooks/useShapes/line/prepare-data.js +2 -1
  47. package/build/plugins/d3/renderer/hooks/useShapes/scatter/prepare-data.d.ts +2 -2
  48. package/build/plugins/d3/renderer/hooks/useShapes/scatter/prepare-data.js +5 -2
  49. package/build/plugins/d3/renderer/hooks/useShapes/waterfall/prepare-data.d.ts +1 -1
  50. package/build/plugins/d3/renderer/hooks/useShapes/waterfall/prepare-data.js +1 -1
  51. package/build/plugins/d3/renderer/utils/index.d.ts +2 -0
  52. package/build/plugins/d3/renderer/utils/index.js +11 -0
  53. package/build/plugins/d3/renderer/utils/text.js +1 -1
  54. package/build/plugins/d3/renderer/validation/index.js +13 -4
  55. package/build/plugins/d3/utils/pie-center-text.js +1 -1
  56. package/build/plugins/highcharts/renderer/helpers/config/config.js +2 -2
  57. package/build/types/widget-data/area.d.ts +2 -0
  58. package/build/types/widget-data/bar-x.d.ts +2 -0
  59. package/build/types/widget-data/line.d.ts +2 -0
  60. package/build/types/widget-data/scatter.d.ts +2 -0
  61. package/package.json +2 -1
@@ -8,9 +8,9 @@ export declare const DEFAULT_DASH_STYLE = DashStyle.Solid;
8
8
  export declare const DEFAULT_MARKER: {
9
9
  enabled: boolean;
10
10
  symbol: "circle" | "diamond" | "square" | "triangle" | "triangle-down";
11
- radius: number;
12
11
  borderColor: string;
13
12
  borderWidth: number;
13
+ radius: number;
14
14
  };
15
15
  type PrepareLineSeriesArgs = {
16
16
  colorScale: ScaleOrdinal<string, string>;
@@ -74,6 +74,7 @@ export function prepareLineSeries(args) {
74
74
  linecap: prepareLinecap(dashStyle, series, seriesOptions),
75
75
  opacity: get(series, 'opacity', null),
76
76
  cursor: get(series, 'cursor', null),
77
+ yAxis: get(series, 'yAxis', 0),
77
78
  };
78
79
  return prepared;
79
80
  }, []);
@@ -40,6 +40,7 @@ export function prepareScatterSeries(args) {
40
40
  data: s.data,
41
41
  marker: prepareMarker(s, seriesOptions, index),
42
42
  cursor: get(s, 'cursor', null),
43
+ yAxis: get(s, 'yAxis', 0),
43
44
  };
44
45
  return prepared;
45
46
  }, []);
@@ -76,6 +76,7 @@ export type PreparedScatterSeries = {
76
76
  };
77
77
  };
78
78
  };
79
+ yAxis: number;
79
80
  } & BasePreparedSeries;
80
81
  export type PreparedBarXSeries = {
81
82
  type: BarXSeries['type'];
@@ -89,6 +90,7 @@ export type PreparedBarXSeries = {
89
90
  allowOverlap: boolean;
90
91
  padding: number;
91
92
  };
93
+ yAxis: number;
92
94
  } & BasePreparedSeries;
93
95
  export type PreparedBarYSeries = {
94
96
  type: BarYSeries['type'];
@@ -164,6 +166,7 @@ export type PreparedLineSeries = {
164
166
  dashStyle: DashStyle;
165
167
  linecap: LineCap;
166
168
  opacity: number | null;
169
+ yAxis: number;
167
170
  } & BasePreparedSeries;
168
171
  export type PreparedAreaSeries = {
169
172
  type: AreaSeries['type'];
@@ -196,6 +199,7 @@ export type PreparedAreaSeries = {
196
199
  };
197
200
  };
198
201
  };
202
+ yAxis: number;
199
203
  } & BasePreparedSeries;
200
204
  export type PreparedTreemapSeries = {
201
205
  type: TreemapSeries['type'];
@@ -7,5 +7,6 @@ export declare const prepareAreaData: (args: {
7
7
  xAxis: PreparedAxis;
8
8
  xScale: ChartScale;
9
9
  yAxis: PreparedAxis[];
10
- yScale: ChartScale;
10
+ yScale: ChartScale[];
11
+ boundsHeight: number;
11
12
  }) => PreparedAreaData[];
@@ -1,5 +1,5 @@
1
1
  import { group, sort } from 'd3';
2
- import { getLabelsSize, getLeftPosition } from '../../../utils';
2
+ import { getDataCategoryValue, getLabelsSize, getLeftPosition } from '../../../utils';
3
3
  import { getXValue, getYValue } from '../utils';
4
4
  function getLabelData(point, series, xMax) {
5
5
  const text = String(point.data.label || point.data.y);
@@ -28,9 +28,12 @@ function getLabelData(point, series, xMax) {
28
28
  return labelData;
29
29
  }
30
30
  function getXValues(series, xAxis, xScale) {
31
+ const categories = xAxis.categories || [];
31
32
  const xValues = series.reduce((acc, s) => {
32
33
  s.data.forEach((d) => {
33
- const key = String(d.x);
34
+ const key = String(xAxis.type === 'category'
35
+ ? getDataCategoryValue({ axisDirection: 'x', categories, data: d })
36
+ : d.x);
34
37
  if (!acc.has(key)) {
35
38
  acc.set(key, getXValue({ point: d, xAxis, xScale }));
36
39
  }
@@ -38,7 +41,7 @@ function getXValues(series, xAxis, xScale) {
38
41
  return acc;
39
42
  }, new Map());
40
43
  if (xAxis.type === 'category') {
41
- return (xAxis.categories || []).reduce((acc, category) => {
44
+ return categories.reduce((acc, category) => {
42
45
  const xValue = xValues.get(category);
43
46
  if (typeof xValue === 'number') {
44
47
  acc.push([category, xValue]);
@@ -49,13 +52,9 @@ function getXValues(series, xAxis, xScale) {
49
52
  return sort(Array.from(xValues), ([_x, xValue]) => xValue);
50
53
  }
51
54
  export const prepareAreaData = (args) => {
52
- const { series, xAxis, xScale, yScale } = args;
53
- const yLinearScale = yScale;
54
- const plotHeight = yLinearScale(yLinearScale.domain()[0]);
55
- const yAxis = args.yAxis[0];
55
+ const { series, xAxis, xScale, yAxis, yScale, boundsHeight: plotHeight } = args;
56
56
  const [_xMin, xRangeMax] = xScale.range();
57
57
  const xMax = xRangeMax / (1 - xAxis.maxPadding);
58
- const [yMin, _yMax] = yScale.range();
59
58
  return Array.from(group(series, (s) => s.stackId)).reduce((result, [_stackId, seriesStack]) => {
60
59
  const xValues = getXValues(seriesStack, xAxis, xScale);
61
60
  const accumulatedYValues = new Map();
@@ -63,8 +62,19 @@ export const prepareAreaData = (args) => {
63
62
  accumulatedYValues.set(key, 0);
64
63
  });
65
64
  const seriesStackData = seriesStack.reduce((acc, s) => {
65
+ const yAxisIndex = s.yAxis;
66
+ const seriesYAxis = yAxis[yAxisIndex];
67
+ const seriesYScale = yScale[yAxisIndex];
68
+ const yMin = getYValue({ point: { y: 0 }, yAxis: seriesYAxis, yScale: seriesYScale });
66
69
  const seriesData = s.data.reduce((m, d) => {
67
- return m.set(String(d.x), d);
70
+ const key = String(xAxis.type === 'category'
71
+ ? getDataCategoryValue({
72
+ axisDirection: 'x',
73
+ categories: xAxis.categories || [],
74
+ data: d,
75
+ })
76
+ : d.x);
77
+ return m.set(key, d);
68
78
  }, new Map());
69
79
  const points = xValues.reduce((pointsAcc, [x, xValue]) => {
70
80
  const accumulatedYValue = accumulatedYValues.get(x) || 0;
@@ -74,7 +84,8 @@ export const prepareAreaData = (args) => {
74
84
  // FIXME: think about how to break the series into separate areas(null Y values)
75
85
  y: 0,
76
86
  };
77
- const yValue = getYValue({ point: d, yAxis, yScale }) - accumulatedYValue;
87
+ const yValue = getYValue({ point: d, yAxis: seriesYAxis, yScale: seriesYScale }) -
88
+ accumulatedYValue;
78
89
  accumulatedYValues.set(x, yMin - yValue);
79
90
  pointsAcc.push({
80
91
  y0: yMin - accumulatedYValue,
@@ -8,5 +8,6 @@ export declare const prepareBarXData: (args: {
8
8
  xAxis: PreparedAxis;
9
9
  xScale: ChartScale;
10
10
  yAxis: PreparedAxis[];
11
- yScale: ChartScale;
11
+ yScale: ChartScale[];
12
+ boundsHeight: number;
12
13
  }) => PreparedBarXData[];
@@ -24,9 +24,7 @@ function getLabelData(d) {
24
24
  };
25
25
  }
26
26
  export const prepareBarXData = (args) => {
27
- const { series, seriesOptions, xAxis, xScale, yScale } = args;
28
- const yLinearScale = yScale;
29
- const plotHeight = yLinearScale(yLinearScale.domain()[0]);
27
+ const { series, seriesOptions, xAxis, xScale, yScale, boundsHeight: plotHeight } = args;
30
28
  const categories = get(xAxis, 'categories', []);
31
29
  const barMaxWidth = get(seriesOptions, 'bar-x.barMaxWidth');
32
30
  const barPadding = get(seriesOptions, 'bar-x.barPadding');
@@ -100,6 +98,8 @@ export const prepareBarXData = (args) => {
100
98
  ? sort(yValues, (a, b) => comparator(get(a, sortKey), get(b, sortKey)))
101
99
  : yValues;
102
100
  sortedData.forEach((yValue) => {
101
+ const yAxisIndex = yValue.series.yAxis;
102
+ const seriesYScale = yScale[yAxisIndex];
103
103
  let xCenter;
104
104
  if (xAxis.type === 'category') {
105
105
  const xBandScale = xScale;
@@ -110,11 +110,13 @@ export const prepareBarXData = (args) => {
110
110
  xCenter = xLinearScale(Number(xValue));
111
111
  }
112
112
  const x = xCenter - currentGroupWidth / 2 + (rectWidth + rectGap) * groupItemIndex;
113
- const y = yLinearScale(yValue.data.y);
114
- const height = plotHeight - y;
113
+ const yDataValue = yValue.data.y;
114
+ const y = seriesYScale(yDataValue);
115
+ const base = seriesYScale(0);
116
+ const height = yDataValue > 0 ? base - y : y - base;
115
117
  const barData = {
116
118
  x,
117
- y: y - stackHeight,
119
+ y: yDataValue > 0 ? y - stackHeight : seriesYScale(0),
118
120
  width: rectWidth,
119
121
  height,
120
122
  opacity: get(yValue.data, 'opacity', null),
@@ -8,5 +8,5 @@ export declare const prepareBarYData: (args: {
8
8
  xAxis: PreparedAxis;
9
9
  xScale: ChartScale;
10
10
  yAxis: PreparedAxis[];
11
- yScale: ChartScale;
11
+ yScale: ChartScale[];
12
12
  }) => PreparedBarYData[];
@@ -48,7 +48,7 @@ function getBandWidth(series, yAxis, yScale) {
48
48
  return bandWidth;
49
49
  }
50
50
  export const prepareBarYData = (args) => {
51
- const { series, seriesOptions, yAxis, xScale, yScale } = args;
51
+ const { series, seriesOptions, yAxis, xScale, yScale: [yScale], } = args;
52
52
  const xLinearScale = xScale;
53
53
  const plotWidth = xLinearScale(xLinearScale.domain()[1]);
54
54
  const barMaxWidth = get(seriesOptions, 'bar-y.barMaxWidth');
@@ -81,7 +81,8 @@ export const prepareBarYData = (args) => {
81
81
  const stacks = Object.values(val);
82
82
  const currentBarHeight = barHeight * stacks.length + rectGap * (stacks.length - 1);
83
83
  stacks.forEach((measureValues, groupItemIndex) => {
84
- let stackSum = 0;
84
+ const base = xLinearScale(0);
85
+ let stackSum = base;
85
86
  const stackItems = [];
86
87
  const sortedData = sortKey
87
88
  ? sort(measureValues, (a, b) => comparator(get(a, sortKey), get(b, sortKey)))
@@ -97,9 +98,10 @@ export const prepareBarYData = (args) => {
97
98
  center = scale(Number(yValue));
98
99
  }
99
100
  const y = center - currentBarHeight / 2 + (barHeight + rectGap) * groupItemIndex;
100
- const width = xLinearScale(data.x);
101
+ const xValue = Number(data.x);
102
+ const width = xValue > 0 ? xLinearScale(xValue) - base : base - xLinearScale(xValue);
101
103
  stackItems.push({
102
- x: stackSum,
104
+ x: xValue > 0 ? stackSum : stackSum - width,
103
105
  y,
104
106
  width,
105
107
  height: barHeight,
@@ -23,7 +23,7 @@ type Args = {
23
23
  xAxis: PreparedAxis;
24
24
  yAxis: PreparedAxis[];
25
25
  xScale?: ChartScale;
26
- yScale?: ChartScale;
26
+ yScale?: ChartScale[];
27
27
  };
28
28
  export declare const useShapes: (args: Args) => {
29
29
  shapes: React.ReactElement<any, string | React.JSXElementConstructor<any>>[];
@@ -32,6 +32,7 @@ export const useShapes = (args) => {
32
32
  xScale,
33
33
  yAxis,
34
34
  yScale,
35
+ boundsHeight,
35
36
  });
36
37
  acc.push(React.createElement(BarXSeriesShapes, { key: "bar-x", dispatcher: dispatcher, seriesOptions: seriesOptions, preparedData: preparedData }));
37
38
  shapesData.push(...preparedData);
@@ -90,6 +91,7 @@ export const useShapes = (args) => {
90
91
  xScale,
91
92
  yAxis,
92
93
  yScale,
94
+ boundsHeight,
93
95
  });
94
96
  acc.push(React.createElement(AreaSeriesShapes, { key: "area", dispatcher: dispatcher, seriesOptions: seriesOptions, preparedData: preparedData }));
95
97
  shapesData.push(...preparedData);
@@ -102,7 +104,7 @@ export const useShapes = (args) => {
102
104
  series: chartSeries,
103
105
  xAxis,
104
106
  xScale,
105
- yAxis: yAxis[0],
107
+ yAxis,
106
108
  yScale,
107
109
  });
108
110
  acc.push(React.createElement(ScatterSeriesShape, { key: "scatter", dispatcher: dispatcher, preparedData: preparedData, seriesOptions: seriesOptions }));
@@ -7,5 +7,5 @@ export declare const prepareLineData: (args: {
7
7
  xAxis: PreparedAxis;
8
8
  xScale: ChartScale;
9
9
  yAxis: PreparedAxis[];
10
- yScale: ChartScale;
10
+ yScale: ChartScale[];
11
11
  }) => PreparedLineData[];
@@ -32,9 +32,10 @@ export const prepareLineData = (args) => {
32
32
  const [_xMin, xRangeMax] = xScale.range();
33
33
  const xMax = xRangeMax / (1 - xAxis.maxPadding);
34
34
  return series.reduce((acc, s) => {
35
+ const seriesYScale = yScale[s.yAxis];
35
36
  const points = s.data.map((d) => ({
36
37
  x: getXValue({ point: d, xAxis, xScale }),
37
- y: getYValue({ point: d, yAxis, yScale }),
38
+ y: getYValue({ point: d, yAxis, yScale: seriesYScale }),
38
39
  active: true,
39
40
  data: d,
40
41
  series: s,
@@ -6,6 +6,6 @@ export declare const prepareScatterData: (args: {
6
6
  series: PreparedScatterSeries[];
7
7
  xAxis: PreparedAxis;
8
8
  xScale: ChartScale;
9
- yAxis: PreparedAxis;
10
- yScale: ChartScale;
9
+ yAxis: PreparedAxis[];
10
+ yScale: ChartScale[];
11
11
  }) => PreparedScatterData[];
@@ -6,7 +6,10 @@ const getFilteredLinearScatterData = (data) => {
6
6
  export const prepareScatterData = (args) => {
7
7
  const { series, xAxis, xScale, yAxis, yScale } = args;
8
8
  return series.reduce((acc, s) => {
9
- const filteredData = xAxis.type === 'category' || yAxis.type === 'category'
9
+ const yAxisIndex = get(s, 'yAxis', 0);
10
+ const seriesYAxis = yAxis[yAxisIndex];
11
+ const seriesYScale = yScale[yAxisIndex];
12
+ const filteredData = xAxis.type === 'category' || seriesYAxis.type === 'category'
10
13
  ? s.data
11
14
  : getFilteredLinearScatterData(s.data);
12
15
  filteredData.forEach((d) => {
@@ -15,7 +18,7 @@ export const prepareScatterData = (args) => {
15
18
  data: d,
16
19
  series: s,
17
20
  x: getXValue({ point: d, xAxis, xScale }),
18
- y: getYValue({ point: d, yAxis, yScale }),
21
+ y: getYValue({ point: d, yAxis: seriesYAxis, yScale: seriesYScale }),
19
22
  opacity: get(d, 'opacity', null),
20
23
  },
21
24
  hovered: false,
@@ -8,5 +8,5 @@ export declare const prepareWaterfallData: (args: {
8
8
  xAxis: PreparedAxis;
9
9
  xScale: ChartScale;
10
10
  yAxis: PreparedAxis[];
11
- yScale: ChartScale;
11
+ yScale: ChartScale[];
12
12
  }) => PreparedWaterfallData[];
@@ -50,7 +50,7 @@ function getBandWidth(args) {
50
50
  return bandWidth;
51
51
  }
52
52
  export const prepareWaterfallData = (args) => {
53
- const { series, seriesOptions, xAxis, xScale, yAxis: [yAxis], yScale, } = args;
53
+ const { series, seriesOptions, xAxis, xScale, yAxis: [yAxis], yScale: [yScale], } = args;
54
54
  const yLinearScale = yScale;
55
55
  const plotHeight = yLinearScale(yLinearScale.domain()[0]);
56
56
  const barMaxWidth = get(seriesOptions, 'waterfall.barMaxWidth');
@@ -8,6 +8,7 @@ export * from './axis';
8
8
  export * from './labels';
9
9
  export * from './symbol';
10
10
  export * from './series';
11
+ export declare const CHART_SERIES_WITH_VOLUME: ChartKitWidgetSeries['type'][];
11
12
  export type AxisDirection = 'x' | 'y';
12
13
  type UnknownSeries = {
13
14
  type: ChartKitWidgetSeries['type'];
@@ -39,6 +40,7 @@ export declare function isSeriesWithCategoryValues(series: UnknownSeries): serie
39
40
  }[];
40
41
  };
41
42
  export declare const getDomainDataXBySeries: (series: UnknownSeries[]) => number[];
43
+ export declare function getDefaultMaxXAxisValue(series: UnknownSeries[]): 0 | undefined;
42
44
  export declare const getDomainDataYBySeries: (series: UnknownSeries[]) => unknown[];
43
45
  export declare const getSeriesNames: (series: ChartKitWidgetSeries[]) => string[];
44
46
  export declare const getOnlyVisibleSeries: <T extends {
@@ -15,6 +15,11 @@ export * from './labels';
15
15
  export * from './symbol';
16
16
  export * from './series';
17
17
  const CHARTS_WITHOUT_AXIS = ['pie', 'treemap'];
18
+ export const CHART_SERIES_WITH_VOLUME = [
19
+ 'bar-x',
20
+ 'area',
21
+ 'waterfall',
22
+ ];
18
23
  /**
19
24
  * Checks whether the series should be drawn with axes.
20
25
  *
@@ -41,6 +46,12 @@ export const getDomainDataXBySeries = (series) => {
41
46
  return acc;
42
47
  }, []);
43
48
  };
49
+ export function getDefaultMaxXAxisValue(series) {
50
+ if (series.some((s) => s.type === 'bar-y')) {
51
+ return 0;
52
+ }
53
+ return undefined;
54
+ }
44
55
  export const getDomainDataYBySeries = (series) => {
45
56
  const groupedSeries = group(series, (item) => item.type);
46
57
  return Array.from(groupedSeries).reduce((acc, [type, seriesList]) => {
@@ -1,4 +1,4 @@
1
- import { select } from 'd3';
1
+ import { select } from 'd3-selection';
2
2
  export function setEllipsisForOverflowText(selection, maxWidth) {
3
3
  var _a, _b, _c, _d;
4
4
  let text = selection.text();
@@ -6,9 +6,19 @@ import { CHARTKIT_ERROR_CODE, ChartKitError } from '../../../../libs';
6
6
  import { DEFAULT_AXIS_TYPE } from '../constants';
7
7
  const AVAILABLE_SERIES_TYPES = Object.values(SeriesType);
8
8
  const validateXYSeries = (args) => {
9
- const { series, xAxis, yAxis } = args;
9
+ const { series, xAxis, yAxis = [] } = args;
10
+ const yAxisIndex = get(series, 'yAxis', 0);
11
+ const seriesYAxis = yAxis[yAxisIndex];
12
+ if (yAxisIndex !== 0 && typeof seriesYAxis === 'undefined') {
13
+ throw new ChartKitError({
14
+ code: CHARTKIT_ERROR_CODE.INVALID_DATA,
15
+ message: i18n('error', 'label_invalid-y-axis-index', {
16
+ index: yAxisIndex,
17
+ }),
18
+ });
19
+ }
10
20
  const xType = get(xAxis, 'type', DEFAULT_AXIS_TYPE);
11
- const yType = get(yAxis, 'type', DEFAULT_AXIS_TYPE);
21
+ const yType = get(seriesYAxis, 'type', DEFAULT_AXIS_TYPE);
12
22
  series.data.forEach(({ x, y }) => {
13
23
  switch (xType) {
14
24
  case 'category': {
@@ -203,7 +213,6 @@ export const validateData = (data) => {
203
213
  });
204
214
  }
205
215
  data.series.data.forEach((series) => {
206
- var _a;
207
- validateSeries({ series, yAxis: (_a = data.yAxis) === null || _a === void 0 ? void 0 : _a[0], xAxis: data.xAxis });
216
+ validateSeries({ series, yAxis: data.yAxis, xAxis: data.xAxis });
208
217
  });
209
218
  };
@@ -1,4 +1,4 @@
1
- import { create } from 'd3';
1
+ import { create } from 'd3-selection';
2
2
  import get from 'lodash/get';
3
3
  import { getLabelsSize } from '../renderer/utils';
4
4
  const MAX_FONT_SIZE = 64;
@@ -1328,8 +1328,8 @@ export function prepareConfig(data, options, isMobile, holidays) {
1328
1328
  // Callback setExtremes used because of it obligatory invocation on every zoom event
1329
1329
  // setTimeout used because of absence resetZoomButton node in dom on first zoom event
1330
1330
  setTimeout(() => {
1331
- var _a;
1332
- const text = (_a = this.chart.resetZoomButton) === null || _a === void 0 ? void 0 : _a.text;
1331
+ var _a, _b;
1332
+ const text = (_b = (_a = this.chart) === null || _a === void 0 ? void 0 : _a.resetZoomButton) === null || _b === void 0 ? void 0 : _b.text;
1333
1333
  if (text) {
1334
1334
  text.translate(0, -6);
1335
1335
  }
@@ -70,4 +70,6 @@ export type AreaSeries<T = any> = BaseSeries & {
70
70
  };
71
71
  /** Options for the point markers of line in area series */
72
72
  marker?: AreaMarkerOptions;
73
+ /** Y-axis index (when using two axes) */
74
+ yAxis?: number;
73
75
  };
@@ -61,4 +61,6 @@ export type BarXSeries<T = any> = BaseSeries & {
61
61
  legend?: ChartKitWidgetLegend & {
62
62
  symbol?: RectLegendSymbolOptions;
63
63
  };
64
+ /** Y-axis index (when using two axes) */
65
+ yAxis?: number;
64
66
  };
@@ -51,4 +51,6 @@ export type LineSeries<T = any> = BaseSeries & {
51
51
  linecap?: `${LineCap}`;
52
52
  /** Individual opacity for the line. */
53
53
  opacity?: number;
54
+ /** Y-axis index (when using two axes) */
55
+ yAxis?: number;
54
56
  };
@@ -40,4 +40,6 @@ export type ScatterSeries<T = any> = BaseSeries & {
40
40
  legend?: ChartKitWidgetLegend & {
41
41
  symbol?: RectLegendSymbolOptions;
42
42
  };
43
+ /** Y-axis index (when using two axes) */
44
+ yAxis?: number;
43
45
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/chartkit",
3
- "version": "5.5.0",
3
+ "version": "5.7.0",
4
4
  "description": "React component used to render charts based on any sources you need",
5
5
  "license": "MIT",
6
6
  "repository": "git@github.com:gravity-ui/ChartKit.git",
@@ -75,6 +75,7 @@
75
75
  "@storybook/react": "^7.0.26",
76
76
  "@storybook/react-webpack5": "^7.0.26",
77
77
  "@types/d3": "^7.4.0",
78
+ "@types/d3-selection": "^3.0.10",
78
79
  "@types/jest": "^28.1.3",
79
80
  "@types/lodash": "^4.14.177",
80
81
  "@types/node": "^18.0.0",