@gravity-ui/charts 1.43.0 → 1.43.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.
Files changed (55) hide show
  1. package/dist/cjs/components/ChartInner/index.js +3 -3
  2. package/dist/cjs/components/ChartInner/useChartInnerHandlers.d.ts +3 -3
  3. package/dist/cjs/components/ChartInner/useChartInnerHandlers.js +10 -12
  4. package/dist/cjs/components/ChartInner/useChartInnerProps.js +8 -4
  5. package/dist/cjs/components/ChartInner/utils/title.d.ts +3 -2
  6. package/dist/cjs/components/ChartInner/utils/title.js +19 -14
  7. package/dist/cjs/components/Title/index.d.ts +1 -3
  8. package/dist/cjs/components/Title/index.js +2 -2
  9. package/dist/cjs/core/constants/index.d.ts +0 -1
  10. package/dist/cjs/core/constants/index.js +0 -1
  11. package/dist/cjs/core/utils/labels.d.ts +1 -1
  12. package/dist/cjs/core/utils/labels.js +3 -2
  13. package/dist/cjs/hooks/useSeries/index.js +8 -2
  14. package/dist/cjs/hooks/useShapes/area/index.js +2 -2
  15. package/dist/cjs/hooks/useShapes/area/prepare-data.js +4 -4
  16. package/dist/cjs/hooks/useShapes/area/types.d.ts +2 -2
  17. package/dist/cjs/hooks/useShapes/bar-x/index.js +2 -2
  18. package/dist/cjs/hooks/useShapes/bar-x/prepare-data.js +15 -12
  19. package/dist/cjs/hooks/useShapes/bar-x/types.d.ts +2 -2
  20. package/dist/cjs/hooks/useShapes/index.js +18 -5
  21. package/dist/cjs/hooks/useShapes/line/index.js +7 -16
  22. package/dist/cjs/hooks/useShapes/line/prepare-data.d.ts +2 -0
  23. package/dist/cjs/hooks/useShapes/line/prepare-data.js +11 -7
  24. package/dist/cjs/hooks/useShapes/line/types.d.ts +2 -2
  25. package/dist/cjs/types/chart-ui.d.ts +4 -0
  26. package/dist/esm/components/ChartInner/index.js +3 -3
  27. package/dist/esm/components/ChartInner/useChartInnerHandlers.d.ts +3 -3
  28. package/dist/esm/components/ChartInner/useChartInnerHandlers.js +10 -12
  29. package/dist/esm/components/ChartInner/useChartInnerProps.js +8 -4
  30. package/dist/esm/components/ChartInner/utils/title.d.ts +3 -2
  31. package/dist/esm/components/ChartInner/utils/title.js +19 -14
  32. package/dist/esm/components/Title/index.d.ts +1 -3
  33. package/dist/esm/components/Title/index.js +2 -2
  34. package/dist/esm/core/constants/index.d.ts +0 -1
  35. package/dist/esm/core/constants/index.js +0 -1
  36. package/dist/esm/core/utils/labels.d.ts +1 -1
  37. package/dist/esm/core/utils/labels.js +3 -2
  38. package/dist/esm/hooks/useSeries/index.js +8 -2
  39. package/dist/esm/hooks/useShapes/area/index.js +2 -2
  40. package/dist/esm/hooks/useShapes/area/prepare-data.js +4 -4
  41. package/dist/esm/hooks/useShapes/area/types.d.ts +2 -2
  42. package/dist/esm/hooks/useShapes/bar-x/index.js +2 -2
  43. package/dist/esm/hooks/useShapes/bar-x/prepare-data.js +15 -12
  44. package/dist/esm/hooks/useShapes/bar-x/types.d.ts +2 -2
  45. package/dist/esm/hooks/useShapes/index.js +18 -5
  46. package/dist/esm/hooks/useShapes/line/index.js +7 -16
  47. package/dist/esm/hooks/useShapes/line/prepare-data.d.ts +2 -0
  48. package/dist/esm/hooks/useShapes/line/prepare-data.js +11 -7
  49. package/dist/esm/hooks/useShapes/line/types.d.ts +2 -2
  50. package/dist/esm/types/chart-ui.d.ts +4 -0
  51. package/package.json +1 -1
  52. package/dist/cjs/core/constants/misc.d.ts +0 -1
  53. package/dist/cjs/core/constants/misc.js +0 -7
  54. package/dist/esm/core/constants/misc.d.ts +0 -1
  55. package/dist/esm/core/constants/misc.js +0 -7
@@ -1,4 +1,4 @@
1
- import { getLabelsSize, getTextSizeFn } from '../../../core/utils';
1
+ import { filterOverlappingLabels, getLabelsSize, getTextSizeFn } from '../../../core/utils';
2
2
  import { getFormattedValue } from '../../../core/utils/format';
