@gravity-ui/charts 1.9.0 → 1.10.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 (199) hide show
  1. package/dist/cjs/components/Axis/AxisX.d.ts +2 -1
  2. package/dist/cjs/components/Axis/AxisX.js +147 -143
  3. package/dist/cjs/components/Axis/AxisY.d.ts +2 -1
  4. package/dist/cjs/components/Axis/AxisY.js +113 -91
  5. package/dist/cjs/components/ChartInner/index.js +23 -10
  6. package/dist/cjs/components/ChartInner/useChartInnerHandlers.d.ts +1 -1
  7. package/dist/cjs/components/ChartInner/useChartInnerProps.d.ts +8 -5
  8. package/dist/cjs/components/ChartInner/useChartInnerProps.js +55 -9
  9. package/dist/cjs/components/ChartInner/utils.d.ts +3 -0
  10. package/dist/cjs/components/ChartInner/utils.js +28 -0
  11. package/dist/cjs/components/Legend/index.js +199 -196
  12. package/dist/cjs/components/Tooltip/ChartTooltipContent.d.ts +1 -1
  13. package/dist/cjs/components/Tooltip/DefaultContent.d.ts +1 -1
  14. package/dist/cjs/components/Tooltip/DefaultContent.js +1 -1
  15. package/dist/cjs/components/Tooltip/index.d.ts +1 -1
  16. package/dist/cjs/hooks/hooks-utils/index.d.ts +1 -0
  17. package/dist/cjs/hooks/hooks-utils/index.js +1 -0
  18. package/dist/cjs/hooks/hooks-utils/zoom.d.ts +8 -0
  19. package/dist/cjs/hooks/hooks-utils/zoom.js +81 -0
  20. package/dist/cjs/hooks/useAxisScales/index.d.ts +4 -2
  21. package/dist/cjs/hooks/useAxisScales/index.js +22 -8
  22. package/dist/cjs/hooks/useBrush/index.d.ts +3 -0
  23. package/dist/cjs/hooks/useBrush/index.js +70 -0
  24. package/dist/cjs/hooks/useBrush/styles.css +10 -0
  25. package/dist/cjs/hooks/useBrush/types.d.ts +24 -0
  26. package/dist/cjs/hooks/useBrush/types.js +1 -0
  27. package/dist/cjs/hooks/useChartDimensions/index.d.ts +3 -3
  28. package/dist/cjs/hooks/useChartDimensions/index.js +2 -2
  29. package/dist/cjs/hooks/useChartDimensions/utils.d.ts +2 -2
  30. package/dist/cjs/hooks/useChartOptions/chart.d.ts +2 -1
  31. package/dist/cjs/hooks/useChartOptions/chart.js +80 -1
  32. package/dist/cjs/hooks/useChartOptions/index.js +3 -2
  33. package/dist/cjs/hooks/useChartOptions/types.d.ts +3 -1
  34. package/dist/cjs/hooks/useChartOptions/x-axis.d.ts +3 -3
  35. package/dist/cjs/hooks/useChartOptions/x-axis.js +11 -11
  36. package/dist/cjs/hooks/useChartOptions/y-axis.d.ts +3 -3
  37. package/dist/cjs/hooks/useChartOptions/y-axis.js +22 -18
  38. package/dist/cjs/hooks/useCrosshair/index.d.ts +1 -1
  39. package/dist/cjs/hooks/useCrosshair/index.js +2 -2
  40. package/dist/cjs/hooks/useSeries/index.d.ts +8 -6
  41. package/dist/cjs/hooks/useSeries/index.js +41 -22
  42. package/dist/cjs/hooks/useSeries/prepare-bar-y.d.ts +27 -2
  43. package/dist/cjs/hooks/useSeries/prepare-bar-y.js +5 -5
  44. package/dist/cjs/hooks/useSeries/prepare-legend.d.ts +1 -1
  45. package/dist/cjs/hooks/useSeries/prepare-legend.js +6 -5
  46. package/dist/cjs/hooks/useSeries/prepareSeries.d.ts +1 -1
  47. package/dist/cjs/hooks/useSeries/prepareSeries.js +2 -2
  48. package/dist/cjs/hooks/useShapes/area/index.js +1 -1
  49. package/dist/cjs/hooks/useShapes/area/prepare-data.d.ts +1 -1
  50. package/dist/cjs/hooks/useShapes/area/prepare-data.js +32 -16
  51. package/dist/cjs/hooks/useShapes/area/types.d.ts +1 -0
  52. package/dist/cjs/hooks/useShapes/bar-x/prepare-data.d.ts +1 -1
  53. package/dist/cjs/hooks/useShapes/bar-x/prepare-data.js +17 -13
  54. package/dist/cjs/hooks/useShapes/bar-y/prepare-data.d.ts +1 -1
  55. package/dist/cjs/hooks/useShapes/bar-y/prepare-data.js +6 -6
  56. package/dist/cjs/hooks/useShapes/index.d.ts +1 -1
  57. package/dist/cjs/hooks/useShapes/index.js +40 -31
  58. package/dist/cjs/hooks/useShapes/line/prepare-data.d.ts +1 -1
  59. package/dist/cjs/hooks/useShapes/line/prepare-data.js +14 -11
  60. package/dist/cjs/hooks/useShapes/line/types.d.ts +1 -0
  61. package/dist/cjs/hooks/useShapes/marker.js +2 -2
  62. package/dist/cjs/hooks/useShapes/pie/index.js +3 -3
  63. package/dist/cjs/hooks/useShapes/pie/prepare-data.d.ts +1 -1
  64. package/dist/cjs/hooks/useShapes/pie/prepare-data.js +15 -11
  65. package/dist/cjs/hooks/useShapes/radar/prepare-data.d.ts +1 -1
  66. package/dist/cjs/hooks/useShapes/radar/prepare-data.js +6 -7
  67. package/dist/cjs/hooks/useShapes/radar/types.d.ts +1 -0
  68. package/dist/cjs/hooks/useShapes/scatter/index.js +0 -1
  69. package/dist/cjs/hooks/useShapes/scatter/prepare-data.js +2 -0
  70. package/dist/cjs/hooks/useShapes/scatter/types.d.ts +1 -0
  71. package/dist/cjs/hooks/useShapes/treemap/prepare-data.d.ts +1 -1
  72. package/dist/cjs/hooks/useShapes/treemap/prepare-data.js +19 -16
  73. package/dist/cjs/hooks/useShapes/waterfall/prepare-data.d.ts +1 -1
  74. package/dist/cjs/hooks/useShapes/waterfall/prepare-data.js +8 -7
  75. package/dist/cjs/hooks/useZoom/index.d.ts +18 -0
  76. package/dist/cjs/hooks/useZoom/index.js +54 -0
  77. package/dist/cjs/hooks/useZoom/types.d.ts +19 -0
  78. package/dist/cjs/hooks/useZoom/types.js +1 -0
  79. package/dist/cjs/hooks/useZoom/utils.d.ts +12 -0
  80. package/dist/cjs/hooks/useZoom/utils.js +128 -0
  81. package/dist/cjs/types/chart/chart.d.ts +5 -0
  82. package/dist/cjs/types/chart/pie.d.ts +1 -1
  83. package/dist/cjs/types/chart/tooltip.d.ts +1 -1
  84. package/dist/cjs/types/chart/zoom.d.ts +36 -0
  85. package/dist/cjs/types/chart/zoom.js +1 -0
  86. package/dist/cjs/types/index.d.ts +1 -0
  87. package/dist/cjs/types/index.js +1 -0
  88. package/dist/cjs/types/misc.d.ts +7 -0
  89. package/dist/cjs/utils/chart/axis-generators/bottom.d.ts +1 -1
  90. package/dist/cjs/utils/chart/axis-generators/bottom.js +25 -25
  91. package/dist/cjs/utils/chart/axis.d.ts +1 -1
  92. package/dist/cjs/utils/chart/axis.js +2 -2
  93. package/dist/cjs/utils/chart/get-closest-data.js +1 -1
  94. package/dist/cjs/utils/chart/text.d.ts +7 -7
  95. package/dist/cjs/utils/chart/text.js +37 -29
  96. package/dist/cjs/utils/chart-ui/pie-center-text.d.ts +1 -1
  97. package/dist/cjs/utils/chart-ui/pie-center-text.js +2 -2
  98. package/dist/cjs/validation/index.d.ts +1 -1
  99. package/dist/cjs/validation/index.js +16 -16
  100. package/dist/esm/components/Axis/AxisX.d.ts +2 -1
  101. package/dist/esm/components/Axis/AxisX.js +147 -143
  102. package/dist/esm/components/Axis/AxisY.d.ts +2 -1
  103. package/dist/esm/components/Axis/AxisY.js +113 -91
  104. package/dist/esm/components/ChartInner/index.js +23 -10
  105. package/dist/esm/components/ChartInner/useChartInnerHandlers.d.ts +1 -1
  106. package/dist/esm/components/ChartInner/useChartInnerProps.d.ts +8 -5
  107. package/dist/esm/components/ChartInner/useChartInnerProps.js +55 -9
  108. package/dist/esm/components/ChartInner/utils.d.ts +3 -0
  109. package/dist/esm/components/ChartInner/utils.js +28 -0
  110. package/dist/esm/components/Legend/index.js +199 -196
  111. package/dist/esm/components/Tooltip/ChartTooltipContent.d.ts +1 -1
  112. package/dist/esm/components/Tooltip/DefaultContent.d.ts +1 -1
  113. package/dist/esm/components/Tooltip/DefaultContent.js +1 -1
  114. package/dist/esm/components/Tooltip/index.d.ts +1 -1
  115. package/dist/esm/hooks/hooks-utils/index.d.ts +1 -0
  116. package/dist/esm/hooks/hooks-utils/index.js +1 -0
  117. package/dist/esm/hooks/hooks-utils/zoom.d.ts +8 -0
  118. package/dist/esm/hooks/hooks-utils/zoom.js +81 -0
  119. package/dist/esm/hooks/useAxisScales/index.d.ts +4 -2
  120. package/dist/esm/hooks/useAxisScales/index.js +22 -8
  121. package/dist/esm/hooks/useBrush/index.d.ts +3 -0
  122. package/dist/esm/hooks/useBrush/index.js +70 -0
  123. package/dist/esm/hooks/useBrush/styles.css +10 -0
  124. package/dist/esm/hooks/useBrush/types.d.ts +24 -0
  125. package/dist/esm/hooks/useBrush/types.js +1 -0
  126. package/dist/esm/hooks/useChartDimensions/index.d.ts +3 -3
  127. package/dist/esm/hooks/useChartDimensions/index.js +2 -2
  128. package/dist/esm/hooks/useChartDimensions/utils.d.ts +2 -2
  129. package/dist/esm/hooks/useChartOptions/chart.d.ts +2 -1
  130. package/dist/esm/hooks/useChartOptions/chart.js +80 -1
  131. package/dist/esm/hooks/useChartOptions/index.js +3 -2
  132. package/dist/esm/hooks/useChartOptions/types.d.ts +3 -1
  133. package/dist/esm/hooks/useChartOptions/x-axis.d.ts +3 -3
  134. package/dist/esm/hooks/useChartOptions/x-axis.js +11 -11
  135. package/dist/esm/hooks/useChartOptions/y-axis.d.ts +3 -3
  136. package/dist/esm/hooks/useChartOptions/y-axis.js +22 -18
  137. package/dist/esm/hooks/useCrosshair/index.d.ts +1 -1
  138. package/dist/esm/hooks/useCrosshair/index.js +2 -2
  139. package/dist/esm/hooks/useSeries/index.d.ts +8 -6
  140. package/dist/esm/hooks/useSeries/index.js +41 -22
  141. package/dist/esm/hooks/useSeries/prepare-bar-y.d.ts +27 -2
  142. package/dist/esm/hooks/useSeries/prepare-bar-y.js +5 -5
  143. package/dist/esm/hooks/useSeries/prepare-legend.d.ts +1 -1
  144. package/dist/esm/hooks/useSeries/prepare-legend.js +6 -5
  145. package/dist/esm/hooks/useSeries/prepareSeries.d.ts +1 -1
  146. package/dist/esm/hooks/useSeries/prepareSeries.js +2 -2
  147. package/dist/esm/hooks/useShapes/area/index.js +1 -1
  148. package/dist/esm/hooks/useShapes/area/prepare-data.d.ts +1 -1
  149. package/dist/esm/hooks/useShapes/area/prepare-data.js +32 -16
  150. package/dist/esm/hooks/useShapes/area/types.d.ts +1 -0
  151. package/dist/esm/hooks/useShapes/bar-x/prepare-data.d.ts +1 -1
  152. package/dist/esm/hooks/useShapes/bar-x/prepare-data.js +17 -13
  153. package/dist/esm/hooks/useShapes/bar-y/prepare-data.d.ts +1 -1
  154. package/dist/esm/hooks/useShapes/bar-y/prepare-data.js +6 -6
  155. package/dist/esm/hooks/useShapes/index.d.ts +1 -1
  156. package/dist/esm/hooks/useShapes/index.js +40 -31
  157. package/dist/esm/hooks/useShapes/line/prepare-data.d.ts +1 -1
  158. package/dist/esm/hooks/useShapes/line/prepare-data.js +14 -11
  159. package/dist/esm/hooks/useShapes/line/types.d.ts +1 -0
  160. package/dist/esm/hooks/useShapes/marker.js +2 -2
  161. package/dist/esm/hooks/useShapes/pie/index.js +3 -3
  162. package/dist/esm/hooks/useShapes/pie/prepare-data.d.ts +1 -1
  163. package/dist/esm/hooks/useShapes/pie/prepare-data.js +15 -11
  164. package/dist/esm/hooks/useShapes/radar/prepare-data.d.ts +1 -1
  165. package/dist/esm/hooks/useShapes/radar/prepare-data.js +6 -7
  166. package/dist/esm/hooks/useShapes/radar/types.d.ts +1 -0
  167. package/dist/esm/hooks/useShapes/scatter/index.js +0 -1
  168. package/dist/esm/hooks/useShapes/scatter/prepare-data.js +2 -0
  169. package/dist/esm/hooks/useShapes/scatter/types.d.ts +1 -0
  170. package/dist/esm/hooks/useShapes/treemap/prepare-data.d.ts +1 -1
  171. package/dist/esm/hooks/useShapes/treemap/prepare-data.js +19 -16
  172. package/dist/esm/hooks/useShapes/waterfall/prepare-data.d.ts +1 -1
  173. package/dist/esm/hooks/useShapes/waterfall/prepare-data.js +8 -7
  174. package/dist/esm/hooks/useZoom/index.d.ts +18 -0
  175. package/dist/esm/hooks/useZoom/index.js +54 -0
  176. package/dist/esm/hooks/useZoom/types.d.ts +19 -0
  177. package/dist/esm/hooks/useZoom/types.js +1 -0
  178. package/dist/esm/hooks/useZoom/utils.d.ts +12 -0
  179. package/dist/esm/hooks/useZoom/utils.js +128 -0
  180. package/dist/esm/types/chart/chart.d.ts +5 -0
  181. package/dist/esm/types/chart/pie.d.ts +1 -1
  182. package/dist/esm/types/chart/tooltip.d.ts +1 -1
  183. package/dist/esm/types/chart/zoom.d.ts +36 -0
  184. package/dist/esm/types/chart/zoom.js +1 -0
  185. package/dist/esm/types/index.d.ts +1 -0
  186. package/dist/esm/types/index.js +1 -0
  187. package/dist/esm/types/misc.d.ts +7 -0
  188. package/dist/esm/utils/chart/axis-generators/bottom.d.ts +1 -1
  189. package/dist/esm/utils/chart/axis-generators/bottom.js +25 -25
  190. package/dist/esm/utils/chart/axis.d.ts +1 -1
  191. package/dist/esm/utils/chart/axis.js +2 -2
  192. package/dist/esm/utils/chart/get-closest-data.js +1 -1
  193. package/dist/esm/utils/chart/text.d.ts +7 -7
  194. package/dist/esm/utils/chart/text.js +37 -29
  195. package/dist/esm/utils/chart-ui/pie-center-text.d.ts +1 -1
  196. package/dist/esm/utils/chart-ui/pie-center-text.js +2 -2
  197. package/dist/esm/validation/index.d.ts +1 -1
  198. package/dist/esm/validation/index.js +16 -16
  199. package/package.json +2 -1
