Skip to content

Commit 0b6a317

Browse files
committed
added summer/winter + year button in fairness table
1 parent e020622 commit 0b6a317

3 files changed

Lines changed: 78 additions & 6 deletions

File tree

website/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ <h2>What would a fair distribution of Olympic medals look like?</h2>
301301

302302
<div class="intro-column">
303303
<p>
304-
This visualization compares actual medals with a “fair” medal distribution adjusted
304+
These visualizations compare actual medals with a “fair” medal distribution adjusted
305305
by mean population and GDP. By looking beyond the raw medal count, we can question
306306
what Olympic success really means and whether the podium reflects equal opportunity
307307
or broader global inequalities.

website/js/fair-distribution.js

Lines changed: 58 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
country1: null,
1616
country2: null,
1717
populationAdjustment: 100,
18-
gdpAdjustment: 100
18+
gdpAdjustment: 100,
19+
rankingSeason: "Summer",
20+
rankingYear: null
1921
};
2022

2123
const medalOrder = ["Gold", "Silver", "Bronze"];
@@ -389,6 +391,9 @@
389391
"United States of America",
390392
"USA"
391393
]) || countries.find(country => country !== state.country1) || countries[0] || null;
394+
395+
state.rankingSeason = state.season;
396+
state.rankingYear = state.year;
392397
}
393398

394399
function findPreferredCountry(countries, preferredNames) {
@@ -884,27 +889,41 @@
884889
const root = d3.select("#fair-ranking-viz");
885890
if (root.empty()) return;
886891

887-
const countries = getAvailableCountries(state.season, state.year);
892+
if (!state.rankingYear) {
893+
state.rankingSeason = state.season;
894+
state.rankingYear = state.year;
895+
}
896+
897+
const years = getAvailableYears(state.rankingSeason);
898+
const countries = getAvailableCountries(state.rankingSeason, state.rankingYear);
899+
900+
const previousSeason = state.season;
901+
const previousYear = state.year;
902+
903+
state.season = state.rankingSeason;
904+
state.year = state.rankingYear;
888905

889906
const rows = countries.map(country => {
890907
const data = computeFairCounts(country);
891-
892908
return {
893909
country,
894910
actual: data.actual,
895911
fair: data.fair
896912
};
897913
});
898914

899-
const actualRanking = rows
915+
state.season = previousSeason;
916+
state.year = previousYear;
917+
918+
const actualRanking = [...rows]
900919
.sort((a, b) =>
901920
d3.descending(a.actual.Gold, b.actual.Gold) ||
902921
d3.descending(a.actual.Silver, b.actual.Silver) ||
903922
d3.descending(a.actual.Bronze, b.actual.Bronze)
904923
)
905924
.slice(0, 10);
906925

907-
const fairRanking = rows
926+
const fairRanking = [...rows]
908927
.sort((a, b) =>
909928
d3.descending(a.fair.Gold || 0, b.fair.Gold || 0) ||
910929
d3.descending(a.fair.Silver || 0, b.fair.Silver || 0) ||
@@ -913,11 +932,45 @@
913932
.slice(0, 10);
914933

915934
root.html(`
935+
<div class="fair-ranking-controls">
936+
<label>
937+
Season:
938+
<select id="fair-ranking-season">
939+
${getAvailableSeasons().map(season => `
940+
<option value="${season}" ${season === state.rankingSeason ? "selected" : ""}>${season}</option>
941+
`).join("")}
942+
</select>
943+
</label>
944+
945+
<label>
946+
Year:
947+
<select id="fair-ranking-year">
948+
${years.map(year => `
949+
<option value="${year}" ${year === state.rankingYear ? "selected" : ""}>${year}</option>
950+
`).join("")}
951+
</select>
952+
</label>
953+
</div>
954+
916955
<div class="fair-ranking-layout">
917956
${rankingTable("Actual medal table", actualRanking, "actual")}
918957
${rankingTable("Fair medal table", fairRanking, "fair")}
919958
</div>
920959
`);
960+
961+
d3.select("#fair-ranking-season").on("change", function () {
962+
state.rankingSeason = this.value;
963+
const newYears = getAvailableYears(state.rankingSeason);
964+
state.rankingYear = newYears.includes(state.rankingYear)
965+
? state.rankingYear
966+
: newYears[newYears.length - 1];
967+
renderRankingTable();
968+
});
969+
970+
d3.select("#fair-ranking-year").on("change", function () {
971+
state.rankingYear = Number(this.value);
972+
renderRankingTable();
973+
});
921974
}
922975

923976
function rankingTable(title, rows, type) {

website/styles.css

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,6 +1150,25 @@ p {
11501150
text-align: left;
11511151
}
11521152

1153+
.fair-ranking-controls {
1154+
display: flex;
1155+
justify-content: center;
1156+
gap: 24px;
1157+
margin-bottom: 24px;
1158+
font-size: 18px;
1159+
font-weight: 700;
1160+
}
1161+
1162+
.fair-ranking-controls select {
1163+
background: #f4b400;
1164+
color: #111;
1165+
border: 3px solid #222;
1166+
border-radius: 12px;
1167+
padding: 8px 14px;
1168+
font-size: 18px;
1169+
font-weight: 700;
1170+
}
1171+
11531172
/* =============================================
11541173
Footer
11551174
=========================================== */

0 commit comments

Comments
 (0)