@gravity-ui/charts 1.17.0 → 1.18.1

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 (115) hide show
  1. package/dist/cjs/components/AxisY/prepare-axis-data.d.ts +4 -2
  2. package/dist/cjs/components/AxisY/prepare-axis-data.js +11 -10
  3. package/dist/cjs/components/AxisY/utils.d.ts +4 -2
  4. package/dist/cjs/components/AxisY/utils.js +47 -23
  5. package/dist/cjs/components/ChartInner/index.js +11 -5
  6. package/dist/cjs/components/ChartInner/useChartInnerProps.d.ts +1 -1
  7. package/dist/cjs/components/ChartInner/useChartInnerProps.js +3 -2
  8. package/dist/cjs/components/Tooltip/ChartTooltipContent.d.ts +1 -0
  9. package/dist/cjs/components/Tooltip/ChartTooltipContent.js +2 -2
  10. package/dist/cjs/components/Tooltip/DefaultTooltipContent/index.d.ts +2 -1
  11. package/dist/cjs/components/Tooltip/DefaultTooltipContent/index.js +3 -3
  12. package/dist/cjs/components/Tooltip/DefaultTooltipContent/utils.d.ts +4 -3
  13. package/dist/cjs/components/Tooltip/DefaultTooltipContent/utils.js +6 -9
  14. package/dist/cjs/components/Tooltip/index.js +1 -1
  15. package/dist/cjs/hooks/useAxisScales/index.d.ts +3 -4
  16. package/dist/cjs/hooks/useAxisScales/index.js +82 -28
  17. package/dist/cjs/hooks/useChartOptions/index.d.ts +3 -1
  18. package/dist/cjs/hooks/useChartOptions/index.js +3 -3
  19. package/dist/cjs/hooks/useChartOptions/tooltip.d.ts +4 -1
  20. package/dist/cjs/hooks/useChartOptions/tooltip.js +18 -3
  21. package/dist/cjs/hooks/useChartOptions/utils.d.ts +5 -2
  22. package/dist/cjs/hooks/useChartOptions/utils.js +2 -3
  23. package/dist/cjs/hooks/useChartOptions/x-axis.js +21 -9
  24. package/dist/cjs/hooks/useChartOptions/y-axis.d.ts +1 -3
  25. package/dist/cjs/hooks/useChartOptions/y-axis.js +23 -12
  26. package/dist/cjs/hooks/useCrosshair/index.d.ts +1 -1
  27. package/dist/cjs/hooks/useCrosshair/index.js +2 -1
  28. package/dist/cjs/hooks/useSeries/prepare-bar-y.js +3 -1
  29. package/dist/cjs/hooks/useShapes/area/prepare-data.d.ts +1 -1
  30. package/dist/cjs/hooks/useShapes/area/prepare-data.js +3 -0
  31. package/dist/cjs/hooks/useShapes/bar-x/prepare-data.d.ts +1 -1
  32. package/dist/cjs/hooks/useShapes/bar-x/prepare-data.js +3 -0
  33. package/dist/cjs/hooks/useShapes/bar-y/prepare-data.d.ts +5 -3
  34. package/dist/cjs/hooks/useShapes/bar-y/prepare-data.js +46 -20
  35. package/dist/cjs/hooks/useShapes/index.d.ts +1 -1
  36. package/dist/cjs/hooks/useShapes/index.js +2 -0
  37. package/dist/cjs/hooks/useShapes/line/prepare-data.d.ts +1 -1
  38. package/dist/cjs/hooks/useShapes/line/prepare-data.js +3 -0
  39. package/dist/cjs/hooks/useShapes/scatter/prepare-data.d.ts +1 -1
  40. package/dist/cjs/hooks/useShapes/scatter/prepare-data.js +6 -0
  41. package/dist/cjs/hooks/useShapes/waterfall/prepare-data.d.ts +1 -1
  42. package/dist/cjs/hooks/useShapes/waterfall/prepare-data.js +6 -3
  43. package/dist/cjs/hooks/useZoom/index.d.ts +1 -1
  44. package/dist/cjs/hooks/useZoom/types.d.ts +1 -1
  45. package/dist/cjs/hooks/useZoom/utils.d.ts +1 -1
  46. package/dist/cjs/hooks/useZoom/utils.js +46 -18
  47. package/dist/cjs/hooks/utils/bar-y.d.ts +7 -10
  48. package/dist/cjs/hooks/utils/bar-y.js +33 -18
  49. package/dist/cjs/types/chart/tooltip.d.ts +3 -0
  50. package/dist/cjs/utils/chart/array.d.ts +1 -0
  51. package/dist/cjs/utils/chart/array.js +12 -0
  52. package/dist/cjs/utils/chart/format.js +2 -2
  53. package/dist/cjs/utils/chart/index.d.ts +1 -0
  54. package/dist/cjs/utils/chart/index.js +3 -1
  55. package/dist/cjs/utils/chart/labels.d.ts +27 -5
  56. package/dist/cjs/utils/chart/labels.js +39 -3
  57. package/dist/cjs/utils/chart/zoom.js +14 -8
  58. package/dist/esm/components/AxisY/prepare-axis-data.d.ts +4 -2
  59. package/dist/esm/components/AxisY/prepare-axis-data.js +11 -10
  60. package/dist/esm/components/AxisY/utils.d.ts +4 -2
  61. package/dist/esm/components/AxisY/utils.js +47 -23
  62. package/dist/esm/components/ChartInner/index.js +11 -5
  63. package/dist/esm/components/ChartInner/useChartInnerProps.d.ts +1 -1
  64. package/dist/esm/components/ChartInner/useChartInnerProps.js +3 -2
  65. package/dist/esm/components/Tooltip/ChartTooltipContent.d.ts +1 -0
  66. package/dist/esm/components/Tooltip/ChartTooltipContent.js +2 -2
  67. package/dist/esm/components/Tooltip/DefaultTooltipContent/index.d.ts +2 -1
  68. package/dist/esm/components/Tooltip/DefaultTooltipContent/index.js +3 -3
  69. package/dist/esm/components/Tooltip/DefaultTooltipContent/utils.d.ts +4 -3
  70. package/dist/esm/components/Tooltip/DefaultTooltipContent/utils.js +6 -9
  71. package/dist/esm/components/Tooltip/index.js +1 -1
  72. package/dist/esm/hooks/useAxisScales/index.d.ts +3 -4
  73. package/dist/esm/hooks/useAxisScales/index.js +82 -28
  74. package/dist/esm/hooks/useChartOptions/index.d.ts +3 -1
  75. package/dist/esm/hooks/useChartOptions/index.js +3 -3
  76. package/dist/esm/hooks/useChartOptions/tooltip.d.ts +4 -1
  77. package/dist/esm/hooks/useChartOptions/tooltip.js +18 -3
  78. package/dist/esm/hooks/useChartOptions/utils.d.ts +5 -2
  79. package/dist/esm/hooks/useChartOptions/utils.js +2 -3
  80. package/dist/esm/hooks/useChartOptions/x-axis.js +21 -9
  81. package/dist/esm/hooks/useChartOptions/y-axis.d.ts +1 -3
  82. package/dist/esm/hooks/useChartOptions/y-axis.js +23 -12
  83. package/dist/esm/hooks/useCrosshair/index.d.ts +1 -1
  84. package/dist/esm/hooks/useCrosshair/index.js +2 -1
  85. package/dist/esm/hooks/useSeries/prepare-bar-y.js +3 -1
  86. package/dist/esm/hooks/useShapes/area/prepare-data.d.ts +1 -1
  87. package/dist/esm/hooks/useShapes/area/prepare-data.js +3 -0
  88. package/dist/esm/hooks/useShapes/bar-x/prepare-data.d.ts +1 -1
  89. package/dist/esm/hooks/useShapes/bar-x/prepare-data.js +3 -0
  90. package/dist/esm/hooks/useShapes/bar-y/prepare-data.d.ts +5 -3
  91. package/dist/esm/hooks/useShapes/bar-y/prepare-data.js +46 -20
  92. package/dist/esm/hooks/useShapes/index.d.ts +1 -1
  93. package/dist/esm/hooks/useShapes/index.js +2 -0
  94. package/dist/esm/hooks/useShapes/line/prepare-data.d.ts +1 -1
  95. package/dist/esm/hooks/useShapes/line/prepare-data.js +3 -0
  96. package/dist/esm/hooks/useShapes/scatter/prepare-data.d.ts +1 -1
  97. package/dist/esm/hooks/useShapes/scatter/prepare-data.js +6 -0
  98. package/dist/esm/hooks/useShapes/waterfall/prepare-data.d.ts +1 -1
  99. package/dist/esm/hooks/useShapes/waterfall/prepare-data.js +6 -3
  100. package/dist/esm/hooks/useZoom/index.d.ts +1 -1
  101. package/dist/esm/hooks/useZoom/types.d.ts +1 -1
  102. package/dist/esm/hooks/useZoom/utils.d.ts +1 -1
  103. package/dist/esm/hooks/useZoom/utils.js +46 -18
  104. package/dist/esm/hooks/utils/bar-y.d.ts +7 -10
  105. package/dist/esm/hooks/utils/bar-y.js +33 -18
  106. package/dist/esm/types/chart/tooltip.d.ts +3 -0
  107. package/dist/esm/utils/chart/array.d.ts +1 -0
  108. package/dist/esm/utils/chart/array.js +12 -0
  109. package/dist/esm/utils/chart/format.js +2 -2
  110. package/dist/esm/utils/chart/index.d.ts +1 -0
  111. package/dist/esm/utils/chart/index.js +3 -1
  112. package/dist/esm/utils/chart/labels.d.ts +27 -5
  113. package/dist/esm/utils/chart/labels.js +39 -3
  114. package/dist/esm/utils/chart/zoom.js +14 -8
  115. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
