Skip to content

Commit b97829d

Browse files
committed
changed tooltip and how numbers display on graph
1 parent 2cc1c22 commit b97829d

File tree

2 files changed

+30
-36
lines changed

2 files changed

+30
-36
lines changed

src/app/components/Chart.jsx

Lines changed: 28 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@ class Chart extends Component {
7878
const d3root = tree(hierarchy);
7979

8080
g.selectAll('.link')
81-
// root.links() gets an array of all the links,
82-
// where each element is an object containing a
83-
// source property, which represents the link's source node,
84-
// and a target property, which represents the link's target node.
81+
// root.links() gets an array of all the links,
82+
// where each element is an object containing a
83+
// source property, which represents the link's source node,
84+
// and a target property, which represents the link's target node.
8585
.data(d3root.links())
8686
.enter()
8787
.append('path')
@@ -104,21 +104,36 @@ class Chart extends Component {
104104
});
105105

106106
node.append('circle')
107-
.attr('r', 10);
107+
.attr('r', 10)
108+
.on('mouseover', function (d) {
109+
d3.select(this)
110+
.transition(100)
111+
.duration(20)
112+
.attr('r', 20);
108113

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+
tooltipDiv.transition()
115+
.duration(200)
116+
.style('opacity', 0.9);
114117

115-
// // invoking tooltip for nodes
116-
// node.call(tip);
118+
tooltipDiv.html(JSON.stringify(d.data.stateSnapshot.children[0].state), this)
119+
.style('left', (d3.event.pageX) + 'px')
120+
.style('top', (d3.event.pageY - 28) + 'px');
121+
})
122+
// eslint-disable-next-line no-unused-vars
123+
.on('mouseout', function (d) {
124+
d3.select(this)
125+
.transition()
126+
.duration(200)
127+
.attr('r', 12);
117128

129+
tooltipDiv.transition()
130+
.duration(500)
131+
.style('opacity', 0);
132+
});
118133
node
119134
.append('text')
120135
// adjusts the y coordinates for the node text
121-
.attr('dy', '0.35em')
136+
.attr('dy', '-1.5em')
122137
.attr('x', function (d) {
123138
// this positions how far the text is from leaf nodes (ones without children)
124139
// negative number before the colon moves the text of rightside nodes,
@@ -166,27 +181,6 @@ class Chart extends Component {
166181
.style('opacity', 0);
167182

168183
// applying tooltip on mouseover and removes it when mouse cursor moves away
169-
node
170-
.on('mouseover', function (d) {
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');
177-
})
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);
190184

191185
function reinfeldTidierAlgo(x, y) {
192186
return [(y = +y) * Math.cos(x -= Math.PI / 2), y * Math.sin(x)];

src/app/styles/components/d3graph.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ div.tooltip {
4747
position: absolute;
4848
text-align: center;
4949
display: inline;
50-
max-width: 400px;
50+
max-width: 250px;
5151
overflow-wrap: break-word;
5252
padding: 6px;
5353
color: #320a5c;
54-
font-size: 15px;
54+
font-size: 12px;
5555
font-family: "Overpass Mono", monospace;
5656
background: #9cf4df;
5757
border-radius: 8px;

0 commit comments

Comments
 (0)