Skip to content

Commit ff5688e

Browse files
authored
Merge branch 'frontendstudygroup:master' into master
2 parents 524778e + a83b774 commit ff5688e

File tree

4 files changed

+132
-0
lines changed

4 files changed

+132
-0
lines changed

src/components/Api/GitApi.js

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import React, { useEffect, useState } from "react";
2+
import Bubblechart from "../Resources/Bubblechart";
3+
4+
const GitApi = () => {
5+
6+
const [contributor, setContributor] = useState([]);
7+
8+
useEffect(() => {
9+
const url = "https://api.github.com/repos/frontendstudygroup/frontendstudygroup.github.io/contributors";
10+
11+
const fetchData = async () => {
12+
try {
13+
const response = await fetch(url);
14+
const json = await response.json();
15+
setContributor(json)
16+
17+
} catch (error) {
18+
console.log("error", error);
19+
}
20+
};
21+
22+
fetchData();
23+
24+
}, []);
25+
26+
return (
27+
28+
<div>
29+
30+
<Bubblechart data = {contributor}></Bubblechart>
31+
32+
</div>
33+
);
34+
};
35+
36+
37+
export default GitApi;
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
text {
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;
14+
}
15+
16+
.chart-svg {
17+
width: 100%;
18+
height: 100%;
19+
}
20+
21+
+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import { React } from 'react';
2+
import * as d3 from 'd3';
3+
import "./Bubblechart.css";
4+
5+
6+
const Bubblechart = (aData) => {
7+
let jsonToDisplay = { "children":[...aData.data] };
8+
var diameter = 1000,
9+
color = d3.scaleOrdinal(["#1f77b4", "#ff7f0e", "#2ca02c", "#d62728", "#9467bd", "#8c564b", "#e377c2", "#7f7f7f", "#bcbd22", "#17becf"]);
10+
var bubble = d3.pack()
11+
.size([diameter, diameter])
12+
.padding(2);
13+
14+
var margin = {
15+
left: 100,
16+
right: 100,
17+
top: 0,
18+
bottom: 0
19+
}
20+
21+
var svg = d3.select('#chart').append('svg')
22+
.attr('viewBox', '0 0 ' + (diameter + margin.right) + ' ' + diameter)
23+
.attr('width', (diameter + margin.right))
24+
.attr('height', diameter)
25+
.attr('class', 'chart-svg');
26+
27+
28+
var root = d3.hierarchy(jsonToDisplay)
29+
.sum(function (d) { return d.id })
30+
.sort(function (a, b) { return b.id - a.id });
31+
32+
33+
bubble(root);
34+
35+
var node = svg.selectAll('.node')
36+
.data(root.children)
37+
.enter()
38+
.append('g').attr('class', 'node')
39+
.attr('transform', function (d) { return 'translate(' + d.x + ' ' + d.y + ')'; })
40+
.append('g').attr('class', 'graph');
41+
42+
node.append("circle")
43+
.attr('r', function (d) {
44+
return d.r;
45+
})
46+
.style("fill", function (d) {
47+
return color(d);
48+
});
49+
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");
55+
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");
61+
62+
63+
return (
64+
<div>
65+
<svg id="chart" className="chart" ></svg>
66+
</div>
67+
);
68+
}
69+
export default Bubblechart;

src/components/Router.js

+5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import SingleResource from "./SingleResource/SingleResource";
88
import Contact from "./ContactUs/Contact";
99
import About from "./About/About";
1010
import TableView from "./Resources/TableView";
11+
import Bubblechart from "./Resources/Bubblechart";
12+
import GitApi from "./Api/GitApi";
1113

1214

1315
const Router = () => (
@@ -22,6 +24,9 @@ const Router = () => (
2224
<Route exact path="/contact" component={Contact} />
2325
<Route exact path="/about" component={About} />
2426
<Route exact path="/TableView" component={TableView} />
27+
<Route exact path="/bubblechart" component={Bubblechart} />
28+
<Route exact path="/gitapi" component={GitApi} />
29+
2530
</Switch>
2631
<Footer/>
2732
</BrowserRouter>

0 commit comments

Comments
 (0)