Skip to content

Commit 0607cec

Browse files
committed
style: click and hover fair ranking
1 parent 3829117 commit 0607cec

3 files changed

Lines changed: 148 additions & 38 deletions

File tree

website/index.html

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,20 +455,30 @@ <h2>Project Gamma</h2>
455455
let lastMove = 0;
456456
let touchStartY = null;
457457

458+
document.querySelectorAll(".fair-ranking-card").forEach(card => {
459+
card.addEventListener("wheel", function (event) {
460+
event.stopPropagation();
461+
}, { passive: false, capture: true });
462+
});
463+
458464
function shouldForceScroll(target) {
459465
const activeSection = document.querySelector(".fp-section.active");
460466
const activeSlide = activeSection?.querySelector(".fp-slide.active");
461467
const slideAnchor = activeSlide?.dataset.anchor;
462468

469+
if (target.closest(".fair-ranking-card")) return false;
470+
463471
return (
464472
slideAnchor === "bodytype-viz" ||
465473
slideAnchor === "body-types-viz" ||
466474
slideAnchor === "geopolitics-viz" ||
467475
slideAnchor === "fair-viz" ||
476+
slideAnchor === "fair-ranking" ||
468477
target.closest("#bodytype-viz") ||
469478
target.closest("#geopolitics-map-viz") ||
470479
target.closest("#geo-event-list") ||
471-
target.closest("#fair-viz")
480+
target.closest("#fair-viz") ||
481+
target.closest("#fair-ranking-viz")
472482
);
473483
}
474484

@@ -495,6 +505,11 @@ <h2>Project Gamma</h2>
495505
document.addEventListener("wheel", function (event) {
496506
const target = event.target;
497507

508+
if (target.closest(".fair-ranking-scroll")) {
509+
event.stopPropagation();
510+
return;
511+
}
512+
498513
if (target.closest("select, option, button, input, textarea, a, .geo-popup-overlay")) {
499514
return;
500515
}

website/js/fair-distribution.js

Lines changed: 113 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
gdpAdjustment: 100,
1919
rankingSeason: "Summer",
2020
rankingYear: null,
21-
expandedPredictionCountry: null
21+
expandedPredictionCountry: null,
22+
highlightedCountry: null,
2223
};
2324

2425
const medalOrder = ["Gold", "Silver", "Bronze"];
@@ -1000,8 +1001,8 @@
10001001
</div>
10011002
10021003
<div class="fair-ranking-layout">
1003-
${rankingTable("Actual medal table", actualRanking, "actual")}
1004-
${rankingTable("Fair medal table", fairRanking, "fair")}
1004+
${rankingTable("Actual medal ranking", actualRanking, "actual")}
1005+
${rankingTable("Fair medal ranking", fairRanking, "fair")}
10051006
</div>
10061007
`);
10071008

@@ -1018,34 +1019,96 @@
10181019
state.rankingYear = Number(this.value);
10191020
renderRankingTable();
10201021
});
1022+
1023+
// Click highlight country
1024+
d3.selectAll(".fair-ranking-table tbody tr").style("cursor", "pointer")
1025+
.on("click", function () {
1026+
const country = d3.select(this).select("td:nth-child(2)").text().trim();
1027+
const alreadyHighlighted = state.highlightedCountry === country;
1028+
state.highlightedCountry = alreadyHighlighted ? null : country;
1029+
if (state.highlightedCountry) {
1030+
highlightCountryInRanking(state.highlightedCountry);
1031+
} else {
1032+
clearRankingHighlight();
1033+
}
1034+
});
1035+
1036+
if (state.highlightedCountry) {
1037+
highlightCountryInRanking(state.highlightedCountry);
1038+
}
1039+
1040+
// Hover country
1041+
d3.selectAll(".fair-ranking-table tbody tr")
1042+
.on("mouseover", function () {
1043+
const country = d3.select(this).select("td:nth-child(2)").text().trim();
1044+
const indicators = getCountryIndicators(country);
1045+
1046+
const tooltip = d3.select("body").select(".fair-ranking-tooltip");
1047+
1048+
const html = `
1049+
<strong>${country}</strong><br>
1050+
Population: ${formatBig(indicators.population)}<br>
1051+
GDP per capita: ${formatBig(indicators.gdp)}
1052+
`;
1053+
1054+
tooltip.html(html).style("opacity", 1);
1055+
})
1056+
.on("mousemove", function (event) {
1057+
d3.select(".fair-ranking-tooltip")
1058+
.style("left", `${event.pageX + 14}px`)
1059+
.style("top", `${event.pageY + 14}px`);
1060+
})
1061+
.on("mouseleave", function () {
1062+
d3.select(".fair-ranking-tooltip").style("opacity", 0);
1063+
});
1064+
1065+
if (d3.select("body").select(".fair-ranking-tooltip").empty()) {
1066+
d3.select("body").append("div").attr("class", "fair-ranking-tooltip")
1067+
.style("position", "fixed")
1068+
.style("pointer-events", "none")
1069+
.style("opacity", 0)
1070+
.style("background", "rgba(20,20,20,0.96)")
1071+
.style("color", "white")
1072+
.style("border", "1px solid rgba(255,255,255,0.18)")
1073+
.style("border-radius", "10px")
1074+
.style("padding", "10px 12px")
1075+
.style("font-size", "14px")
1076+
.style("font-family", "'Elms Sans', sans-serif")
1077+
.style("line-height", "1.35")
1078+
.style("max-width", "260px")
1079+
.style("z-index", "99999")
1080+
.style("box-shadow", "0 8px 25px rgba(0,0,0,0.35)");
1081+
}
10211082
}
10221083

10231084
function rankingTable(title, rows, type) {
10241085
return `
10251086
<div class="fair-ranking-card">
1026-
<h2>${title}</h2>
1027-
<table class="fair-ranking-table">
1028-
<thead>
1029-
<tr>
1030-
<th>#</th>
1031-
<th>Country</th>
1032-
<th>Gold</th>
1033-
<th>Silver</th>
1034-
<th>Bronze</th>
1035-
</tr>
1036-
</thead>
1037-
<tbody>
1038-
${rows.map((row, i) => `
1087+
<p>${title}</p>
1088+
<div class="fair-ranking-scroll">
1089+
<table class="fair-ranking-table">
1090+
<thead>
10391091
<tr>
1040-
<td>${i + 1}</td>
1041-
<td>${row.country}</td>
1042-
<td>${formatFair(row[type].Gold)}</td>
1043-
<td>${formatFair(row[type].Silver)}</td>
1044-
<td>${formatFair(row[type].Bronze)}</td>
1092+
<th>#</th>
1093+
<th>Country</th>
1094+
<th>Gold</th>
1095+
<th>Silver</th>
1096+
<th>Bronze</th>
10451097
</tr>
1046-
`).join("")}
1047-
</tbody>
1048-
</table>
1098+
</thead>
1099+
<tbody>
1100+
${rows.map((row, i) => `
1101+
<tr>
1102+
<td>${i + 1}</td>
1103+
<td>${row.country}</td>
1104+
<td>${formatFair(row[type].Gold)}</td>
1105+
<td>${formatFair(row[type].Silver)}</td>
1106+
<td>${formatFair(row[type].Bronze)}</td>
1107+
</tr>
1108+
`).join("")}
1109+
</tbody>
1110+
</table>
1111+
</div>
10491112
</div>
10501113
`;
10511114
}
@@ -1101,4 +1164,30 @@
11011164
</div>
11021165
`;
11031166
}
1167+
1168+
function highlightCountryInRanking(country) {
1169+
d3.selectAll(".fair-ranking-table tbody tr")
1170+
.each(function () {
1171+
const row = d3.select(this);
1172+
const rowCountry = row.select("td:nth-child(2)").text().trim();
1173+
const isMatch = rowCountry === country;
1174+
1175+
row.style("background", isMatch ? "rgba(244, 180, 0, 0.25)" : null)
1176+
.style("color", isMatch ? "#f4b400" : null)
1177+
.style("font-weight", isMatch ? "800" : null)
1178+
.attr("data-highlighted", isMatch ? "true" : null);
1179+
1180+
if (isMatch) {
1181+
this.scrollIntoView({ behavior: "smooth", block: "nearest" });
1182+
}
1183+
});
1184+
}
1185+
1186+
function clearRankingHighlight() {
1187+
d3.selectAll(".fair-ranking-table tbody tr")
1188+
.style("background", null)
1189+
.style("color", null)
1190+
.style("font-weight", null)
1191+
.attr("data-highlighted", null);
1192+
}
11041193
})();

