Skip to content

Commit 239adbf

Browse files
committed
Included contributors git avatar image inside bubbles
1 parent 181ae80 commit 239adbf

File tree

1 file changed

+29
-11
lines changed

1 file changed

+29
-11
lines changed

src/components/Resources/Bubblechart.js

+29-11
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);
@@ -25,9 +25,10 @@ const Bubblechart = (aData) => {
2525
.attr('class', 'chart-svg');
2626

2727

28+
2829
let root = d3.hierarchy(jsonToDisplay)
2930
.sum(function (d) { return d.id })
30-
.sort(function (a, b) { return b.id - a.id });
31+
//.sort(function (a, b) { return b.id - a.id });
3132

3233

3334
bubble(root);
@@ -36,30 +37,47 @@ const Bubblechart = (aData) => {
3637
.data(root.children)
3738
.enter()
3839
.append('g').attr('class', 'node')
39-
.attr('transform', function (d) {return 'translate(' + d.x + ' ' + d.y + ')'; })
40+
.attr('transform', function (d) { return 'translate(' + d.x + ' ' + d.y + ')'; })
41+
42+
let defs = node.append('defs');
4043

44+
defs.append("pattern")
45+
.attr("id", function (d) { return d.data.id })
46+
47+
.attr("width", 10)
48+
.attr("height", 10)
49+
.append("image")
50+
.attr("xlink:href", function (d) {
51+
return d.data.avatar_url
52+
})
53+
.attr('height', function (d) { return d.r * 2 })
54+
.attr('width', function (d) { return d.r * 2 * 1.02 })
55+
.attr("x", 0)
56+
.attr("y", 0);
4157

4258
node.append("circle")
4359
.attr('r', function (d) {
44-
return d.r;
60+
return d.r/(Math.sqrt(1.5));
4561
})
46-
.style("fill", function (d) {
47-
return color(d);
48-
});
62+
.style("fill", "#fff")
63+
.style("fill", function (d) { return "url(#" + d.data.id + ")" })
64+
.style("stroke", "black")
65+
4966

5067
node.append("text")
5168
.attr("dy", ".3em")
5269
.style("text-anchor", "middle")
53-
.text(function (d) { return d.data.login})
70+
.text(function (d) { return d.data.login })
5471
.style("fill", "#ffffff");
5572

5673
node.append("text")
5774
.attr("dy", "2em")
5875
.style("text-anchor", "middle")
59-
.text(function (d) { return d.data.contributions})
76+
.text(function (d) { return d.data.contributions })
6077
.style("fill", "#EEEfff");
6178

6279

80+
6381
return (
6482
<div>
6583
<svg id="chart" className="chart" ></svg>

0 commit comments

Comments
 (0)