@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.
- package/dist/cjs/components/Axis/AxisX.d.ts +2 -1
- package/dist/cjs/components/Axis/AxisX.js +147 -143
- package/dist/cjs/components/Axis/AxisY.d.ts +2 -1
- package/dist/cjs/components/Axis/AxisY.js +113 -91
- package/dist/cjs/components/ChartInner/index.js +23 -10
- package/dist/cjs/components/ChartInner/useChartInnerHandlers.d.ts +1 -1
- package/dist/cjs/components/ChartInner/useChartInnerProps.d.ts +8 -5
- package/dist/cjs/components/ChartInner/useChartInnerProps.js +55 -9
- package/dist/cjs/components/ChartInner/utils.d.ts +3 -0
- package/dist/cjs/components/ChartInner/utils.js +28 -0
- package/dist/cjs/components/Legend/index.js +199 -196
- package/dist/cjs/components/Tooltip/ChartTooltipContent.d.ts +1 -1
- package/dist/cjs/components/Tooltip/DefaultContent.d.ts +1 -1
- package/dist/cjs/components/Tooltip/DefaultContent.js +1 -1
- package/dist/cjs/components/Tooltip/index.d.ts +1 -1
- package/dist/cjs/hooks/hooks-utils/index.d.ts +1 -0
- package/dist/cjs/hooks/hooks-utils/index.js +1 -0
- package/dist/cjs/hooks/hooks-utils/zoom.d.ts +8 -0
- package/dist/cjs/hooks/hooks-utils/zoom.js +81 -0
- package/dist/cjs/hooks/useAxisScales/index.d.ts +4 -2
- package/dist/cjs/hooks/useAxisScales/index.js +22 -8
- package/dist/cjs/hooks/useBrush/index.d.ts +3 -0
- package/dist/cjs/hooks/useBrush/index.js +70 -0
- package/dist/cjs/hooks/useBrush/styles.css +10 -0
- package/dist/cjs/hooks/useBrush/types.d.ts +24 -0
- package/dist/cjs/hooks/useBrush/types.js +1 -0
- package/dist/cjs/hooks/useChartDimensions/index.d.ts +3 -3
- package/dist/cjs/hooks/useChartDimensions/index.js +2 -2
- package/dist/cjs/hooks/useChartDimensions/utils.d.ts +2 -2
- package/dist/cjs/hooks/useChartOptions/chart.d.ts +2 -1
- package/dist/cjs/hooks/useChartOptions/chart.js +80 -1
- package/dist/cjs/hooks/useChartOptions/index.js +3 -2
- package/dist/cjs/hooks/useChartOptions/types.d.ts +3 -1
- package/dist/cjs/hooks/useChartOptions/x-axis.d.ts +3 -3
- package/dist/cjs/hooks/useChartOptions/x-axis.js +11 -11
- package/dist/cjs/hooks/useChartOptions/y-axis.d.ts +3 -3
- package/dist/cjs/hooks/useChartOptions/y-axis.js +22 -18
- package/dist/cjs/hooks/useCrosshair/index.d.ts +1 -1
- package/dist/cjs/hooks/useCrosshair/index.js +2 -2
- package/dist/cjs/hooks/useSeries/index.d.ts +8 -6
- package/dist/cjs/hooks/useSeries/index.js +41 -22
- package/dist/cjs/hooks/useSeries/prepare-bar-y.d.ts +27 -2
- package/dist/cjs/hooks/useSeries/prepare-bar-y.js +5 -5
- package/dist/cjs/hooks/useSeries/prepare-legend.d.ts +1 -1
- package/dist/cjs/hooks/useSeries/prepare-legend.js +6 -5
- package/dist/cjs/hooks/useSeries/prepareSeries.d.ts +1 -1
- package/dist/cjs/hooks/useSeries/prepareSeries.js +2 -2
- package/dist/cjs/hooks/useShapes/area/index.js +1 -1
- package/dist/cjs/hooks/useShapes/area/prepare-data.d.ts +1 -1
- package/dist/cjs/hooks/useShapes/area/prepare-data.js +32 -16
- package/dist/cjs/hooks/useShapes/area/types.d.ts +1 -0
- package/dist/cjs/hooks/useShapes/bar-x/prepare-data.d.ts +1 -1
- package/dist/cjs/hooks/useShapes/bar-x/prepare-data.js +17 -13
- package/dist/cjs/hooks/useShapes/bar-y/prepare-data.d.ts +1 -1
- package/dist/cjs/hooks/useShapes/bar-y/prepare-data.js +6 -6
- package/dist/cjs/hooks/useShapes/index.d.ts +1 -1
- package/dist/cjs/hooks/useShapes/index.js +40 -31
- package/dist/cjs/hooks/useShapes/line/prepare-data.d.ts +1 -1
- package/dist/cjs/hooks/useShapes/line/prepare-data.js +14 -11
- package/dist/cjs/hooks/useShapes/line/types.d.ts +1 -0
- package/dist/cjs/hooks/useShapes/marker.js +2 -2
- package/dist/cjs/hooks/useShapes/pie/index.js +3 -3
- package/dist/cjs/hooks/useShapes/pie/prepare-data.d.ts +1 -1
- package/dist/cjs/hooks/useShapes/pie/prepare-data.js +15 -11
- package/dist/cjs/hooks/useShapes/radar/prepare-data.d.ts +1 -1
- package/dist/cjs/hooks/useShapes/radar/prepare-data.js +6 -7
- package/dist/cjs/hooks/useShapes/radar/types.d.ts +1 -0
- package/dist/cjs/hooks/useShapes/scatter/index.js +0 -1
- package/dist/cjs/hooks/useShapes/scatter/prepare-data.js +2 -0
- package/dist/cjs/hooks/useShapes/scatter/types.d.ts +1 -0
- package/dist/cjs/hooks/useShapes/treemap/prepare-data.d.ts +1 -1
- package/dist/cjs/hooks/useShapes/treemap/prepare-data.js +19 -16
- package/dist/cjs/hooks/useShapes/waterfall/prepare-data.d.ts +1 -1
- package/dist/cjs/hooks/useShapes/waterfall/prepare-data.js +8 -7
- package/dist/cjs/hooks/useZoom/index.d.ts +18 -0
- package/dist/cjs/hooks/useZoom/index.js +54 -0
- package/dist/cjs/hooks/useZoom/types.d.ts +19 -0
- package/dist/cjs/hooks/useZoom/types.js +1 -0
- package/dist/cjs/hooks/useZoom/utils.d.ts +12 -0
- package/dist/cjs/hooks/useZoom/utils.js +128 -0
- package/dist/cjs/types/chart/chart.d.ts +5 -0
- package/dist/cjs/types/chart/pie.d.ts +1 -1
- package/dist/cjs/types/chart/tooltip.d.ts +1 -1
- package/dist/cjs/types/chart/zoom.d.ts +36 -0
- package/dist/cjs/types/chart/zoom.js +1 -0
- package/dist/cjs/types/index.d.ts +1 -0
- package/dist/cjs/types/index.js +1 -0
- package/dist/cjs/types/misc.d.ts +7 -0
- package/dist/cjs/utils/chart/axis-generators/bottom.d.ts +1 -1
- package/dist/cjs/utils/chart/axis-generators/bottom.js +25 -25
- package/dist/cjs/utils/chart/axis.d.ts +1 -1
- package/dist/cjs/utils/chart/axis.js +2 -2
- package/dist/cjs/utils/chart/get-closest-data.js +1 -1
- package/dist/cjs/utils/chart/text.d.ts +7 -7
- package/dist/cjs/utils/chart/text.js +37 -29
- package/dist/cjs/utils/chart-ui/pie-center-text.d.ts +1 -1
- package/dist/cjs/utils/chart-ui/pie-center-text.js +2 -2
- package/dist/cjs/validation/index.d.ts +1 -1
- package/dist/cjs/validation/index.js +16 -16
- package/dist/esm/components/Axis/AxisX.d.ts +2 -1
- package/dist/esm/components/Axis/AxisX.js +147 -143
- package/dist/esm/components/Axis/AxisY.d.ts +2 -1
- package/dist/esm/components/Axis/AxisY.js +113 -91
- package/dist/esm/components/ChartInner/index.js +23 -10
- package/dist/esm/components/ChartInner/useChartInnerHandlers.d.ts +1 -1
- package/dist/esm/components/ChartInner/useChartInnerProps.d.ts +8 -5
- package/dist/esm/components/ChartInner/useChartInnerProps.js +55 -9
- package/dist/esm/components/ChartInner/utils.d.ts +3 -0
- package/dist/esm/components/ChartInner/utils.js +28 -0
- package/dist/esm/components/Legend/index.js +199 -196
- package/dist/esm/components/Tooltip/ChartTooltipContent.d.ts +1 -1
- package/dist/esm/components/Tooltip/DefaultContent.d.ts +1 -1
- package/dist/esm/components/Tooltip/DefaultContent.js +1 -1
- package/dist/esm/components/Tooltip/index.d.ts +1 -1
- package/dist/esm/hooks/hooks-utils/index.d.ts +1 -0
- package/dist/esm/hooks/hooks-utils/index.js +1 -0
- package/dist/esm/hooks/hooks-utils/zoom.d.ts +8 -0
- package/dist/esm/hooks/hooks-utils/zoom.js +81 -0
- package/dist/esm/hooks/useAxisScales/index.d.ts +4 -2
- package/dist/esm/hooks/useAxisScales/index.js +22 -8
- package/dist/esm/hooks/useBrush/index.d.ts +3 -0
- package/dist/esm/hooks/useBrush/index.js +70 -0
- package/dist/esm/hooks/useBrush/styles.css +10 -0
- package/dist/esm/hooks/useBrush/types.d.ts +24 -0
- package/dist/esm/hooks/useBrush/types.js +1 -0
- package/dist/esm/hooks/useChartDimensions/index.d.ts +3 -3
- package/dist/esm/hooks/useChartDimensions/index.js +2 -2
- package/dist/esm/hooks/useChartDimensions/utils.d.ts +2 -2
- package/dist/esm/hooks/useChartOptions/chart.d.ts +2 -1
- package/dist/esm/hooks/useChartOptions/chart.js +80 -1
- package/dist/esm/hooks/useChartOptions/index.js +3 -2
- package/dist/esm/hooks/useChartOptions/types.d.ts +3 -1
- package/dist/esm/hooks/useChartOptions/x-axis.d.ts +3 -3
- package/dist/esm/hooks/useChartOptions/x-axis.js +11 -11
- package/dist/esm/hooks/useChartOptions/y-axis.d.ts +3 -3
- package/dist/esm/hooks/useChartOptions/y-axis.js +22 -18
- package/dist/esm/hooks/useCrosshair/index.d.ts +1 -1
- package/dist/esm/hooks/useCrosshair/index.js +2 -2
- package/dist/esm/hooks/useSeries/index.d.ts +8 -6
- package/dist/esm/hooks/useSeries/index.js +41 -22
- package/dist/esm/hooks/useSeries/prepare-bar-y.d.ts +27 -2
- package/dist/esm/hooks/useSeries/prepare-bar-y.js +5 -5
- package/dist/esm/hooks/useSeries/prepare-legend.d.ts +1 -1
- package/dist/esm/hooks/useSeries/prepare-legend.js +6 -5
- package/dist/esm/hooks/useSeries/prepareSeries.d.ts +1 -1
- package/dist/esm/hooks/useSeries/prepareSeries.js +2 -2
- package/dist/esm/hooks/useShapes/area/index.js +1 -1
- package/dist/esm/hooks/useShapes/area/prepare-data.d.ts +1 -1
- package/dist/esm/hooks/useShapes/area/prepare-data.js +32 -16
- package/dist/esm/hooks/useShapes/area/types.d.ts +1 -0
- package/dist/esm/hooks/useShapes/bar-x/prepare-data.d.ts +1 -1
- package/dist/esm/hooks/useShapes/bar-x/prepare-data.js +17 -13
- package/dist/esm/hooks/useShapes/bar-y/prepare-data.d.ts +1 -1
- package/dist/esm/hooks/useShapes/bar-y/prepare-data.js +6 -6
- package/dist/esm/hooks/useShapes/index.d.ts +1 -1
- package/dist/esm/hooks/useShapes/index.js +40 -31
- package/dist/esm/hooks/useShapes/line/prepare-data.d.ts +1 -1
- package/dist/esm/hooks/useShapes/line/prepare-data.js +14 -11
- package/dist/esm/hooks/useShapes/line/types.d.ts +1 -0
- package/dist/esm/hooks/useShapes/marker.js +2 -2
- package/dist/esm/hooks/useShapes/pie/index.js +3 -3
- package/dist/esm/hooks/useShapes/pie/prepare-data.d.ts +1 -1
- package/dist/esm/hooks/useShapes/pie/prepare-data.js +15 -11
- package/dist/esm/hooks/useShapes/radar/prepare-data.d.ts +1 -1
- package/dist/esm/hooks/useShapes/radar/prepare-data.js +6 -7
- package/dist/esm/hooks/useShapes/radar/types.d.ts +1 -0
- package/dist/esm/hooks/useShapes/scatter/index.js +0 -1
- package/dist/esm/hooks/useShapes/scatter/prepare-data.js +2 -0
- package/dist/esm/hooks/useShapes/scatter/types.d.ts +1 -0
- package/dist/esm/hooks/useShapes/treemap/prepare-data.d.ts +1 -1
- package/dist/esm/hooks/useShapes/treemap/prepare-data.js +19 -16
- package/dist/esm/hooks/useShapes/waterfall/prepare-data.d.ts +1 -1
- package/dist/esm/hooks/useShapes/waterfall/prepare-data.js +8 -7
- package/dist/esm/hooks/useZoom/index.d.ts +18 -0
- package/dist/esm/hooks/useZoom/index.js +54 -0
- package/dist/esm/hooks/useZoom/types.d.ts +19 -0
- package/dist/esm/hooks/useZoom/types.js +1 -0
- package/dist/esm/hooks/useZoom/utils.d.ts +12 -0
- package/dist/esm/hooks/useZoom/utils.js +128 -0
- package/dist/esm/types/chart/chart.d.ts +5 -0
- package/dist/esm/types/chart/pie.d.ts +1 -1
- package/dist/esm/types/chart/tooltip.d.ts +1 -1
- package/dist/esm/types/chart/zoom.d.ts +36 -0
- package/dist/esm/types/chart/zoom.js +1 -0
- package/dist/esm/types/index.d.ts +1 -0
- package/dist/esm/types/index.js +1 -0
- package/dist/esm/types/misc.d.ts +7 -0
- package/dist/esm/utils/chart/axis-generators/bottom.d.ts +1 -1
- package/dist/esm/utils/chart/axis-generators/bottom.js +25 -25
- package/dist/esm/utils/chart/axis.d.ts +1 -1
- package/dist/esm/utils/chart/axis.js +2 -2
- package/dist/esm/utils/chart/get-closest-data.js +1 -1
- package/dist/esm/utils/chart/text.d.ts +7 -7
- package/dist/esm/utils/chart/text.js +37 -29
- package/dist/esm/utils/chart-ui/pie-center-text.d.ts +1 -1
- package/dist/esm/utils/chart-ui/pie-center-text.js +2 -2
- package/dist/esm/validation/index.d.ts +1 -1
- package/dist/esm/validation/index.js +16 -16
- 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,
|
|
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,
|
|
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
|
-
|
|
19
|
+
const size = await getLabelsSize({
|
|
20
20
|
labels,
|
|
21
21
|
style: axis.labels.style,
|
|
22
22
|
rotation: axis.labels.rotation,
|
|
23
|
-
})
|
|
23
|
+
});
|
|
24
|
+
return size.maxWidth;
|
|
24
25
|
};
|
|
25
|
-
function getAxisMin(axis,
|
|
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
|
-
(
|
|
29
|
-
return
|
|
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 = ({
|
|
46
|
+
export const getPreparedYAxis = ({ seriesData, yAxis, height, }) => {
|
|
46
47
|
const axisByPlot = [];
|
|
47
48
|
const axisItems = yAxis || [{}];
|
|
48
|
-
const hasAxisRelatedSeries =
|
|
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,
|
|
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({
|
|
145
|
+
preparedAxis.labels.width = await getAxisLabelMaxWidth({
|
|
146
|
+
axis: preparedAxis,
|
|
147
|
+
seriesData,
|
|
148
|
+
});
|
|
145
149
|
}
|
|
146
150
|
return preparedAxis;
|
|
147
|
-
});
|
|
151
|
+
}));
|
|
148
152
|
};
|
|
@@ -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
|
-
|
|
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:
|
|
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,
|
|
10
|
-
const preparedLegend = React.
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
|
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
|
-
|
|
73
|
-
|
|
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
|
|
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):
|
|
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
|
|
23
|
-
|
|
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
|
-
|
|
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);
|
|
@@ -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 '
|
|
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';
|
|
@@ -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
|
-
|
|
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 =
|
|
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({
|
|
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({
|
|
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: {
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
163
|
-
}
|
|
177
|
+
result.push(...seriesStackData);
|
|
178
|
+
}
|
|
179
|
+
return result;
|
|
164
180
|
};
|
|
@@ -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).
|
|
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.
|
|
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.
|
|
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 =
|
|
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 -
|
|
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
|
};
|