Victory: Implement victory-tooltip

Created on 3 Dec 2015  路  27Comments  路  Source: FormidableLabs/victory

Requirements:

  • similar to label in that tooltips get positioned by their parents and are provided with data
  • should be positioned above other components (react-gateway? react-portal?)
  • should have some automatic events like hover
  • Integration into parents should be flexible i.e. should be able to pass custom tooltip components.
feature

Most helpful comment

This will be in the next release!

All 27 comments

+1

+1

If we're going to be rendering the tooltip outside of the svg context, react-gateway may be of interest.

:+1: Would love to see this.

Hi,
I think it could be helpful to have a callback function like onMouseHoverData={({mouseX, mouseY, values=[...]}) => {...}} as a low level api, so we can implement some custom tooltips.

is there any work being done with this?

@luisrudge yes. There is work going on in victory to support event handling generally, and @dandelany I believe is working on a specific tooltip component.

:+1: Only thing holding me back from using Victory right now :)

Awesooooooome. Thanks everyone.

Requirements:

  • similar to label in that tooltips get positioned by their parents and are provided with data
  • should be positioned above other components (react-gateway? react-portal?)
  • should have some automatic events like hover
  • Integration into parents should be flexible i.e. should be able to pass custom tooltip components.

:+1:

Agree with others about passing a custom component for tooltip being nice.

Would also be nice if tooltip had an optional "crosshairs" attribute for adding a line on x and/or y axis that would point to hovered data point from the axis. If this is outside scope, maybe a separate victory component for this.

The folks at recharts done this already, maybe worth iterating on their work or getting some ideas, see: https://github.com/recharts/recharts/blob/master/src/component/Tooltip.js

seems to work pretty well.

Any updates on this? :)

This will be in the next release!

馃憤

This is getting pushed back on more release (mid June). Sorry everyone! This release (today) will have support for controlling events between Victory Components, so the pieces are all in place for a flexible tooltip implementation. For a quick fix, you should be able to create tooltips scoped to a single Victory Component with the current event system and custom label components.

Thanks for the update @boygirl.
I've been using Victory but tooltips are not very easy to implement as of how the code is structured (or was structured).
Could you provide a simple example implementation for having tooltips scoped to a Victory component?

@syrusakbary so long as you don't _also_ need labels you can pass in a custom labelComponent and trigger events as you would on label. I'll get some examples up next week.

@boygirl I would be interested in examples as well, the exact scenario you describe (where you don't need labels but need tooltips) is what I am hoping to attain.

You can use a d3 bisector to figure out which data point is closest to the mouse position. You will need to use the proper xScale and yScale. You can feed the x,y coordinates to a component that is overlayed on your VictoryChart with the same width/height. Position your tooltip in there using the x,y you passed in.

@boygirl Any news? Really looking forward to this component :)

@hasSean

We realized that there are a million ways to write a tooltip, and took a bit of a step back. This will still happen, but we want to make sure we build the right thing. In the meantime, all the pieces are in place to support custom tooltips in the current api. Check out the example we've published http://formidable.com/open-source/victory/recipes/tooltip

@boygirl Thanks for the quick response! I'll look into the example recipe then for my current project.

v1 of VictoryTooltip is coming at the end of the month!

  • VictoryTooltip v1 will be scoped to a single component
  • VictoryTooltip will be passed in as <LabelComponent/>
  • VictoryTooltip will have it's own events that will be pushed onto the events array of it's containing component.
  • VictoryTooltip will take an events prop, but default events will also be provided.

awesome :heart:

Was this page helpful?
0 / 5 - 0 ratings