-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
145 lines (132 loc) · 5.27 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>PSET7 D3 Visualization Webpage</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/7.1.1/d3.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300,500" rel="stylesheet">
<style type="text/css">
.text-styling{
font-family: 'Open Sans';
font-weight: 300;
font-size: 14px;
}
.title-styling{
font-family: 'Open Sans';
font-weight: 500;
font-size: 18px;
}
.text-block{
background-color: #e0fff5;
}
.course-styling{
font-size: 14px;
font-weight: 300;
}
.assignment-styling{
font-size: 14px;
font-variant: small-caps;
}
.author-styling{
font-size: 14px;
font-style: italic;
}
.footer-styling{
font-size: 10px;
font-weight: 100;
}
</style>
</head>
<body>
<main>
<section class="container">
<div class="row">
<h1 class="fw-bold mt-3">Visualizing Agricultural Land</h1>
<hr/>
</div>
<div class="row">
<div class="col-5">
<p class="my-5 text-block">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum</p>
<p class="fw-bold my-2">Big Data, Visualization, and Society</p>
<p class="course-styling">Course: 11.154/11.4454</p>
<p class="assignment-styling">Assignment: PSET7 - D3 Visualization Webpage</p>
<p class="author-styling">Author: Ophelia Zhu</p>
</div>
<div class="col-7">
<div id="viz"></div>
<p class="footer-styling">Data Source: World Bank</p>
</div>
</div>
</section>
</main>
<script type="text/javascript">
const agriculturedata = [
["Brazil", 33.9],
["Canada", 6.9],
["Costa Rica", 34.5],
["Denmark", 62],
["Fiji", 23.3],
["France", 52.4],
["Greenland", .6],
["Italy", 43.2],
["Mali",33.8],
["Netherlands",53.3]
];
const width = 600;
const height = 500;
const marginLeft = 150;
const marginTop = 80;
const barHeight = 30;
const widthMultiplier = 2 * 3;
const gap = 5;
const textLength = 50;
const titleBottomMargin = 20;
// define svg
const svg = d3.select("#viz")
.append("svg")
.attr("viewBox", [0, 0, width, height]);
// add rectangle bars
svg.append("g")
.attr("class", "rect-bars")
.selectAll("rect")
.data(agriculturedata)
.enter()
.append("rect")
.attr("y", (d, i) => i * (barHeight + gap) + marginTop)
.attr("x", marginLeft)
.attr("width", d => d[1] * widthMultiplier)
.attr("height", barHeight)
.attr("fill", "green")
.attr("opacity", 0.7);
// labels
svg.append("g")
.attr("class", "text-styling")
.attr("text-anchor", "end")
.selectAll("text")
.data(agriculturedata)
.enter()
.append("text")
.attr("y", (d, i) => i * (barHeight + gap) + marginTop + (barHeight / 2) + 5)
.attr("x", marginLeft - 10)
.text(d => d[0]);
// percentages
svg.append("g")
.attr("class", "text-styling")
.attr("text-anchor", "end")
.selectAll("text")
.data(agriculturedata)
.enter()
.append("text")
.attr("y", (d, i) => i * (barHeight + gap) + marginTop + (barHeight / 2) + 5)
.attr("x", d => d[1] * widthMultiplier + marginLeft + textLength)
.text(d => d[1] + "%");
// titles
svg.append("text")
.attr("class", "title-styling")
.attr("x", marginLeft)
.attr("y", marginTop - titleBottomMargin)
.text("Proportion of Agricultural Land in 2016");
</script>
</body>
</html>