This repository has been archived by the owner on Jun 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
210 lines (180 loc) · 11.5 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="Content-Security-Policy" content="frame-ancestors https://*.observablehq.com">
<title>The FIFA Story</title>
<!-- linking stylesheet -->
<link rel="stylesheet" href="./static/styles.css">
<!-- linking d3.js -->
<script src="https://d3js.org/d3.v6.min.js"></script>
<!-- linking fonts -->
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Anton&display=swap">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Permanent+Marker&display=swap" rel="stylesheet">
</head>
<body style="overflow-y: auto;">
<div id="main_div">
<div id="top_bar">The FIFA Story</div>
<div class="graph_titles">WC Winners</div>
<div id="choropleth" style="height: 60vh; overflow: auto;">
<!-- Adjusted height and added overflow for scrolling -->
<svg width="100%" height="80%" viewBox="0 0 2000 1000"></svg>
<script>
const colorScale = d3.scaleLinear()
.domain([0, 5])
.range(["#ADD8E6", " #191970"]);
// here, I am trying to load the geoJSON file that is given to us
d3.json("https://enjalot.github.io/wwsd/data/world/world-110m.geojson").then(function (world) {
d3.csv("./data/WorldCupMatches.csv").then(function (data) {
// variable for win counts
let winCount = {};
// Parse the CSV data and iterate over each row
data.forEach(row => {
// Check if the match stage is "Final"
if (row.Stage === "Final") {
// Get the home and away team names
const homeTeam = row["Home Team Name"];
const awayTeam = row["Away Team Name"];
// Initialize the win count for each team if not already present
if (!winCount[homeTeam]) {
winCount[homeTeam] = 0;
}
if (!winCount[awayTeam]) {
winCount[awayTeam] = 0;
}
// Determine the winner based on home team goals and away team goals
if (row["Home Team Goals"] > row["Away Team Goals"]) {
winCount[homeTeam]++; // Increment win count for the home team
} else if (row["Home Team Goals"] < row["Away Team Goals"]) {
winCount[awayTeam]++; // Increment win count for the away team
}
// In case of a draw, no team gets a win count increment
}
});
// editing winCount by hardcoding due to Dataset Inconsistency (small errors for only some countries)
// making Brazil wins as 5
winCount["Brazil"] = 5;
// making Italy wins as 4
winCount["Italy"] = 4;
// making Germany wins as 4
winCount["Germany"] = 4;
// making Uruguay wins as 2
winCount["Uruguay"] = 2;
// making France wins as 2
winCount["France"] = 2;
// checking again
console.log(winCount);
// this is the projection and path generator
const projection = d3.geoMercator()
.fitSize([2000, 1000], world);
const path = d3.geoPath().projection(projection);
// drawing countries, direct template from online documentation
const svg = d3.select("svg");
const map = svg.append("g");
map.selectAll("path")
.data(world.features)
.enter().append("path")
.attr("d", path)
.attr("fill", d => {
// Get the name of the country
const countryName = d.properties.name;
// Get the number of trophies won by the country, defaulting to 0 if not found
const trophiesWon = winCount[countryName] || 0;
// Map the number of trophies to the color scale
return colorScale(trophiesWon);
})
.on("mouseover", function (event, d) {
// Transitioning to light blue
d3.select(this)
.transition()
.duration(500)
.attr("fill", "lightpink");
// Get the name of the country
const countryName = d.properties.name;
// Get the number of trophies won by the country, defaulting to 0 if not found
const trophiesWon = winCount[countryName] || 0;
// Append a group element to hold the box and text
const tooltipGroup = svg.append("g")
.attr("class", "tooltip-group");
// Append a rectangle to act as the box
const tooltipBox = tooltipGroup.append("rect")
.attr("class", "tooltip-box")
.attr("rx", 5)
.attr("ry", 5);
// Append the text inside the box, including country name and trophies won
const tooltipText1 = tooltipGroup.append("text")
.attr("class", "tooltip-text")
.text(`${countryName}`)
.style("font-size", "30px");
const tooltipText2 = tooltipGroup.append("text")
.attr("class", "tooltip-text")
.text(`Cups: ${trophiesWon}`)
.style("font-size", "20px")
.attr("dy", "1.2em"); // Move the second text line down by 1.2 times the line height
// Get the size of the text and box
const textBBox1 = tooltipText1.node().getBBox();
const textBBox2 = tooltipText2.node().getBBox();
const boxWidth = Math.max(textBBox1.width, textBBox2.width) + 20;
const boxHeight = textBBox1.height + textBBox2.height + 20;
// Calculate the position of the box relative to the mouse pointer
const mouseX = event.pageX;
const mouseY = event.pageY;
const xOffset = mouseX + 5; // Offset for better positioning
const yOffset = mouseY - boxHeight - 20; // Position the tooltip above the cursor
// Set the attributes of the box and text based on the calculated position
tooltipBox.attr("x", xOffset)
.attr("y", yOffset)
.attr("width", boxWidth)
.attr("height", boxHeight);
tooltipText1.attr("x", xOffset + 10)
.attr("y", yOffset + 35);
tooltipText2.attr("x", xOffset + 10)
.attr("y", yOffset + 40); // Position the second text line below the first
// Add border effect to the box
tooltipBox.style("stroke", "black")
.style("stroke-width", "1px")
.style("fill", "lightgray");
})
.on("mouseout", function () {
// transitioning to white again
d3.select(this) // Select the path
.transition() // Apply transition
.duration(200) // Set duration for the transition
.attr("fill", d => {
// Get the name of the country
const countryName = d.properties.name;
// Get the number of trophies won by the country, defaulting to 0 if not found
const trophiesWon = winCount[countryName] || 0;
// Map the number of trophies to the color scale
return colorScale(trophiesWon);
})
// Remove the tooltip when mouse leaves the path
svg.select(".tooltip-group").remove();
});
});
});
</script>
</div>
<div class="inference-card" style="overflow-y: auto; max-height: 40vh;">
<!-- Added max-height and overflow for scrolling -->
<h2 class="inference-title">Inference</h2>
<p class="inference-text">Choropleth is the best way to start off with this story as we can show the base
line facts about FIFA and that how only very very few centric countries are winning the cups and where
there are placed geographically.</p>
<p class="inference-text">This inference could also lead us to thinking about the fact that the best culture
for Football as not just a sport but also a passion and profession is also found in these same regions
colored darker on the choropleth.</p>
<p class="inference-text">Further, the interactability of the same also help us actually see the number of
FIFA Cups won by each of the coutries when we hover over them. Although, most countries have 0 cups but
then, this visualisation could easily handle the same data with addition of number of times the country
getting qualified for FIFA also making it a little more vivid and more informative than this one.</p>
</div>
<button onclick="window.location.href = 'vis2.html';"
style="font-size: 20px; padding: 10px 20px; background-color: #4CAF50; color: white; border: none; border-radius: 5px; cursor: pointer; margin-bottom:30px">Go
to Word Cloud - Most Winning Teams</button>
</div>
</body>
</html>