@gravity-ui/charts 1.17.0 → 1.18.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 (93) hide show
  1. package/dist/cjs/components/AxisY/prepare-axis-data.d.ts +2 -1
  2. package/dist/cjs/components/AxisY/prepare-axis-data.js +7 -6
  3. package/dist/cjs/components/AxisY/utils.js +1 -10
  4. package/dist/cjs/components/ChartInner/index.js +10 -5
  5. package/dist/cjs/components/ChartInner/useChartInnerProps.d.ts +1 -1
  6. package/dist/cjs/components/ChartInner/useChartInnerProps.js +2 -0
  7. package/dist/cjs/components/Tooltip/ChartTooltipContent.d.ts +1 -0
  8. package/dist/cjs/components/Tooltip/ChartTooltipContent.js +2 -2
  9. package/dist/cjs/components/Tooltip/DefaultTooltipContent/index.d.ts +2 -1
  10. package/dist/cjs/components/Tooltip/DefaultTooltipContent/index.js +3 -3
  11. package/dist/cjs/components/Tooltip/DefaultTooltipContent/utils.d.ts +4 -3
  12. package/dist/cjs/components/Tooltip/DefaultTooltipContent/utils.js +6 -9
  13. package/dist/cjs/components/Tooltip/index.js +1 -1
  14. package/dist/cjs/hooks/useAxisScales/index.d.ts +3 -3
  15. package/dist/cjs/hooks/useAxisScales/index.js +40 -7
  16. package/dist/cjs/hooks/useChartOptions/index.d.ts +3 -1
  17. package/dist/cjs/hooks/useChartOptions/index.js +3 -3
  18. package/dist/cjs/hooks/useChartOptions/tooltip.d.ts +4 -1
  19. package/dist/cjs/hooks/useChartOptions/tooltip.js +18 -3
  20. package/dist/cjs/hooks/useChartOptions/x-axis.js +21 -9
  21. package/dist/cjs/hooks/useChartOptions/y-axis.js +20 -7
  22. package/dist/cjs/hooks/useCrosshair/index.d.ts +1 -1
  23. package/dist/cjs/hooks/useCrosshair/index.js +2 -1
  24. package/dist/cjs/hooks/useShapes/area/prepare-data.d.ts +1 -1
  25. package/dist/cjs/hooks/useShapes/area/prepare-data.js +3 -0
  26. package/dist/cjs/hooks/useShapes/bar-x/prepare-data.d.ts +1 -1
  27. package/dist/cjs/hooks/useShapes/bar-x/prepare-data.js +3 -0
  28. package/dist/cjs/hooks/useShapes/bar-y/prepare-data.d.ts +1 -1
  29. package/dist/cjs/hooks/useShapes/bar-y/prepare-data.js +8 -1
  30. package/dist/cjs/hooks/useShapes/index.d.ts +1 -1
  31. package/dist/cjs/hooks/useShapes/line/prepare-data.d.ts +1 -1
  32. package/dist/cjs/hooks/useShapes/line/prepare-data.js +3 -0
  33. package/dist/cjs/hooks/useShapes/scatter/prepare-data.d.ts +1 -1
  34. package/dist/cjs/hooks/useShapes/scatter/prepare-data.js +6 -0
  35. package/dist/cjs/hooks/useShapes/waterfall/prepare-data.d.ts +1 -1
  36. package/dist/cjs/hooks/useShapes/waterfall/prepare-data.js +6 -3
  37. package/dist/cjs/hooks/useZoom/index.d.ts +1 -1
  38. package/dist/cjs/hooks/useZoom/types.d.ts +1 -1
  39. package/dist/cjs/hooks/useZoom/utils.d.ts +1 -1
  40. package/dist/cjs/hooks/useZoom/utils.js +22 -10
  41. package/dist/cjs/types/chart/tooltip.d.ts +3 -0
  42. package/dist/cjs/utils/chart/array.d.ts +1 -0
  43. package/dist/cjs/utils/chart/array.js +9 -0
  44. package/dist/cjs/utils/chart/index.d.ts +1 -0
  45. package/dist/cjs/utils/chart/index.js +1 -0
  46. package/dist/cjs/utils/chart/zoom.js +14 -8
  47. package/dist/esm/components/AxisY/prepare-axis-data.d.ts +2 -1
  48. package/dist/esm/components/AxisY/prepare-axis-data.js +7 -6
  49. package/dist/esm/components/AxisY/utils.js +1 -10
  50. package/dist/esm/components/ChartInner/index.js +10 -5
  51. package/dist/esm/components/ChartInner/useChartInnerProps.d.ts +1 -1
  52. package/dist/esm/components/ChartInner/useChartInnerProps.js +2 -0
  53. package/dist/esm/components/Tooltip/ChartTooltipContent.d.ts +1 -0
  54. package/dist/esm/components/Tooltip/ChartTooltipContent.js +2 -2
  55. package/dist/esm/components/Tooltip/DefaultTooltipContent/index.d.ts +2 -1
  56. package/dist/esm/components/Tooltip/DefaultTooltipContent/index.js +3 -3
  57. package/dist/esm/components/Tooltip/DefaultTooltipContent/utils.d.ts +4 -3
  58. package/dist/esm/components/Tooltip/DefaultTooltipContent/utils.js +6 -9
  59. package/dist/esm/components/Tooltip/index.js +1 -1
  60. package/dist/esm/hooks/useAxisScales/index.d.ts +3 -3
  61. package/dist/esm/hooks/useAxisScales/index.js +40 -7
  62. package/dist/esm/hooks/useChartOptions/index.d.ts +3 -1
  63. package/dist/esm/hooks/useChartOptions/index.js +3 -3
  64. package/dist/esm/hooks/useChartOptions/tooltip.d.ts +4 -1
  65. package/dist/esm/hooks/useChartOptions/tooltip.js +18 -3
  66. package/dist/esm/hooks/useChartOptions/x-axis.js +21 -9
  67. package/dist/esm/hooks/useChartOptions/y-axis.js +20 -7
  68. package/dist/esm/hooks/useCrosshair/index.d.ts +1 -1
  69. package/dist/esm/hooks/useCrosshair/index.js +2 -1
  70. package/dist/esm/hooks/useShapes/area/prepare-data.d.ts +1 -1
  71. package/dist/esm/hooks/useShapes/area/prepare-data.js +3 -0
  72. package/dist/esm/hooks/useShapes/bar-x/prepare-data.d.ts +1 -1
  73. package/dist/esm/hooks/useShapes/bar-x/prepare-data.js +3 -0
  74. package/dist/esm/hooks/useShapes/bar-y/prepare-data.d.ts +1 -1
  75. package/dist/esm/hooks/useShapes/bar-y/prepare-data.js +8 -1
  76. package/dist/esm/hooks/useShapes/index.d.ts +1 -1
  77. package/dist/esm/hooks/useShapes/line/prepare-data.d.ts +1 -1
  78. package/dist/esm/hooks/useShapes/line/prepare-data.js +3 -0
  79. package/dist/esm/hooks/useShapes/scatter/prepare-data.d.ts +1 -1
  80. package/dist/esm/hooks/useShapes/scatter/prepare-data.js +6 -0
  81. package/dist/esm/hooks/useShapes/waterfall/prepare-data.d.ts +1 -1
  82. package/dist/esm/hooks/useShapes/waterfall/prepare-data.js +6 -3
  83. package/dist/esm/hooks/useZoom/index.d.ts +1 -1
  84. package/dist/esm/hooks/useZoom/types.d.ts +1 -1
  85. package/dist/esm/hooks/useZoom/utils.d.ts +1 -1
  86. package/dist/esm/hooks/useZoom/utils.js +22 -10
  87. package/dist/esm/types/chart/tooltip.d.ts +3 -0
  88. package/dist/esm/utils/chart/array.d.ts +1 -0
  89. package/dist/esm/utils/chart/array.js +9 -0
  90. package/dist/esm/utils/chart/index.d.ts +1 -0
  91. package/dist/esm/utils/chart/index.js +1 -0
  92. package/dist/esm/utils/chart/zoom.js +14 -8
  93. package/package.json +1 -1