@@ -2,12 +2,12 @@ import get from 'lodash/get';
2
2
  import { DASH_STYLE, DEFAULT_AXIS_LABEL_FONT_SIZE, DEFAULT_AXIS_TYPE, axisCrosshairDefaults, axisLabelsDefaults, yAxisTitleDefaults, } from '../../constants';
3
3
  import { CHART_SERIES_WITH_VOLUME_ON_Y_AXIS, formatAxisTickLabel, getClosestPointsRange, getHorisontalSvgTextHeight, getLabelsSize, getScaleTicks, getWaterfallPointSubtotal, isAxisRelatedSeries, wrapText, } from '../../utils';
4
4
  import { createYScale } from '../useAxisScales';
5
- const getAxisLabelMaxWidth = (args) => {
6
- const { axis, series } = args;
5
+ const getAxisLabelMaxWidth = async (args) => {
6
+ const { axis, seriesData } = args;
7
7
  if (!axis.labels.enabled) {
8
8
  return 0;
9
9
  }
10
- const scale = createYScale(axis, series, 1);
10
+ const scale = createYScale(axis, seriesData, 1);
11
11
  const ticks = getScaleTicks(scale);
12
12
  // FIXME: it is necessary to filter data, since we do not draw overlapping ticks
13
13
  const step = getClosestPointsRange(axis, ticks);
@@ -16,17 +16,18 @@ const getAxisLabelMaxWidth = (args) => {
16
16
  value: tick,
17
17
  step,
18
18
  }));
