Skip to content

Commit 3f7165c

Browse files
committed
Refactored the code
1 parent e0a075f commit 3f7165c

File tree

1 file changed

+26
-62
lines changed

1 file changed

+26
-62
lines changed

src/components/Resources/Bubblechart.js

Lines changed: 26 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -19,65 +19,29 @@ const Bubblechart = (aData) => {
1919
}
2020

2121
let svg = d3.select('#chart').append('svg')
22-
22+
2323
.attr('viewBox', '0 0 ' + (diameter + margin.right) + ' ' + diameter)
2424
.attr('width', (diameter + margin.right))
2525
.attr('height', diameter)
2626
.attr('class', 'chart-svg');
2727

28-
29-
28+
29+
3030

3131
let root = d3.hierarchy(jsonToDisplay)
3232
.sum(function (d) { console.log(d.id); return d.id; })
33-
33+
3434
.sort(function (a, b) { return b.id - a.id });
35-
36-
35+
36+
3737
bubble(root);
3838

3939
let node = svg.selectAll('node')
4040
.data(root.children)
41-
.enter().append('g')
41+
.enter().append('g')
4242
.attr('class', 'node')
4343
.attr('transform', function (d) { return 'translate(' + d.x + ' ' + d.y + ')'; })
4444

45-
46-
47-
/*let tooltip = node.append('tooltip')
48-
.append("div")
49-
.style("opacity", 0)
50-
.attr("class", "tooltip")
51-
.style("z-index", "10")
52-
.style("background-color", "black")
53-
.style("border-radius", "5px")
54-
.style("padding", "10px")
55-
.style("color", "white")
56-
57-
let showTooltip = function(d) {
58-
tooltip
59-
.transition()
60-
.duration(200)
61-
.style("opacity", 1)
62-
.style("stroke", "black")
63-
.text(function (d) {
64-
console.log("contribution" + d.data.contributions);
65-
return "Name : " + d.data.login + "<br/>Contribution: " + d.contributions })
66-
.style("left", (d.x + (d3.pointer(this)[0] + 90)) + "px")
67-
.style("top", (d.y + (d3.pointer(this)[1])) + "px");
68-
}
69-
let moveTooltip = function(d) {
70-
tooltip
71-
.style("left", (d.x + (d3.pointer(this)[0] + 30)) + "px")
72-
.style("top", (d.y + (d3.pointer(this)[1] + 30)) + "px");
73-
}
74-
let hideTooltip = function(d) {
75-
tooltip
76-
.transition()
77-
.duration(200)
78-
.style("opacity", 0)
79-
.style("visibility", "hidden");
80-
}*/
8145

8246
let defs = node.append('defs');
8347

@@ -94,13 +58,13 @@ const Bubblechart = (aData) => {
9458
.attr('width', function (d) { return d.r * 2 * 1.02 })
9559
.attr("x", 0)
9660
.attr("y", 0);
97-
98-
99-
100-
61+
62+
63+
64+
10165
node.append("circle")
10266
.attr('r', function (d) {
103-
return d.r/(Math.sqrt(1.5));
67+
return d.r / (Math.sqrt(1.5));
10468
})
10569
.style("fill", "#fff")
10670
.style("fill", function (d) { return "url(#" + d.data.id + ")" })
@@ -109,27 +73,27 @@ const Bubblechart = (aData) => {
10973
.on("mousemove", mousemove)
11074
.on("mouseout", mouseout);
11175

112-
113-
let div = d3.select("#bubble").append("div")
76+
77+
let div = d3.select("#bubble").append("div")
11478
.attr("class", "tooltip")
11579
.style("display", "none");
11680

117-
function mouseover() {
118-
div.style("display", "inline");
119-
}
81+
function mouseover() {
82+
div.style("display", "inline");
83+
}
12084

121-
function mousemove(event,d) {
122-
const[x, y] = d3.pointer(event);
123-
div
85+
function mousemove(event, d) {
86+
const [x, y] = d3.pointer(event);
87+
div
12488
.text(x + ", " + y)
12589
.style("left", (x) + "px")
12690
.style("top", (y) + "px");
127-
}
91+
}
92+
93+
function mouseout() {
94+
div.style("display", "none");
95+
}
12896

129-
function mouseout() {
130-
div.style("display", "none");
131-
}
132-
13397

13498
node.append("text")
13599
.attr("dy", ".3em")
@@ -146,7 +110,7 @@ function mouseout() {
146110

147111

148112
return (
149-
<div id ="bubble" className ="bubble">
113+
<div id="bubble" className="bubble">
150114
<svg id="chart" className="chart" ></svg>
151115
</div>
152116
);

0 commit comments

Comments
 (0)