@@ -7,7 +7,7 @@ export declare const prepareAreaData: (args: {
7
7
  xAxis: PreparedAxis;
8
8
  xScale: ChartScale;
9
9
  yAxis: PreparedAxis[];
10
- yScale: ChartScale[];
10
+ yScale: (ChartScale | undefined)[];
11
11
  boundsHeight: number;
12
12
  isOutsideBounds: (x: number, y: number) => boolean;
13
13
  }) => Promise<PreparedAreaData[]>;
@@ -71,6 +71,9 @@ export const prepareAreaData = async (args) => {
71
71
  const yAxisIndex = s.yAxis;
72
72
  const seriesYAxis = yAxis[yAxisIndex];
73
73
  const seriesYScale = yScale[yAxisIndex];
74
+ if (!seriesYScale) {
75
+ continue;
76
+ }
74
77
  const yMin = getYValue({
75
78
  point: { y: 0 },
76
79
  points: s.data,
@@ -8,6 +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 | undefined)[];
12
12
  boundsHeight: number;
13
13
  }) => Promise<PreparedBarXData[]>;
@@ -112,6 +112,9 @@ export const prepareBarXData = async (args) => {
112
112
  const yValue = sortedData[yValueIndex];
113
113
  const yAxisIndex = yValue.series.yAxis;
114
114
  const seriesYScale = yScale[yAxisIndex];
115
+ if (!seriesYScale) {
116
+ continue;
117
+ }
115
118
  let xCenter;
116
119
  if (xAxis.type === 'category') {
117
120
  const xBandScale = xScale;
@@ -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 | undefined)[];
12
12
  }) => Promise<BarYShapesArgs>;
@@ -10,6 +10,13 @@ export const prepareBarYData = async (args) => {
10
10
  const stackGap = seriesOptions['bar-y'].stackGap;
11
11
  const xLinearScale = xScale;
12
12
  const yLinearScale = yScale;
13
+ if (!yLinearScale) {
14
+ return {
15
+ shapes: [],
16
+ labels: [],
17
+ htmlElements: [],
18
+ };
19
+ }
13
20
  const yScaleRange = yLinearScale.range();
14
21
  const plotHeight = Math.abs(yScaleRange[0] - yScaleRange[1]);
15
22
  const sortingOptions = get(seriesOptions, 'bar-y.dataSorting');
@@ -29,7 +36,7 @@ export const prepareBarYData = async (args) => {
29
36
  })();
