Skip to content

Commit e0a075f

Browse files
committed
tooltip shows up but not on the bubble
1 parent f500117 commit e0a075f

File tree

2 files changed

+51
-14
lines changed

2 files changed

+51
-14
lines changed

src/components/Resources/Bubblechart.css

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,23 @@ text {
1111
.chart {
1212
width: 1500px;
1313
height: 1500px;
14+
background: rgb(13, 13, 14);
15+
1416
}
1517

1618
.chart-svg {
1719
width: 100%;
1820
height: 100%;
1921
}
2022

21-
23+
div.tooltip {
24+
position: absolute;
25+
text-align: center;
26+
width: 160px;
27+
height: 50px;
28+
padding: 8px;
29+
margin-top: -20px;
30+
font: 16px sans-serif;
31+
background: #ddd;
32+
pointer-events: none;
33+
}

src/components/Resources/Bubblechart.js

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ const Bubblechart = (aData) => {
2525
.attr('height', diameter)
2626
.attr('class', 'chart-svg');
2727

28-
28+
29+
2930

3031
let root = d3.hierarchy(jsonToDisplay)
3132
.sum(function (d) { console.log(d.id); return d.id; })
@@ -40,26 +41,28 @@ const Bubblechart = (aData) => {
4041
.enter().append('g')
4142
.attr('class', 'node')
4243
.attr('transform', function (d) { return 'translate(' + d.x + ' ' + d.y + ')'; })
44+
45+
4346

44-
let tooltip = svg
47+
/*let tooltip = node.append('tooltip')
4548
.append("div")
46-
.style("opacity", 1)
47-
.attr("id", "tooltip")
49+
.style("opacity", 0)
50+
.attr("class", "tooltip")
4851
.style("z-index", "10")
4952
.style("background-color", "black")
5053
.style("border-radius", "5px")
5154
.style("padding", "10px")
5255
.style("color", "white")
53-
.style("position", "absolute");
56+
5457
let showTooltip = function(d) {
5558
tooltip
5659
.transition()
5760
.duration(200)
58-
tooltip
5961
.style("opacity", 1)
60-
.style("visibility", "visible")
6162
.style("stroke", "black")
62-
.text("Player: jklkjljljljlklklkljjkljlkj <br> Points with franchise: " )
63+
.text(function (d) {
64+
console.log("contribution" + d.data.contributions);
65+
return "Name : " + d.data.login + "<br/>Contribution: " + d.contributions })
6366
.style("left", (d.x + (d3.pointer(this)[0] + 90)) + "px")
6467
.style("top", (d.y + (d3.pointer(this)[1])) + "px");
6568
}
@@ -74,7 +77,7 @@ const Bubblechart = (aData) => {
7477
.duration(200)
7578
.style("opacity", 0)
7679
.style("visibility", "hidden");
77-
}
80+
}*/
7881

7982
let defs = node.append('defs');
8083

@@ -102,9 +105,31 @@ const Bubblechart = (aData) => {
102105
.style("fill", "#fff")
103106
.style("fill", function (d) { return "url(#" + d.data.id + ")" })
104107
.style("stroke", "black")
105-
.on("mouseover", showTooltip)
106-
.on("mousemove", moveTooltip)
107-
.on("mouseleave", hideTooltip)
108+
.on("mouseover", mouseover)
109+
.on("mousemove", mousemove)
110+
.on("mouseout", mouseout);
111+
112+
113+
let div = d3.select("#bubble").append("div")
114+
.attr("class", "tooltip")
115+
.style("display", "none");
116+
117+
function mouseover() {
118+
div.style("display", "inline");
119+
}
120+
121+
function mousemove(event,d) {
122+
const[x, y] = d3.pointer(event);
123+
div
124+
.text(x + ", " + y)
125+
.style("left", (x) + "px")
126+
.style("top", (y) + "px");
127+
}
128+
129+
function mouseout() {
130+
div.style("display", "none");
131+
}
132+
108133

109134
node.append("text")
110135
.attr("dy", ".3em")
@@ -121,7 +146,7 @@ const Bubblechart = (aData) => {
121146

122147

123148
return (
124-
<div>
149+
<div id ="bubble" className ="bubble">
125150
<svg id="chart" className="chart" ></svg>
126151
</div>
127152
);

0 commit comments

Comments
 (0)