@gravity-ui/chartkit 4.4.0 → 4.4.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.
- package/build/plugins/d3/renderer/components/AxisX.js +13 -19
- package/build/plugins/d3/renderer/hooks/useAxisScales/index.js +8 -8
- package/build/plugins/d3/renderer/hooks/useShapes/index.js +1 -3
- package/build/plugins/d3/renderer/hooks/useShapes/scatter.js +2 -5
- package/build/plugins/d3/renderer/utils/index.js +0 -3
- package/package.json +1 -1
|
@@ -4,24 +4,6 @@ import { block } from '../../../../utils/cn';
|
|
|
4
4
|
import { formatAxisTickLabel, parseTransformStyle } from '../utils';
|
|
5
5
|
const b = block('d3-axis');
|
|
6
6
|
const EMPTY_SPACE_BETWEEN_LABELS = 10;
|
|
7
|
-
// Note: this method do not prepared for rotated labels
|
|
8
|
-
const removeOverlappingXTicks = (axis) => {
|
|
9
|
-
var _a;
|
|
10
|
-
const a = axis.selectAll('g.tick').nodes();
|
|
11
|
-
if (a.length <= 1) {
|
|
12
|
-
return;
|
|
13
|
-
}
|
|
14
|
-
for (let i = 0, x = 0; i < a.length; i++) {
|
|
15
|
-
const node = a[i];
|
|
16
|
-
const r = node.getBoundingClientRect();
|
|
17
|
-
if (r.left < x) {
|
|
18
|
-
(_a = node === null || node === void 0 ? void 0 : node.parentNode) === null || _a === void 0 ? void 0 : _a.removeChild(node);
|
|
19
|
-
}
|
|
20
|
-
else {
|
|
21
|
-
x = r.right + EMPTY_SPACE_BETWEEN_LABELS;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
7
|
// FIXME: add overflow ellipsis for the labels that out of boundaries
|
|
26
8
|
export const AxisX = ({ axis, width, height, scale }) => {
|
|
27
9
|
const ref = React.useRef(null);
|
|
@@ -75,7 +57,19 @@ export const AxisX = ({ axis, width, height, scale }) => {
|
|
|
75
57
|
.attr('font-size', axis.title.style.fontSize)
|
|
76
58
|
.text(axis.title.text);
|
|
77
59
|
}
|
|
78
|
-
|
|
60
|
+
let elementX = 0;
|
|
61
|
+
svgElement
|
|
62
|
+
.selectAll('.tick')
|
|
63
|
+
.filter(function () {
|
|
64
|
+
const node = this;
|
|
65
|
+
const r = node.getBoundingClientRect();
|
|
66
|
+
if (r.left < elementX) {
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
elementX = r.right + EMPTY_SPACE_BETWEEN_LABELS;
|
|
70
|
+
return false;
|
|
71
|
+
})
|
|
72
|
+
.remove();
|
|
79
73
|
}, [axis, width, height, scale]);
|
|
80
74
|
return React.createElement("g", { ref: ref });
|
|
81
75
|
};
|
|
@@ -7,15 +7,15 @@ const isNumericalArrayData = (data) => {
|
|
|
7
7
|
};
|
|
8
8
|
const filterCategoriesByVisibleSeries = (args) => {
|
|
9
9
|
const { axisDirection, categories, series } = args;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
});
|
|
10
|
+
const visibleCategories = new Set();
|
|
11
|
+
series.forEach((s) => {
|
|
12
|
+
if (isSeriesWithCategoryValues(s)) {
|
|
13
|
+
s.data.forEach((d) => {
|
|
14
|
+
visibleCategories.add(getDataCategoryValue({ axisDirection, categories, data: d }));
|
|
15
|
+
});
|
|
16
|
+
}
|
|
18
17
|
});
|
|
18
|
+
return categories.filter((c) => visibleCategories.has(c));
|
|
19
19
|
};
|
|
20
20
|
const createScales = (args) => {
|
|
21
21
|
const { boundsWidth, boundsHeight, series, xAxis, yAxis } = args;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { group } from 'd3';
|
|
3
|
-
import { getRandomCKId } from '../../../../../utils';
|
|
4
3
|
import { getOnlyVisibleSeries } from '../../utils';
|
|
5
4
|
import { BarXSeriesShapes } from './bar-x';
|
|
6
5
|
import { ScatterSeriesShape } from './scatter';
|
|
@@ -23,8 +22,7 @@ export const useShapes = (args) => {
|
|
|
23
22
|
case 'scatter': {
|
|
24
23
|
if (xScale && yScale) {
|
|
25
24
|
const scatterShapes = chartSeries.map((scatterSeries, i) => {
|
|
26
|
-
|
|
27
|
-
return (React.createElement(ScatterSeriesShape, { key: `${i}-${id}`, top: top, left: left, series: scatterSeries, xAxis: xAxis, xScale: xScale, yAxis: yAxis, yScale: yScale, onSeriesMouseMove: onSeriesMouseMove, onSeriesMouseLeave: onSeriesMouseLeave, svgContainer: svgContainer }));
|
|
25
|
+
return (React.createElement(ScatterSeriesShape, { key: i, top: top, left: left, series: scatterSeries, xAxis: xAxis, xScale: xScale, yAxis: yAxis, yScale: yScale, onSeriesMouseMove: onSeriesMouseMove, onSeriesMouseLeave: onSeriesMouseLeave, svgContainer: svgContainer }));
|
|
28
26
|
});
|
|
29
27
|
acc.push(...scatterShapes);
|
|
30
28
|
}
|
|
@@ -47,16 +47,13 @@ export function ScatterSeriesShape(props) {
|
|
|
47
47
|
return;
|
|
48
48
|
}
|
|
49
49
|
const svgElement = select(ref.current);
|
|
50
|
-
svgElement.selectAll('*').remove();
|
|
51
50
|
const preparedData = xAxis.type === 'category' || ((_a = yAxis[0]) === null || _a === void 0 ? void 0 : _a.type) === 'category'
|
|
52
51
|
? series.data
|
|
53
52
|
: prepareLinearScatterData(series.data);
|
|
54
53
|
svgElement
|
|
55
|
-
.selectAll('
|
|
54
|
+
.selectAll('circle')
|
|
56
55
|
.data(preparedData)
|
|
57
|
-
.enter()
|
|
58
|
-
.append('circle')
|
|
59
|
-
.attr('class', b('point'))
|
|
56
|
+
.join((enter) => enter.append('circle').attr('class', b('point')), (update) => update, (exit) => exit.remove())
|
|
60
57
|
.attr('fill', (d) => d.color || series.color || '')
|
|
61
58
|
.attr('r', (d) => d.radius || DEFAULT_SCATTER_POINT_RADIUS)
|
|
62
59
|
.attr('cx', (d) => getCxAttr({ point: d, xAxis, xScale }))
|
|
@@ -150,8 +150,5 @@ const extractCategoryValue = (args) => {
|
|
|
150
150
|
export const getDataCategoryValue = (args) => {
|
|
151
151
|
const { axisDirection, categories, data } = args;
|
|
152
152
|
const categoryValue = extractCategoryValue({ axisDirection, categories, data });
|
|
153
|
-
if (!categories.includes(categoryValue)) {
|
|
154
|
-
throw new Error('It seems you are trying to use category value that is not in categories array');
|
|
155
|
-
}
|
|
156
153
|
return categoryValue;
|
|
157
154
|
};
|
package/package.json
CHANGED