Skip to content

Commit b3e51a0

Browse files
authored
Merge branch 'frontendstudygroup:master' into master
2 parents 8d606a6 + 94c84ce commit b3e51a0

File tree

2 files changed

+87
-38
lines changed

2 files changed

+87
-38
lines changed

src/components/Resources/Bubblechart.css

+30-16
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,33 @@
11
text {
2-
font: 14px sans-serif;
3-
fill: #fff;
4-
transition: all 0.3s;
5-
}
2+
font: 16px sans-serif;
3+
fill: #fff;
4+
transition: all 0.3s;
5+
}
6+
7+
.label {
8+
fill: #000;
9+
}
10+
11+
.chart {
12+
width: 1500px;
13+
height: 1500px;
614

7-
.label {
8-
fill: #000;
9-
}
15+
}
16+
17+
.chart-svg {
18+
width: 100%;
19+
height: 100%;
20+
}
21+
22+
div.tooltip {
23+
position: absolute;
24+
text-align: center;
25+
width: 160px;
26+
height: 50px;
27+
padding: 8px;
28+
margin-top: -20px;
29+
font: 16px sans-serif;
30+
background: #ddd;
31+
pointer-events: none;
32+
}
1033

11-
.chart {
12-
width: 1200px;
13-
height: 1060px;
14-
}
15-
16-
.chart-svg {
17-
width: 100%;
18-
height: 100%;
19-
}

src/components/Resources/Bubblechart.js

+57-22
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import "./Bubblechart.css";
44

55

66
const Bubblechart = (aData) => {
7-
let jsonToDisplay = { "children":[...aData.data] };
8-
let diameter = 1000,
9-
color = d3.scaleOrdinal(["#1f77b4", "#ff7f0e", "#2ca02c", "#d62728", "#9467bd", "#8c564b", "#e377c2", "#7f7f7f", "#bcbd22", "#17becf"]);
7+
let jsonToDisplay = { "children": [...aData.data] };
8+
let diameter = 1000;
9+
// color = d3.scaleOrdinal(["#1f77b4", "#ff7f0e", "#2ca02c", "#d62728", "#9467bd", "#8c564b", "#e377c2", "#7f7f7f", "#bcbd22", "#17becf"]);
1010
let bubble = d3.pack()
1111
.size([diameter, diameter])
1212
.padding(2);
@@ -19,49 +19,84 @@ 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)
2526
.attr('class', 'chart-svg');
2627

2728

29+
30+
2831
let root = d3.hierarchy(jsonToDisplay)
29-
.sum(function (d) { return d.id })
32+
.sum(function (d) { console.log(d.id); return d.id; })
33+
3034
.sort(function (a, b) { return b.id - a.id });
3135

3236

3337
bubble(root);
3438

3539
let node = svg.selectAll('node')
3640
.data(root.children)
37-
.enter()
38-
.append('g').attr('class', 'node')
39-
.attr('transform', function (d) {return 'translate(' + d.x + ' ' + d.y + ')'; })
41+
.enter().append('g')
42+
.attr('class', 'node')
43+
.attr('transform', function (d) { return 'translate(' + d.x + ' ' + d.y + ')'; })
44+
45+
46+
let defs = node.append('defs');
47+
48+
defs.append("pattern")
49+
.attr("id", function (d) { console.log(d.data.id); return d.data.id })
50+
51+
.attr("width", 10)
52+
.attr("height", 10)
53+
.append("image")
54+
.attr("xlink:href", function (d) {
55+
return d.data.avatar_url
56+
})
57+
.attr('height', function (d) { return d.r * 2 })
58+
.attr('width', function (d) { return d.r * 2 * 1.02 })
59+
.attr("x", 0)
60+
.attr("y", 0);
4061

4162

4263
node.append("circle")
4364
.attr('r', function (d) {
44-
return d.r;
65+
return d.r / (Math.sqrt(1.5));
4566
})
46-
.style("fill", function (d) {
47-
return color(d);
48-
});
67+
.style("fill", "#fff")
68+
.style("fill", function (d) { return "url(#" + d.data.id + ")" })
69+
.style("stroke", "black")
70+
.on("mouseover", mouseover)
71+
.on("mousemove", mousemove)
72+
.on("mouseout", mouseout);
73+
74+
75+
let div = d3.select("#bubble").append("div")
76+
.attr("class", "tooltip")
77+
.style("display", "none");
78+
79+
function mouseover() {
80+
div.style("display", "inline");
81+
}
82+
83+
function mousemove(event, d) {
84+
85+
div
86+
.text(d.data.login + ", " + d.data.contributions)
87+
.style("left", (d.x + 150) + "px")
88+
.style("top", (d.y ) + "px")
89+
90+
}
4991

50-
node.append("text")
51-
.attr("dy", ".3em")
52-
.style("text-anchor", "middle")
53-
.text(function (d) { return d.data.login})
54-
.style("fill", "#ffffff");
92+
function mouseout(d) {
93+
div.style("display", "none");
94+
}
5595

56-
node.append("text")
57-
.attr("dy", "2em")
58-
.style("text-anchor", "middle")
59-
.text(function (d) { return d.data.contributions})
60-
.style("fill", "#EEEfff");
6196

6297

6398
return (
64-
<div>
99+
<div id="bubble" className="bubble">
65100
<svg id="chart" className="chart" ></svg>
66101
</div>
67102
);

0 commit comments

Comments
 (0)