@gravity-ui/chartkit 4.20.0 → 4.20.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.
@@ -1,40 +1,16 @@
1
1
  import React from 'react';
2
2
  import isNil from 'lodash/isNil';
3
+ import { Popup, useVirtualElementRef } from '@gravity-ui/uikit';
3
4
  import { block } from '../../../../../utils/cn';
4
5
  import { DefaultContent } from './DefaultContent';
5
6
  export * from './TooltipTriggerArea';
6
7
  const b = block('d3-tooltip');
7
- const POINTER_OFFSET_X = 20;
8
8
  export const Tooltip = (props) => {
9
- const { tooltip, svgContainer, xAxis, yAxis, hovered, pointerPosition } = props;
10
- const ref = React.useRef(null);
11
- const size = React.useMemo(() => {
12
- if (ref.current && hovered) {
13
- const { width, height } = ref.current.getBoundingClientRect();
14
- return { width, height };
15
- }
16
- return undefined;
17
- // eslint-disable-next-line react-hooks/exhaustive-deps
18
- }, [hovered, pointerPosition]);
19
- const position = React.useMemo(() => {
20
- if (hovered && pointerPosition && size) {
21
- const { clientWidth } = document.documentElement;
22
- const { width, height } = size;
23
- const rect = (svgContainer === null || svgContainer === void 0 ? void 0 : svgContainer.getBoundingClientRect()) || { left: 0, top: 0 };
24
- const [pointerLeft, pointetTop] = pointerPosition;
25
- const outOfRightBoudary = pointerLeft + width + rect.left + POINTER_OFFSET_X >= clientWidth;
26
- const outOfTopBoundary = pointetTop - height / 2 <= 0;
27
- const left = outOfRightBoudary
28
- ? pointerLeft - width - POINTER_OFFSET_X
29
- : pointerLeft + POINTER_OFFSET_X;
30
- const top = outOfTopBoundary ? 0 : pointetTop - height / 2;
31
- return { left, top };
32
- }
33
- else if (hovered && pointerPosition) {
34
- return { left: -1000, top: -1000 };
35
- }
36
- return undefined;
37
- }, [hovered, pointerPosition, size, svgContainer]);
9
+ const { tooltip, xAxis, yAxis, hovered, svgContainer, pointerPosition } = props;
10
+ const containerRect = (svgContainer === null || svgContainer === void 0 ? void 0 : svgContainer.getBoundingClientRect()) || { left: 0, top: 0 };
11
+ const left = ((pointerPosition === null || pointerPosition === void 0 ? void 0 : pointerPosition[0]) || 0) + containerRect.left;
12
+ const top = ((pointerPosition === null || pointerPosition === void 0 ? void 0 : pointerPosition[1]) || 0) + containerRect.top;
13
+ const anchorRef = useVirtualElementRef({ rect: { top, left } });
38
14
  const content = React.useMemo(() => {
39
15
  var _a;
40
16
  if (!hovered) {
@@ -43,14 +19,9 @@ export const Tooltip = (props) => {
43
19
  const customTooltip = (_a = tooltip.renderer) === null || _a === void 0 ? void 0 : _a.call(tooltip, { hovered });
44
20
  return isNil(customTooltip) ? (React.createElement(DefaultContent, { hovered: hovered, xAxis: xAxis, yAxis: yAxis })) : (customTooltip);
45
21
  }, [hovered, tooltip, xAxis, yAxis]);
46
- if (!position || !hovered) {
47
- return null;
48
- }
49
- const { left, top } = position;
50
- const style = {
51
- position: 'absolute',
52
- top,
53
- left: left,
54
- };
55
- return (React.createElement("div", { ref: ref, className: b(), style: style }, content));
22
+ React.useEffect(() => {
23
+ window.dispatchEvent(new CustomEvent('scroll'));
24
+ }, [left, top]);
25
+ return hovered ? (React.createElement(Popup, { className: b(), open: true, anchorRef: anchorRef, offset: [0, 20], placement: ['right', 'left', 'top', 'bottom'], modifiers: [{ name: 'preventOverflow', options: { padding: 10, altAxis: true } }] },
26
+ React.createElement("div", { className: b('content') }, content))) : null;
56
27
  };
@@ -75,13 +75,22 @@
75
75
  fill: var(--g-color-text-primary);
76
76
  }
77
77
 
78
- .chartkit-d3-tooltip {
79
- position: absolute;
78
+ .chartkit-d3-tooltip[class] {
79
+ --yc-popup-border-width: 0;
80
+ pointer-events: none;
81
+ }
82
+
83
+ .chartkit-d3-tooltip[class] > div {
84
+ animation-duration: unset;
85
+ animation-timing-function: unset;
86
+ animation-fill-mode: unset;
87
+ }
88
+
89
+ .chartkit-d3-tooltip__content {
80
90
  padding: 10px 14px;
81
91
  background-color: var(--g-color-infographics-tooltip-bg);
82
92
  border: 1px solid var(--g-color-line-generic);
83
93
  border-radius: 3px;
84
94
  box-shadow: 0 2px 12px var(--g-color-sfx-shadow);
85
- z-index: 100001;
86
95
  text-wrap: nowrap;
87
96
  }
@@ -10,7 +10,7 @@ export function preparePieSeries(args) {
10
10
  const colorScale = scaleOrdinal(dataNames, DEFAULT_PALETTE);
11
11
  const stackId = getRandomCKId();
12
12
  const seriesHoverState = get(seriesOptions, 'pie.states.hover');
13
- const preparedSeries = series.data.map((dataItem) => {
13
+ const preparedSeries = series.data.map((dataItem, i) => {
14
14
  var _a, _b, _c;
15
15
  const result = {
16
16
  type: 'pie',
@@ -29,7 +29,7 @@ export function preparePieSeries(args) {
29
29
  value: dataItem.value,
30
30
  visible: typeof dataItem.visible === 'boolean' ? dataItem.visible : true,
31
31
  name: dataItem.name,
32
- id: '',
32
+ id: `Series ${i}`,
33
33
  color: dataItem.color || colorScale(dataItem.name),
34
34
  legend: {
35
35
  enabled: get(series, 'legend.enabled', legend.enabled),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/chartkit",
3
- "version": "4.20.0",
3
+ "version": "4.20.1",
4
4
  "description": "React component used to render charts based on any sources you need",
5
5
  "license": "MIT",
6
6
  "repository": "git@github.com:gravity-ui/ChartKit.git",