|
13 | 13 | season: "Summer", |
14 | 14 | year: null, |
15 | 15 | country1: null, |
16 | | - country2: null |
| 16 | + country2: null, |
| 17 | + populationAdjustment: 100, |
| 18 | + gdpAdjustment: 100 |
17 | 19 | }; |
18 | 20 |
|
19 | 21 | const medalOrder = ["Gold", "Silver", "Bronze"]; |
|
346 | 348 | <span class="bottom">country GDP</span> |
347 | 349 | </span> |
348 | 350 | </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> |
349 | 369 | </div> |
350 | 370 | `; |
351 | 371 | } |
|
411 | 431 | state.country2 = this.value; |
412 | 432 | render(); |
413 | 433 | }); |
| 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 | + }); |
414 | 446 | } |
415 | 447 |
|
416 | 448 | function updateCountriesAfterSeasonOrYearChange() { |
|
703 | 735 | Number.isFinite(meanGDP) && |
704 | 736 | meanGDP > 0 |
705 | 737 | ) { |
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; |
707 | 742 | } |
708 | 743 |
|
709 | 744 | const fair = {}; |
|
0 commit comments