Skip to content

Commit 0d5067b

Browse files
committed
feat: change Actual medals vs. Fair medals bars into medals
1 parent f029ca0 commit 0d5067b

2 files changed

Lines changed: 51 additions & 35 deletions

File tree

website/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ <h2>What would a fair distribution of Olympic medals look like?</h2>
325325
</div>
326326
</div>
327327
<div class="slide" data-anchor="fair-viz">
328-
<h2 class="fair-viz-title">Actual medals vs. fair medals</h2>
328+
<h2 class="fair-viz-title">Actual medals vs. Fair medals</h2>
329329
<p class="fair-viz-subtitle">
330330
Compare two countries and see how medal counts change when population and GDP are taken into account.
331331
</p>

website/js/fair-distribution.js

Lines changed: 50 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@
221221
.fair-medal-row {
222222
display: grid;
223223
grid-template-columns: 72px 1fr 50px;
224-
align-items: center;
224+
align-items: start;
225225
gap: 12px;
226226
margin: 11px 0;
227227
}
@@ -230,26 +230,36 @@
230230
font-size: 14px;
231231
font-weight: 800;
232232
color: white;
233+
padding-top: 2px;
233234
}
234235
235236
.fair-medal-value {
236237
font-size: 14px;
237238
font-weight: 800;
238239
color: white;
239240
text-align: right;
241+
padding-top: 2px;
240242
}
241243
242-
.fair-bar-bg {
243-
height: 14px;
244-
background: rgba(255,255,255,0.15);
245-
border-radius: 999px;
246-
overflow: hidden;
244+
.fair-medal-icons {
245+
display: flex;
246+
flex-wrap: wrap;
247+
gap: 3px;
248+
align-items: center;
247249
}
248250
249-
.fair-bar-fill {
250-
height: 100%;
251-
border-radius: 999px;
252-
min-width: 0;
251+
.fair-medal-icon {
252+
width: 16px;
253+
height: 16px;
254+
border-radius: 50%;
255+
flex-shrink: 0;
256+
}
257+
258+
.fair-medal-half-wrap {
259+
width: 8px;
260+
height: 16px;
261+
overflow: hidden;
262+
flex-shrink: 0;
253263
}
254264
255265
.fair-note {
@@ -267,6 +277,12 @@
267277
margin-top: 8px;
268278
}
269279
280+
.fair-warning--lg {
281+
font-size: 14px;
282+
margin-top: 12px;
283+
line-height: 1.5;
284+
}
285+
270286
.fair-error {
271287
color: white;
272288
text-align: center;
@@ -832,6 +848,22 @@
832848
renderRankingTable();
833849
}
834850

851+
function renderMedalIcons(value, color) {
852+
const rounded = Math.round((value || 0) * 2) / 2;
853+
const fullCount = Math.floor(rounded);
854+
const hasHalf = rounded % 1 === 0.5;
855+
856+
const full = Array(fullCount).fill(0).map(() =>
857+
`<div class="fair-medal-icon" style="background:${color}"></div>`
858+
).join("");
859+
860+
const half = hasHalf
861+
? `<div class="fair-medal-half-wrap"><div class="fair-medal-icon" style="background:${color}"></div></div>`
862+
: "";
863+
864+
return `<div class="fair-medal-icons">${full}${half}</div>`;
865+
}
866+
835867
function renderCountryCard(country, data, maxScale) {
836868
const fairUnavailable = data.factor === null;
837869

@@ -847,18 +879,17 @@
847879
<div class="fair-box">
848880
<div class="fair-box-title">Actual medals</div>
849881
850-
${medalOrder.map(medal => {
882+
${data.similarCountry ? `
883+
<div class="fair-warning fair-warning--lg">
884+
No medals for ${country}. Fair values are estimated from ${data.similarCountry},
885+
a medal-winning country with similar GDP.
886+
</div>
887+
` : medalOrder.map(medal => {
851888
const value = data.actual[medal] || 0;
852-
const width =
853-
value === 0 ? 0 : Math.max(3, (100 * value) / maxScale);
854-
855889
return `
856890
<div class="fair-medal-row">
857891
<div class="fair-medal-label">${medal}</div>
858-
<div class="fair-bar-bg">
859-
<div class="fair-bar-fill"
860-
style="width:${width}%; background:${medalColors[medal]}"></div>
861-
</div>
892+
${renderMedalIcons(value, medalColors[medal])}
862893
<div class="fair-medal-value">${value}</div>
863894
</div>
864895
`;
@@ -870,27 +901,12 @@
870901
Fair medals with average population and average GDP
871902
</div>
872903
873-
${data.similarCountry ? `
874-
<div class="fair-warning">
875-
No medals for ${country}. Fair values are estimated from ${data.similarCountry},
876-
a medal-winning country with similar GDP.
877-
</div>
878-
` : ""}
879-
880904
${medalOrder.map(medal => {
881905
const value = data.fair[medal];
882-
const width =
883-
value === null || value === 0
884-
? 0
885-
: Math.max(3, (100 * value) / maxScale);
886-
887906
return `
888907
<div class="fair-medal-row">
889908
<div class="fair-medal-label">${medal}</div>
890-
<div class="fair-bar-bg">
891-
<div class="fair-bar-fill"
892-
style="width:${width}%; background:${medalColors[medal]}"></div>
893-
</div>
909+
${value === null ? `<div class="fair-medal-icons"></div>` : renderMedalIcons(value, medalColors[medal])}
894910
<div class="fair-medal-value">
895911
${value === null ? "n/a" : formatFair(value)}
896912
</div>

0 commit comments

Comments
 (0)