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

Incorrect hovering behaviour of StackedBarChart #5124

Closed
mfialko opened this issue Oct 17, 2024 · 20 comments · Fixed by #5400
Closed

Incorrect hovering behaviour of StackedBarChart #5124

mfialko opened this issue Oct 17, 2024 · 20 comments · Fixed by #5400
Assignees
Labels
3.0 Issues we need fixed before releasing 3.0 bug General bug label Tooltip Issues that deal with the Tooltip content, its behaviour, and bugs.

Comments

@mfialko
Copy link

mfialko commented Oct 17, 2024

Do you want to request a feature or report a bug?

Bug

What is the current behavior?

I want to highlight only the rectangles within the bar that I hovered over. I set it up to have a different tooltip for each rectangle in the bar via <Tooltip shared={false} />. I use <Bar activeBar={{ fill: "#82ca9dCC" }} /> to fill the hovered area with a lighter color. However, when I hover over the bar, the active bar overlaps the remaining bars.

Steps to reproduce and demo of the problem

Codesandbox: https://codesandbox.io/p/sandbox/stacked-bar-chart-forked-p3tp97

Here is the demo:

Screen Recording 2024-10-17 at 20 02 29

What is the expected behavior?

When I hover an area - it is highlighted.

Which versions of Recharts, and which browser / OS are affected by this issue?

Recharts: 2.13.0
Google Chrome: 129
OS: MacOS 15.0

@ckifer
Copy link
Member

ckifer commented Oct 17, 2024

Does this happen on previous versions or no?

@mfialko
Copy link
Author

mfialko commented Oct 17, 2024

v2.13.0-alpha.5 - yes, same behaviour
v2.13.0-alpha.4 - yes

releases from 2.12.0 to 2.12.7 show me error minPointSize is not a function for this codesandbox

@ckifer
Copy link
Member

ckifer commented Oct 17, 2024

I'll take a look but I'm currently on vacation and can't address this for ~2 weeks

@ckifer ckifer added the bug General bug label label Oct 28, 2024
@ckifer
Copy link
Member

ckifer commented Oct 28, 2024

it looks like the hovering functionality for shared is messed up in general and it has been since 2.9.0 when activeBar was added.

@ckifer
Copy link
Member

ckifer commented Oct 28, 2024

https://codesandbox.io/p/sandbox/stacked-bar-chart-forked-p3tp97

This is possible only without an activeBar prop at this time in 2.x.

activeBar is based on indices and with shared={false} we can no longer rely on indices as the indices were axis item based. This should be possible in 3.x

@ckifer ckifer added the 3.0 Issues we need fixed before releasing 3.0 label Oct 28, 2024
@kaaviya-min
Copy link

Adding onMouseEnter and onMouseLeave to <Bar /> with tooltip shared false. Doesn't render the active value on the tooltip. Will this also fix on version 3.0?

@ckifer
Copy link
Member

ckifer commented Oct 31, 2024

I would think so but not sure, I'll check and get back

@ckifer ckifer added the Tooltip Issues that deal with the Tooltip content, its behaviour, and bugs. label Nov 7, 2024
@ckifer
Copy link
Member

ckifer commented Nov 8, 2024

I can't seem to reproduce the issue with onMouseEnter/Leave

@PavelVanecek
Copy link
Collaborator

Hello everyone who's watching this issue! We have released an alpha version 3.0.0-alpha.2 which fixes this problem.

Here is a migration guide: https://github.com/recharts/recharts/wiki/3.0-migration-guide

As of now we have fixed all the new 3.x bugs we are aware of so, and are ready for your feedback. Please feel free to try recharts: 3.0.0-alpha.2 in a test build and let us know how it went!

@zommerberg
Copy link

@PavelVanecek

Seems like after upgrading to v3 i get a "XXX cannot be used as a JSX component" whenever i import anything like a Barchart or similar.
In my ts config i have ES2022 as a target, were there any other typescript requirement changes?

{
  "$schema": "https://json.schemastore.org/tsconfig",
  "display": "Default",
  "compilerOptions": {
    "declaration": true,
    "declarationMap": true,
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "incremental": false,
    "isolatedModules": true,
    "lib": ["es2022", "DOM", "DOM.Iterable"],
    "moduleDetection": "force",
    "resolveJsonModule": true,
    "skipLibCheck": true,
    "strict": true,
    "target": "ES2022",
    "strictNullChecks": true,
    "plugins": [{ "name": "next" }],
    "module": "ESNext",
    "moduleResolution": "Bundler",
    "allowJs": true,
    "jsx": "preserve",
    "noEmit": true
    }
}