19
- return getLabelsSize({
19
+ const size = await getLabelsSize({
20
20
  labels,
21
21
  style: axis.labels.style,
22
22
  rotation: axis.labels.rotation,
23
- }).maxWidth;
23
+ });
24
+ return size.maxWidth;
24
25
  };
25
- function getAxisMin(axis, series) {
26
+ function getAxisMin(axis, seriesData) {
26
27
  const min = axis === null || axis === void 0 ? void 0 : axis.min;
27
28
  if (typeof min === 'undefined' &&
28
- (series === null || series === void 0 ? void 0 : series.some((s) => CHART_SERIES_WITH_VOLUME_ON_Y_AXIS.includes(s.type)))) {
29
- return series.reduce((minValue, s) => {
29
+ (seriesData === null || seriesData === void 0 ? void 0 : seriesData.some((s) => CHART_SERIES_WITH_VOLUME_ON_Y_AXIS.includes(s.type)))) {
30
+ return seriesData.reduce((minValue, s) => {
30
31
  switch (s.type) {
31
32
  case 'waterfall': {
32
33
  const minSubTotal = s.data.reduce((res, d) => Math.min(res, getWaterfallPointSubtotal(d, s) || 0), 0);
@@ -42,14 +43,14 @@ function getAxisMin(axis, series) {
42
43
  }
43
44
  return min;
44
45
  }
45
- export const getPreparedYAxis = ({ series, yAxis, height, }) => {
46
+ export const getPreparedYAxis = ({ seriesData, yAxis, height, }) => {
46
47
  const axisByPlot = [];
47
48
  const axisItems = yAxis || [{}];
48
- const hasAxisRelatedSeries = series.some(isAxisRelatedSeries);
49
+ const hasAxisRelatedSeries = seriesData.some(isAxisRelatedSeries);
49
50
  if (!hasAxisRelatedSeries) {
50
- return [];
51
+ return Promise.resolve([]);
51
52
  }
52
- return axisItems.map((axisItem) => {
53
+ return Promise.all(axisItems.map(async (axisItem) => {
53
54
  var _a;
54
55
  const plotIndex = get(axisItem, 'plotIndex', 0);
55
56
  const firstPlotAxis = !axisByPlot[plotIndex];
@@ -65,12 +66,12 @@ export const getPreparedYAxis = ({ series, yAxis, height, }) => {
65
66
  const titleText = get(axisItem, 'title.text', '');
66
67
  const titleStyle = Object.assign(Object.assign({}, yAxisTitleDefaults.style), get(axisItem, 'title.style'));
67
68
  const titleMaxRowsCount = get(axisItem, 'title.maxRowCount', yAxisTitleDefaults.maxRowCount);
68
- const estimatedTitleRows = wrapText({
69
+ const estimatedTitleRows = (await wrapText({
69
70
  text: titleText,
70
71
  style: titleStyle,
71
72
  width: height,
72
- }).slice(0, titleMaxRowsCount);
73
- const titleSize = getLabelsSize({ labels: [titleText], style: titleStyle });
73
+ })).slice(0, titleMaxRowsCount);
74
+ const titleSize = await getLabelsSize({ labels: [titleText], style: titleStyle });
74
75
  const axisType = get(axisItem, 'type', DEFAULT_AXIS_TYPE);
75
76
  const preparedAxis = {
76
77
  type: axisType,
@@ -103,7 +104,7 @@ export const getPreparedYAxis = ({ series, yAxis, height, }) => {
103
104
  align: get(axisItem, 'title.align', yAxisTitleDefaults.align),
104
105
  maxRowCount: titleMaxRowsCount,
105
106
  },
106
- min: getAxisMin(axisItem, series),
107
+ min: getAxisMin(axisItem, seriesData),
107
108
  maxPadding: get(axisItem, 'maxPadding', 0.05),
108
109
  grid: {
109
110
  enabled: get(axisItem, 'grid.enabled', firstPlotAxis ||
@@ -141,8 +142,11 @@ export const getPreparedYAxis = ({ series, yAxis, height, }) => {
141
142
  visible: get(axisItem, 'visible', true),
142
143
  };
143
144
  if (labelsEnabled) {
144
- preparedAxis.labels.width = getAxisLabelMaxWidth({ axis: preparedAxis, series });
145
+ preparedAxis.labels.width = await getAxisLabelMaxWidth({
146
+ axis: preparedAxis,
147
+ seriesData,
148
+ });
145
149
  }
146
150
  return preparedAxis;
147
- });
151
+ }));
148
152
  };
@@ -1,7 +1,7 @@
1
1
  import type { Dispatch } from 'd3';
2
2
  import type { ChartScale, PreparedAxis, PreparedSplit } from '../../hooks';
3
3
  type Props = {
4
- xAxis: PreparedAxis;
4
+ xAxis: PreparedAxis | null;
5
5
  yAxes: PreparedAxis[];
6
6
  width: number;
7
7
  height: number;
@@ -5,7 +5,7 @@ import { useCrosshairHover } from './useCrosshairHover';
5
5
  export const useCrosshair = (props) => {
6
6
  var _a, _b;
7
7
  const { xScale, plotElement, yScale, dispatcher, xAxis, yAxes, split, width, height: totalHeight, boundsOffsetTop, boundsOffsetLeft, } = props;
8
- const crosshairEnabled = xAxis.crosshair.enabled || yAxes.some((axis) => axis.crosshair.enabled);
8
+ const crosshairEnabled = (xAxis === null || xAxis === void 0 ? void 0 : xAxis.crosshair.enabled) || yAxes.some((axis) => axis.crosshair.enabled);
9
9
  const { hovered, pointerPosition } = useCrosshairHover({ dispatcher, enabled: crosshairEnabled });
10
10
  const pointerXPos = (_a = pointerPosition === null || pointerPosition === void 0 ? void 0 : pointerPosition[0]) !== null && _a !== void 0 ? _a : 0;
11
11
  const pointerYPos = (_b = pointerPosition === null || pointerPosition === void 0 ? void 0 : pointerPosition[1]) !== null && _b !== void 0 ? _b : 0;
@@ -17,7 +17,7 @@ export const useCrosshair = (props) => {
17
17
  const svgElement = select(plotElement);
18
18
  svgElement.selectAll(`[${plotCrosshairDataAttr}]`).remove();
19
19
  const lineGenerator = line();
20
- if (xAxis.crosshair.enabled && (hovered === null || hovered === void 0 ? void 0 : hovered.length)) {
20
+ if ((xAxis === null || xAxis === void 0 ? void 0 : xAxis.crosshair.enabled) && (hovered === null || hovered === void 0 ? void 0 : hovered.length)) {
21
21
  const xAxisScale = xScale;
22
22
  const crosshairDataAttr = 'data-crosshair-x-line';
23
23
  const crosshairSelection = svgElement
@@ -1,17 +1,19 @@
1
1
  import type { ChartData } from '../../types';
2
2
  import type { PreparedAxis, PreparedChart } from '../useChartOptions/types';
3
- import type { OnLegendItemClick, PreparedSeries } from './types';
3
+ import type { OnLegendItemClick, PreparedLegend, PreparedSeries } from './types';
4
4
  type Args = {
5
5
  chartWidth: number;
6
6
  chartHeight: number;
7
7
  chartMargin: PreparedChart['margin'];
8
+ colors: string[];
8
9
  legend: ChartData['legend'];
9
- series: ChartData['series'];
10
+ originalSeriesData: ChartData['series']['data'];
11
+ seriesData: ChartData['series']['data'];
12
+ seriesOptions: ChartData['series']['options'];
10
13
  preparedYAxis: PreparedAxis[];
11
- colors: string[];
12
14
  };
13
15
  export declare const useSeries: (args: Args) => {
14
- legendItems: import("./types").LegendItem[][];
16
+ legendItems: never[] | import("./types").LegendItem[][];
15
17
  legendConfig: {
16
18
  offset: {
17
19
  left: number;
@@ -23,8 +25,8 @@ export declare const useSeries: (args: Args) => {
23
25
  end: number;
24
26
  }[];
25
27
  } | undefined;
26
- };
27
- preparedLegend: import("./types").PreparedLegend;
28
+ } | undefined;
29
+ preparedLegend: PreparedLegend | null;
28
30
  preparedSeries: PreparedSeries[];
29
31
  preparedSeriesOptions: import("../../constants").SeriesOptionsDefaults;
30
32
  handleLegendItemClick: OnLegendItemClick;
@@ -1,33 +1,48 @@
1
1
  import React from 'react';
2
2
  import { group, scaleOrdinal } from 'd3';
3
3
  import { getSeriesNames } from '../../utils';
4
+ import { usePrevious } from '../usePrevious';
4
5
  import { getLegendComponents, getPreparedLegend } from './prepare-legend';
5
6
  import { getPreparedOptions } from './prepare-options';
6
7
  import { prepareSeries } from './prepareSeries';
7
8
  import { getActiveLegendItems, getAllLegendItems } from './utils';
8
9
  export const useSeries = (args) => {
9
- const { chartWidth, chartHeight, chartMargin, legend, preparedYAxis, series: { data: series, options: seriesOptions }, colors, } = args;
10
- const preparedLegend = React.useMemo(() => getPreparedLegend({ legend, series }), [legend, series]);
11
- const preparedSeries = React.useMemo(() => {
12
- const seriesNames = getSeriesNames(series);
13
- const colorScale = scaleOrdinal(seriesNames, colors);
14
- const groupedSeries = group(series, (item) => item.type);
15
- return Array.from(groupedSeries).reduce((acc, [seriesType, seriesList]) => {
16
- acc.push(...prepareSeries({
17
- type: seriesType,
18
- series: seriesList,
19
- seriesOptions,
20
- legend: preparedLegend,
21
- colorScale,
22
- colors,
23
- }));
24
- return acc;
25
- }, []);
26
- }, [series, seriesOptions, preparedLegend]);
10
+ const { chartWidth, chartHeight, chartMargin, legend, originalSeriesData, preparedYAxis, seriesData, seriesOptions, colors, } = args;
11
+ const [preparedLegend, setPreparedLegend] = React.useState(null);
12
+ React.useEffect(() => {
13
+ getPreparedLegend({ legend, series: seriesData }).then((value) => setPreparedLegend(value));
14
+ }, [legend, seriesData]);
15
+ const [preparedSeries, setPreparedSeries] = React.useState([]);
16
+ const [activeLegendItems, setActiveLegendItems] = React.useState(getActiveLegendItems(preparedSeries));
17
+ React.useEffect(() => {
18
+ (async () => {
19
+ const seriesNames = getSeriesNames(seriesData);
20
+ const colorScale = scaleOrdinal(seriesNames, colors);
21
+ const groupedSeries = group(seriesData, (item) => item.type);
22
+ const acc = [];
23
+ if (!preparedLegend) {
24
+ return;
25
+ }
26
+ const list = Array.from(groupedSeries);
27
+ for (let i = 0; i < list.length; i++) {
28
+ const [seriesType, seriesList] = list[i];
29
+ acc.push(...(await prepareSeries({
30
+ type: seriesType,
31
+ series: seriesList,
32
+ seriesOptions,
33
+ legend: preparedLegend,
34
+ colorScale,
35
+ colors,
36
+ })));
37
+ }
38
+ setPreparedSeries(acc);
39
+ setActiveLegendItems(getActiveLegendItems(acc));
40
+ })();
41
+ }, [seriesData, seriesOptions, preparedLegend, colors]);
27
42
  const preparedSeriesOptions = React.useMemo(() => {
28
43
  return getPreparedOptions(seriesOptions);
29
44
  }, [seriesOptions]);
30
- const [activeLegendItems, setActiveLegendItems] = React.useState(getActiveLegendItems(preparedSeries));
45
+ const prevOriginalSeriesData = usePrevious(originalSeriesData);
31
46
  const chartSeries = React.useMemo(() => {
32
47
  return preparedSeries.map((singleSeries) => {
33
48
  if (singleSeries.legend.enabled) {
@@ -37,6 +52,9 @@ export const useSeries = (args) => {
37
52
  });
38
53
  }, [preparedSeries, activeLegendItems]);
39
54
  const { legendConfig, legendItems } = React.useMemo(() => {
55
+ if (!preparedLegend) {
56
+ return { legendConfig: undefined, legendItems: [] };
57
+ }
40
58
  return getLegendComponents({
41
59
  chartHeight,
42
60
  chartMargin,
@@ -67,10 +85,11 @@ export const useSeries = (args) => {
67
85
  }
68
86
  setActiveLegendItems(nextActiveLegendItems);
69
87
  }, [preparedSeries, activeLegendItems]);
70
- // FIXME: remove effect. It initiates extra rerender
71
88
  React.useEffect(() => {
72
- setActiveLegendItems(getActiveLegendItems(preparedSeries));
73
- }, [preparedSeries]);
89
+ if (prevOriginalSeriesData !== originalSeriesData) {
90
+ setActiveLegendItems(getActiveLegendItems(preparedSeries));
91
+ }
92
+ }, [originalSeriesData, prevOriginalSeriesData, preparedSeries]);
74
93
  return {
75
94
  legendItems,
76
95
  legendConfig,
@@ -1,11 +1,36 @@
1
1
  import type { ScaleOrdinal } from 'd3';
2
2
  import type { BarYSeries, ChartSeriesOptions } from '../../types';
3
- import type { PreparedLegend, PreparedSeries } from './types';
3
+ import type { PreparedLegend } from './types';
4
4
  type PrepareBarYSeriesArgs = {
5
5
  colorScale: ScaleOrdinal<string, string>;
6
6
  series: BarYSeries[];
7
7
  legend: PreparedLegend;
8
8
  seriesOptions?: ChartSeriesOptions;
9
9
  };
10
- export declare function prepareBarYSeries(args: PrepareBarYSeriesArgs): PreparedSeries[];
10
+ export declare function prepareBarYSeries(args: PrepareBarYSeriesArgs): Promise<({
11
+ type: BarYSeries["type"];
12
+ data: import("../../types").BarYSeriesData[];
13
+ stackId: string;
14
+ stacking: BarYSeries["stacking"];
15
+ dataLabels: {
16
+ enabled: boolean;
17
+ inside: boolean;
18
+ style: import("../../types").BaseTextStyle;
19
+ maxHeight: number;
20
+ maxWidth: number;
21
+ html: boolean;
22
+ format?: import("../../types").ValueFormat;
23
+ };
24
+ borderRadius: number;
25
+ } & {
26
+ color: string;
27
+ name: string;
28
+ id: string;
29
+ visible: boolean;
30
+ legend: {
31
+ enabled: boolean;
32
+ symbol: import("./types").PreparedLegendSymbol;
33
+ };
34
+ cursor: string | null;
35
+ })[]>;
11
36
  export {};
@@ -3,7 +3,7 @@ import { DEFAULT_DATALABELS_STYLE } from '../../constants';
3
3
  import { getLabelsSize, getUniqId } from '../../utils';
4
4
  import { getFormattedValue } from '../../utils/chart/format';
5
5
  import { getSeriesStackId, prepareLegendSymbol } from './utils';
6
- function prepareDataLabels(series) {
6
+ async function prepareDataLabels(series) {
7
7
  var _a, _b;
8
8
  const enabled = get(series, 'dataLabels.enabled', false);
9
9
  const style = Object.assign({}, DEFAULT_DATALABELS_STYLE, (_a = series.dataLabels) === null || _a === void 0 ? void 0 : _a.style);
@@ -11,7 +11,7 @@ function prepareDataLabels(series) {
11
11
  const labels = enabled
12
12
  ? series.data.map((d) => getFormattedValue(Object.assign({ value: d.x || d.label }, series.dataLabels)))
13
13
  : [];
14
- const { maxHeight = 0, maxWidth = 0 } = getLabelsSize({
14
+ const { maxHeight = 0, maxWidth = 0 } = await getLabelsSize({
15
15
  labels,
16
16
  style,
17
17
  html,
@@ -29,7 +29,7 @@ function prepareDataLabels(series) {
29
29
  }
30
30
  export function prepareBarYSeries(args) {
31
31
  const { colorScale, series: seriesList, seriesOptions, legend } = args;
32
- return seriesList.map((series) => {
32
+ return Promise.all(seriesList.map(async (series) => {
33
33
  var _a, _b, _c;
34
34
  const name = series.name || '';
35
35
  const color = series.color || colorScale(name);
@@ -46,9 +46,9 @@ export function prepareBarYSeries(args) {
46
46
  data: series.data.filter((d) => d.x !== null),
47
47
  stacking: series.stacking,
48
48
  stackId: getSeriesStackId(series),
49
- dataLabels: prepareDataLabels(series),
49
+ dataLabels: await prepareDataLabels(series),
50
50
  cursor: get(series, 'cursor', null),
51
51
  borderRadius: (_c = (_a = series.borderRadius) !== null && _a !== void 0 ? _a : (_b = seriesOptions === null || seriesOptions === void 0 ? void 0 : seriesOptions['bar-y']) === null || _b === void 0 ? void 0 : _b.borderRadius) !== null && _c !== void 0 ? _c : 0,
52
52
  };
53
- }, []);
53
+ }));
54
54
  }
@@ -4,7 +4,7 @@ import type { LegendItem, PreparedLegend, PreparedSeries } from './types';
4
4
  export declare function getPreparedLegend(args: {
5
5
  legend: ChartData['legend'];
6
6
  series: ChartData['series']['data'];
7
- }): PreparedLegend;
7
+ }): Promise<PreparedLegend>;
8
8
  export declare function getLegendComponents(args: {
9
9
  chartWidth: number;
10
10
  chartHeight: number;
@@ -6,7 +6,7 @@ import { CONTINUOUS_LEGEND_SIZE, legendDefaults } from '../../constants';
6
6
  import { getDefaultColorStops, getDomainForContinuousColorScale, getHorisontalSvgTextHeight, getLabelsSize, } from '../../utils';
7
7
  import { getBoundsWidth } from '../useChartDimensions';
8
8
  import { getYAxisWidth } from '../useChartDimensions/utils';
9
- export function getPreparedLegend(args) {
9
+ export async function getPreparedLegend(args) {
10
10
  var _a, _b, _c, _d, _e, _f, _g;
11
11
  const { legend, series } = args;
12
12
  const enabled = Boolean(typeof (legend === null || legend === void 0 ? void 0 : legend.enabled) === 'boolean' ? legend === null || legend === void 0 ? void 0 : legend.enabled : series.length > 1);
@@ -19,9 +19,8 @@ export function getPreparedLegend(args) {
19
19
  const titleMargin = isTitleEnabled ? get(legend, 'title.margin', 4) : 0;
20
20
  const titleStyle = Object.assign({ fontSize: '12px', fontWeight: 'bold' }, get(legend, 'title.style'));
21
21
  const titleText = isTitleEnabled ? get(legend, 'title.text', '') : '';
22
- const titleHeight = isTitleEnabled
23
- ? getLabelsSize({ labels: [titleText], style: titleStyle }).maxHeight
24
- : 0;
22
+ const titleSize = await getLabelsSize({ labels: [titleText], style: titleStyle });
23
+ const titleHeight = isTitleEnabled ? titleSize.maxHeight : 0;
25
24
  const ticks = {
26
25
  labelsMargin: 4,
27
26
  labelsLineHeight: 12,
@@ -177,7 +176,9 @@ export function getLegendComponents(args) {
177
176
  let pagination;
178
177
  if (preparedLegend.type === 'discrete') {
179
178
  const lineHeights = items.reduce((acc, item) => {
180
- acc.push(Math.max(...item.map((item) => item.height)));
179
+ if (item.length) {
180
+ acc.push(Math.max(...item.map(({ height }) => height)));
181
+ }
181
182
  return acc;
182
183
  }, []);
183
184
  let legendHeight = lineHeights.reduce((acc, height) => acc + height, 0);
@@ -8,4 +8,4 @@ export declare function prepareSeries(args: {
8
8
  legend: PreparedLegend;
9
9
  colors: string[];
10
10
  colorScale: ScaleOrdinal<string, string>;
11
- }): PreparedSeries[];
11
+ }): Promise<PreparedSeries[]>;
@@ -9,7 +9,7 @@ import { prepareSankeySeries } from './prepare-sankey';
9
9
  import { prepareScatterSeries } from './prepare-scatter';
10
10
  import { prepareTreemap } from './prepare-treemap';
11
11
  import { prepareWaterfallSeries } from './prepare-waterfall';
12
- export function prepareSeries(args) {
12
+ export async function prepareSeries(args) {
13
13
  const { type, series, seriesOptions, legend, colors, colorScale } = args;
14
14
  switch (type) {
15
15
  case 'pie': {
@@ -32,7 +32,7 @@ export function prepareSeries(args) {
32
32
  });
33
33
  }
34
34
  case 'bar-y': {
35
- return prepareBarYSeries({
35
+ return await prepareBarYSeries({
36
36
  series: series,
37
37
  legend,
38
38
  colorScale,
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
  import { area as areaGenerator, color, line as lineGenerator, select } from 'd3';
3
3
  import get from 'lodash/get';
4
- import { block, filterOverlappingLabels } from '../../..//utils';
4
+ import { block, filterOverlappingLabels } from '../../../utils';
5
5
  import { HtmlLayer } from '../HtmlLayer';
6
6
  import { getMarkerHaloVisibility, getMarkerVisibility, renderMarker, selectMarkerHalo, selectMarkerSymbol, setMarker, } from '../marker';
7
7
  import { setActiveState } from '../utils';
@@ -9,4 +9,4 @@ export declare const prepareAreaData: (args: {
9
9
  yAxis: PreparedAxis[];
10
10
  yScale: ChartScale[];
11
11
  boundsHeight: number;
12
- }) => PreparedAreaData[];
12
+ }) => Promise<PreparedAreaData[]>;
@@ -2,10 +2,10 @@ import { group, sort } from 'd3';
2
2
  import { getDataCategoryValue, getLabelsSize, getLeftPosition } from '../../../utils';
3
3
  import { getFormattedValue } from '../../../utils/chart/format';
4
4
  import { getXValue, getYValue } from '../utils';
5
- function getLabelData(point, series, xMax) {
5
+ async function getLabelData(point, series, xMax) {
6
6
  const text = getFormattedValue(Object.assign({ value: point.data.label || point.data.y }, series.dataLabels));
7
7
  const style = series.dataLabels.style;
8
- const size = getLabelsSize({ labels: [text], style, html: series.dataLabels.html });
8
+ const size = await getLabelsSize({ labels: [text], style, html: series.dataLabels.html });
9
9
  const labelData = {
10
10
  text,
11
11
  x: point.x,
@@ -52,21 +52,30 @@ function getXValues(series, xAxis, xScale) {
52
52
  }
53
53
  return sort(Array.from(xValues), ([_x, xValue]) => xValue);
54
54
  }
55
- export const prepareAreaData = (args) => {
55
+ export const prepareAreaData = async (args) => {
56
56
  const { series, xAxis, xScale, yAxis, yScale, boundsHeight: plotHeight } = args;
57
57
  const [_xMin, xRangeMax] = xScale.range();
58
58
  const xMax = xRangeMax / (1 - xAxis.maxPadding);
59
- return Array.from(group(series, (s) => s.stackId)).reduce((result, [_stackId, seriesStack]) => {
59
+ const result = [];
60
+ const list = Array.from(group(series, (s) => s.stackId));
61
+ for (let i = 0; i < list.length; i++) {
62
+ const [_stackId, seriesStack] = list[i];
60
63
  const xValues = getXValues(seriesStack, xAxis, xScale);
61
64
  const accumulatedYValues = new Map();
62
65
  xValues.forEach(([key]) => {
63
66
  accumulatedYValues.set(key, 0);
64
67
  });
65
- const seriesStackData = seriesStack.reduce((acc, s) => {
68
+ const seriesStackData = [];
69
+ for (let j = 0; j < seriesStack.length; j++) {
70
+ const s = seriesStack[j];
66
71
  const yAxisIndex = s.yAxis;
67
72
  const seriesYAxis = yAxis[yAxisIndex];
68
73
  const seriesYScale = yScale[yAxisIndex];
69
- const yMin = getYValue({ point: { y: 0 }, yAxis: seriesYAxis, yScale: seriesYScale });
74
+ const yMin = getYValue({
75
+ point: { y: 0 },
76
+ yAxis: seriesYAxis,
77
+ yScale: seriesYScale,
78
+ });
70
79
  const seriesData = s.data.reduce((m, d) => {
71
80
  const key = String(xAxis.type === 'category'
72
81
  ? getDataCategoryValue({
@@ -100,20 +109,27 @@ export const prepareAreaData = (args) => {
100
109
  let labels = [];
101
110
  const htmlElements = [];
102
111
  if (s.dataLabels.enabled) {
103
- const labelItems = points.map((p) => getLabelData(p, s, xMax));
112
+ const labelItems = await Promise.all(points.map((p) => getLabelData(p, s, xMax)));
104
113
  if (s.dataLabels.html) {
105
- const htmlLabels = labelItems.map((l) => {
114
+ const htmlLabels = await Promise.all(labelItems.map(async (l) => {
106
115
  var _a;
107
116
  const style = (_a = l.style) !== null && _a !== void 0 ? _a : s.dataLabels.style;
108
- const labelSize = getLabelsSize({ labels: [l.text], style, html: true });
117
+ const labelSize = await getLabelsSize({
118
+ labels: [l.text],
119
+ style,
120
+ html: true,
121
+ });
109
122
  return {
110
123
  x: l.x - l.size.width / 2,
111
124
  y: l.y,
112
125
  content: l.text,
113
- size: { width: labelSize.maxWidth, height: labelSize.maxHeight },
126
+ size: {
127
+ width: labelSize.maxWidth,
128
+ height: labelSize.maxHeight,
129
+ },
114
130
  style,
115
131
  };
116
- });
132
+ }));
117
133
  htmlElements.push(...htmlLabels);
118
134
  }
119
135
  else {
@@ -128,7 +144,7 @@ export const prepareAreaData = (args) => {
128
144
  hovered: false,
129
145
  }));
130
146
  }
131
- acc.push({
147
+ seriesStackData.push({
132
148
  points,
133
149
  markers,
134
150
  labels,
@@ -141,8 +157,7 @@ export const prepareAreaData = (args) => {
141
157
  id: s.id,
142
158
  htmlElements,
143
159
  });
144
- return acc;
145
- }, []);
160
+ }
146
161
  if (series.some((s) => s.stacking === 'percent')) {
147
162
  xValues.forEach(([x], index) => {
148
163
  const stackHeight = accumulatedYValues.get(x) || 0;
@@ -159,6 +174,7 @@ export const prepareAreaData = (args) => {
159
174
  });
160
175
  });
161
176
  }
162
- return result.concat(seriesStackData);
163
- }, []);
177
+ result.push(...seriesStackData);
178
+ }
179
+ return result;
164
180
  };
@@ -6,6 +6,7 @@ export type PointData = {
6
6
  y: number;
7
7
  data: AreaSeriesData;
8
8
  series: PreparedAreaSeries;
9
+ color?: string;
9
10
  };
10
11
  export type MarkerData = {
11
12
  point: PointData;
@@ -10,4 +10,4 @@ export declare const prepareBarXData: (args: {
10
10
  yAxis: PreparedAxis[];
11
11
  yScale: ChartScale[];
12
12
  boundsHeight: number;
13
- }) => PreparedBarXData[];
13
+ }) => Promise<PreparedBarXData[]>;
@@ -3,14 +3,14 @@ import get from 'lodash/get';
3
3
  import { getDataCategoryValue, getLabelsSize } from '../../../utils';
4
4
  import { getFormattedValue } from '../../../utils/chart/format';
5
5
  import { MIN_BAR_GAP, MIN_BAR_GROUP_GAP, MIN_BAR_WIDTH } from '../constants';
6
- function getLabelData(d) {
6
+ async function getLabelData(d) {
7
7
  if (!d.series.dataLabels.enabled) {
8
8
  return undefined;
9
9
  }
10
10
  const text = getFormattedValue(Object.assign({ value: d.data.label || d.data.y }, d.series.dataLabels));
11
11
  const style = d.series.dataLabels.style;
12
12
  const html = d.series.dataLabels.html;
13
- const { maxHeight: height, maxWidth: width } = getLabelsSize({
13
+ const { maxHeight: height, maxWidth: width } = await getLabelsSize({
14
14
  labels: [text],
15
15
  style,
16
16
  html,
@@ -30,7 +30,7 @@ function getLabelData(d) {
30
30
  series: d.series,
31
31
  };
32
32
  }
33
- export const prepareBarXData = (args) => {
33
+ export const prepareBarXData = async (args) => {
34
34
  const { series, seriesOptions, xAxis, xScale, yScale, boundsHeight: plotHeight } = args;
35
35
  const categories = get(xAxis, 'categories', []);
36
36
  const barMaxWidth = get(seriesOptions, 'bar-x.barMaxWidth');
@@ -95,28 +95,32 @@ export const prepareBarXData = (args) => {
95
95
  const rectGap = Math.max(bandWidth * barPadding, MIN_BAR_GAP);
96
96
  const rectWidth = Math.max(MIN_BAR_WIDTH, Math.min(groupWidth / maxGroupSize - rectGap, barMaxWidth));
97
97
  const result = [];
98
- Object.entries(data).forEach(([xValue, val]) => {
98
+ await Promise.all(Object.entries(data).map(async ([xValue, val]) => {
99
99
  const stacks = Object.values(val);
100
100
  const currentGroupWidth = rectWidth * stacks.length + rectGap * (stacks.length - 1);
101
- stacks.forEach((yValues, groupItemIndex) => {
101
+ await Promise.all(stacks.map(async (yValues, groupItemIndex) => {
102
102
  let stackHeight = 0;
103
103
  const stackItems = [];
104
104
  const sortedData = sortKey
105
105
  ? sort(yValues, (a, b) => comparator(get(a, sortKey), get(b, sortKey)))
106
106
  : yValues;
107
- sortedData.forEach((yValue, yValueIndex) => {
107
+ await Promise.all(sortedData.map(async (yValue, yValueIndex) => {
108
108
  const yAxisIndex = yValue.series.yAxis;
109
109
  const seriesYScale = yScale[yAxisIndex];
110
110
  let xCenter;
111
111
  if (xAxis.type === 'category') {
112
112
  const xBandScale = xScale;
113
- xCenter = (xBandScale(xValue) || 0) + xBandScale.bandwidth() / 2;
113
+ xCenter =
114
+ (xBandScale(xValue) || 0) +
115
+ xBandScale.bandwidth() / 2;
114
116
  }
115
117
  else {
116
118
  const xLinearScale = xScale;
117
119
  xCenter = xLinearScale(Number(xValue));
118
120
  }
119
- const x = xCenter - currentGroupWidth / 2 + (rectWidth + rectGap) * groupItemIndex;
121
+ const x = xCenter -
122
+ currentGroupWidth / 2 +
123
+ (rectWidth + rectGap) * groupItemIndex;
120
124
  const yDataValue = yValue.data.y;
121
125
  const y = seriesYScale(yDataValue);
122
126
  const base = seriesYScale(0);
@@ -132,7 +136,7 @@ export const prepareBarXData = (args) => {
132
136
  htmlElements: [],
133
137
  isLastStackItem: yValueIndex === sortedData.length - 1,
134
138
  };
135
- const label = getLabelData(barData);
139
+ const label = await getLabelData(barData);
136
140
  if (yValue.series.dataLabels.html && label) {
137
141
  barData.htmlElements.push({
138
142
  x: label.x,
@@ -143,11 +147,11 @@ export const prepareBarXData = (args) => {
143
147
  });
144
148
  }
145
149
  else {
146
- barData.label = getLabelData(barData);
150
+ barData.label = await getLabelData(barData);
147
151
  }
148
152
  stackItems.push(barData);
149
153
  stackHeight += height + 1;
150
- });
154
+ }));
151
155
  if (series.some((s) => s.stacking === 'percent')) {
152
156
  let acc = 0;
153
157
  const ratio = plotHeight / (stackHeight - stackItems.length);
@@ -158,7 +162,7 @@ export const prepareBarXData = (args) => {
158
162
  });
159
163
  }
160
164
  result.push(...stackItems);
161
- });
162
- });
165
+ }));
166
+ }));
163
167
  return result;
164
168
  };
@@ -9,4 +9,4 @@ export declare const prepareBarYData: (args: {
9
9
  xScale: ChartScale;
10
10
  yAxis: PreparedAxis[];
11
11
  yScale: ChartScale[];
12
- }) => PreparedBarYData[];
12
+ }) => Promise<PreparedBarYData[]>;