3
3
  import { getXValue, getYValue } from '../utils';
4
4
  async function getHtmlLabel(point, series, xMax) {
@@ -16,7 +16,7 @@ async function getHtmlLabel(point, series, xMax) {
16
16
  }
17
17
  export const prepareLineData = async (args) => {
18
18
  var _a, _b, _c, _d;
19
- const { series, xAxis, yAxis, xScale, yScale, split, isOutsideBounds, isRangeSlider } = args;
19
+ const { series, xAxis, yAxis, xScale, yScale, split, isOutsideBounds, isRangeSlider, otherLayers, } = args;
20
20
  const [_xMin, xRangeMax] = xScale.range();
21
21
  const xMax = xRangeMax;
22
22
  const acc = [];
@@ -44,8 +44,8 @@ export const prepareLineData = async (args) => {
44
44
  series: s,
45
45
  };
46
46
  });
47
- const htmlElements = [];
48
- const labels = [];
47
+ let htmlElements = [];
48
+ let svgLabels = [];
49
49
  if (s.dataLabels.enabled && !isRangeSlider) {
50
50
  if (s.dataLabels.html) {
51
51
  const list = await Promise.all(points.reduce((result, p) => {
@@ -83,11 +83,15 @@ export const prepareLineData = async (args) => {
83
83
  series: s,
84
84
  active: true,
85
85
  };
86
- labels.push(labelData);
86
+ svgLabels.push(labelData);
87
87
  }
88
88
  }
89
89
  }
90
90
  }
91
+ if (!s.dataLabels.allowOverlap) {
92
+ svgLabels = filterOverlappingLabels(svgLabels, otherLayers.map((l) => l.svgLabels).flat());
93
+ htmlElements = filterOverlappingLabels(htmlElements, otherLayers.map((l) => l.htmlLabels).flat());
94
+ }
91
95
  let markers = [];
92
96
  const hasPerPointNormalMarkers = s.data.some((d) => { var _a, _b, _c; return (_c = (_b = (_a = d.marker) === null || _a === void 0 ? void 0 : _a.states) === null || _b === void 0 ? void 0 : _b.normal) === null || _c === void 0 ? void 0 : _c.enabled; });
93
97
  if (s.marker.states.normal.enabled || hasPerPointNormalMarkers) {
@@ -111,12 +115,12 @@ export const prepareLineData = async (args) => {
111
115
  const result = {
112
116
  points,
113
117
  markers,
114
- labels,
118
+ svgLabels: svgLabels,
115
119
  series: s,
116
120
  hovered: false,
117
121
  active: true,
118
122
  id: s.id,
119
- htmlElements,
123
+ htmlLabels: htmlElements,
120
124
  color: s.color,
121
125
  lineWidth: (_c = (isRangeSlider ? s.rangeSlider.lineWidth : undefined)) !== null && _c !== void 0 ? _c : s.lineWidth,
122
126
  dashStyle: s.dashStyle,
@@ -25,8 +25,8 @@ export type PreparedLineData = {
25
25
  series: PreparedLineSeries;
26
26
  hovered: boolean;
27
27
  active: boolean;
28
- labels: LabelData[];
29
- htmlElements: HtmlItem[];
28
+ svgLabels: LabelData[];
29
+ htmlLabels: HtmlItem[];
30
30
  color: string;
31
31
  dashStyle: DashStyle;
32
32
  linecap: LineCap;
@@ -25,6 +25,10 @@ export interface HtmlItem {
25
25
  };
26
26
  style?: BaseTextStyle & React.CSSProperties;
27
27
  }
28
+ export interface ShapeDataWithLabels {
29
+ svgLabels: LabelData[];
30
+ htmlLabels: HtmlItem[];
31
+ }
28
32
  export interface ShapeDataWithHtmlItems {
29
33
  htmlElements: HtmlItem[];
30
34
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/charts",
3
- "version": "1.43.0",
3
+ "version": "1.43.1",
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",
@@ -1 +0,0 @@
1
- export declare const IS_TOUCH_ENABLED: boolean;
@@ -1,7 +0,0 @@
1
- function isTouchEnabled() {
2
- if (typeof window !== 'object') {
3
- return false;
4
- }
5
- return 'ontouchstart' in window || navigator.maxTouchPoints > 0;
6
- }
7
- export const IS_TOUCH_ENABLED = isTouchEnabled();
@@ -1 +0,0 @@
1
- export declare const IS_TOUCH_ENABLED: boolean;
@@ -1,7 +0,0 @@
1
- function isTouchEnabled() {
2
- if (typeof window !== 'object') {
3
- return false;
4
- }
5
- return 'ontouchstart' in window || navigator.maxTouchPoints > 0;
6
- }
7
- export const IS_TOUCH_ENABLED = isTouchEnabled();