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

VictoryTooltip not showing when wrapped in another component unless using VictoryVoronoiContainer #2865

Open
2 tasks done
kmzeitgleich opened this issue May 3, 2024 · 1 comment
Labels
Type: Bug 🐛 Oh no! A bug or unintentional behavior

Comments

@kmzeitgleich
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Code of Conduct

  • I agree to follow this project's Code of Conduct

Victory version

37.0.2

Code Sandbox link

No response

Bug report

When using simple tooltips without VictoryVoronoi for VictoryBar, VictoryScatter and I guesss probably all other kinds of charts, the tooltip will only display when it is not a custom one

meaning I can only use labelComponent={<VicoryTooltip />} and not labelComponent={{<CustomTooltip />}
The active prop does not seem to get passed. Maybe the events get lost?

Code Snippet from the website https://commerce.nearform.com/open-source/victory/guides/tooltips#customizing-tooltips


class CustomFlyout extends React.Component {
  render() {
    const {x, y, orientation} = this.props;
    const newY = orientation === "bottom" ? y - 35 : y + 35;
    return (
      <g>
        <circle cx={x} cy={newY} r="20" stroke="tomato" fill="none"/>
        <circle cx={x} cy={newY} r="25" stroke="orange" fill="none"/>
        <circle cx={x} cy={newY} r="30" stroke="gold" fill="none"/>
      </g>
    );
  }
}

class CustomTooltip extends React.Component {
  render() {
// This does not work
    return (<VictoryTooltip
                {...this.props}
                //text="test"
                //active // it shows up properly when active is true!
              />)
  }
}

class App extends React.Component {
  render() {
    return (
      <VictoryChart
          domain={{ x: [0, 11], y: [-10, 10] }}
        >
          <VictoryBar
            labelComponent={
// does not work
              <CustomTooltip
//<VictoryTooltip // works
                //flyoutComponent={<CustomFlyout/>}
              />
            }
            data={[
              {x: 2, y: 5, label: "A"},
              {x: 4, y: -6, label: "B"},
              {x: 6, y: 4, label: "C"},
              {x: 8, y: -5, label: "D"},
              {x: 10, y: 7, label: "E"}
            ]}
            style={{
              data: {fill: "tomato", width: 20},
              labels: { fill: "tomato"}
            }}
          />
        </VictoryChart>
    );
  }
}
render(<App/>);


The reason why I don't want to use a VictoryVoronoiContainer is because I want to see the Tooltips when hovering ther bar and not the nearest Point.
When I have two bars, one has a high value and one a low value and I use VictoryVoronoiContainer, the tooltip will be shown for the low value bar, even when my mouse is on the higher value bar

Steps to reproduce

1. Copy the Code perhaps into the live editor on the website
2. Hover over a bar, see nothing
3. Change the labelComponent to VictoryTooltip
4. Hover over a bar, see a tooltip

Expected behavior

The tooltip should show up, even when the VictoryTooltip is wrapped in another component

Actual behavior

The active prop never gets passed, so the CustomTooltip never shows

Environment

- Device: Desktip
- OS: Multiple
- Node: 16
- npm: 8.19
@kmzeitgleich kmzeitgleich added the Type: Bug 🐛 Oh no! A bug or unintentional behavior label May 3, 2024
@kmzeitgleich
Copy link
Author

example

Example of tooltips being wrong when using VictoryVoronoiContainer and having the curser hovering over the left bar, but the tooltip shows the middle bar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug 🐛 Oh no! A bug or unintentional behavior
Projects
None yet
Development

No branches or pull requests

1 participant