Skip to content

fixed tooltip for pie chart #192

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/grafana-ui/src/components/Portal/Portal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ interface Props {
forwardedRef?: React.ForwardedRef<HTMLDivElement>;
}

export function Portal(props: PropsWithChildren<Props>) {
export const Portal: React.FC<PropsWithChildren<Props>> = (props) => {
const { children, className, root, forwardedRef } = props;
const theme = useTheme2();
const node = useRef<HTMLDivElement | null>(null);
Expand Down
18 changes: 6 additions & 12 deletions public/app/plugins/panel/piechart/PieChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { localPoint } from '@visx/event';
import { RadialGradient } from '@visx/gradient';
import { Group } from '@visx/group';
import Pie, { PieArcDatum, ProvidedProps } from '@visx/shape/lib/shapes/Pie';
import { useTooltip, useTooltipInPortal } from '@visx/tooltip';
import { useTooltip } from '@visx/tooltip';
import { UseTooltipParams } from '@visx/tooltip/lib/hooks/useTooltip';
import { useCallback } from 'react';
import * as React from 'react';
Expand Down Expand Up @@ -60,10 +60,6 @@ export const PieChart = ({
const componentInstanceId = useComponentInstanceId('PieChart');
const styles = useStyles2(getStyles);
const tooltip = useTooltip<SeriesTableRowProps[]>();
const { containerRef, TooltipInPortal } = useTooltipInPortal({
detectBounds: true,
scroll: true,
});

const filteredFieldDisplayValues = fieldDisplayValues.filter(filterDisplayItems);

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

return (
<div className={styles.container}>
<svg width={layout.size} height={layout.size} ref={containerRef} style={{ overflow: 'visible' }}>
<svg width={layout.size} height={layout.size} style={{ overflow: 'visible' }}>
<Group top={layout.position} left={layout.position}>
{colors.map((color) => {
return (
Expand Down Expand Up @@ -169,16 +165,14 @@ export const PieChart = ({
</Group>
</svg>
{showTooltip ? (
<TooltipInPortal
<div
key={Math.random()}
top={tooltip.tooltipTop}
style={{ position: 'absolute', top: layout.position,
left: layout.position, zIndex: 9999 }}
className={styles.tooltipPortal}
left={tooltip.tooltipLeft}
unstyled={true}
applyPositionStyle={true}
>
<SeriesTable series={tooltip.tooltipData!} />
</TooltipInPortal>
</div>
) : null}
</div>
);
Expand Down