Skip to content

Commit

Permalink
fix tooltip hover on value chart (#1491)
Browse files Browse the repository at this point in the history
  • Loading branch information
SrushtiGangireddy authored Jan 28, 2025
1 parent d35730d commit bc59407
Showing 1 changed file with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ interface Props {
}

export class ValueReactChartComponent extends React.Component<Props, State> {
chartRef: React.RefObject<any>;
constructor(props) {
super(props);
this.state = {
options: null,
pageX: 0,
pageY: 0,
};
this.chartRef = React.createRef();
}

componentDidMount() {
Expand Down Expand Up @@ -169,12 +171,24 @@ export class ValueReactChartComponent extends React.Component<Props, State> {
useHTML: true,
};
}

newBaseOptions.tooltip.positioner = (width, height, point) => {
return {
x: this.state.pageX - 144,
y: this.state.pageY - 90,
};
const chart = this.chartRef.current?.chart; // Access chart via ref
if (!chart) return { x: 0, y: 0 };

const chartWidth = chart.chartWidth;
const chartHeight = chart.chartHeight;

const xPos = point.plotX + chart.plotLeft + point.shapeArgs.width;
const yPos = point.plotY + chart.plotTop - height / 2;

// Ensure the tooltip stays within chart bounds
const adjustedX = Math.max(0, Math.min(chartWidth - width, xPos));
const adjustedY = Math.max(0, Math.min(chartHeight - height, yPos));

return { x: adjustedX, y: adjustedY };
};

this.setState({ options: newBaseOptions });
}

Expand Down

0 comments on commit bc59407

Please sign in to comment.