30
37
  const groupedData = groupBarYDataByYValue(series, yAxis);
31
38
  const { bandSize, barGap, barSize } = yAxis[0].type === 'category'
32
- ? getBarYLayoutForCategoryScale({ groupedData, seriesOptions, yScale })
39
+ ? getBarYLayoutForCategoryScale({ groupedData, seriesOptions, yScale: yLinearScale })
33
40
  : getBarYLayoutForNumericScale({
34
41
  groupedData,
35
42
  seriesOptions,
@@ -25,7 +25,7 @@ type Args = {
25
25
  xAxis: PreparedAxis | null;
26
26
  yAxis: PreparedAxis[];
27
27
  xScale?: ChartScale;
28
- yScale?: ChartScale[];
28
+ yScale?: (ChartScale | undefined)[];
29
29
  split: PreparedSplit;
30
30
  htmlLayout: HTMLElement | null;
31
31
  clipPathId: string;
@@ -8,7 +8,7 @@ export declare const prepareLineData: (args: {
8
8
  xAxis: PreparedAxis;
9
9
  xScale: ChartScale;
10
10
  yAxis: PreparedAxis[];
11
- yScale: ChartScale[];
11
+ yScale: (ChartScale | undefined)[];
12
12
  split: PreparedSplit;
13
13
  isOutsideBounds: (x: number, y: number) => boolean;
14
14
  }) => Promise<PreparedLineData[]>;
@@ -50,6 +50,9 @@ export const prepareLineData = async (args) => {
50
50
  const seriesYAxis = yAxis[yAxisIndex];
51
51
  const yAxisTop = ((_a = split.plots[seriesYAxis.plotIndex]) === null || _a === void 0 ? void 0 : _a.top) || 0;
52
52
  const seriesYScale = yScale[s.yAxis];
53
+ if (!seriesYScale) {
54
+ continue;
55
+ }
53
56
  const points = s.data.map((d) => ({
54
57
  x: getXValue({ point: d, points: s.data, xAxis, xScale }),
55
58
  y: yAxisTop +
@@ -7,6 +7,6 @@ export declare const prepareScatterData: (args: {
7
7
  xAxis: PreparedAxis;
8
8
  xScale: ChartScale;
9
9
  yAxis: PreparedAxis[];
10
- yScale: ChartScale[];
10
+ yScale: (ChartScale | undefined)[];
11
11
  isOutsideBounds: (x: number, y: number) => boolean;
12
12
  }) => PreparedScatterData[];
@@ -9,6 +9,9 @@ export const prepareScatterData = (args) => {
9
9
  const yAxisIndex = get(s, 'yAxis', 0);
10
10
  const seriesYAxis = yAxis[yAxisIndex];
11
11
  const seriesYScale = yScale[yAxisIndex];
12
+ if (!seriesYScale) {
13
+ return acc;
14
+ }
12
15
  const filteredData = xAxis.type === 'category' || seriesYAxis.type === 'category'
13
16
  ? s.data
14
17
  : getFilteredLinearScatterData(s.data);
@@ -16,6 +19,9 @@ export const prepareScatterData = (args) => {
16
19
  var _a;
17
20
  const x = getXValue({ point: d, xAxis, xScale });
18
21
  const y = getYValue({ point: d, yAxis: seriesYAxis, yScale: seriesYScale });
22
+ if (typeof x === 'undefined' || typeof y === 'undefined') {
23
+ return;
24
+ }
19
25
  acc.push({
20
26
  point: {
21
27
  data: d,
@@ -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 | undefined)[];
12
12
  }) => Promise<PreparedWaterfallData[]>;
@@ -55,6 +55,9 @@ function getBandWidth(args) {
55
55
  export const prepareWaterfallData = async (args) => {
56
56
  const { series, seriesOptions, xAxis, xScale, yAxis: [yAxis], yScale: [yScale], } = args;
57
57
  const yLinearScale = yScale;
58
+ if (!yLinearScale) {
59
+ return [];
60
+ }
58
61
  const plotHeight = yLinearScale(yLinearScale.domain()[0]);
59
62
  const barMaxWidth = get(seriesOptions, 'waterfall.barMaxWidth');
60
63
  const barPadding = get(seriesOptions, 'waterfall.barPadding');
@@ -72,7 +75,7 @@ export const prepareWaterfallData = async (args) => {
72
75
  const rectWidth = Math.max(MIN_BAR_WIDTH, Math.min(bandWidth - rectGap, barMaxWidth));
73
76
  const yZero = getYValue({
74
77
  point: { y: 0 },
75
- yScale,
78
+ yScale: yLinearScale,
76
79
  yAxis,
77
80
  });
78
81
  let totalValue = 0;
@@ -92,7 +95,7 @@ export const prepareWaterfallData = async (args) => {
92
95
  const height = yZero -
93
96
  getYValue({
94
97
  point: { y: Math.abs(yValue) },
95
- yScale,
98
+ yScale: yLinearScale,
96
99
  yAxis,
97
100
  });
98
101
  let y;
@@ -101,7 +104,7 @@ export const prepareWaterfallData = async (args) => {
101
104
  point: {
102
105
  y: yValue > 0 ? yValue : 0,
103
106
  },
104
- yScale,
107
+ yScale: yLinearScale,
105
108
  yAxis,
106
109
  });
107
110
  }
@@ -12,7 +12,7 @@ interface UseZoomProps {
12
12
  xAxis: PreparedAxis | null;
13
13
  xScale?: ChartScale;
14
14
  yAxis: PreparedAxis[];
15
- yScale?: ChartScale[];
15
+ yScale?: (ChartScale | undefined)[];
16
16
  }
17
17
  export declare function useZoom(props: UseZoomProps): void;
18
18
  export {};
@@ -15,5 +15,5 @@ export interface ZoomState {
15
15
  * or the category index from the categories array specified in the axis settings (if the axis type is `category`).
16
16
  * The second element is the corresponding maximum value.
17
17
  */
18
- y: [number, number][];
18
+ y: ([number, number] | undefined)[];
19
19
  }
@@ -7,6 +7,6 @@ export declare function selectionToZoomBounds(args: {
7
7
  xAxis: PreparedAxis;
8
8
  xScale: ChartScale;
9
9
  yAxes: PreparedAxis[];
10
- yScales: ChartScale[];
10
+ yScales: (ChartScale | undefined)[];
11
11
  zoomType: PreparedZoom['type'];
12
12
  }): Partial<ZoomState>;
@@ -13,11 +13,17 @@ export function selectionToZoomBounds(args) {
13
13
  if (!Array.isArray(zoomState.y)) {
14
14
  zoomState.y = [];
15
15
  }
16
- zoomState.y.push(selectionYToZoomBounds({
17
- yAxis,
18
- yScale: yScales[index],
19
- selection: [y1, y0],
20
- }));
16
+ const yScale = yScales[index];
17
+ if (yScale) {
18
+ zoomState.y.push(selectionYToZoomBounds({
19
+ yAxis,
20
+ yScale,
21
+ selection: [y1, y0],
22
+ }));
23
+ }
24
+ else {
25
+ zoomState.y.push(undefined);
26
+ }
21
27
  });
22
28
  break;
23
29
  }
@@ -29,11 +35,17 @@ export function selectionToZoomBounds(args) {
29
35
  if (!Array.isArray(zoomState.y)) {
30
36
  zoomState.y = [];
31
37
  }
32
- zoomState.y.push(selectionYToZoomBounds({
33
- yAxis,
34
- yScale: yScales[index],
35
- selection: [y0, y1],
36
- }));
38
+ const yScale = yScales[index];
39
+ if (yScale) {
40
+ zoomState.y.push(selectionYToZoomBounds({
41
+ yAxis,
42
+ yScale,
43
+ selection: [y0, y1],
44
+ }));
45
+ }
46
+ else {
47
+ zoomState.y.push(undefined);
48
+ }
37
49
  });
38
50
  break;
39
51
  }
@@ -130,4 +130,7 @@ export interface ChartTooltip<T = MeaningfulAny> {
130
130
  /** Formatting settings for totals tooltip value. */
131
131
  valueFormat?: ValueFormat;
132
132
  };
133
+ /** Can be used for the UI automated test.
134
+ * It is assigned as a data-qa attribute to an element. */
135
+ qa?: string;
133
136
  }
@@ -0,0 +1 @@
1
+ export declare function getMinSpaceBetween<T>(arr: T[], iterator: (item: T) => number): number;
@@ -0,0 +1,9 @@
1
+ export function getMinSpaceBetween(arr, iterator) {
2
+ return arr.reduce((acc, item, index) => {
3
+ const prev = arr[index - 1];
4
+ if (prev) {
5
+ return Math.min(acc, Math.abs(iterator(prev) - iterator(item)));
6
+ }
7
+ return acc;
8
+ }, Infinity);
9
+ }
@@ -1,6 +1,7 @@
1
1
  import type { BaseTextStyle, ChartSeries, ChartSeriesData } from '../../types';
2
2
  import type { AxisDirection } from './types';
3
3
  export * from './axis';
4
+ export * from './array';
4
5
  export * from './color';
5
6
  export * from './format';
6
7
  export * from './labels';
@@ -6,6 +6,7 @@ import { DEFAULT_AXIS_LABEL_FONT_SIZE } from '../../constants';
6
6
  import { getSeriesStackId } from '../../hooks/useSeries/utils';
7
7
  import { getWaterfallPointSubtotal } from './series/waterfall';
8
8
  export * from './axis';
9
+ export * from './array';
9
10
  export * from './color';
10
11
  export * from './format';
11
12
  export * from './labels';
@@ -76,14 +76,20 @@ export function getZoomedSeriesData(args) {
76
76
  const yAxisIndex = 'yAxis' in seriesItem && typeof seriesItem.yAxis === 'number'
77
77
  ? seriesItem.yAxis
78
78
  : 0;
79
- const [yMin, yMax] = zoomState.y[yAxisIndex];
80
- const y = 'y' in point ? point.y : undefined;
81
- inYRange = isValueInRange({
82
- axis: yAxes === null || yAxes === void 0 ? void 0 : yAxes[yAxisIndex],
83
- value: y,
84
- min: yMin,
85
- max: yMax,
86
- });
79
+ const zoomStateY = zoomState.y[yAxisIndex];
80
+ if (zoomStateY) {
81
+ const [yMin, yMax] = zoomStateY;
82
+ const y = 'y' in point ? point.y : undefined;
83
+ inYRange = isValueInRange({
84
+ axis: yAxes === null || yAxes === void 0 ? void 0 : yAxes[yAxisIndex],
85
+ value: y,
86
+ min: yMin,
87
+ max: yMax,
88
+ });
89
+ }
90
+ else {
91
+ inYRange = false;
92
+ }
87
93
  }
88
94
  currentPointInRange = inXRange && inYRange;
89
95
  if (currentPointInRange) {
@@ -1,9 +1,10 @@
1
1
  import type { ChartScale, PreparedAxis, PreparedSplit } from '../../hooks';
2
2
  import type { AxisYData } from './types';
3
- export declare function prepareAxisData({ axis, split, scale, width, height, }: {
3
+ export declare function prepareAxisData({ axis, split, scale, top: topOffset, width, height, }: {
4
4
  axis: PreparedAxis;
5
5
  split: PreparedSplit;
6
6
  scale: ChartScale;
7
+ top: number;
7
8
  width: number;
8
9
  height: number;
9
10
  }): Promise<AxisYData>;
@@ -1,7 +1,7 @@
1
1
  import { getUniqId } from '@gravity-ui/uikit';
2
2
  import { calculateCos, calculateSin, getBandsPosition, getLabelFormatter, getLabelsSize, getTextSizeFn, getTextWithElipsis, wrapText, } from '../../utils';
3
3
  import { getTickValues } from './utils';
4
- async function getSvgAxisLabel({ getTextSize, text, axis, top, left, labelMaxHeight, }) {
4
+ async function getSvgAxisLabel({ getTextSize, text, axis, top, left, labelMaxHeight, topOffset, }) {
5
5
  var _a;
6
6
  const originalTextSize = await getTextSize(text);
7
7
  // Currently, a preliminary label calculation is used to build the chart - we cannot exceed it here.
@@ -17,7 +17,7 @@ async function getSvgAxisLabel({ getTextSize, text, axis, top, left, labelMaxHei
17
17
  width: labelMaxWidth,
18
18
  getTextSize,
19
19
  });
20
- let topOffset = top;
20
+ let labelTopOffset = top;
21
21
  let newLabelWidth = 0;
22
22
  let newLabelHeight = 0;
23
23
  for (let textRowIndex = 0; textRowIndex < textRows.length; textRowIndex++) {
@@ -49,10 +49,10 @@ async function getSvgAxisLabel({ getTextSize, text, axis, top, left, labelMaxHei
49
49
  content.push({
50
50
  text: rowText,
51
51
  x,
52
- y: topOffset,
52
+ y: labelTopOffset,
53
53
  size: textSize,
54
54
  });
55
- topOffset += textSize.height;
55
+ labelTopOffset += textSize.height;
56
56
  }
57
57
  }
58
58
  content.forEach((row) => {
@@ -68,7 +68,7 @@ async function getSvgAxisLabel({ getTextSize, text, axis, top, left, labelMaxHei
68
68
  content.push({
69
69
  text,
70
70
  x,
71
- y: Math.max(0, top - size.height / 2),
71
+ y: Math.max(-topOffset, top - size.height / 2),
72
72
  size,
73
73
  });
74
74
  }
@@ -81,7 +81,7 @@ async function getSvgAxisLabel({ getTextSize, text, axis, top, left, labelMaxHei
81
81
  return svgLabel;
82
82
  }
83
83
  // eslint-disable-next-line complexity
84
- export async function prepareAxisData({ axis, split, scale, width, height, }) {
84
+ export async function prepareAxisData({ axis, split, scale, top: topOffset, width, height, }) {
85
85
  var _a, _b, _c;
86
86
  const axisPlotTopPosition = ((_a = split.plots[axis.plotIndex]) === null || _a === void 0 ? void 0 : _a.top) || 0;
87
87
  const axisHeight = ((_b = split.plots[axis.plotIndex]) === null || _b === void 0 ? void 0 : _b.height) || height;
@@ -133,6 +133,7 @@ export async function prepareAxisData({ axis, split, scale, width, height, }) {
133
133
  top: y,
134
134
  left: domainX,
135
135
  labelMaxHeight,
136
+ topOffset,
136
137
  });
137
138
  }
138
139
  }
@@ -1,4 +1,4 @@
1
- import { getTicksCount, isBandScale } from '../../utils';
1
+ import { getMinSpaceBetween, getTicksCount, isBandScale } from '../../utils';
2
2
  function thinOut(items, delta) {
3
3
  const arr = [];
4
4
  for (let i = 0; i < items.length; i = i + delta) {
@@ -6,15 +6,6 @@ function thinOut(items, delta) {
6
6
  }
7
7
  return arr;
8
8
  }
9
- function getMinSpaceBetween(arr, iterator) {
10
- return arr.reduce((acc, item, index) => {
11
- const prev = arr[index - 1];
12
- if (prev) {
13
- return Math.min(acc, Math.abs(iterator(prev) - iterator(item)));
14
- }
15
- return acc;
16
- }, Infinity);
17
- }
18
9
  export function getTickValues({ scale, axis, labelLineHeight, }) {
19
10
  if ('ticks' in scale && typeof scale.ticks === 'function') {
20
11
  const range = scale.range();
@@ -96,6 +96,7 @@ export const ChartInner = (props) => {
96
96
  const axisData = await prepareAxisData({
97
97
  axis,
98
98
  scale,
99
+ top: boundsOffsetTop,
99
100
  width: boundsWidth,
100
101
  height: boundsHeight,
101
102
  split: preparedSplit,
@@ -107,7 +108,7 @@ export const ChartInner = (props) => {
107
108
  setYAxisDataItems(items);
108
109
  }
109
110
  })();
110
- }, [boundsHeight, boundsWidth, preparedSplit, yAxis, yScale]);
111
+ }, [boundsHeight, boundsOffsetTop, boundsWidth, preparedSplit, yAxis, yScale]);
111
112
  return (React.createElement("div", { className: b() },
112
113
  React.createElement("svg", { ref: svgRef, width: width, height: height,
113
114
  // We use onPointerMove here because onMouseMove works incorrectly when the zoom setting is enabled:
@@ -121,10 +122,14 @@ export const ChartInner = (props) => {
121
122
  return React.createElement(PlotTitle, { key: `plot-${index}`, title: plot.title });
122
123
  })),
123
124
  React.createElement("g", { width: boundsWidth, height: boundsHeight, transform: `translate(${[boundsOffsetLeft, boundsOffsetTop].join(',')})`, ref: plotRef },
124
- xScale && (yScale === null || yScale === void 0 ? void 0 : yScale.length) && (React.createElement(React.Fragment, null,
125
- yAxisDataItems.map((axisData, index) => (React.createElement(AxisY, { key: index, htmlLayout: htmlLayout, plotAfterRef: plotAfterRef, plotBeforeRef: plotBeforeRef, preparedAxisData: axisData }))),
126
- xAxis && (React.createElement("g", { transform: `translate(0, ${boundsHeight})` },
127
- React.createElement(AxisX, { axis: xAxis, boundsOffsetLeft: boundsOffsetLeft, boundsOffsetTop: boundsOffsetTop, height: boundsHeight, htmlLayout: htmlLayout, leftmostLimit: svgXPos, plotAfterRef: plotAfterRef, plotBeforeRef: plotBeforeRef, scale: xScale, split: preparedSplit, width: boundsWidth }))))),
125
+ xScale && xAxis && (React.createElement("g", { transform: `translate(0, ${boundsHeight})` },
126
+ React.createElement(AxisX, { axis: xAxis, boundsOffsetLeft: boundsOffsetLeft, boundsOffsetTop: boundsOffsetTop, height: boundsHeight, htmlLayout: htmlLayout, leftmostLimit: svgXPos, plotAfterRef: plotAfterRef, plotBeforeRef: plotBeforeRef, scale: xScale, split: preparedSplit, width: boundsWidth }))),
127
+ Boolean(yAxisDataItems.length) && (React.createElement(React.Fragment, null, yAxisDataItems.map((axisData, index) => {
128
+ if (!axisData) {
129
+ return null;
130
+ }
131
+ return (React.createElement(AxisY, { key: index, htmlLayout: htmlLayout, plotAfterRef: plotAfterRef, plotBeforeRef: plotBeforeRef, preparedAxisData: axisData }));
132
+ }))),
128
133
  React.createElement("g", { ref: plotBeforeRef }),
129
134
  shapes,
130
135
  React.createElement("g", { ref: plotAfterRef })),
@@ -51,6 +51,6 @@ export declare function useChartInnerProps(props: Props): {
51
51
  xAxis: PreparedAxis | null;
52
52
  xScale: import("../../hooks").ChartScale | undefined;
53
53
  yAxis: PreparedAxis[];
54
- yScale: import("../../hooks").ChartScale[] | undefined;
54
+ yScale: (import("../../hooks").ChartScale | undefined)[] | undefined;
55
55
  };
56
56
  export {};
@@ -20,6 +20,8 @@ export function useChartInnerProps(props) {
20
20
  colors: data.colors,
21
21
  title: data.title,
22
22
  tooltip: data.tooltip,
23
+ xAxis: data.xAxis,
24
+ yAxes: data.yAxis,
23
25
  });
24
26
  const preparedSeriesOptions = React.useMemo(() => {
25
27
  return getPreparedOptions(data.series.options);
@@ -10,5 +10,6 @@ export interface ChartTooltipContentProps {
10
10
  totals?: ChartTooltip['totals'];
11
11
  xAxis?: ChartXAxis | null;
12
12
  yAxis?: ChartYAxis;
13
+ qa?: string;
13
14
  }
14
15
  export declare const ChartTooltipContent: (props: ChartTooltipContentProps) => React.JSX.Element | null;
@@ -2,10 +2,10 @@ import React from 'react';
2
2
  import isNil from 'lodash/isNil';
3
3
  import { DefaultTooltipContent } from './DefaultTooltipContent';
4
4
  export const ChartTooltipContent = (props) => {
5
- const { hovered, xAxis, yAxis, renderer, rowRenderer, valueFormat, headerFormat, totals, pinned, } = props;
5
+ const { hovered, xAxis, yAxis, renderer, rowRenderer, valueFormat, headerFormat, totals, pinned, qa, } = props;
6
6
  if (!hovered) {
7
7
  return null;
8
8
  }
9
9
  const customTooltip = renderer === null || renderer === void 0 ? void 0 : renderer({ hovered, xAxis, yAxis });
10
- return isNil(customTooltip) ? (React.createElement(DefaultTooltipContent, { hovered: hovered, pinned: pinned, rowRenderer: rowRenderer, totals: totals, valueFormat: valueFormat, headerFormat: headerFormat, xAxis: xAxis, yAxis: yAxis })) : (customTooltip);
10
+ return isNil(customTooltip) ? (React.createElement(DefaultTooltipContent, { hovered: hovered, pinned: pinned, rowRenderer: rowRenderer, totals: totals, valueFormat: valueFormat, headerFormat: headerFormat, xAxis: xAxis, yAxis: yAxis, qa: qa })) : (customTooltip);
11
11
  };
@@ -9,6 +9,7 @@ type Props = {
9
9
  headerFormat?: ChartTooltip['headerFormat'];
10
10
  xAxis?: ChartXAxis | null;
11
11
  yAxis?: ChartYAxis;
12
+ qa?: string;
12
13
  };
13
- export declare const DefaultTooltipContent: ({ hovered, pinned, rowRenderer, totals, valueFormat, headerFormat, xAxis, yAxis, }: Props) => React.JSX.Element;
14
+ export declare const DefaultTooltipContent: ({ hovered, pinned, rowRenderer, totals, valueFormat, headerFormat, xAxis, yAxis, qa, }: Props) => React.JSX.Element;
14
15
  export {};
@@ -10,13 +10,13 @@ import { Row } from './Row';
10
10
  import { RowWithAggregation } from './RowWithAggregation';
11
11
  import { getDefaultValueFormat, getHoveredValues, getMeasureValue, getPreparedAggregation, getXRowData, } from './utils';
12
12
  const b = block('tooltip');
13
- export const DefaultTooltipContent = ({ hovered, pinned, rowRenderer, totals, valueFormat, headerFormat, xAxis, yAxis, }) => {
13
+ export const DefaultTooltipContent = ({ hovered, pinned, rowRenderer, totals, valueFormat, headerFormat, xAxis, yAxis, qa, }) => {
14
14
  var _a;
15
15
  const [visibleRows, setVisibleRows] = React.useState();
16
16
  const [maxContentRowsHeight, setMaxContentRowsHeight] = React.useState();
17
17
  const [scrollBarWidth, setScrollBarWidth] = React.useState(0);
18
18
  const contentRowsRef = React.useRef(null);
19
- const measureValue = getMeasureValue({ data: hovered, xAxis, yAxis });
19
+ const measureValue = getMeasureValue({ data: hovered, xAxis, yAxis, headerFormat });
20
20
  const hoveredValues = getHoveredValues({ hovered, xAxis, yAxis });
21
21
  const prevHoveredValues = usePrevious(hoveredValues);
22
22
  const visibleHovered = pinned || !visibleRows ? hovered : hovered.slice(0, visibleRows);
@@ -83,7 +83,7 @@ export const DefaultTooltipContent = ({ hovered, pinned, rowRenderer, totals, va
83
83
  setScrollBarWidth(0);
84
84
  }
85
85
  }, [pinned]);
86
- return (React.createElement("div", { className: b('content') },
86
+ return (React.createElement("div", { className: b('content'), "data-qa": qa },
87
87
  formattedHeadValue && (React.createElement("div", { className: b('series-name'), dangerouslySetInnerHTML: { __html: formattedHeadValue } })),
88
88
  React.createElement("div", { className: b('content-rows', { pinned }), ref: contentRowsRef, style: { maxHeight: maxContentRowsHeight } },
89
89
  visibleHovered.map((seriesItem, i) => {
@@ -1,14 +1,15 @@
1
1
  import type { ChartSeriesData, ChartTooltip, ChartTooltipTotalsAggregationValue, ChartTooltipTotalsBuiltInAggregation, ChartXAxis, ChartYAxis, TooltipDataChunk, ValueFormat } from '../../../types';
2
2
  export type HoveredValue = string | number | null | undefined;
3
3
  export declare function getXRowData(data: ChartSeriesData, xAxis?: ChartXAxis | null): string | number | undefined;
4
- export declare function getDefaultValueFormat({ axis, }: {
4
+ export declare function getDefaultValueFormat({ axis, closestPointsRange, }: {
5
5
  axis?: ChartXAxis | ChartYAxis | null;
6
+ closestPointsRange?: number;
6
7
  }): ValueFormat | undefined;
7
- export declare const getMeasureValue: ({ data, xAxis, yAxis, valueFormat, }: {
8
+ export declare const getMeasureValue: ({ data, xAxis, yAxis, headerFormat, }: {
8
9
  data: TooltipDataChunk[];
9
10
  xAxis?: ChartXAxis | null;
10
11
  yAxis?: ChartYAxis;
11
- valueFormat?: ValueFormat;
12
+ headerFormat?: ChartTooltip["headerFormat"];
12
13
  }) => {
13
14
  value: string | null;
14
15
  formattedValue?: undefined;
@@ -1,7 +1,6 @@
1
1
  import get from 'lodash/get';
2
- import { DEFAULT_DATE_FORMAT } from '../../../constants';
3
2
  import { i18n } from '../../../i18n';
4
- import { getDataCategoryValue } from '../../../utils';
3
+ import { getDataCategoryValue, getDefaultDateFormat } from '../../../utils';
5
4
  import { getFormattedValue } from '../../../utils/chart/format';
6
5
  function getRowData(fieldName, data, axis) {
7
6
  switch (axis === null || axis === void 0 ? void 0 : axis.type) {
@@ -20,7 +19,7 @@ export function getXRowData(data, xAxis) {
20
19
  function getYRowData(data, yAxis) {
21
20
  return getRowData('y', data, yAxis);
22
21
  }
23
- export function getDefaultValueFormat({ axis, }) {
22
+ export function getDefaultValueFormat({ axis, closestPointsRange, }) {
24
23
  switch (axis === null || axis === void 0 ? void 0 : axis.type) {
25
24
  case 'linear':
26
25
  case 'logarithmic': {
@@ -31,14 +30,14 @@ export function getDefaultValueFormat({ axis, }) {
31
30
  case 'datetime': {
32
31
  return {
33
32
  type: 'date',
34
- format: DEFAULT_DATE_FORMAT,
33
+ format: getDefaultDateFormat(closestPointsRange),
35
34
  };
36
35
  }
37
36
  default:
38
37
  return undefined;
39
38
  }
40
39
  }
41
- export const getMeasureValue = ({ data, xAxis, yAxis, valueFormat, }) => {
40
+ export const getMeasureValue = ({ data, xAxis, yAxis, headerFormat, }) => {
42
41
  var _a, _b, _c, _d, _e, _f;
43
42
  if (data.every((item) => ['pie', 'treemap', 'waterfall', 'sankey'].includes(item.series.type))) {
44
43
  return null;
@@ -49,18 +48,16 @@ export const getMeasureValue = ({ data, xAxis, yAxis, valueFormat, }) => {
49
48
  }
50
49
  if (data.some((item) => item.series.type === 'bar-y')) {
51
50
  const value = getYRowData((_c = data[0]) === null || _c === void 0 ? void 0 : _c.data, yAxis);
52
- const format = valueFormat !== null && valueFormat !== void 0 ? valueFormat : getDefaultValueFormat({ axis: yAxis });
53
51
  const formattedValue = getFormattedValue({
54
52
  value: getYRowData((_d = data[0]) === null || _d === void 0 ? void 0 : _d.data, yAxis),
55
- format,
53
+ format: headerFormat,
56
54
  });
57
55
  return { value, formattedValue };
58
56
  }
59
57
  const value = getXRowData((_e = data[0]) === null || _e === void 0 ? void 0 : _e.data, xAxis);
60
- const format = valueFormat !== null && valueFormat !== void 0 ? valueFormat : getDefaultValueFormat({ axis: xAxis });
61
58
  const formattedValue = getFormattedValue({
62
59
  value: getXRowData((_f = data[0]) === null || _f === void 0 ? void 0 : _f.data, xAxis),
63
- format,
60
+ format: headerFormat,
64
61
  });
65
62
  return { value, formattedValue };
66
63
  };
@@ -23,5 +23,5 @@ export const Tooltip = (props) => {
23
23
  }, [left, top]);
24
24
  return (hovered === null || hovered === void 0 ? void 0 : hovered.length) ? (React.createElement(Popup, { anchorElement: anchor, className: b({ pinned: tooltipPinned }), disableTransition: true, floatingStyles: tooltipPinned ? undefined : { pointerEvents: 'none' }, offset: { mainAxis: 20 }, onOpenChange: tooltipPinned ? handleOnOpenChange : undefined, open: true, placement: ['right', 'left', 'top', 'bottom'] },
25
25
  React.createElement("div", { className: b('popup-content') },
26
- React.createElement(ChartTooltipContent, { hovered: hovered, pinned: tooltipPinned, renderer: tooltip.renderer, rowRenderer: tooltip.rowRenderer, totals: tooltip.totals, valueFormat: tooltip.valueFormat, headerFormat: tooltip.headerFormat, xAxis: xAxis, yAxis: yAxis })))) : null;
26
+ React.createElement(ChartTooltipContent, { hovered: hovered, pinned: tooltipPinned, renderer: tooltip.renderer, rowRenderer: tooltip.rowRenderer, totals: tooltip.totals, valueFormat: tooltip.valueFormat, headerFormat: tooltip.headerFormat, xAxis: xAxis, yAxis: yAxis, qa: tooltip.qa })))) : null;
27
27
  };