amcharts / amcharts5

The newest, fastest, and most advanced amCharts charting library for JavaScript and TypeScript apps.
Other
345 stars 92 forks source link

Bug tooltip outside the chartContainer #1653

Closed SinGlEBW closed 2 weeks ago

SinGlEBW commented 1 month ago

The error is that if you use a tooltip outside the chartContainer container and then create it separately, the tooltip loses its position relative to the element it belongs to.

If you use resize windows or ckick by slice, the tooltip is set to the correct position

"@amcharts/amcharts5": "^5.9.13", "react": "^18.3.1", "react-dom": "^18.3.1"

GoogleChrome: Version 126.0.6478.127 (Официальная сборка), (64 бит)

https://stackblitz.com/edit/vitejs-vite-mofybj?file=src%2FPieByCategory%2FPieByCategory.tsx

The solution was found by me using an adapter: "pointTo"

tooltipButton.adapters.add('pointTo', (value) => {
       const containerButtonBounds = containerButton.bounds();
       const buttonBounds = button.bounds();
       const buttonCenterY = button.height() / 2;
       return {
         ...value,
        y: containerButtonBounds.top + buttonCenterY + buttonBounds.top,
       } as am5.IPoint;
    });

//adapter "y" no correct:

tooltipButton.adapters.add('y', (value) => {
     /*Strange behavior of a small triangle if you use manual calculation of the Y axis in the adapter "y" */
    const containerButtonBounds = containerButton.bounds();
       const buttonBounds = button.bounds();
       const buttonCenterY = button.height() / 2;
      return containerButtonBounds.top + buttonCenterY + buttonBounds.top
})
martynasma commented 1 month ago

I'm afraid the target demo is too broad for our scope of support.

Please consider providing a scaled down version with just the relevant code.

github-actions[bot] commented 3 weeks ago

This issue is stale because it has been open 30 days with no activity. It will be closed in 5 days unless a new comment is added.