6

How to enable tooltip on React-vis?

<Sunburst
 hideRootNode
 colorType="literal"
 data={data}
 height={300}
 width={350}/>

I don't see tooltip on vizualisation, how can I see a tool on hovering the chart?

In the case of SunBurst, there's an example on Uber github page, and you have to recompute the position of the tooltip based on the angle of your datapoint which is not super convenient.

awzx
  • 1,023
  • 2
  • 12
  • 31

1 Answers1

3

You need to manually add a tooltip if you want one! React-vis tries not to make assumptions about how you will be using it, it just tries to offers a flexible platform. You can see an example of how to do this here: https://github.com/uber/react-vis/blob/master/showcase/sunbursts/sunburst-with-tooltips.js but I can give a quick example here as well:

<Sunburst hideRootNode colorType="literal" data={data} height={300} width={350}> <Hint value={hoveredValue} /> </Sunburst> Where hoveredValues is an appropriate hover value (perhaps garnered from a hover listener on the sunburst it self). You may need to modify the value you get from you on hover method

function buildValue(hoveredCell) {
  const {radius, angle, angle0} = hoveredCell;
  const truedAngle = (angle + angle0) / 2;
  return {
    x: radius * Math.cos(truedAngle),
    y: radius * Math.sin(truedAngle)
  };
}

I've opened a PR to add the content of this answer to the sunburst documentation (#552), which I hope helps.

mcnutt
  • 663
  • 8
  • 12
  • It seems buggy... I will display the content of my tooltip inside an external component. Would be cleaner than the current placement. – awzx Aug 16 '17 at 21:39
  • I'm not sure what you mean? can you say more? – mcnutt Aug 17 '17 at 20:06
  • I've been able to display Tooltip using the example, for circle on left it was almost fine, and circle on right, the tooltip went on the right of the screen, like current x + 500 – awzx Aug 17 '17 at 20:25
  • That's exactly what I did, but the Hint went crazy.... I'll try to solve that, and if so I'll open a PR for this feature if the problem was not mine. For now I'm just displaying what I want in a static label, but it'd be more convenient to have real tooltips... – awzx Aug 17 '17 at 23:14