Skip to content

Commit e020622

Browse files
committed
sliders in fair distribution
1 parent 575a299 commit e020622

2 files changed

Lines changed: 74 additions & 2 deletions

File tree

website/js/fair-distribution.js

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
season: "Summer",
1414
year: null,
1515
country1: null,
16-
country2: null
16+
country2: null,
17+
populationAdjustment: 100,
18+
gdpAdjustment: 100
1719
};
1820

1921
const medalOrder = ["Gold", "Silver", "Bronze"];
@@ -346,6 +348,24 @@
346348
<span class="bottom">country GDP</span>
347349
</span>
348350
</div>
351+
352+
<p class="fair-slider-explanation">
353+
Use the sliders to adjust how much weight population and GDP have in the fair medal calculation.
354+
</p>
355+
356+
<div class="fair-sliders">
357+
<label class="fair-slider-control">
358+
<span>Population adjustment:</span>
359+
<input id="fair-pop-adjustment" type="range" min="0" max="200" value="100" step="10">
360+
<strong id="fair-pop-value">100%</strong>
361+
</label>
362+
363+
<label class="fair-slider-control">
364+
<span>GDP adjustment:</span>
365+
<input id="fair-gdp-adjustment" type="range" min="0" max="200" value="100" step="10">
366+
<strong id="fair-gdp-value">100%</strong>
367+
</label>
368+
</div>
349369
</div>
350370
`;
351371
}
@@ -411,6 +431,18 @@
411431
state.country2 = this.value;
412432
render();
413433
});
434+
435+
d3.select("#fair-pop-adjustment").on("input", function () {
436+
state.populationAdjustment = Number(this.value);
437+
d3.select("#fair-pop-value").text(`${state.populationAdjustment}%`);
438+
render();
439+
});
440+
441+
d3.select("#fair-gdp-adjustment").on("input", function () {
442+
state.gdpAdjustment = Number(this.value);
443+
d3.select("#fair-gdp-value").text(`${state.gdpAdjustment}%`);
444+
render();
445+
});
414446
}
415447

416448
function updateCountriesAfterSeasonOrYearChange() {
@@ -703,7 +735,10 @@
703735
Number.isFinite(meanGDP) &&
704736
meanGDP > 0
705737
) {
706-
factor = (meanPopulation / population) * (meanGDP / gdp);
738+
const populationFactor = Math.pow(meanPopulation / population, state.populationAdjustment / 100);
739+
const gdpFactor = Math.pow(meanGDP / gdp, state.gdpAdjustment / 100);
740+
741+
factor = populationFactor * gdpFactor;
707742
}
708743

709744
const fair = {};

website/styles.css

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,6 +1113,43 @@ p {
11131113
color: #f4b400;
11141114
}
11151115

1116+
.fair-slider-explanation {
1117+
width: 100%;
1118+
text-align: center;
1119+
font-size: 16px;
1120+
margin: 10px auto 8px;
1121+
color: rgba(255,255,255,0.8);
1122+
}
1123+
1124+
.fair-sliders {
1125+
display: flex;
1126+
justify-content: center;
1127+
gap: 36px;
1128+
align-items: center;
1129+
margin: 8px auto 0;
1130+
flex-wrap: wrap;
1131+
}
1132+
1133+
.fair-slider-control {
1134+
display: flex;
1135+
align-items: center;
1136+
gap: 12px;
1137+
color: white;
1138+
font-size: 16px;
1139+
font-weight: 700;
1140+
}
1141+
1142+
.fair-slider-control input {
1143+
width: 220px;
1144+
accent-color: #f4b400;
1145+
}
1146+
1147+
.fair-slider-control strong {
1148+
color: #f4b400;
1149+
min-width: 52px;
1150+
text-align: left;
1151+
}
1152+
11161153
/* =============================================
11171154
Footer
11181155
=========================================== */

0 commit comments

Comments
 (0)