Skip to content

Commit f500117

Browse files
committed
tooltip added
1 parent a830fa6 commit f500117

File tree

1 file changed

+51
-9
lines changed

1 file changed

+51
-9
lines changed

src/components/Resources/Bubblechart.js

Lines changed: 51 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const Bubblechart = (aData) => {
1919
}
2020

2121
let svg = d3.select('#chart').append('svg')
22+
2223
.attr('viewBox', '0 0 ' + (diameter + margin.right) + ' ' + diameter)
2324
.attr('width', (diameter + margin.right))
2425
.attr('height', diameter)
@@ -27,22 +28,58 @@ const Bubblechart = (aData) => {
2728

2829

2930
let root = d3.hierarchy(jsonToDisplay)
30-
.sum(function (d) { return d.id })
31-
//.sort(function (a, b) { return b.id - a.id });
32-
33-
31+
.sum(function (d) { console.log(d.id); return d.id; })
32+
33+
.sort(function (a, b) { return b.id - a.id });
34+
35+
3436
bubble(root);
3537

3638
let node = svg.selectAll('node')
3739
.data(root.children)
38-
.enter()
39-
.append('g').attr('class', 'node')
40+
.enter().append('g')
41+
.attr('class', 'node')
4042
.attr('transform', function (d) { return 'translate(' + d.x + ' ' + d.y + ')'; })
43+
44+
let tooltip = svg
45+
.append("div")
46+
.style("opacity", 1)
47+
.attr("id", "tooltip")
48+
.style("z-index", "10")
49+
.style("background-color", "black")
50+
.style("border-radius", "5px")
51+
.style("padding", "10px")
52+
.style("color", "white")
53+
.style("position", "absolute");
54+
let showTooltip = function(d) {
55+
tooltip
56+
.transition()
57+
.duration(200)
58+
tooltip
59+
.style("opacity", 1)
60+
.style("visibility", "visible")
61+
.style("stroke", "black")
62+
.text("Player: jklkjljljljlklklkljjkljlkj <br> Points with franchise: " )
63+
.style("left", (d.x + (d3.pointer(this)[0] + 90)) + "px")
64+
.style("top", (d.y + (d3.pointer(this)[1])) + "px");
65+
}
66+
let moveTooltip = function(d) {
67+
tooltip
68+
.style("left", (d.x + (d3.pointer(this)[0] + 30)) + "px")
69+
.style("top", (d.y + (d3.pointer(this)[1] + 30)) + "px");
70+
}
71+
let hideTooltip = function(d) {
72+
tooltip
73+
.transition()
74+
.duration(200)
75+
.style("opacity", 0)
76+
.style("visibility", "hidden");
77+
}
4178

4279
let defs = node.append('defs');
4380

4481
defs.append("pattern")
45-
.attr("id", function (d) { return d.data.id })
82+
.attr("id", function (d) { console.log(d.data.id); return d.data.id })
4683

4784
.attr("width", 10)
4885
.attr("height", 10)
@@ -54,15 +91,20 @@ const Bubblechart = (aData) => {
5491
.attr('width', function (d) { return d.r * 2 * 1.02 })
5592
.attr("x", 0)
5693
.attr("y", 0);
57-
94+
95+
96+
97+
5898
node.append("circle")
5999
.attr('r', function (d) {
60100
return d.r/(Math.sqrt(1.5));
61101
})
62102
.style("fill", "#fff")
63103
.style("fill", function (d) { return "url(#" + d.data.id + ")" })
64104
.style("stroke", "black")
65-
105+
.on("mouseover", showTooltip)
106+
.on("mousemove", moveTooltip)
107+
.on("mouseleave", hideTooltip)
66108

67109
node.append("text")
68110
.attr("dy", ".3em")

0 commit comments

Comments
 (0)