@@ -90,21 +90,36 @@ class Chart extends Component {
90
90
node . append ( "circle" )
91
91
. attr ( "r" , 15 )
92
92
93
+ // creating a d3.tip method where the html has a function that returns the data we passed into tip.show from line 120
94
+ let tip = d3 . tip ( )
95
+ . attr ( "class" , "d3-tip" )
96
+ . html ( function ( d ) { return "State Snapshot: " + d ; } )
97
+ // invoking tooltip for nodes
98
+ node . call ( tip )
99
+
93
100
node
94
101
. append ( "text" )
95
102
// adjusts the y coordinates for the node text
96
103
. attr ( "dy" , "0.276em" )
97
104
. attr ( "x" , function ( d ) {
98
105
// this positions how far the text is from leaf nodes (ones without children)
99
106
// negative number before the colon moves the text of rightside nodes, positive number moves the text for the leftside nodes
100
- return d . x < Math . PI === ! d . children ? - 6 : 7 ;
107
+ return d . x < Math . PI === ! d . children ? - 5 : 9 ;
101
108
} )
102
109
. attr ( "text-anchor" , function ( d ) { return d . x < Math . PI === ! d . children ? "start" : "end" ; } )
103
110
// this arranges the angle of the text
104
111
. attr ( "transform" , function ( d ) { return "rotate(" + ( d . x < Math . PI ? d . x - Math . PI / 2 : d . x + Math . PI / 2 ) * 1 / Math . PI + ")" ; } )
105
112
. text ( function ( d ) {
106
113
return d . data . index ;
107
114
} ) ;
115
+
116
+ //applying tooltip on mouseover and removes it when mouse cursor moves away
117
+ node
118
+ . on ( 'mouseover' , function ( d ) {
119
+ // without JSON.stringify, data will display as object Object
120
+ tip . show ( JSON . stringify ( d . data . stateSnaphot ) )
121
+ } )
122
+ . on ( 'mouseout' , tip . hide )
108
123
109
124
function reinfeldTidierAlgo ( x , y ) {
110
125
return [ ( y = + y ) * Math . cos ( x -= Math . PI / 2 ) , y * Math . sin ( x ) ] ;
0 commit comments