-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOrigin.html
More file actions
253 lines (234 loc) · 9.94 KB
/
Origin.html
File metadata and controls
253 lines (234 loc) · 9.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Final Origin Countries Chart</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/7.8.5/d3.min.js"></script>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 20px;
background-color: #f5f5f5;
}
.container {
max-width: 1200px;
margin: 0 auto;
background: white;
padding: 30px;
border-radius: 10px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}
.chart-container {
position: relative;
overflow: hidden;
}
.line {
fill: none;
stroke-width: 3;
transition: all 0.3s ease;
}
.line:hover {
stroke-width: 5;
opacity: 1 !important;
}
.dot {
fill: white;
stroke-width: 2;
r: 4;
transition: all 0.3s ease;
}
.dot:hover {
r: 6;
}
.country-label {
font-size: 12px;
font-weight: bold;
fill: #333;
alignment-baseline: middle;
}
.time-label {
font-size: 14px;
font-weight: bold;
fill: #666;
text-anchor: middle;
}
.tooltip {
position: absolute;
background: rgba(0,0,0,0.9);
color: white;
padding: 8px 12px;
border-radius: 4px;
font-size: 12px;
pointer-events: none;
opacity: 0;
transition: opacity 0.3s;
}
.legend {
margin-top: 20px;
font-size: 12px;
color: #666;
}
</style>
</head>
<body>
<div class="container">
<div class="chart-container">
<svg id="bump-chart"></svg>
<div class="tooltip"></div>
</div>
<div class="legend">
<p><strong>Note:</strong> Hover over lines to see country details. Lower rank numbers indicate higher positions.</p>
<p><strong>Color coding by continent:</strong>
<span style="color: #2E8B57; font-weight: bold;">■ Asia</span> |
<span style="color: #4169E1; font-weight: bold;">■ Europe</span> |
<span style="color: #FF6347; font-weight: bold;">■ Africa</span> |
<span style="color: #9932CC; font-weight: bold;">■ North America</span> |
<span style="color: #20B2AA; font-weight: bold;">■ Oceania</span> |
<span style="color: #FF8C00; font-weight: bold;">■ South America</span>
</p>
<p><strong>Markers:</strong> <strong>Colored squares</strong> for series ending in 2019*. <em>*2019 is the latest available data (no 2020 data)</em></p>
</div>
</div>
<script>
// Final Origin Countries data with continent grouping
const data = [
{country: "Russian Federation", values: [1, 1, 1, 2, 3, 3, 4], continent: "Europe"},
{country: "Afghanistan", values: [2, 7, 7, 9, 7, 9, 10], continent: "Asia"},
{country: "India", values: [3, 2, 3, 3, 1, 1, 1], continent: "Asia"},
{country: "Ukraine", values: [4, 4, 5, 6, 6, 8, 8], continent: "Europe"},
{country: "Bangladesh", values: [5, 5, 6, 5, 5, 5, 6], continent: "Asia"},
{country: "Mexico", values: [6, 3, 2, 1, 2, 2, 2], continent: "North America"},
{country: "China", values: [7, 6, 4, 4, 4, 4, 3], continent: "Asia"},
{country: "United Kingdom", values: [8, 8, 8, 7, 10, 12, 13], continent: "Europe"},
{country: "Pakistan", values: [9, 9, 10, 8, 8, 7, 7], continent: "Asia"},
{country: "Kazakhstan", values: [10, 10, 9, 10, 11, 14, 15], continent: "Asia"},
{country: "Germany", values: [11, 11, 11, 12, 13, 15, 14], continent: "Europe"},
{country: "Turkey", values: [12, 12, 13, 16, 17, 18, 20], continent: "Europe"},
{country: "Philippines", values: [13, 13, 12, 11, 9, 10, 9], continent: "Asia"},
{country: "State of Palestine", values: [14, 14, 14, 13, 16, 16, 16], continent: "Asia"},
{country: "Indonesia", values: [15, 15, 15, 15, 14, 11, 11], continent: "Asia"},
{country: "Poland", values: [16, 16, 16, 14, 12, 13, 12], continent: "Europe"},
{country: "Egypt", values: [17, 17, 17, 18, 18, 19, 19], continent: "Africa"},
{country: "Romania", values: [18, 18, 19, 17, 15, 17, 18], continent: "Europe"},
{country: "Myanmar", values: [19, 19, 18, 19, 19, 20, 17], continent: "Asia"},
{country: "Syrian Arab Republic", values: [20, 20, 20, 20, 20, 6, 5], continent: "Asia"}
];
const years = [1990, 1995, 2000, 2005, 2010, 2015, 2019];
// Continent color mapping
const continentColors = {
"Asia": "#2E8B57",
"Europe": "#4169E1",
"Africa": "#FF6347",
"North America": "#9932CC",
"Oceania": "#20B2AA",
"South America": "#FF8C00"
};
// Set up dimensions
const margin = {top: 60, right: 150, bottom: 40, left: 200};
const width = 1000 - margin.left - margin.right;
const height = 900 - margin.bottom - margin.top;
// Create SVG
const svg = d3.select("#bump-chart")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom);
const g = svg.append("g")
.attr("transform", `translate(${margin.left},${margin.top})`);
// Scales
const xScale = d3.scalePoint()
.domain(years)
.range([0, width]);
const yScale = d3.scaleLinear()
.domain([1, 20])
.range([0, height]);
// Add year labels with asterisk for 2019
g.selectAll(".time-label")
.data(years)
.enter().append("text")
.attr("class", "time-label")
.attr("x", d => xScale(d))
.attr("y", -20)
.text(d => d === 2019 ? "2019*" : d);
// Tooltip
const tooltip = d3.select(".tooltip");
// Create line generator
const line = d3.line()
.x((d, i) => xScale(years[i]))
.y(d => yScale(d))
.curve(d3.curveMonotoneX);
// Add grid lines
g.selectAll(".grid-line")
.data(years)
.enter().append("line")
.attr("class", "grid-line")
.attr("x1", d => xScale(d))
.attr("x2", d => xScale(d))
.attr("y1", 0)
.attr("y2", height)
.style("stroke", "#e0e0e0")
.style("stroke-width", 1);
// Add lines and dots for each country
data.forEach(countryData => {
const countryGroup = g.append("g").attr("class", "country");
// Add line
countryGroup.append("path")
.attr("class", "line")
.attr("d", line(countryData.values))
.style("stroke", continentColors[countryData.continent])
.style("opacity", 0.7)
.on("mouseover", function(event) {
d3.select(this).style("opacity", 1);
g.selectAll(".line").style("opacity", 0.2);
d3.select(this).style("opacity", 1);
const lastRank = countryData.values[countryData.values.length - 1];
tooltip.style("opacity", 1)
.html("<strong>" + countryData.country + "</strong><br/>" +
"Continent: " + countryData.continent + "<br/>" +
"1990: Rank " + countryData.values[0] + "<br/>" +
"2019: Rank " + lastRank)
.style("left", (event.pageX + 10) + "px")
.style("top", (event.pageY - 10) + "px");
})
.on("mouseout", function() {
g.selectAll(".line").style("opacity", 0.7);
tooltip.style("opacity", 0);
});
// Add dots
countryData.values.forEach((value, i) => {
const isLastPoint = i === countryData.values.length - 1;
const currentYear = years[i];
if (isLastPoint) {
// Add square for final points
countryGroup.append("rect")
.attr("class", "dot")
.attr("x", xScale(currentYear) - 4)
.attr("y", yScale(value) - 4)
.attr("width", 8)
.attr("height", 8)
.style("stroke", continentColors[countryData.continent])
.style("fill", continentColors[countryData.continent]);
} else {
// Add circle for regular points
countryGroup.append("circle")
.attr("class", "dot")
.attr("cx", xScale(currentYear))
.attr("cy", yScale(value))
.style("stroke", continentColors[countryData.continent])
.style("fill", "white")
.attr("r", 4);
}
});
// Add country label
countryGroup.append("text")
.attr("class", "country-label")
.attr("x", -40)
.attr("y", yScale(countryData.values[0]))
.text(countryData.country)
.style("fill", continentColors[countryData.continent])
.style("font-size", "11px")
.style("text-anchor", "end");
});
</script>
</body>
</html>