@gravity-ui/charts 1.34.8 → 1.34.10
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/AxisX.js +0 -1
- package/dist/cjs/components/AxisX/prepare-axis-data.js +4 -23
- package/dist/cjs/components/AxisX/types.d.ts +1 -9
- package/dist/cjs/components/AxisY/prepare-axis-title.js +3 -34
- package/dist/cjs/components/AxisY/types.d.ts +1 -9
- package/dist/cjs/components/ChartInner/index.js +6 -6
- package/dist/cjs/components/ChartInner/useChartInnerProps.d.ts +0 -1
- package/dist/cjs/components/ChartInner/useChartInnerProps.js +16 -6
- package/dist/cjs/components/ChartInner/useChartInnerState.d.ts +2 -3
- package/dist/cjs/components/ChartInner/useChartInnerState.js +14 -22
- package/dist/cjs/components/RangeSlider/index.d.ts +0 -1
- package/dist/cjs/components/RangeSlider/index.js +1 -8
- package/dist/cjs/components/Tooltip/DefaultTooltipContent/index.js +2 -1
- package/dist/cjs/components/Tooltip/styles.css +7 -0
- package/dist/cjs/components/types/index.d.ts +9 -0
- package/dist/cjs/components/types/index.js +1 -0
- package/dist/cjs/components/utils/axis-title.d.ts +6 -0
- package/dist/cjs/components/utils/axis-title.js +39 -0
- package/dist/cjs/components/{utils.d.ts → utils/index.d.ts} +3 -3
- package/dist/cjs/components/{utils.js → utils/index.js} +1 -1
- package/dist/cjs/hooks/useAxisScales/index.js +3 -1
- package/dist/cjs/hooks/useAxisScales/x-scale.d.ts +0 -6
- package/dist/cjs/hooks/useAxisScales/x-scale.js +12 -35
- package/dist/cjs/hooks/useRangeSlider/types.d.ts +1 -1
- package/dist/cjs/hooks/useSeries/prepare-legend.js +2 -1
- package/dist/cjs/utils/chart/text.js +14 -9
- package/dist/cjs/utils/chart/zoom.d.ts +2 -1
- package/dist/cjs/utils/chart/zoom.js +9 -0
- package/dist/esm/components/AxisX/AxisX.js +0 -1
- package/dist/esm/components/AxisX/prepare-axis-data.js +4 -23
- package/dist/esm/components/AxisX/types.d.ts +1 -9
- package/dist/esm/components/AxisY/prepare-axis-title.js +3 -34
- package/dist/esm/components/AxisY/types.d.ts +1 -9
- package/dist/esm/components/ChartInner/index.js +6 -6
- package/dist/esm/components/ChartInner/useChartInnerProps.d.ts +0 -1
- package/dist/esm/components/ChartInner/useChartInnerProps.js +16 -6
- package/dist/esm/components/ChartInner/useChartInnerState.d.ts +2 -3
- package/dist/esm/components/ChartInner/useChartInnerState.js +14 -22
- package/dist/esm/components/RangeSlider/index.d.ts +0 -1
- package/dist/esm/components/RangeSlider/index.js +1 -8
- package/dist/esm/components/Tooltip/DefaultTooltipContent/index.js +2 -1
- package/dist/esm/components/Tooltip/styles.css +7 -0
- package/dist/esm/components/types/index.d.ts +9 -0
- package/dist/esm/components/types/index.js +1 -0
- package/dist/esm/components/utils/axis-title.d.ts +6 -0
- package/dist/esm/components/utils/axis-title.js +39 -0
- package/dist/esm/components/{utils.d.ts → utils/index.d.ts} +3 -3
- package/dist/esm/components/{utils.js → utils/index.js} +1 -1
- package/dist/esm/hooks/useAxisScales/index.js +3 -1
- package/dist/esm/hooks/useAxisScales/x-scale.d.ts +0 -6
- package/dist/esm/hooks/useAxisScales/x-scale.js +12 -35
- package/dist/esm/hooks/useRangeSlider/types.d.ts +1 -1
- package/dist/esm/hooks/useSeries/prepare-legend.js +2 -1
- package/dist/esm/utils/chart/text.js +14 -9
- package/dist/esm/utils/chart/zoom.d.ts +2 -1
- package/dist/esm/utils/chart/zoom.js +9 -0
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { extent, scaleBand, scaleLinear, scaleLog, scaleUtc } from 'd3';
|
|
2
2
|
import get from 'lodash/get';
|
|
3
3
|
import { DEFAULT_AXIS_TYPE, SERIES_TYPE } from '../../constants';
|
|
4
|
-
import {
|
|
4
|
+
import { getDefaultMaxXAxisValue, getDefaultMinXAxisValue, getDomainDataXBySeries, getEffectiveXRange, } from '../../utils';
|
|
5
5
|
import { getBandSize } from '../utils/get-band-size';
|
|
6
6
|
import { checkIsPointDomain, filterCategoriesByVisibleSeries, getMinMaxPropsOrState, hasOnlyMarkerSeries, validateArrayData, } from './utils';
|
|
7
7
|
const X_AXIS_ZOOM_PADDING = 0.02;
|
|
@@ -27,23 +27,6 @@ function isSeriesWithXAxisOffset(series) {
|
|
|
27
27
|
const types = [SERIES_TYPE.Heatmap, SERIES_TYPE.BarX];
|
|
28
28
|
return series.some((s) => types.includes(s.type));
|
|
29
29
|
}
|
|
30
|
-
export function getXMaxDomainResult(args) {
|
|
31
|
-
const { xMaxDomain, xMaxProps, xMaxRangeSlider, xMaxZoom } = args;
|
|
32
|
-
let xMaxDomainResult = xMaxDomain;
|
|
33
|
-
// When xMaxRangeSlider is provided, we use it directly without considering xMaxDomain.
|
|
34
|
-
// This is intentional: the range slider needs to display the chart's maxPadding area,
|
|
35
|
-
// which would be clipped if we constrained it to xMaxDomain.
|
|
36
|
-
if (typeof xMaxRangeSlider === 'number') {
|
|
37
|
-
xMaxDomainResult = xMaxRangeSlider;
|
|
38
|
-
}
|
|
39
|
-
else if (typeof xMaxZoom === 'number' && xMaxZoom < xMaxDomain) {
|
|
40
|
-
xMaxDomainResult = xMaxZoom;
|
|
41
|
-
}
|
|
42
|
-
else if (typeof xMaxProps === 'number' && xMaxProps < xMaxDomain) {
|
|
43
|
-
xMaxDomainResult = xMaxProps;
|
|
44
|
-
}
|
|
45
|
-
return xMaxDomainResult;
|
|
46
|
-
}
|
|
47
30
|
function getXScaleRange({ boundsWidth, hasZoomX }) {
|
|
48
31
|
const xAxisZoomPadding = boundsWidth * X_AXIS_ZOOM_PADDING;
|
|
49
32
|
const xRange = [0, boundsWidth];
|
|
@@ -54,22 +37,17 @@ function getXScaleRange({ boundsWidth, hasZoomX }) {
|
|
|
54
37
|
// eslint-disable-next-line complexity
|
|
55
38
|
export function createXScale(args) {
|
|
56
39
|
const { axis, boundsWidth, series, rangeSliderState, zoomStateX } = args;
|
|
40
|
+
const effectiveX = getEffectiveXRange(zoomStateX, rangeSliderState);
|
|
41
|
+
const effectiveXMin = effectiveX === null || effectiveX === void 0 ? void 0 : effectiveX[0];
|
|
42
|
+
const effectiveXMax = effectiveX === null || effectiveX === void 0 ? void 0 : effectiveX[1];
|
|
57
43
|
const [xMinPropsOrState, xMaxPropsOrState] = getMinMaxPropsOrState({
|
|
58
44
|
axis,
|
|
59
|
-
maxValues: [
|
|
60
|
-
minValues: [
|
|
45
|
+
maxValues: [effectiveXMax],
|
|
46
|
+
minValues: [effectiveXMin],
|
|
61
47
|
});
|
|
62
48
|
const xType = get(axis, 'type', DEFAULT_AXIS_TYPE);
|
|
63
49
|
const hasZoomX = Boolean(zoomStateX);
|
|
64
|
-
|
|
65
|
-
if (rangeSliderState && xCategories) {
|
|
66
|
-
xCategories = getAxisCategories({
|
|
67
|
-
categories: xCategories,
|
|
68
|
-
min: rangeSliderState.min,
|
|
69
|
-
max: rangeSliderState.max,
|
|
70
|
-
order: axis.order,
|
|
71
|
-
});
|
|
72
|
-
}
|
|
50
|
+
const xCategories = get(axis, 'categories');
|
|
73
51
|
const maxPadding = get(axis, 'maxPadding', 0);
|
|
74
52
|
const xAxisMaxPadding = boundsWidth * maxPadding + calculateXAxisPadding(series);
|
|
75
53
|
const range = getXScaleRange({
|
|
@@ -193,12 +171,11 @@ export function createXScale(args) {
|
|
|
193
171
|
!isPointDomain
|
|
194
172
|
? xMinPropsOrState
|
|
195
173
|
: xMinTimestamp;
|
|
196
|
-
const xMax =
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
});
|
|
174
|
+
const xMax = typeof xMaxPropsOrState === 'number' &&
|
|
175
|
+
xMaxPropsOrState < xMaxTimestamp &&
|
|
176
|
+
!isPointDomain
|
|
177
|
+
? xMaxPropsOrState
|
|
178
|
+
: xMaxTimestamp;
|
|
202
179
|
domain = [xMin, xMax];
|
|
203
180
|
const scale = scaleUtc().domain(domain).range(range);
|
|
204
181
|
let offsetMin = 0;
|
|
@@ -13,7 +13,7 @@ export interface RangeSliderProps {
|
|
|
13
13
|
boundsWidth: number;
|
|
14
14
|
height: number;
|
|
15
15
|
htmlLayout: HTMLElement | null;
|
|
16
|
-
onUpdate: (nextRangeSliderState?: RangeSliderState
|
|
16
|
+
onUpdate: (nextRangeSliderState?: RangeSliderState) => void;
|
|
17
17
|
preparedChart: PreparedChart;
|
|
18
18
|
preparedLegend: PreparedLegend | null;
|
|
19
19
|
preparedRangeSlider: PreparedRangeSlider;
|
|
@@ -8,7 +8,8 @@ import { getDefaultColorStops, getDomainForContinuousColorScale, getLabelsSize }
|
|
|
8
8
|
export async function getPreparedLegend(args) {
|
|
9
9
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
10
10
|
const { legend, series } = args;
|
|
11
|
-
const
|
|
11
|
+
const seriesWithEnabledLegend = series.filter((s) => { var _a; return ((_a = s.legend) === null || _a === void 0 ? void 0 : _a.enabled) !== false; });
|
|
12
|
+
const enabled = Boolean(typeof (legend === null || legend === void 0 ? void 0 : legend.enabled) === 'boolean' ? legend === null || legend === void 0 ? void 0 : legend.enabled : seriesWithEnabledLegend.length > 1);
|
|
12
13
|
const defaultItemStyle = clone(legendDefaults.itemStyle);
|
|
13
14
|
const itemStyle = get(legend, 'itemStyle');
|
|
14
15
|
const computedItemStyle = merge(defaultItemStyle, itemStyle);
|
|
@@ -205,18 +205,23 @@ export function getTextSizeFn({ style }) {
|
|
|
205
205
|
// We ignore an inaccuracy of less than a pixel.
|
|
206
206
|
// To do this, we round the font size down when comparing it, and the size of the allowed space up.
|
|
207
207
|
export async function getTextWithElipsis({ text: originalText, getTextWidth, maxWidth, }) {
|
|
208
|
-
|
|
208
|
+
const textWidth = Math.floor(await getTextWidth(originalText));
|
|
209
209
|
const textMaxWidth = Math.ceil(maxWidth);
|
|
210
210
|
if (textWidth <= textMaxWidth) {
|
|
211
211
|
return originalText;
|
|
212
212
|
}
|
|
213
|
-
let
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
213
|
+
let low = 0;
|
|
214
|
+
let high = originalText.length;
|
|
215
|
+
while (low < high) {
|
|
216
|
+
const mid = Math.floor((low + high + 1) / 2);
|
|
217
|
+
const candidate = originalText.slice(0, mid) + '…';
|
|
218
|
+
const candidateWidth = Math.floor(await getTextWidth(candidate));
|
|
219
|
+
if (candidateWidth <= textMaxWidth) {
|
|
220
|
+
low = mid;
|
|
221
|
+
}
|
|
222
|
+
else {
|
|
223
|
+
high = mid - 1;
|
|
224
|
+
}
|
|
220
225
|
}
|
|
221
|
-
return
|
|
226
|
+
return low > 0 ? originalText.slice(0, low) + '…' : '';
|
|
222
227
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { PreparedSeries, PreparedXAxis, PreparedYAxis } from '../../hooks';
|
|
1
|
+
import type { PreparedSeries, PreparedXAxis, PreparedYAxis, RangeSliderState } from '../../hooks';
|
|
2
2
|
import type { ZoomState } from '../../hooks/useZoom/types';
|
|
3
3
|
import type { ChartXAxis, ChartYAxis } from '../../types';
|
|
4
4
|
export declare function getZoomedSeriesData(args: {
|
|
@@ -10,3 +10,4 @@ export declare function getZoomedSeriesData(args: {
|
|
|
10
10
|
preparedSeries: PreparedSeries[];
|
|
11
11
|
preparedShapesSeries: PreparedSeries[];
|
|
12
12
|
};
|
|
13
|
+
export declare function getEffectiveXRange(zoomStateX: [number, number] | undefined, rangeSliderState: RangeSliderState | undefined): [number, number] | undefined;
|
|
@@ -123,3 +123,12 @@ export function getZoomedSeriesData(args) {
|
|
|
123
123
|
preparedShapesSeries: zoomedShapesSeriesData,
|
|
124
124
|
};
|
|
125
125
|
}
|
|
126
|
+
export function getEffectiveXRange(zoomStateX, rangeSliderState) {
|
|
127
|
+
if (zoomStateX && rangeSliderState) {
|
|
128
|
+
return [
|
|
129
|
+
Math.max(zoomStateX[0], rangeSliderState.min),
|
|
130
|
+
Math.min(zoomStateX[1], rangeSliderState.max),
|
|
131
|
+
];
|
|
132
|
+
}
|
|
133
|
+
return (zoomStateX !== null && zoomStateX !== void 0 ? zoomStateX : (rangeSliderState ? [rangeSliderState.min, rangeSliderState.max] : undefined));
|
|
134
|
+
}
|