website/styles.css

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,10 +1134,22 @@ h4 {
11341134
padding: 24px;
11351135
}
11361136

1137-
.fair-ranking-card h2 {
1138-
font-size: 28px;
1137+
.fair-ranking-card p {
1138+
font-family: "Elms Sans", sans-serif;
1139+
font-size: 20px;
1140+
font-weight: 700;
1141+
color: white;
1142+
margin-top: 0;
1143+
margin-bottom: 14px;
11391144
width: 100%;
1140-
padding-bottom: 18px;
1145+
text-align: center;
1146+
}
1147+
1148+
.fair-ranking-scroll {
1149+
max-height: 420px;
1150+
overflow-y: auto;
1151+
overflow-x: hidden;
1152+
overscroll-behavior: contain;
11411153
}
11421154

11431155
.fair-ranking-table {
@@ -1266,22 +1278,16 @@ h4 {
12661278
justify-content: space-between;
12671279
}
12681280

1269-
.fair-ranking-card {
1270-
max-height: 520px;
1271-
overflow-y: auto;
1272-
overflow-x: hidden;
1273-
}
1274-
1275-
.fair-ranking-card::-webkit-scrollbar {
1281+
.fair-ranking-scroll::-webkit-scrollbar {
12761282
width: 8px;
12771283
}
12781284

1279-
.fair-ranking-card::-webkit-scrollbar-track {
1285+
.fair-ranking-scroll::-webkit-scrollbar-track {
12801286
background: rgba(255,255,255,0.08);
12811287
border-radius: 999px;
12821288
}
12831289

1284-
.fair-ranking-card::-webkit-scrollbar-thumb {
1290+
.fair-ranking-scroll::-webkit-scrollbar-thumb {
12851291
background: #f4b400;
12861292
border-radius: 999px;
12871293
}
@@ -1290,7 +1296,7 @@ h4 {
12901296
position: sticky;
12911297
top: 0;
12921298
background: #111;
1293-
z-index: 2;
1299+
z-index: 10;
12941300
}
12951301

12961302
.medal-tooltip {

0 commit comments

Comments
 (0)