|
221 | 221 | .fair-medal-row { |
222 | 222 | display: grid; |
223 | 223 | grid-template-columns: 72px 1fr 50px; |
224 | | - align-items: center; |
| 224 | + align-items: start; |
225 | 225 | gap: 12px; |
226 | 226 | margin: 11px 0; |
227 | 227 | } |
|
230 | 230 | font-size: 14px; |
231 | 231 | font-weight: 800; |
232 | 232 | color: white; |
| 233 | + padding-top: 2px; |
233 | 234 | } |
234 | 235 |
|
235 | 236 | .fair-medal-value { |
236 | 237 | font-size: 14px; |
237 | 238 | font-weight: 800; |
238 | 239 | color: white; |
239 | 240 | text-align: right; |
| 241 | + padding-top: 2px; |
240 | 242 | } |
241 | 243 |
|
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; |
247 | 249 | } |
248 | 250 |
|
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; |
253 | 263 | } |
254 | 264 |
|
255 | 265 | .fair-note { |
|
267 | 277 | margin-top: 8px; |
268 | 278 | } |
269 | 279 |
|
| 280 | + .fair-warning--lg { |
| 281 | + font-size: 14px; |
| 282 | + margin-top: 12px; |
| 283 | + line-height: 1.5; |
| 284 | + } |
| 285 | +
|
270 | 286 | .fair-error { |
271 | 287 | color: white; |
272 | 288 | text-align: center; |
|
832 | 848 | renderRankingTable(); |
833 | 849 | } |
834 | 850 |
|
| 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 | + |
835 | 867 | function renderCountryCard(country, data, maxScale) { |
836 | 868 | const fairUnavailable = data.factor === null; |
837 | 869 |
|
|
847 | 879 | <div class="fair-box"> |
848 | 880 | <div class="fair-box-title">Actual medals</div> |
849 | 881 |
|
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 => { |
851 | 888 | const value = data.actual[medal] || 0; |
852 | | - const width = |
853 | | - value === 0 ? 0 : Math.max(3, (100 * value) / maxScale); |
854 | | -
|
855 | 889 | return ` |
856 | 890 | <div class="fair-medal-row"> |
857 | 891 | <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])} |
862 | 893 | <div class="fair-medal-value">${value}</div> |
863 | 894 | </div> |
864 | 895 | `; |
|
870 | 901 | Fair medals with average population and average GDP |
871 | 902 | </div> |
872 | 903 |
|
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 | | -
|
880 | 904 | ${medalOrder.map(medal => { |
881 | 905 | const value = data.fair[medal]; |
882 | | - const width = |
883 | | - value === null || value === 0 |
884 | | - ? 0 |
885 | | - : Math.max(3, (100 * value) / maxScale); |
886 | | -
|
887 | 906 | return ` |
888 | 907 | <div class="fair-medal-row"> |
889 | 908 | <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])} |
894 | 910 | <div class="fair-medal-value"> |
895 | 911 | ${value === null ? "n/a" : formatFair(value)} |
896 | 912 | </div> |
|
0 commit comments