|
12 | 12 | import React, { Component } from 'react'; |
13 | 13 | // import PropTypes from 'prop-types'; |
14 | 14 | import * as d3 from 'd3'; |
15 | | -import d3Tip from 'd3-tip'; |
| 15 | +// import d3Tip from 'd3-tip'; |
16 | 16 |
|
17 | 17 | let root = {}; |
18 | 18 | class Chart extends Component { |
@@ -106,14 +106,14 @@ class Chart extends Component { |
106 | 106 | node.append('circle') |
107 | 107 | .attr('r', 10); |
108 | 108 |
|
109 | | - // creating a d3.tip method where the html has a function that returns |
110 | | - // the data we passed into tip.show from line 120 |
111 | | - const tip = d3Tip() |
112 | | - .attr('class', 'd3-tip') |
113 | | - .html(function (d) { return 'State: ' + d; }); |
| 109 | + // // creating a d3.tip method where the html has a function that returns |
| 110 | + // // the data we passed into tip.show from line 120 |
| 111 | + // const tip = d3Tip() |
| 112 | + // .attr('class', 'd3-tip') |
| 113 | + // .html(function (d) { return 'State: ' + d; }); |
114 | 114 |
|
115 | | - // invoking tooltip for nodes |
116 | | - node.call(tip); |
| 115 | + // // invoking tooltip for nodes |
| 116 | + // node.call(tip); |
117 | 117 |
|
118 | 118 | node |
119 | 119 | .append('text') |
@@ -160,14 +160,33 @@ class Chart extends Component { |
160 | 160 | g.attr('transform', d3.event.transform); |
161 | 161 | } |
162 | 162 |
|
| 163 | + // define the div for the tooltip |
| 164 | + const tooltipDiv = d3.select('body').append('div') |
| 165 | + .attr('class', 'tooltip') |
| 166 | + .style('opacity', 0); |
| 167 | + |
163 | 168 | // applying tooltip on mouseover and removes it when mouse cursor moves away |
164 | 169 | node |
165 | 170 | .on('mouseover', function (d) { |
166 | | - // without JSON.stringify, data will display as object Object |
167 | | - // console.log('d.data --> ', JSON.stringify(d.data)) |
168 | | - tip.show(JSON.stringify(d.data.stateSnapshot.children[0].state), this); |
| 171 | + tooltipDiv.transition() |
| 172 | + .duration(200) |
| 173 | + .style('opacity', 0.9); |
| 174 | + tooltipDiv.html(JSON.stringify(d.data.stateSnapshot.children[0].state), this) |
| 175 | + .style('left', (d3.event.pageX) + 'px') |
| 176 | + .style('top', (d3.event.pageY - 28) + 'px'); |
169 | 177 | }) |
170 | | - .on('mouseout', tip.hide); |
| 178 | + // eslint-disable-next-line no-unused-vars |
| 179 | + .on('mouseout', function (d) { |
| 180 | + tooltipDiv.transition() |
| 181 | + .duration(500) |
| 182 | + .style('opacity', 0); |
| 183 | + }); |
| 184 | + // .on('mouseover', function (d) { |
| 185 | + // // without JSON.stringify, data will display as object Object |
| 186 | + // // console.log('d.data --> ', JSON.stringify(d.data)) |
| 187 | + // tip.show(JSON.stringify(d.data.stateSnapshot.children[0].state), this); |
| 188 | + // }) |
| 189 | + // .on('mouseout', tip.hide); |
171 | 190 |
|
172 | 191 | function reinfeldTidierAlgo(x, y) { |
173 | 192 | return [(y = +y) * Math.cos(x -= Math.PI / 2), y * Math.sin(x)]; |
|
0 commit comments