Skip to content

Commit f633be4

Browse files
authoredNov 11, 2024
fixed tooltip for pie chart (#192)
1 parent 4e1ac22 commit f633be4

File tree

2 files changed

+7
-13
lines changed

2 files changed

+7
-13
lines changed
 

‎packages/grafana-ui/src/components/Portal/Portal.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ interface Props {
1313
forwardedRef?: React.ForwardedRef<HTMLDivElement>;
1414
}
1515

16-
export function Portal(props: PropsWithChildren<Props>) {
16+
export const Portal: React.FC<PropsWithChildren<Props>> = (props) => {
1717
const { children, className, root, forwardedRef } = props;
1818
const theme = useTheme2();
1919
const node = useRef<HTMLDivElement | null>(null);

‎public/app/plugins/panel/piechart/PieChart.tsx

+6-12
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { localPoint } from '@visx/event';
33
import { RadialGradient } from '@visx/gradient';
44
import { Group } from '@visx/group';
55
import Pie, { PieArcDatum, ProvidedProps } from '@visx/shape/lib/shapes/Pie';
6-
import { useTooltip, useTooltipInPortal } from '@visx/tooltip';
6+
import { useTooltip } from '@visx/tooltip';
77
import { UseTooltipParams } from '@visx/tooltip/lib/hooks/useTooltip';
88
import { useCallback } from 'react';
99
import * as React from 'react';
@@ -60,10 +60,6 @@ export const PieChart = ({
6060
const componentInstanceId = useComponentInstanceId('PieChart');
6161
const styles = useStyles2(getStyles);
6262
const tooltip = useTooltip<SeriesTableRowProps[]>();
63-
const { containerRef, TooltipInPortal } = useTooltipInPortal({
64-
detectBounds: true,
65-
scroll: true,
66-
});
6763

6864
const filteredFieldDisplayValues = fieldDisplayValues.filter(filterDisplayItems);
6965

@@ -85,7 +81,7 @@ export const PieChart = ({
8581

8682
return (
8783
<div className={styles.container}>
88-
<svg width={layout.size} height={layout.size} ref={containerRef} style={{ overflow: 'visible' }}>
84+
<svg width={layout.size} height={layout.size} style={{ overflow: 'visible' }}>
8985
<Group top={layout.position} left={layout.position}>
9086
{colors.map((color) => {
9187
return (
@@ -169,16 +165,14 @@ export const PieChart = ({
169165
</Group>
170166
</svg>
171167
{showTooltip ? (
172-
<TooltipInPortal
168+
<div
173169
key={Math.random()}
174-
top={tooltip.tooltipTop}
170+
style={{ position: 'absolute', top: layout.position,
171+
left: layout.position, zIndex: 9999 }}
175172
className={styles.tooltipPortal}
176-
left={tooltip.tooltipLeft}
177-
unstyled={true}
178-
applyPositionStyle={true}
179173
>
180174
<SeriesTable series={tooltip.tooltipData!} />
181-
</TooltipInPortal>
175+
</div>
182176
) : null}
183177
</div>
184178
);

0 commit comments

Comments
 (0)
Failed to load comments.