- import type { ChartSeries, ChartTitle, ChartTooltip, ChartOptions as GeneralChartOptions } from '../../types';
1
+ import type { ChartSeries, ChartTitle, ChartTooltip, ChartXAxis, ChartYAxis, ChartOptions as GeneralChartOptions } from '../../types';
2
2
  import type { ChartOptions } from './types';
3
3
  type Args = {
4
4
  seriesData: ChartSeries[];
@@ -6,6 +6,8 @@ type Args = {
6
6
  colors?: string[];
7
7
  title?: ChartTitle;
8
8
  tooltip?: ChartTooltip;
9
+ yAxes?: ChartYAxis[];
10
+ xAxis?: ChartXAxis;
9
11
  };
10
12
  export declare const useChartOptions: (args: Args) => ChartOptions;
11
13
  export {};
@@ -4,10 +4,10 @@ import { getPreparedChart } from './chart';
4
4
  import { getPreparedTitle } from './title';
5
5
  import { getPreparedTooltip } from './tooltip';
6
6
  export const useChartOptions = (args) => {
7
- const { chart, colors, seriesData, title, tooltip } = args;
7
+ const { chart, colors, seriesData, title, tooltip, yAxes, xAxis } = args;
8
8
  const options = React.useMemo(() => {
9
9
  const preparedTitle = getPreparedTitle({ title });
10
- const preparedTooltip = getPreparedTooltip({ tooltip });
10
+ const preparedTooltip = getPreparedTooltip({ tooltip, seriesData, yAxes, xAxis });
11
11
  const preparedChart = getPreparedChart({
12
12
  chart,
13
13
  preparedTitle,
@@ -19,6 +19,6 @@ export const useChartOptions = (args) => {
19
19
  title: preparedTitle,
20
20
  tooltip: preparedTooltip,
21
21
  };
22
- }, [chart, colors, seriesData, title, tooltip]);
22
+ }, [chart, colors, seriesData, title, tooltip, xAxis, yAxes]);
23
23
  return options;
24
24
  };
@@ -1,5 +1,8 @@
1
- import type { ChartData } from '../../types';
1
+ import type { ChartData, ChartSeries, ChartXAxis, ChartYAxis } from '../../types';
2
2
  import type { PreparedTooltip } from './types';
3
3
  export declare const getPreparedTooltip: (args: {
4
4
  tooltip: ChartData["tooltip"];
5
+ seriesData: ChartSeries[];
6
+ yAxes?: ChartYAxis[];
7
+ xAxis?: ChartXAxis;
5
8
  }) => PreparedTooltip;
@@ -1,6 +1,21 @@
1
1
  import get from 'lodash/get';
2
+ import { getDefaultValueFormat } from '../../components/Tooltip/DefaultTooltipContent/utils';
3
+ import { getDomainDataXBySeries, getDomainDataYBySeries, getMinSpaceBetween } from '../../utils';
4
+ function getDefaultHeaderFormat({ seriesData, yAxes, xAxis, }) {
5
+ if (seriesData.every((item) => ['pie', 'treemap', 'waterfall', 'sankey', 'radar'].includes(item.type))) {
6
+ return undefined;
7
+ }
8
+ if (seriesData.some((item) => item.type === 'bar-y')) {
9
+ const domainData = getDomainDataYBySeries(seriesData);
10
+ const closestPointsRange = getMinSpaceBetween(domainData, (d) => d);
11
+ return getDefaultValueFormat({ axis: yAxes === null || yAxes === void 0 ? void 0 : yAxes[0], closestPointsRange });
12
+ }
13
+ const domainData = getDomainDataXBySeries(seriesData);
14
+ const closestPointsRange = getMinSpaceBetween(domainData, (d) => d);
15
+ return getDefaultValueFormat({ axis: xAxis, closestPointsRange });
16
+ }
2
17
  export const getPreparedTooltip = (args) => {
3
- var _a;
4
- const { tooltip } = args;
5
- return Object.assign(Object.assign({}, tooltip), { enabled: get(tooltip, 'enabled', true), throttle: (_a = tooltip === null || tooltip === void 0 ? void 0 : tooltip.throttle) !== null && _a !== void 0 ? _a : 0 });
18
+ var _a, _b;
19
+ const { tooltip, seriesData, yAxes, xAxis } = args;
20
+ return Object.assign(Object.assign({}, tooltip), { enabled: get(tooltip, 'enabled', true), throttle: (_a = tooltip === null || tooltip === void 0 ? void 0 : tooltip.throttle) !== null && _a !== void 0 ? _a : 0, headerFormat: (_b = tooltip === null || tooltip === void 0 ? void 0 : tooltip.headerFormat) !== null && _b !== void 0 ? _b : getDefaultHeaderFormat({ seriesData, yAxes, xAxis }) });
6
21
  };
@@ -1,4 +1,4 @@
1
- import type { AxisPlot, ChartYAxis } from '../../types';
1
+ import type { AxisPlot, ChartAxis } from '../../types';
2
2
  export declare function prepareAxisPlotLabel(d: AxisPlot): {
3
3
  text: string;
4
4
  style: {
@@ -8,4 +8,7 @@ export declare function prepareAxisPlotLabel(d: AxisPlot): {
8
8
  };
9
9
  padding: number;
10
10
  };
11
- export declare function getAxisCategories(axis?: ChartYAxis): string[] | undefined;
11
+ export declare function getAxisCategories({ categories, order, }?: {
12
+ categories?: string[];
13
+ order?: ChartAxis['order'];
14
+ }): string[] | undefined;
@@ -8,10 +8,9 @@ export function prepareAxisPlotLabel(d) {
8
8
  padding: (_e = (_d = d.label) === null || _d === void 0 ? void 0 : _d.padding) !== null && _e !== void 0 ? _e : 5,
9
9
  };
10
10
  }
11
- export function getAxisCategories(axis) {
12
- const categories = axis === null || axis === void 0 ? void 0 : axis.categories;
11
+ export function getAxisCategories({ categories, order, } = {}) {
13
12
  if (categories) {
14
- switch (axis.order) {
13
+ switch (order) {
15
14
  case 'reverse': {
16
15
  return reverse(categories);
17
16
  }
@@ -1,10 +1,15 @@
1
1
  import get from 'lodash/get';
2
2
  import { DASH_STYLE, DEFAULT_AXIS_LABEL_FONT_SIZE, axisCrosshairDefaults, axisLabelsDefaults, xAxisTitleDefaults, } from '../../constants';
3
- import { calculateCos, calculateNumericProperty, formatAxisTickLabel, getAxisItems, getClosestPointsRange, getHorizontalHtmlTextHeight, getHorizontalSvgTextHeight, getLabelsSize, getMaxTickCount, getTicksCount, hasOverlappingLabels, wrapText, } from '../../utils';
3
+ import { calculateCos, calculateNumericProperty, formatAxisTickLabel, getAxisItems, getClosestPointsRange, getDefaultDateFormat, getHorizontalHtmlTextHeight, getHorizontalSvgTextHeight, getLabelsSize, getMaxTickCount, getTicksCount, hasOverlappingLabels, wrapText, } from '../../utils';
4
4
  import { createXScale } from '../useAxisScales';
5
5
  import { getAxisCategories, prepareAxisPlotLabel } from './utils';
6
- async function getLabelSettings({ axis, seriesData, seriesOptions, width, autoRotation = true, }) {
6
+ async function setLabelSettings({ axis, seriesData, seriesOptions, width, autoRotation = true, }) {
7
7
  const scale = createXScale({ axis, series: seriesData, seriesOptions, boundsWidth: width });
8
+ if (!scale) {
9
+ axis.labels.height = 0;
10
+ axis.labels.rotation = 0;
11
+ return;
12
+ }
8
13
  const tickCount = getTicksCount({ axis, range: width });
9
14
  const ticks = getAxisItems({
10
15
  scale: scale,
@@ -12,6 +17,9 @@ async function getLabelSettings({ axis, seriesData, seriesOptions, width, autoRo
12
17
  maxCount: getMaxTickCount({ width, axis }),
13
18
  });
14
19
  const step = getClosestPointsRange(axis, ticks);
20
+ if (axis.type === 'datetime' && !axis.labels.dateFormat) {
21
+ axis.labels.dateFormat = getDefaultDateFormat(step);
22
+ }
15
23
  const labels = ticks.map((value) => {
16
24
  return formatAxisTickLabel({
17
25
  axis,
@@ -38,10 +46,11 @@ async function getLabelSettings({ axis, seriesData, seriesOptions, width, autoRo
38
46
  })).maxHeight
39
47
  : axis.labels.lineHeight;
40
48
  const maxHeight = rotation ? calculateCos(rotation) * axis.labels.maxWidth : labelsHeight;
41
- return { height: Math.min(maxHeight, labelsHeight), rotation };
49
+ axis.labels.height = Math.min(maxHeight, labelsHeight);
50
+ axis.labels.rotation = rotation;
42
51
  }
43
52
  export const getPreparedXAxis = async ({ xAxis, seriesData, seriesOptions, width, }) => {
44
- var _a, _b, _c;
53
+ var _a, _b, _c, _d, _e;
45
54
  const titleText = get(xAxis, 'title.text', '');
46
55
  const titleStyle = Object.assign(Object.assign({}, xAxisTitleDefaults.style), get(xAxis, 'title.style'));
47
56
  const titleMaxRowsCount = get(xAxis, 'title.maxRowCount', xAxisTitleDefaults.maxRowCount);
@@ -96,7 +105,12 @@ export const getPreparedXAxis = async ({ xAxis, seriesData, seriesOptions, width
96
105
  enabled: get(xAxis, 'grid.enabled', true),
97
106
  },
98
107
  ticks: {
99
- pixelInterval: get(xAxis, 'ticks.pixelInterval'),
108
+ pixelInterval: ((_c = xAxis === null || xAxis === void 0 ? void 0 : xAxis.ticks) === null || _c === void 0 ? void 0 : _c.interval)
109
+ ? calculateNumericProperty({
110
+ base: width,
111
+ value: xAxis.ticks.interval,
112
+ })
113
+ : (_d = xAxis === null || xAxis === void 0 ? void 0 : xAxis.ticks) === null || _d === void 0 ? void 0 : _d.pixelInterval,
100
114
  },
101
115
  position: 'bottom',
102
116
  plotIndex: 0,
@@ -129,14 +143,12 @@ export const getPreparedXAxis = async ({ xAxis, seriesData, seriesOptions, width
129
143
  visible: get(xAxis, 'visible', true),
130
144
  order: xAxis === null || xAxis === void 0 ? void 0 : xAxis.order,
131
145
  };
132
- const { height, rotation } = await getLabelSettings({
146
+ await setLabelSettings({
133
147
  axis: preparedXAxis,
134
148
  seriesData,
135
149
  seriesOptions,
136
150
  width,
137
- autoRotation: (_c = xAxis === null || xAxis === void 0 ? void 0 : xAxis.labels) === null || _c === void 0 ? void 0 : _c.autoRotation,
151
+ autoRotation: (_e = xAxis === null || xAxis === void 0 ? void 0 : xAxis.labels) === null || _e === void 0 ? void 0 : _e.autoRotation,
138
152
  });
139
- preparedXAxis.labels.height = height;
140
- preparedXAxis.labels.rotation = rotation;
141
153
  return preparedXAxis;
142
154
  };
@@ -1,11 +1,9 @@
1
1
  import type { ChartSeries, ChartYAxis } from '../../types';
2
- import type { PreparedSeriesOptions } from '../useSeries/types';
3
2
  import type { PreparedAxis } from './types';
4
- export declare const getPreparedYAxis: ({ height, boundsHeight, width, seriesData, seriesOptions, yAxis, }: {
3
+ export declare const getPreparedYAxis: ({ height, boundsHeight, width, seriesData, yAxis, }: {
5
4
  height: number;
6
5
  boundsHeight: number;
7
6
  width: number;
8
7
  seriesData: ChartSeries[];
9
- seriesOptions: PreparedSeriesOptions;
10
8
  yAxis: ChartYAxis[] | undefined;
11
9
  }) => Promise<PreparedAxis[]>;
@@ -1,11 +1,11 @@
1
1
  import get from 'lodash/get';
2
2
  import { getTickValues } from '../../components/AxisY/utils';
3
3
  import { DASH_STYLE, DEFAULT_AXIS_LABEL_FONT_SIZE, DEFAULT_AXIS_TYPE, axisCrosshairDefaults, axisLabelsDefaults, yAxisTitleDefaults, } from '../../constants';
4
- import { calculateNumericProperty, getDefaultMinYAxisValue, getHorizontalHtmlTextHeight, getHorizontalSvgTextHeight, getLabelFormatter, getLabelsSize, getTextSizeFn, isAxisRelatedSeries, wrapText, } from '../../utils';
4
+ import { calculateNumericProperty, formatAxisTickLabel, getClosestPointsRange, getDefaultDateFormat, getDefaultMinYAxisValue, getHorizontalHtmlTextHeight, getHorizontalSvgTextHeight, getLabelsSize, getScaleTicks, getTextSizeFn, isAxisRelatedSeries, wrapText, } from '../../utils';
5
5
  import { createYScale } from '../useAxisScales';
6
6
  import { getAxisCategories, prepareAxisPlotLabel } from './utils';
7
7
  const getAxisLabelMaxWidth = async (args) => {
8
- const { axis, seriesData, seriesOptions, height } = args;
8
+ const { axis, seriesData, height } = args;
9
9
  if (!axis.labels.enabled) {
10
10
  return { height: 0, width: 0 };
11
11
  }
@@ -13,13 +13,23 @@ const getAxisLabelMaxWidth = async (args) => {
13
13
  axis,
14
14
  boundsHeight: height,
15
15
  series: seriesData,
16
- seriesOptions,
17
16
  });
17
+ if (!scale) {
18
+ return { height: 0, width: 0 };
19
+ }
18
20
  const getTextSize = getTextSizeFn({ style: axis.labels.style });
19
21
  const labelLineHeight = (await getTextSize('Tmp')).height;
20
- const tickValues = getTickValues({ axis, scale, labelLineHeight });
21
- const labelFormatter = getLabelFormatter({ axis, scale });
22
- const labels = tickValues.map((tick) => labelFormatter(tick.value));
22
+ const tickValues = getTickValues({ axis, scale, labelLineHeight, series: seriesData });
23
+ const ticks = getScaleTicks(scale);
24
+ const tickStep = getClosestPointsRange(axis, ticks);
25
+ if (axis.type === 'datetime' && !axis.labels.dateFormat) {
26
+ axis.labels.dateFormat = getDefaultDateFormat(tickStep);
27
+ }
28
+ const labels = tickValues.map((tick) => formatAxisTickLabel({
29
+ axis,
30
+ value: tick.value,
31
+ step: tickStep,
32
+ }));
23
33
  const size = await getLabelsSize({
24
34
  labels,
25
35
  style: axis.labels.style,
@@ -28,7 +38,7 @@ const getAxisLabelMaxWidth = async (args) => {
28
38
  });
29
39
  return { height: size.maxHeight, width: size.maxWidth };
30
40
  };
31
- export const getPreparedYAxis = ({ height, boundsHeight, width, seriesData, seriesOptions, yAxis, }) => {
41
+ export const getPreparedYAxis = ({ height, boundsHeight, width, seriesData, yAxis, }) => {
32
42
  const axisByPlot = [];
33
43
  const axisItems = yAxis || [{}];
34
44
  const hasAxisRelatedSeries = seriesData.some(isAxisRelatedSeries);
@@ -100,10 +110,12 @@ export const getPreparedYAxis = ({ height, boundsHeight, width, seriesData, seri
100
110
  (!firstPlotAxis && !((_d = axisByPlot[plotIndex][0].visible) !== null && _d !== void 0 ? _d : true))),
101
111
  },
102
112
  ticks: {
103
- pixelInterval: (_f = (_e = axisItem.ticks) === null || _e === void 0 ? void 0 : _e.pixelInterval) !== null && _f !== void 0 ? _f : calculateNumericProperty({
104
- base: height,
105
- value: (_g = axisItem.ticks) === null || _g === void 0 ? void 0 : _g.interval,
106
- }),
113
+ pixelInterval: ((_e = axisItem.ticks) === null || _e === void 0 ? void 0 : _e.interval)
114
+ ? calculateNumericProperty({
115
+ base: height,
116
+ value: (_f = axisItem.ticks) === null || _f === void 0 ? void 0 : _f.interval,
117
+ })
118
+ : (_g = axisItem.ticks) === null || _g === void 0 ? void 0 : _g.pixelInterval,
107
119
  },
108
120
  position: get(axisItem, 'position', defaultAxisPosition),
109
121
  plotIndex: get(axisItem, 'plotIndex', 0),
@@ -140,7 +152,6 @@ export const getPreparedYAxis = ({ height, boundsHeight, width, seriesData, seri
140
152
  const { height: labelsHeight, width: labelsWidth } = await getAxisLabelMaxWidth({
141
153
  axis: preparedAxis,
142
154
  seriesData,
143
- seriesOptions,
144
155
  height: boundsHeight,
145
156
  });
146
157
  preparedAxis.labels.height = labelsHeight;
@@ -6,7 +6,7 @@ type Props = {
6
6
  width: number;
7
7
  height: number;
8
8
  xScale?: ChartScale;
9
- yScale?: ChartScale[];
9
+ yScale?: (ChartScale | undefined)[];
10
10
  split: PreparedSplit;
11
11
  plotElement: SVGGElement | null;
12
12
  dispatcher: Dispatch<object>;
@@ -63,7 +63,8 @@ export const useCrosshair = (props) => {
63
63
  }
64
64
  yAxes.forEach((yAxis, index, currentArr) => {
65
65
  const yAxisScale = yScale[index];
66
- if (index !== 0 && !yAxis.crosshair.snap && !currentArr[0].crosshair.snap) {
66
+ if (!yAxisScale ||
67
+ (index !== 0 && !yAxis.crosshair.snap && !currentArr[0].crosshair.snap)) {
67
68
  return;
68
69
  }
69
70
  if (yAxis.crosshair.enabled && (hovered === null || hovered === void 0 ? void 0 : hovered.length)) {
@@ -9,7 +9,9 @@ async function prepareDataLabels(series) {
9
9
  const style = Object.assign({}, DEFAULT_DATALABELS_STYLE, (_a = series.dataLabels) === null || _a === void 0 ? void 0 : _a.style);
10
10
  const html = get(series, 'dataLabels.html', false);
11
11
  const labels = enabled
12
- ? series.data.map((d) => getFormattedValue(Object.assign({ value: d.x || d.label }, series.dataLabels)))
12
+ ? series.data
13
+ .filter((d) => Boolean(d.x || d.label))
14
+ .map((d) => getFormattedValue(Object.assign({ value: d.x || d.label }, series.dataLabels)))
13
15
  : [];
14
16
  const { maxHeight = 0, maxWidth = 0 } = await getLabelsSize({
15
17
  labels,
@@ -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;
@@ -2,11 +2,13 @@ import type { ChartScale } from '../../useAxisScales';
2
2
  import type { PreparedAxis } from '../../useChartOptions/types';
3
3
  import type { PreparedBarYSeries, PreparedSeriesOptions } from '../../useSeries/types';
4
4
  import type { BarYShapesArgs } from './types';
5
- export declare const prepareBarYData: (args: {
5
+ export declare function prepareBarYData(args: {
6
+ boundsHeight: number;
7
+ boundsWidth: number;
6
8
  series: PreparedBarYSeries[];
7
9
  seriesOptions: PreparedSeriesOptions;
8
10
  xAxis: PreparedAxis;
9
11
  xScale: ChartScale;
10
12
  yAxis: PreparedAxis[];
11
- yScale: ChartScale[];
12
- }) => Promise<BarYShapesArgs>;
13
+ yScale: (ChartScale | undefined)[];
14
+ }): Promise<BarYShapesArgs>;
@@ -1,17 +1,23 @@
1
1
  import { ascending, descending, sort } from 'd3';
2
2
  import get from 'lodash/get';
3
- import { filterOverlappingLabels, getLabelsSize, getTextSizeFn } from '../../../utils';
3
+ import { filterOverlappingLabels, getHtmlLabelConstraintedPosition, getLabelsSize, getSvgLabelConstraintedPosition, getTextSizeFn, } from '../../../utils';
4
4
  import { getFormattedValue } from '../../../utils/chart/format';
5
- import { getBarYLayoutForCategoryScale, getBarYLayoutForNumericScale, groupBarYDataByYValue, } from '../../utils';
5
+ import { getBarYLayout, groupBarYDataByYValue } from '../../utils';
6
6
  const DEFAULT_LABEL_PADDING = 7;
7
- export const prepareBarYData = async (args) => {
7
+ export async function prepareBarYData(args) {
8
8
  var _a;
9
- const { series, seriesOptions, yAxis, xScale, yScale: [yScale], } = args;
9
+ const { boundsHeight, boundsWidth, series, seriesOptions, yAxis, xScale, yScale: [yScale], } = 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
- const plotHeight = Math.abs(yScaleRange[0] - yScaleRange[1]);
15
21
  const sortingOptions = get(seriesOptions, 'bar-y.dataSorting');
16
22
  const comparator = (sortingOptions === null || sortingOptions === void 0 ? void 0 : sortingOptions.direction) === 'desc' ? descending : ascending;
17
23
  const sortKey = (() => {
@@ -28,13 +34,13 @@ export const prepareBarYData = async (args) => {
28
34
  }
29
35
  })();
30
36
  const groupedData = groupBarYDataByYValue(series, yAxis);
31
- const { bandSize, barGap, barSize } = yAxis[0].type === 'category'
32
- ? getBarYLayoutForCategoryScale({ groupedData, seriesOptions, yScale })
33
- : getBarYLayoutForNumericScale({
34
- groupedData,
35
- seriesOptions,
36
- plotHeight: plotHeight - plotHeight * yAxis[0].maxPadding,
37
- });
37
+ const plotHeight = Math.abs(yScaleRange[0] - yScaleRange[1]);
38
+ const { bandSize, barGap, barSize } = getBarYLayout({
39
+ groupedData,
40
+ seriesOptions,
41
+ plotHeight,
42
+ scale: yScale,
43
+ });
38
44
  const result = [];
39
45
  const baseRangeValue = xLinearScale.range()[0];
40
46
  Object.entries(groupedData).forEach(([yValue, val]) => {
@@ -99,7 +105,7 @@ export const prepareBarYData = async (args) => {
99
105
  });
100
106
  });
101
107
  let labels = [];
102
- const htmlElements = [];
108
+ let htmlElements = [];
103
109
  const map = new Map();
104
110
  for (let i = 0; i < result.length; i++) {
105
111
  const prepared = result[i];
@@ -117,12 +123,20 @@ export const prepareBarYData = async (args) => {
117
123
  style: dataLabels.style,
118
124
  html: dataLabels.html,
119
125
  });
120
- htmlElements.push({
126
+ const constrainedPosition = getHtmlLabelConstraintedPosition({
127
+ boundsHeight,
128
+ boundsWidth,
129
+ height,
130
+ width,
121
131
  x,
122
132
  y: y - height / 2,
133
+ });
134
+ htmlElements.push({
123
135
  content,
124
136
  size: { width, height },
125
137
  style: dataLabels.style,
138
+ x: constrainedPosition.x,
139
+ y: constrainedPosition.y,
126
140
  });
127
141
  }
128
142
  else {
@@ -131,24 +145,36 @@ export const prepareBarYData = async (args) => {
131
145
  }
132
146
  const getTextSize = map.get(dataLabels.style);
133
147
  const { width, height } = await getTextSize(content);
134
- labels.push({
148
+ const constrainedPosition = getSvgLabelConstraintedPosition({
149
+ boundsHeight,
150
+ boundsWidth,
151
+ height,
152
+ width,
135
153
  x,
136
154
  y: y + height / 2,
155
+ });
156
+ labels.push({
157
+ size: { width, height },
158
+ series: prepared.series,
159
+ style: dataLabels.style,
137
160
  text: content,
138
161
  textAnchor: dataLabels.inside ? 'middle' : 'right',
139
- style: dataLabels.style,
140
- series: prepared.series,
141
- size: { width, height },
162
+ x: constrainedPosition.x,
163
+ y: constrainedPosition.y,
142
164
  });
143
165
  }
144
166
  }
145
167
  }
146
- if (!((_a = result[0]) === null || _a === void 0 ? void 0 : _a.series.dataLabels.allowOverlap)) {
168
+ const allowOverlap = (_a = result[0]) === null || _a === void 0 ? void 0 : _a.series.dataLabels.allowOverlap;
169
+ if (labels.length && !allowOverlap) {
147
170
  labels = filterOverlappingLabels(labels);
148
171
  }
172
+ else if (htmlElements.length && !allowOverlap) {
173
+ htmlElements = filterOverlappingLabels(htmlElements);
174
+ }
149
175
  return {
150
176
  shapes: result,
151
177
  labels,
152
178
  htmlElements,
153
179
  };
154
- };
180
+ }
@@ -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;
@@ -56,6 +56,8 @@ export const useShapes = (args) => {
56
56
  case 'bar-y': {
57
57
  if (xAxis && xScale && (yScale === null || yScale === void 0 ? void 0 : yScale.length)) {
58
58
  const preparedData = await prepareBarYData({
59
+ boundsHeight,
60
+ boundsWidth,
59
61
  series: chartSeries,
60
62
  seriesOptions,
61
63
  xAxis,
@@ -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>;