Skip to content

Commit 54770e0

Browse files
committed
fix: heatmap anchor
1 parent 87ac421 commit 54770e0

File tree

3 files changed

+29
-8
lines changed

3 files changed

+29
-8
lines changed

src/containers/Heatmap/Heatmap.scss

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@
5151
}
5252

5353
&__items {
54+
position: relative;
55+
5456
overflow: auto;
5557
}
5658
&__canvas-container {
@@ -59,6 +61,15 @@
5961
cursor: pointer;
6062
}
6163

64+
&__tooltip-anchor {
65+
position: absolute;
66+
67+
width: 1px;
68+
height: 1px;
69+
70+
pointer-events: none;
71+
}
72+
6273
&__filters {
6374
display: flex;
6475
align-items: center;

src/containers/Heatmap/Heatmap.tsx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22

3-
import {Checkbox, Popup, Select, useVirtualElementRef} from '@gravity-ui/uikit';
3+
import {Checkbox, Popup, Select} from '@gravity-ui/uikit';
44

55
import {ResponseError} from '../../components/Errors/ResponseError';
66
import {Loader} from '../../components/Loader';
@@ -37,10 +37,7 @@ export const Heatmap = ({path, database, databaseFullPath}: HeatmapProps) => {
3737
position: {left: number; top: number};
3838
} | null>(null);
3939
const [isTabletTooltipHovered, setIsTabletTooltipHovered] = React.useState(false);
40-
41-
const tabletTooltipAnchorRef = useVirtualElementRef({
42-
rect: tabletTooltip?.position,
43-
});
40+
const tabletTooltipAnchorRef = React.useRef<HTMLDivElement | null>(null);
4441

4542
const [autoRefreshInterval] = useAutoRefreshInterval();
4643

@@ -133,6 +130,16 @@ export const Heatmap = ({path, database, databaseFullPath}: HeatmapProps) => {
133130

134131
return (
135132
<div ref={itemsContainer} className={b('items')}>
133+
{tabletTooltip ? (
134+
<div
135+
ref={tabletTooltipAnchorRef}
136+
className={b('tooltip-anchor')}
137+
style={{
138+
left: tabletTooltip.position.left,
139+
top: tabletTooltip.position.top,
140+
}}
141+
/>
142+
) : null}
136143
<HeatmapCanvas
137144
tablets={sortedTablets}
138145
parentRef={itemsContainer}
@@ -158,7 +165,7 @@ export const Heatmap = ({path, database, databaseFullPath}: HeatmapProps) => {
158165
open
159166
hasArrow
160167
placement={['top', 'bottom', 'left', 'right']}
161-
anchorRef={tabletTooltipAnchorRef}
168+
anchorElement={tabletTooltipAnchorRef.current}
162169
onOutsideClick={handleHideTabletTooltip}
163170
>
164171
<div

src/containers/Heatmap/HeatmapCanvas/HeatmapCanvas.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,14 +182,17 @@ export const HeatmapCanvas = (props: HeatmapCanvasProps) => {
182182

183183
if (tablet) {
184184
const {columnsCount} = dimensions;
185+
if (!columnsCount) {
186+
return;
187+
}
185188
const colIndex = tabletIndex % columnsCount;
186189
const rowIndex = Math.floor(tabletIndex / columnsCount);
187190

188191
const rectX = colIndex * (TABLET_SIZE + TABLET_PADDING);
189192
const rectY = rowIndex * (TABLET_SIZE + TABLET_PADDING);
190193

191-
const left = getOffsetLeft() - parent.scrollLeft + rectX + TABLET_SIZE / 2;
192-
const top = getOffsetTop() - parent.scrollTop + rectY + TABLET_SIZE / 2;
194+
const left = rectX + TABLET_SIZE / 2;
195+
const top = rectY + TABLET_SIZE / 2;
193196

194197
onShowTabletTooltip(tablet, {left, top});
195198
} else {

0 commit comments

Comments
 (0)