Skip to content

Commit d0208da

Browse files
committed
Refactor common code
1 parent 24aac68 commit d0208da

File tree

6 files changed

+25
-27
lines changed

6 files changed

+25
-27
lines changed

by-year.html

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,9 @@
2929
<script src="by-year.js" defer></script>
3030
<script src="https://unpkg.com/[email protected]/dist/d3.min.js"></script>
3131
<script>
32-
google.charts.load("current", { packages: ["bar"] });
33-
google.charts.setOnLoadCallback(async function () {
32+
window.onload = function () {
3433
getDataAndDrawBarChart();
35-
});
34+
};
3635
</script>
3736
</head>
3837
<body>

by-year.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ function drawBarChart(rows) {
4747
}
4848

4949
async function getDataAndDrawBarChart() {
50-
const url =
51-
"https://raw.githubusercontent.com/python/devguide/main/core-developers/developers.csv";
52-
53-
const csvData = await fetchCsvData(url);
54-
const processedData = processData(csvData);
55-
const dataArray = convertDataToArray(processedData);
56-
drawBarChart(dataArray);
50+
google.charts.load("current", { packages: ["bar"] });
51+
google.charts.setOnLoadCallback(async function () {
52+
const csvData = await fetchCsvData();
53+
const processedData = processData(csvData);
54+
const dataArray = convertDataToArray(processedData);
55+
drawBarChart(dataArray);
56+
});
5757
}

current.html

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,9 @@
2828
<script src="script.js" defer></script>
2929
<script src="https://unpkg.com/[email protected]/dist/d3.min.js"></script>
3030
<script>
31-
google.charts.load("current", { packages: ["timeline"] });
32-
google.charts.setOnLoadCallback(function () {
31+
window.onload = function () {
3332
getDataAndDrawChart(true, false);
34-
});
33+
};
3534
</script>
3635
</head>
3736
<body>

former.html

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,9 @@
2828
<script src="script.js" defer></script>
2929
<script src="https://unpkg.com/[email protected]/dist/d3.min.js"></script>
3030
<script>
31-
google.charts.load("current", { packages: ["timeline"] });
32-
google.charts.setOnLoadCallback(function () {
31+
window.onload = function () {
3332
getDataAndDrawChart(false, true);
34-
});
33+
};
3534
</script>
3635
</head>
3736
<body>

index.html

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,9 @@
2828
<script src="script.js" defer></script>
2929
<script src="https://unpkg.com/[email protected]/dist/d3.min.js"></script>
3030
<script>
31-
google.charts.load("current", { packages: ["timeline"] });
32-
google.charts.setOnLoadCallback(function () {
31+
window.onload = function () {
3332
getDataAndDrawChart();
34-
});
33+
};
3534
</script>
3635
</head>
3736
<body>

script.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
async function fetchCsvData(url) {
1+
async function fetchCsvData() {
2+
const url =
3+
"https://raw.githubusercontent.com/python/devguide/main/core-developers/developers.csv";
24
const response = await fetch(url);
35
const csvText = await response.text();
46
return d3.csvParseRows(csvText, d3.autoType);
@@ -65,11 +67,11 @@ function drawChart(rows) {
6567
}
6668

6769
async function getDataAndDrawChart(showCurrent = true, showFormer = true) {
68-
const url =
69-
"https://raw.githubusercontent.com/python/devguide/main/core-developers/developers.csv";
70-
71-
const csvData = await fetchCsvData(url);
72-
const filteredData = filterData(csvData, showCurrent, showFormer);
73-
const cleanedData = cleanData(filteredData);
74-
drawChart(cleanedData);
70+
google.charts.load("current", { packages: ["timeline"] });
71+
google.charts.setOnLoadCallback(async function () {
72+
const csvData = await fetchCsvData();
73+
const filteredData = filterData(csvData, showCurrent, showFormer);
74+
const cleanedData = cleanData(filteredData);
75+
drawChart(cleanedData);
76+
});
7577
}

0 commit comments

Comments
 (0)