|
25 | 25 | <link rel="stylesheet" href="style.css" /> |
26 | 26 |
|
27 | 27 | <script src="https://www.gstatic.com/charts/loader.js"></script> |
| 28 | + <script src="script.js" defer></script> |
| 29 | + <script src="by-year.js" defer></script> |
28 | 30 | <script src=" https://unpkg.com/[email protected]/dist/d3.min.js" ></script> |
29 | 31 | <script> |
30 | | - async function fetchCsvData(url) { |
31 | | - const response = await fetch(url); |
32 | | - const csvText = await response.text(); |
33 | | - return d3.csvParseRows(csvText, d3.autoType); |
34 | | - } |
35 | | - |
36 | | - function processData(data) { |
37 | | - const countsPerYear = {}; |
38 | | - const today = new Date(); |
39 | | - data.forEach((item) => { |
40 | | - const joinYear = new Date(item[2]).getFullYear(); |
41 | | - countsPerYear[joinYear] = countsPerYear[joinYear] || { joins: 0, leaves: 0 }; |
42 | | - countsPerYear[joinYear].joins++; |
43 | | - if (item[3]) { |
44 | | - const leaveYear = new Date(item[3]).getFullYear(); |
45 | | - countsPerYear[leaveYear] = countsPerYear[leaveYear] || { |
46 | | - joins: 0, |
47 | | - leaves: 0, |
48 | | - }; |
49 | | - countsPerYear[leaveYear].leaves++; |
50 | | - } |
51 | | - }); |
52 | | - const startYear = Object.keys(countsPerYear)[0]; |
53 | | - const endYear = today.getFullYear(); |
54 | | - for (let year = startYear; year <= endYear; year++) { |
55 | | - countsPerYear[year] = countsPerYear[year] || { joins: 0, leaves: 0 }; |
56 | | - } |
57 | | - return countsPerYear; |
58 | | - } |
59 | | - |
60 | | - function convertDataToArray(countsPerYear) { |
61 | | - const countsPerYearArray = Object.entries(countsPerYear).map( |
62 | | - ([year, counts]) => [year, counts.joins], |
63 | | - ); |
64 | | - countsPerYearArray.unshift(["Year", "New core devs"]); |
65 | | - return countsPerYearArray; |
66 | | - } |
67 | | - |
68 | | - function drawBarChart(rows) { |
69 | | - const data = new google.visualization.arrayToDataTable(rows); |
70 | | - const options = { |
71 | | - bars: "vertical", |
72 | | - legend: { position: "none" }, |
73 | | - axes: { x: { 0: { label: "" } } }, |
74 | | - }; |
75 | | - const chart = new google.charts.Bar(document.getElementById("chart_div")); |
76 | | - chart.draw(data, options); |
77 | | - } |
78 | | - |
79 | 32 | google.charts.load("current", { packages: ["bar"] }); |
80 | 33 | google.charts.setOnLoadCallback(async function () { |
81 | | - const url = |
82 | | - "https://raw.githubusercontent.com/python/devguide/main/core-developers/developers.csv"; |
83 | | - const csvData = await fetchCsvData(url); |
84 | | - const processedData = processData(csvData); |
85 | | - const dataArray = convertDataToArray(processedData); |
86 | | - drawBarChart(dataArray); |
| 34 | + getDataAndDrawBarChart(); |
87 | 35 | }); |
88 | 36 | </script> |
89 | 37 | </head> |
|
0 commit comments