Full error:

  Its type 'ForwardRefExoticComponent<CategoricalChartProps & RefAttributes<{ clipPathId: string; container?: HTMLElement | undefined; parseEventsOfWrapper(): { [x: string]: (e?: Event | undefined) => any; } | { ...; }; ... 19 more ...; UNSAFE_componentWillUpdate?(nextProps: Readonly<...>, nextState: Readonly<...>, nextContext:...' is not a valid JSX element type.
    Type 'ForwardRefExoticComponent<CategoricalChartProps & RefAttributes<{ clipPathId: string; container?: HTMLElement | undefined; parseEventsOfWrapper(): { [x: string]: (e?: Event | undefined) => any; } | { ...; }; ... 19 more ...; UNSAFE_componentWillUpdate?(nextProps: Readonly<...>, nextState: Readonly<...>, nextContext:...' is not assignable to type '(props: any) => ReactNode | Promise<ReactNode>'.
      Type 'ReactNode' is not assignable to type 'ReactNode | Promise<ReactNode>'.
        Type 'ReactElement<any, string | JSXElementConstructor<any>>' is not assignable to type 'ReactNode | Promise<ReactNode>'.
          Property 'children' is missing in type 'ReactElement<any, string | JSXElementConstructor<any>>' but required in type 'ReactPortal'.ts(2786)
index.d.ts(387, 9): 'children' is declared here.```

@ckifer
Copy link
Member

ckifer commented Jan 14, 2025

What React and Typescript versions are you using? I can run your config without issue

@zommerberg
Copy link

zommerberg commented Jan 15, 2025

"typescript": "^5.7.3"
"react": "19.0.0",

I will create a full example, i am using a monorepo so there might be something i missed

@zommerberg
Copy link

zommerberg commented Jan 15, 2025

@ckifer I made a brand new nextjs project and just installed recharts: 3.0.0-alpha.2 without even changing the default config to mine and i got the same error:
image

Here is a full repo:
https://github.com/zommerberg/nextjs-recharts-v3-types-bug

CartesianGrid works fine

@ckifer
Copy link
Member

ckifer commented Jan 15, 2025

@zommerberg looks like this is something specific to React 19 and React 19 types or something specific to Next 15 ts-config. Please create a separate issue since this issue isn't related

@ckifer
Copy link
Member

ckifer commented Jan 15, 2025

@zommerberg this is your solution mapbox/mapbox-sdk-js#477 (comment)
Unrelated to recharts or react19. Seems to be a next problem

@PavelVanecek
Copy link
Collaborator

Can confirm npm install @types/react fixes that on the sample project provided. Not sure what we can do from our side.

@zommerberg
Copy link

zommerberg commented Jan 20, 2025

@PavelVanecek You mean moving the types/react from dev dependency to normal dependency? The sample project had this library pre-installer already.

Is there a reason why CartesianGrid works fine without any patches, but the other components require a patch?

@PavelVanecek
Copy link
Collaborator

Ah I didn't notice. I also modified the tsconfig. Following the link from Coltin above.

@zommerberg
Copy link

zommerberg commented Jan 20, 2025

@PavelVanecek @ckifer

The fix might be tricky to do in monorepos and it definitely feels like something is broken with the library itself.

I looked into the CartesianGrid component which works fine without any fixes and compared it with ResponsiveContainer

It seems like export const ResponsiveContainer is bad, but export function CartesianGrid with a CartesianGrid.displayName = 'CartesianGrid' solves the issue

But i havent verified it 100%

@ckifer
Copy link
Member

ckifer commented Jan 20, 2025

but the other components require a patch

Nothing requires a patch. This is a next issue with react types. It seems next cannot find the correct version of react types for whatever reason upon install. Once it can find the types with the TS config changes, everything is fine.

Not sure what else we can do when it works correctly for all other types of new projects. Feel free to investigate more if you'd like

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.0 Issues we need fixed before releasing 3.0 bug General bug label Tooltip Issues that deal with the Tooltip content, its behaviour, and bugs.
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

5 participants