@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.
Files changed (57) hide show
  1. package/dist/cjs/components/AxisX/AxisX.js +0 -1
  2. package/dist/cjs/components/AxisX/prepare-axis-data.js +4 -23
  3. package/dist/cjs/components/AxisX/types.d.ts +1 -9
  4. package/dist/cjs/components/AxisY/prepare-axis-title.js +3 -34
  5. package/dist/cjs/components/AxisY/types.d.ts +1 -9
  6. package/dist/cjs/components/ChartInner/index.js +6 -6
  7. package/dist/cjs/components/ChartInner/useChartInnerProps.d.ts +0 -1
  8. package/dist/cjs/components/ChartInner/useChartInnerProps.js +16 -6
  9. package/dist/cjs/components/ChartInner/useChartInnerState.d.ts +2 -3
  10. package/dist/cjs/components/ChartInner/useChartInnerState.js +14 -22
  11. package/dist/cjs/components/RangeSlider/index.d.ts +0 -1
  12. package/dist/cjs/components/RangeSlider/index.js +1 -8
  13. package/dist/cjs/components/Tooltip/DefaultTooltipContent/index.js +2 -1
  14. package/dist/cjs/components/Tooltip/styles.css +7 -0
  15. package/dist/cjs/components/types/index.d.ts +9 -0
  16. package/dist/cjs/components/types/index.js +1 -0
  17. package/dist/cjs/components/utils/axis-title.d.ts +6 -0
  18. package/dist/cjs/components/utils/axis-title.js +39 -0
  19. package/dist/cjs/components/{utils.d.ts → utils/index.d.ts} +3 -3
  20. package/dist/cjs/components/{utils.js → utils/index.js} +1 -1
  21. package/dist/cjs/hooks/useAxisScales/index.js +3 -1
  22. package/dist/cjs/hooks/useAxisScales/x-scale.d.ts +0 -6
  23. package/dist/cjs/hooks/useAxisScales/x-scale.js +12 -35
  24. package/dist/cjs/hooks/useRangeSlider/types.d.ts +1 -1
  25. package/dist/cjs/hooks/useSeries/prepare-legend.js +2 -1
  26. package/dist/cjs/utils/chart/text.js +14 -9
  27. package/dist/cjs/utils/chart/zoom.d.ts +2 -1
  28. package/dist/cjs/utils/chart/zoom.js +9 -0
  29. package/dist/esm/components/AxisX/AxisX.js +0 -1
  30. package/dist/esm/components/AxisX/prepare-axis-data.js +4 -23
  31. package/dist/esm/components/AxisX/types.d.ts +1 -9
  32. package/dist/esm/components/AxisY/prepare-axis-title.js +3 -34
  33. package/dist/esm/components/AxisY/types.d.ts +1 -9
  34. package/dist/esm/components/ChartInner/index.js +6 -6
  35. package/dist/esm/components/ChartInner/useChartInnerProps.d.ts +0 -1
  36. package/dist/esm/components/ChartInner/useChartInnerProps.js +16 -6
  37. package/dist/esm/components/ChartInner/useChartInnerState.d.ts +2 -3
  38. package/dist/esm/components/ChartInner/useChartInnerState.js +14 -22
  39. package/dist/esm/components/RangeSlider/index.d.ts +0 -1
  40. package/dist/esm/components/RangeSlider/index.js +1 -8
  41. package/dist/esm/components/Tooltip/DefaultTooltipContent/index.js +2 -1
  42. package/dist/esm/components/Tooltip/styles.css +7 -0
  43. package/dist/esm/components/types/index.d.ts +9 -0
  44. package/dist/esm/components/types/index.js +1 -0
  45. package/dist/esm/components/utils/axis-title.d.ts +6 -0
  46. package/dist/esm/components/utils/axis-title.js +39 -0
  47. package/dist/esm/components/{utils.d.ts → utils/index.d.ts} +3 -3
  48. package/dist/esm/components/{utils.js → utils/index.js} +1 -1
  49. package/dist/esm/hooks/useAxisScales/index.js +3 -1
  50. package/dist/esm/hooks/useAxisScales/x-scale.d.ts +0 -6
  51. package/dist/esm/hooks/useAxisScales/x-scale.js +12 -35
  52. package/dist/esm/hooks/useRangeSlider/types.d.ts +1 -1
  53. package/dist/esm/hooks/useSeries/prepare-legend.js +2 -1
  54. package/dist/esm/utils/chart/text.js +14 -9
  55. package/dist/esm/utils/chart/zoom.d.ts +2 -1
  56. package/dist/esm/utils/chart/zoom.js +9 -0
  57. 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 { getAxisCategories, getDefaultMaxXAxisValue, getDefaultMinXAxisValue, getDomainDataXBySeries, } from '../../utils';
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: [zoomStateX === null || zoomStateX === void 0 ? void 0 : zoomStateX[1], rangeSliderState === null || rangeSliderState === void 0 ? void 0 : rangeSliderState.max],
60
- minValues: [zoomStateX === null || zoomStateX === void 0 ? void 0 : zoomStateX[0], rangeSliderState === null || rangeSliderState === void 0 ? void 0 : rangeSliderState.min],
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
- let xCategories = get(axis, 'categories');
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 = getXMaxDomainResult({
197
- xMaxDomain: xMaxTimestamp,
198
- xMaxProps: get(axis, 'max'),
199
- xMaxRangeSlider: rangeSliderState === null || rangeSliderState === void 0 ? void 0 : rangeSliderState.max,
200
- xMaxZoom: zoomStateX === null || zoomStateX === void 0 ? void 0 : zoomStateX[1],
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, syncZoom?: boolean) => void;
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 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);
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
- let textWidth = Math.floor(await getTextWidth(originalText));
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 text = originalText + '…';
214
- while (textWidth > textMaxWidth && text.length > 2) {
215
- text = text.slice(0, -2) + '…';
216
- textWidth = Math.floor(await getTextWidth(text));
217
- }
218
- if (textWidth > textMaxWidth) {
219
- text = '';
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 text;
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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/charts",
3
- "version": "1.34.8",
3
+ "version": "1.34.10",
4
4
  "description": "A flexible JavaScript library for data visualization and chart rendering using React",
5
5
  "license": "MIT",
6
6
  "main": "dist/cjs/index.js",