-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
284 lines (254 loc) · 11 KB
/
index.html
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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://d3js.org/d3.v7.min.js"></script>
<title>Olympics time Again !!</title>
<style>
body {
margin: 0;
font-family: Arial, sans-serif;
}
header,footer {
background-color: #333;
color: white;
padding: 20px;
text-align: center;
}
.summer{
padding-left: 100px;
}
img {
display: block;
margin: 0 auto; /* Center the image */
max-width: 100%; /* Responsive image */
height: 200px; /* Maintain aspect ratio */
}
.chart {
display: inline-block;
margin-right: 50px;
}
.bar {
fill: steelblue;
}
.bar:hover {
fill: brown;
}
.axis text {
font-size: 10px;
}
.axis path,
.axis line {
fill: none;
stroke: #000;
shape-rendering: crispEdges;
}
.tooltip {
position: absolute;
text-align: center;
width: 200px;
height: 60px;
padding: 2px;
font: 12px sans-serif;
background: lightsteelblue;
border: 0px;
border-radius: 8px;
pointer-events: none;
}
.button {
display: inline-block;
padding: 10px 20px;
background-color: #4CAF50;
color: white;
text-decoration: none;
border-radius: 5px;
margin-right: 10px;
}
/* Styling for the actual button element */
button {
padding: 10px 20px;
background-color: #008CBA;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
}
.container {
text-align: center; /* Center text and inline elements */
margin-top: 20px; /* Adjust top margin as needed */
}
</style>
</head>
<body>
<header>
<h1>Its Olympics time Again !!!!</h1>
</header>
<div>
<img src="img/paris-2024-olympics.jpg" alt="Description of Image">
</div>
<main>
<p>The Olympic Games are considered the world's foremost sports competition with more than 200 teams, representing sovereign states and territories, participating.The Olympic Games are held every four years. Since 1994, they have alternated between the Summer and Winter Olympics every two years during the four-year Olympiad. The first Olympics started in 1896 and its been more than 125 years comprising of <b>32</b> summer olympics and <b>24</b> winter olympics. Lets take a quick look at top performing countries and athletes.</p>
<div id="summer">
<br></br>
<div id="chart1" class="chart"></div>
<div id="chart2" class="chart"></div>
<div id="chart3" class="chart"></div>
<div id="chart4" class="chart"></div>
<script>
// Create a tooltip
var tooltip = d3.select("body").append("div")
.attr("class", "tooltip")
.style("opacity", 0);
// Function to create a horizontal bar chart
function createHorizontalBarChart(data, chartId,title) {
const margin = {top: 30, right: 30, bottom: 40, left: 150},
width = 700 - margin.left - margin.right,
height = 400 - margin.top - margin.bottom;
const svg = d3.select(chartId)
.append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", `translate(${margin.left},${margin.top})`);
const x = d3.scaleLinear()
.domain([0, d3.max(data, d => d.count)])
.range([0, width]);
const y = d3.scaleBand()
.range([0, height])
.domain(data.map(d => d.name))
.padding(0.1);
svg.selectAll("rect")
.data(data)
.join("rect")
.attr("class", "bar")
.attr("y", d => y(d.name))
.attr("height", y.bandwidth())
.attr("x", 0)
.attr("width", d => x(d.count));
svg.selectAll(".bar")
.on("mouseover", function(event, d) {
tooltip.transition()
.duration(200)
.style("opacity", .9);
tooltip.html("Name: " + d.name + "-" + d.country + "<br/>" + "Medals: " + d.count)
.style("left", (event.pageX + 5) + "px")
.style("top", (event.pageY - 28) + "px");
})
.on("mouseout", function(d) {
tooltip.transition()
.duration(500)
.style("opacity", 0);
});
svg.append("g")
.attr("class", "x axis")
.attr("transform", `translate(0,${height})`)
.call(d3.axisBottom(x));
svg.append("text")
.attr("x", width / 2)
.attr("y", 0 - (margin.top / 2))
.attr("text-anchor", "middle")
.style("font-size", "16px")
.style("font-weight", "bold")
.text(title);
svg.append("g")
.attr("class", "y axis")
.call(d3.axisLeft(y));
}
// Load and process CSV data
Promise.all([
d3.csv("data/top_countries.csv", d3.autoType),
d3.csv("data/top_athletes.csv", d3.autoType)
]).then(([data1, data2]) => {
createHorizontalBarChart(data1, "#chart1","Top Performing countries in Summer Olympics");
createHorizontalBarChart(data2, "#chart2","Top Performing Athletes in Summer Olympics");
// createHorizontalBarChart(data1, "#chart2","Top Performing countries in Winter Olympics");
// createHorizontalBarChart(data2, "#chart2","Top Performing Athletes in Winter Olympics");
}).catch(error => {
console.error("Error loading the CSV files:", error);
});
</script>
<script>
// Create a tooltip
var tooltip = d3.select("body").append("div")
.attr("class", "tooltip")
.style("opacity", 0);
// Function to create a horizontal bar chart
function createHorizontalBarChart(data, chartId,title) {
const margin = {top: 30, right: 30, bottom: 40, left: 150},
width = 700 - margin.left - margin.right,
height = 400 - margin.top - margin.bottom;
const svg = d3.select(chartId)
.append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", `translate(${margin.left},${margin.top})`);
const x = d3.scaleLinear()
.domain([0, d3.max(data, d => d.count)])
.range([0, width]);
const y = d3.scaleBand()
.range([0, height])
.domain(data.map(d => d.name))
.padding(0.1);
svg.selectAll("rect")
.data(data)
.join("rect")
.attr("class", "bar")
.attr("y", d => y(d.name))
.attr("height", y.bandwidth())
.attr("x", 0)
.attr("width", d => x(d.count));
svg.selectAll(".bar")
.on("mouseover", function(event, d) {
tooltip.transition()
.duration(200)
.style("opacity", .9);
tooltip.html("Name: " + d.name + "<br/>" + "Medals: " + d.count)
.style("left", (event.pageX + 5) + "px")
.style("top", (event.pageY - 28) + "px");
})
.on("mouseout", function(d) {
tooltip.transition()
.duration(500)
.style("opacity", 0);
});
svg.append("g")
.attr("class", "x axis")
.attr("transform", `translate(0,${height})`)
.call(d3.axisBottom(x));
svg.append("text")
.attr("x", width / 2)
.attr("y", 0 - (margin.top / 2))
.attr("text-anchor", "middle")
.style("font-size", "16px")
.style("font-weight", "bold")
.text(title);
svg.append("g")
.attr("class", "y axis")
.call(d3.axisLeft(y));
}
// Load and process CSV data
Promise.all([
d3.csv("data/top_countries_winter.csv", d3.autoType),
d3.csv("data/top_athletes_winter.csv", d3.autoType)
]).then(([data1, data2]) => {
createHorizontalBarChart(data1, "#chart3","Top Performing countries in Winter Olympics");
createHorizontalBarChart(data2, "#chart4","Top Performing Athletes in Winter Olympics");
// createHorizontalBarChart(data1, "#chart2","Top Performing countries in Winter Olympics");
// createHorizontalBarChart(data2, "#chart2","Top Performing Athletes in Winter Olympics");
}).catch(error => {
console.error("Error loading the CSV files:", error);
});
</script>
</div>
<p>Lets go through a Journey with Summer Olympics to answer a question of whether Hosting Olympics improves Performance of a Country !!!!</p>
<div class="container">
<a href="gdp1.html" class="button">Continue</a>
</div>
</main>
<footer>
<p>© 2024.</p>
</footer>
</body>
</html>