-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
252 lines (217 loc) · 10.4 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>French Startup Map | Oil & Energy | Peter Doherty Copyright 2018</title>
<link href="css/style.css" rel="stylesheet">
<link rel="shortcut icon" href="img/pexels-photo-604414.jpeg" />
</head>
<body>
<svg width="1280" height="600"></svg>
<!-- v4.13.0 -->
<script src="js/d3/d3.min.js"></script>
<script>
// Hubs = Paris, Brest etc
// Transit Lines connect hubs
// Spawning from the hubs are lines which startups are located on
var svg = d3.select("svg"),
margin = {top: 10, right: 10, bottom: 10, left: 10},
width = innerWidth - margin.left - margin.right,
height = innerHeight - margin.top - margin.bottom,
g = svg.append("g").attr("transform", "translate(" + margin.left + "," + margin.top + ")");
var title = svg.append("rect")
.attr("x", 0)
.attr("y", 0)
.attr("width", innerWidth)
.attr("height", innerHeight * 0.05)
.attr("fill", "blue");
// Map Title
svg.append("text")
.attr("class", "title")
.attr("x", innerWidth * 0.5)
.attr("y", 20)
.text('French Startup Map | Oil & Energy | V2 | June 2018');
var footer = svg.append("rect")
.attr("x", 0)
.attr("y", innerHeight * 0.88) // innerHeight - 80
.attr("width", innerWidth)
.attr("height", 25)
.attr("fill", "red");
svg.append("text")
.attr("class", "footer")
.attr("x", innerWidth * 0.5)
.attr("y", innerHeight * 0.9) // innerHeight - 65
.text("Copyright 2018 © Peter Doherty. MIT Licence");
// Tooltip
var div = d3.select("body").append("div")
.attr("class", "startuptooltip")
.style("opacity", 0);
// spacing for label text
var spaceX = 1.005;
var scale = 2800;
var legendBackgroundcover = svg.append("rect")
.attr("x", innerWidth * 0.6)
.attr("y", innerHeight * 0.05)
.attr("width", innerWidth * 0.5)
.attr("height", innerHeight - (169)) // can be cleaner
.attr("fill", "#f2eded");
// Rect to be a yellow type color
var legendBackground = svg.append("rect")
.attr("x", innerWidth * 0.6)
.attr("y", innerHeight * 0.1)
.attr("width", innerWidth * 0.35)
.attr("height", innerHeight * 0.65)
.attr("fill", "#fff5ba");
var legend = svg.append("svg")
.attr("x", innerWidth * 0.6)
.attr("y", innerHeight * 0.15)
.attr("width", innerWidth * 0.35 )
.attr("height", innerHeight * 0.7)
.attr("fill", "#fff5ba");
var projection = d3.geoConicConformal()
.center([8.454071, 45.579229]) // trial and error
.scale(scale)
.translate([width / 2, height / 2]);
var path = d3.geoPath()
.projection(projection);
//create zoom handler
//zoom actions is a function that performs the zooming.
var zoom_handler = d3.zoom()
.on("zoom", zoom_actions);
// France Data
d3.json("map_data/lines+border.geojson", function(err, mapData) {
if (err) throw error;
var features = mapData.features;
console.log(features);
// Draw border and lines
g.selectAll("path")
.data(features)
.enter()
.append("path")
.attr("d", path)
.attr("fill", "#f2eded")
.attr("stroke", function (d) { return d.properties.stroke; })
.attr("stroke-width", function (d) { return +d.properties["stroke-width"]; })
.style("vector-effect", "non-scaling-stroke");
legend.selectAll("rect")
.data(features.slice(1,8)) //Lines
.enter()
.append("circle")
.attr("cx", innerWidth * 0.25)
.attr("cy", function(d, i){ return 5 + i * 15;})
.attr("r", "5")
// .attr("stroke", function (d) { return d.properties.stroke; })
// .attr("stroke-width", 0.05)
.style("fill", function (d) { return d.properties.stroke; });
legend.selectAll("rect")
.data(features.slice(1,8))
.enter()
.append("text")
.attr("class", "city-label-legend")
.attr("x", innerWidth * 0.26)
.attr("y", function(d, i){ return 8 + i * 15;})
.text(function(d) { return d.properties["transit-line"]; });
// //Load in startups and cities from CSV data
d3.csv("map_data/fr_startups.csv", function(err, data) {
if (err) throw error;
// Startup and Startup Cities located on the map
g.selectAll("circle")
.data(data)
.enter()
.append("circle")
.attr("cx", function(d) { return projection([d.lon, d.lat])[0]; })
.attr("cy", function(d) { return projection([d.lon, d.lat])[1]; })
.attr("r", function(d) { return d.r * 0.25; })
.attr("stroke", function(d) { return d.stroke; })
.attr("stroke-width", 0.05)
.style("fill", function(d) { return d["marker-color"]; });
// Legend markers
legend.selectAll("rect")
.data(data.slice(10).sort()) //Startups
.enter()
.append("circle")
.attr("cx", innerWidth * 0.015)
.attr("cy", function(d, i){ return 5 + i * 15;})
.attr("r", function(d) { return d.r; })
.attr("stroke", function(d) { return d.stroke; })
.attr("stroke-width", 0.05)
.style("fill", function(d) { return d["marker-color"]; });
// Legend label text for startups
legend.selectAll("rect")
.data(data.slice(10).sort())
.enter()
.append("text")
.attr("class", "startup-label-legend")
.attr("x", innerWidth * 0.02)
.attr("y", function(d, i){ return 8 + i * 15;})
.text(function(d) { return d.id; });
// Legend markers
legend.selectAll("rect")
.data(data.slice(0,10).sort()) //Cities
.enter()
.append("circle")
.attr("cx", innerWidth * 0.15)
.attr("cy", function(d, i){ return 10.5 + i * 25;})
.attr("r", function(d) { return d.r; })
.attr("stroke", function(d) { return d.stroke; })
.attr("stroke-width", 0.8)
.style("fill", function(d) { return d["marker-color"]; });
// Legend label text for cities
legend.selectAll("rect")
.data(data.slice(0,10).sort())
.enter()
.append("text")
.attr("class", "city-label-legend")
.attr("x", innerWidth * 0.16)
.attr("y", function(d, i){ return 14 + i * 25;})
.text(function(d) { return d.name; });
// City or region Title
g.selectAll(".place-label")
.data(data)
.enter()
.append("text")
.attr("class", "place-label")
.attr("transform", function(d) { return "translate(" + projection([d.lon * spaceX, d.lat]) + ")"; })
.style("text-anchor", function(d) { return d.lon > -0.5 ? "start" : "end"; }) // west -> assign labels on LHS; east -> assign labels on RHS
.attr("dy", ".35em")
.text(function(d) { return d.name; });
// Startup Title
g.selectAll(".startup-label")
.data(data)
.enter()
.append("text")
.attr("class", "startup-label")
.attr("transform", function(d) { return "translate(" + projection([d.lon * spaceX, d.lat]) + ")"; },)
.style("text-anchor", function(d) { return d.lon > -1 ? "start" : "end"; })
.attr("dy", ".35em")
.text(function(d) { return d.id; })
.on("mouseover", function(d) {
div.transition()
// .duration(200)
.style("opacity", .9);
div.html("Information:" + "<br>" + '<a href=' + "" + d.website + "" + '>' + d.website + '</a>')
.style("left", (d3.event.pageX + 50) + "px")
.style("top", (d3.event.pageY - 50) + "px");
})
.on("mouseout", function(d) {
div.transition()
.duration(2000)
.style("opacity", 0);
});
});
});
// Zoom http://www.puzzlr.org/zoom-in-d3v4-minimal-example/
//specify what to do when zoom event listener is triggered
function zoom_actions(){
g.attr("transform", d3.event.transform);
g.selectAll("circle")
.attr("r", function(d) { return d.r * 0.015; }); // redraw circles upon zoom in
}
//add zoom behaviour to the svg element
//same as svg.call(zoom_handler);
zoom_handler(svg);
</script>
</body>
</html>