Skip to content

Rotating & hiding <Text /> in Sunburst #1290

Answered by andandio
andandio asked this question in Q&A
Discussion options

You must be logged in to vote

The x0, x1, y0, y1 variables don't update on zoom, so my rotateText() function wasn't updating after zooming. Instead, I moved rotation into state, and then inside a useLayoutEffect() hook, found radians to arc.centroid and assigned the rotation:

 useLayoutEffect(() => {
   let arcAngle = arc.centroid(node)
   let radians = Math.atan2(arcAngle[1], arcAngle[0])
   let degrees = radians * 57.2958
   let rotation =  (degrees < 90 && degrees > -90) ?  degrees : 180 + degrees ;
   setTextRotation(rotation)
  },[pathRef])

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by andandio
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant