@gravity-ui/charts 1.34.2 → 1.34.3
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/AxisX/prepare-axis-data.js +28 -2
- package/dist/cjs/hooks/useAxis/x-axis.js +1 -1
- package/dist/cjs/types/chart/axis.d.ts +4 -1
- package/dist/esm/components/AxisX/prepare-axis-data.js +28 -2
- package/dist/esm/hooks/useAxis/x-axis.js +1 -1
- package/dist/esm/types/chart/axis.d.ts +4 -1
- package/package.json +1 -1
|
@@ -95,8 +95,34 @@ export async function prepareXAxisData({ axis, boundsOffsetLeft, boundsOffsetRig
|
|
|
95
95
|
const ticks = [];
|
|
96
96
|
const getTextSize = getTextSizeFn({ style: axis.labels.style });
|
|
97
97
|
const labelLineHeight = (await getTextSize('Tmp')).height;
|
|
98
|
-
|
|
99
|
-
|
|
98
|
+
let values = getXAxisTickValues({ scale, axis, labelLineHeight, series });
|
|
99
|
+
let tickStep = getMinSpaceBetween(values, (d) => Number(d.value));
|
|
100
|
+
if (axis.labels.enabled &&
|
|
101
|
+
axis.labels.rotation === 0 &&
|
|
102
|
+
!axis.labels.html &&
|
|
103
|
+
axis.type === 'datetime' &&
|
|
104
|
+
values.length > 1) {
|
|
105
|
+
let maxLabelWidth = 0;
|
|
106
|
+
for (let i = 0; i < values.length; i++) {
|
|
107
|
+
const label = formatAxisTickLabel({
|
|
108
|
+
value: values[i].value,
|
|
109
|
+
axis,
|
|
110
|
+
step: tickStep,
|
|
111
|
+
});
|
|
112
|
+
const size = await getTextSize(label);
|
|
113
|
+
maxLabelWidth = Math.max(maxLabelWidth, size.width);
|
|
114
|
+
}
|
|
115
|
+
const currentSpacing = Math.abs(values[0].x - values[1].x) - axis.labels.padding * 2;
|
|
116
|
+
if (maxLabelWidth > currentSpacing) {
|
|
117
|
+
values = getXAxisTickValues({
|
|
118
|
+
scale,
|
|
119
|
+
axis,
|
|
120
|
+
labelLineHeight: maxLabelWidth,
|
|
121
|
+
series,
|
|
122
|
+
});
|
|
123
|
+
tickStep = getMinSpaceBetween(values, (d) => Number(d.value));
|
|
124
|
+
}
|
|
125
|
+
}
|
|
100
126
|
const labelMaxWidth = values.length > 1
|
|
101
127
|
? Math.abs(values[0].x - values[1].x) - axis.labels.padding * 2
|
|
102
128
|
: axisWidth;
|
|
@@ -37,7 +37,7 @@ async function setLabelSettings({ axis, seriesData, width, axisLabels, }) {
|
|
|
37
37
|
}
|
|
38
38
|
return false;
|
|
39
39
|
};
|
|
40
|
-
const autoRotation = (_a = axisLabels === null || axisLabels === void 0 ? void 0 : axisLabels.autoRotation) !== null && _a !== void 0 ? _a :
|
|
40
|
+
const autoRotation = (_a = axisLabels === null || axisLabels === void 0 ? void 0 : axisLabels.autoRotation) !== null && _a !== void 0 ? _a : axis.type !== 'datetime';
|
|
41
41
|
const overlapping = axis.labels.html ? false : await hasOverlappingLabels();
|
|
42
42
|
const defaultRotation = overlapping && autoRotation ? -45 : 0;
|
|
43
43
|
const rotation = axis.labels.html ? 0 : ((_b = axisLabels === null || axisLabels === void 0 ? void 0 : axisLabels.rotation) !== null && _b !== void 0 ? _b : defaultRotation);
|
|
@@ -19,11 +19,14 @@ export interface ChartAxisLabels {
|
|
|
19
19
|
dateFormat?: string;
|
|
20
20
|
numberFormat?: FormatNumberOptions;
|
|
21
21
|
style?: Partial<BaseTextStyle>;
|
|
22
|
-
/**
|
|
22
|
+
/**
|
|
23
|
+
* For horizontal axes, enable label rotation to prevent overlapping labels.
|
|
23
24
|
* If there is enough space, labels are not rotated.
|
|
24
25
|
* As the chart gets narrower, it will start rotating the labels -45 degrees.
|
|
25
26
|
*
|
|
26
27
|
* Does not apply to html labels.
|
|
28
|
+
*
|
|
29
|
+
* @default true for all axis types except `datetime` (defaults to false)
|
|
27
30
|
*/
|
|
28
31
|
autoRotation?: boolean;
|
|
29
32
|
/** Rotation of the labels in degrees.
|
|
@@ -95,8 +95,34 @@ export async function prepareXAxisData({ axis, boundsOffsetLeft, boundsOffsetRig
|
|
|
95
95
|
const ticks = [];
|
|
96
96
|
const getTextSize = getTextSizeFn({ style: axis.labels.style });
|
|
97
97
|
const labelLineHeight = (await getTextSize('Tmp')).height;
|
|
98
|
-
|
|
99
|
-
|
|
98
|
+
let values = getXAxisTickValues({ scale, axis, labelLineHeight, series });
|
|
99
|
+
let tickStep = getMinSpaceBetween(values, (d) => Number(d.value));
|
|
100
|
+
if (axis.labels.enabled &&
|
|
101
|
+
axis.labels.rotation === 0 &&
|
|
102
|
+
!axis.labels.html &&
|
|
103
|
+
axis.type === 'datetime' &&
|
|
104
|
+
values.length > 1) {
|
|
105
|
+
let maxLabelWidth = 0;
|
|
106
|
+
for (let i = 0; i < values.length; i++) {
|
|
107
|
+
const label = formatAxisTickLabel({
|
|
108
|
+
value: values[i].value,
|
|
109
|
+
axis,
|
|
110
|
+
step: tickStep,
|
|
111
|
+
});
|
|
112
|
+
const size = await getTextSize(label);
|
|
113
|
+
maxLabelWidth = Math.max(maxLabelWidth, size.width);
|
|
114
|
+
}
|
|
115
|
+
const currentSpacing = Math.abs(values[0].x - values[1].x) - axis.labels.padding * 2;
|
|
116
|
+
if (maxLabelWidth > currentSpacing) {
|
|
117
|
+
values = getXAxisTickValues({
|
|
118
|
+
scale,
|
|
119
|
+
axis,
|
|
120
|
+
labelLineHeight: maxLabelWidth,
|
|
121
|
+
series,
|
|
122
|
+
});
|
|
123
|
+
tickStep = getMinSpaceBetween(values, (d) => Number(d.value));
|
|
124
|
+
}
|
|
125
|
+
}
|
|
100
126
|
const labelMaxWidth = values.length > 1
|
|
101
127
|
? Math.abs(values[0].x - values[1].x) - axis.labels.padding * 2
|
|
102
128
|
: axisWidth;
|
|
@@ -37,7 +37,7 @@ async function setLabelSettings({ axis, seriesData, width, axisLabels, }) {
|
|
|
37
37
|
}
|
|
38
38
|
return false;
|
|
39
39
|
};
|
|
40
|
-
const autoRotation = (_a = axisLabels === null || axisLabels === void 0 ? void 0 : axisLabels.autoRotation) !== null && _a !== void 0 ? _a :
|
|
40
|
+
const autoRotation = (_a = axisLabels === null || axisLabels === void 0 ? void 0 : axisLabels.autoRotation) !== null && _a !== void 0 ? _a : axis.type !== 'datetime';
|
|
41
41
|
const overlapping = axis.labels.html ? false : await hasOverlappingLabels();
|
|
42
42
|
const defaultRotation = overlapping && autoRotation ? -45 : 0;
|
|
43
43
|
const rotation = axis.labels.html ? 0 : ((_b = axisLabels === null || axisLabels === void 0 ? void 0 : axisLabels.rotation) !== null && _b !== void 0 ? _b : defaultRotation);
|
|
@@ -19,11 +19,14 @@ export interface ChartAxisLabels {
|
|
|
19
19
|
dateFormat?: string;
|
|
20
20
|
numberFormat?: FormatNumberOptions;
|
|
21
21
|
style?: Partial<BaseTextStyle>;
|
|
22
|
-
/**
|
|
22
|
+
/**
|
|
23
|
+
* For horizontal axes, enable label rotation to prevent overlapping labels.
|
|
23
24
|
* If there is enough space, labels are not rotated.
|
|
24
25
|
* As the chart gets narrower, it will start rotating the labels -45 degrees.
|
|
25
26
|
*
|
|
26
27
|
* Does not apply to html labels.
|
|
28
|
+
*
|
|
29
|
+
* @default true for all axis types except `datetime` (defaults to false)
|
|
27
30
|
*/
|
|
28
31
|
autoRotation?: boolean;
|
|
29
32
|
/** Rotation of the labels in degrees.
|