Skip to content
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

Wrong tooltip position #239

Open
evgenoid opened this issue Aug 30, 2024 · 4 comments
Open

Wrong tooltip position #239

evgenoid opened this issue Aug 30, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@evgenoid
Copy link

When I try to load page where the map presents and try to hover some country, tooltip displays in wrong position.

To Reproduce

  1. Just load the page where the map is presented. Reproduces sometimes.

Expected behavior

Tooltip should be displayed near the country

Screenshots

Screenshot 2024-08-30 at 10 05 52 Screenshot 2024-08-30 at 10 06 11

Context

  • Version: 4.3.1
  • Browser: Google Chrome Version 127.0.6533.120 (Official Build) (arm64)

Additional context

List of countries from: https://unpkg.com/world-atlas/countries-50m.json

Configuretion:

    <Chart
      ref={chartRef}
      type="choropleth"
      data={{
        labels: countries.map((d: any) => d.properties.name),
        datasets: [
          {
            label: 'Countries',
            data: countries.map((d) => ({ feature: d })),
            backgroundColor: (context) =>
              isRegionOrContryWise?.includes((context.raw as any)?.feature?.properties?.name)
                ? themePalette.palette.primary700
                : themePalette.tokens.surfaceBadgesFillDefault,
          },
        ],
      }}
      options={{
        plugins: {
          tooltip: {
            backgroundColor: themePalette.palette.primary950_40,
            displayColors: false,
            filter: (context) => isRegionOrContryWise?.includes((context.raw as any)?.feature?.properties?.name),
            callbacks: {
              label: (context: any) => context.element.feature.properties.name,
            },
          },
          legend: {
            display: false,
          },
        },
        scales: {
          projection: {
            axis: 'y',
            projection: 'naturalEarth1',
          },
          color: {
            axis: 'x',
            display: false,
            quantize: 5,
          },
        },
      }}
    />
@evgenoid evgenoid added the bug Something isn't working label Aug 30, 2024
@sgratzl
Copy link
Owner

sgratzl commented Sep 8, 2024

are those native chart.js tooltips or custom ones? I cannot see where the tooltip is supposed to pointing at.

@evgenoid
Copy link
Author

evgenoid commented Sep 9, 2024

are those native chart.js tooltips or custom ones? I cannot see where the tooltip is supposed to pointing at.

Normally it should appears near the country:
Screenshot 2024-09-09 at 09 13 58

@sgratzl
Copy link
Owner

sgratzl commented Oct 6, 2024

not sure what I can do here. The tooltip position is computed by:

getCenterPoint(): { x: number; y: number } {
if (this.cache && this.cache.center) {
return this.cache.center;
}
let center: { x: number; y: number };
if (this.center) {
const p = this.projectionScale.projection([this.center.longitude, this.center.latitude])!;
center = {
x: p[0]!,
y: p[1]!,
};
} else {
const centroid = this.projectionScale.geoPath.centroid(this.feature);
center = {
x: centroid[0],
y: centroid[1],
};
}
this.cache = { ...(this.cache || {}), center };
return center;
}

i.e you can provide a center point in your data or it will compute the centroid fo the geo shape/feature.

@sgratzl
Copy link
Owner

sgratzl commented Oct 26, 2024

I can reproduce it in https://codepen.io/sgratzl/pen/gOaBQep but don't know yet what causes it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants