|
380 | 380 |
|
381 | 381 | state.availableYears = getAvailableYears(season); |
382 | 382 |
|
383 | | - state.currentYear = state.availableYears.includes(1896) |
384 | | - ? 1896 |
385 | | - : state.availableYears[0]; |
| 383 | + const previousYear = state.currentYear; |
| 384 | + if (previousYear && state.availableYears.includes(previousYear)) { |
| 385 | + state.currentYear = previousYear; |
| 386 | + } else if (previousYear) { |
| 387 | + state.currentYear = state.availableYears.reduce((closest, y) => |
| 388 | + Math.abs(y - previousYear) < Math.abs(closest - previousYear) ? y : closest |
| 389 | + ); |
| 390 | + } else { |
| 391 | + state.currentYear = state.availableYears[0]; |
| 392 | + } |
386 | 393 |
|
387 | 394 | updateSliderLimits(); |
388 | 395 | update(); |
|
432 | 439 | } |
433 | 440 |
|
434 | 441 | state.playing = true; |
435 | | - d3.select(selectors.play).text("Ⅱ"); |
| 442 | + d3.select(selectors.play).text("II"); |
436 | 443 |
|
437 | 444 | playNextYear(); |
438 | 445 | } |
|
746 | 753 | root.selectAll("*").remove(); |
747 | 754 |
|
748 | 755 | const width = 1280; |
749 | | - const height = 650; |
750 | | - const margin = { top: 70, right: 40, bottom: 30, left: 40 }; |
| 756 | + const height = 520; |
| 757 | + const margin = { top: 75, right: 40, bottom: 20, left: 40 }; |
751 | 758 |
|
752 | 759 | const svg = root |
753 | 760 | .append("svg") |
|
759 | 766 | .attr("y", 32) |
760 | 767 | .attr("text-anchor", "middle") |
761 | 768 | .attr("fill", "white") |
762 | | - .attr("font-family", "Arial, sans-serif") |
| 769 | + .attr("font-family", "'Elms Sans', sans-serif") |
763 | 770 | .attr("font-size", 24) |
764 | 771 | .attr("font-weight", 700) |
765 | 772 | .text(`Distribution of medals in ${graph.season} Olympics, ${graph.year}`); |
|
769 | 776 | .attr("y", 58) |
770 | 777 | .attr("text-anchor", "middle") |
771 | 778 | .attr("fill", "rgba(255,255,255,0.75)") |
772 | | - .attr("font-family", "Arial, sans-serif") |
| 779 | + .attr("font-family", "'Elms Sans', sans-serif") |
773 | 780 | .attr("font-size", 14) |
774 | 781 | .text(`Flows show ${graph.mode}s → medal type → top 10 sports · ${graph.medalCount} medals shown`); |
775 | 782 |
|
|
779 | 786 | .attr("y", height / 2) |
780 | 787 | .attr("text-anchor", "middle") |
781 | 788 | .attr("fill", "white") |
782 | | - .attr("font-family", "Arial, sans-serif") |
| 789 | + .attr("font-family", "'Elms Sans', sans-serif") |
783 | 790 | .attr("font-size", 22) |
784 | 791 | .text("No medal data available for this year."); |
785 | 792 |
|
|
871 | 878 | .attr("dy", "0.35em") |
872 | 879 | .attr("text-anchor", d => d.x0 < width / 2 ? "start" : "end") |
873 | 880 | .attr("fill", "white") |
874 | | - .attr("font-family", "Arial, sans-serif") |
| 881 | + .attr("font-family", "'Elms Sans', sans-serif") |
875 | 882 | .attr("font-size", 13) |
876 | 883 | .attr("font-weight", d => d.type === "medal" ? 800 : 600) |
877 | 884 | .text(d => shortenLabel(d.name, 22)); |
|
937 | 944 |
|
938 | 945 | header.append("div") |
939 | 946 | .html(` |
940 | | - <div style="font-family:Arial, sans-serif; font-size:28px; font-weight:800;"> |
| 947 | + <div style="font-family:'Elms Sans', sans-serif; font-size:28px; font-weight:800;"> |
941 | 948 | ${detail.medal} medals in ${detail.sport} |
942 | 949 | </div> |
943 | | - <div style="font-family:Arial, sans-serif; font-size:15px; color:rgba(255,255,255,0.72); margin-top:4px;"> |
| 950 | + <div style="font-family:'Elms Sans', sans-serif; font-size:15px; color:rgba(255,255,255,0.72); margin-top:4px;"> |
944 | 951 | ${detail.season} Olympics, ${detail.year} · grouped by ${detail.mode} |
945 | 952 | </div> |
946 | 953 | `); |
|
951 | 958 | .style("border", "2px solid white") |
952 | 959 | .style("border-radius", "10px") |
953 | 960 | .style("padding", "9px 18px") |
954 | | - .style("font-family", "Arial, sans-serif") |
| 961 | + .style("font-family", "'Elms Sans', sans-serif") |
955 | 962 | .style("font-size", "15px") |
956 | 963 | .style("font-weight", "800") |
957 | 964 | .style("cursor", "pointer") |
|
1038 | 1045 | .attr("y", 22) |
1039 | 1046 | .attr("text-anchor", "middle") |
1040 | 1047 | .attr("fill", "white") |
1041 | | - .attr("font-family", "Arial, sans-serif") |
| 1048 | + .attr("font-family", "'Elms Sans', sans-serif") |
1042 | 1049 | .attr("font-size", 16) |
1043 | 1050 | .attr("font-weight", 700) |
1044 | 1051 | .text(`The ${total} ${detail.medal.toLowerCase()} medals in ${detail.sport} are split across ${detail.mode}s`); |
|
1093 | 1100 | .attr("dy", "0.35em") |
1094 | 1101 | .attr("text-anchor", d => d.x0 < width / 2 ? "start" : "end") |
1095 | 1102 | .attr("fill", "white") |
1096 | | - .attr("font-family", "Arial, sans-serif") |
| 1103 | + .attr("font-family", "'Elms Sans', sans-serif") |
1097 | 1104 | .attr("font-size", 15) |
1098 | 1105 | .attr("font-weight", 800) |
1099 | 1106 | .text(d => { |
|
0 commit comments