forked from scharron/ratp-trafic-map
-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.html
382 lines (332 loc) · 12.8 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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
<!DOCTYPE html>
<html>
<head>
<title>Trafic annuel entrant par station à Paris</title>
<link href="http://twitter.github.com/bootstrap/assets/css/bootstrap.css" rel="stylesheet" media="screen">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
#map{
height: 100%;
width: 100%;
position: absolute;
}
#map-container {
display: block;
position: absolute;
left: 0;
right: 250px;
bottom: 0;
top: 0;
}
.background {
fill: #ddd;
}
.paris {
fill: #ccc;
}
.line_branch {
fill: none !important;
stroke-width: 1px;
stroke-opacity: 0.1;
}
.line_branch.active {
stroke-opacity: 0.5;
}
.station_part {
stroke-opacity: 0;
stroke-width: 2px;
fill-opacity: inherit;
stroke-width: 0;
}
.station {
opacity: 0.1;
}
.station.active {
opacity: 1;
}
#header {
position: absolute;
padding: 0;
top: 0;
height: 44px;
right: 250px;
left: 0;
}
#header h1 {
margin: 16px;
text-align: center;
transform: perspective(100px) rotateX(-5deg);
-webkit-transform: perspective(100px) rotateX(-5deg);
}
#header h1 span {
font-size: 90%;
border: 6px solid white;
background-color: #22265b;
color: white;
font-weight: bolder;
font-family: "helvetica";
padding: 8px;
font-variant: small-caps;
}
#infos {
position: absolute;
padding: 10px;
width: 230px;
top:0;
bottom: 0;
right: 0;
}
#infos h2 {
text-align: center;
line-height: 30px;
font-size: 28px;
margin: 4px 0;
}
#infos .infos_station, #infos .infos_line {
display: none;
}
#infos .infos_station h3 {
background-color: #22265b;
text-align: center;
}
#infos .infos_station h3 span {
font-size: 90%;
color: white;
font-weight: bolder;
font-family: "helvetica";
padding: 8px;
font-variant: small-caps;
}
#infos .infos_line .sign {
border-radius: 40px;
width: 40px;
height: 40px;
display: inline-block;
text-align: center;
padding: 0;
}
#infos .infos_line ul {
margin-left: 4px;
list-style: none;
font-size: 80%;
}
#infos .infos_line li {
line-height: 120%;
margin: 0;
}
#infos ul.sources {
margin-left: 4px;
list-style: none;
font-size: 80%;
}
#infos .sources li {
line-height: 120%;
margin: 0;
}
#dp {
background-color: #555;
padding-left:10px;
}
#dp img {
width: 200px;
}
hr {
margin: 10px 0;
}
</style>
<link href="ratp.colors.css" media="screen" rel="stylesheet" type="text/css" />
</head>
<body>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://code.jquery.com/jquery.min.js"></script>
<script src="paris.path.js"></script>
<script src="helpers.js"></script>
<script src="mouse.helpers.js"></script>
<div id="map-container"></div>
<div id="header">
<h1><span>Trafic annuel entrant par station à Paris</span></h1>
</div>
<div id="infos">
<div class="active help">
<h2>Infos</h2>
<p>
Trafic entrant par station : nombre de voyageurs validant un titre de transport dans la station concernée. Les voyageurs en correspondance sur le réseau RATP ne sont pas comptabilisés.
</p>
<p>
Survolez une station ou une ligne pour plus d'informations.
</p>
<hr />
<p>
<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Flabs.data-publica.com/ratp/&layout=button_count&action=like&colorscheme=light" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:100%; height:20px;" allowTransparency="true"></iframe>
<a href="https://twitter.com/share" class="twitter-share-button" data-via="datapublica" data-lang="fr" data-dnt="true">Tweeter</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
<br />
<a href="https://github.com/datapublica/ratp-trafic-map"><img src="http://www.github.com/favicon.ico" /> Github</a>
</p>
<hr />
<div id="dp"><a href="http://data-publica.com#labs-ratp"><img src="http://www.data-publica.com/static/img/logo.png""></a></div>
<span id="tagline"><i>Les données pour votre business</i></span>
<br />
<a href="http://www.data-publica.com/content/">Qui sommes-nous ?</a>
<br />
<a href="http://www.data-publica.com/content/blog/data-news/">Notre blog d'actu</a>
<br />
<a href="http://www.data-publica.com/content/2013/01/le-trafic-metro-2011-en-une-dataviz/">Pourquoi cette dataviz ?</a>
<hr />
<ul class='sources'>
<li>Trafic annuel entrant par station en 2011 : <a href="http://www.data-publica.com/opendata/14699--trafic-annuel-2011-par-station-metro-rer">RATP</a></li>
<li>Positions géographiques des stations : <a href="http://www.data-publica.com/opendata/14405--positions-geographiques-des-stations-du-reseau-ratp">RATP</a></li>
<li>Indices et couleurs de lignes : <a href="http://data.ratp.fr/fr/les-donnees/fiche-de-jeu-de-donnees/dataset/indices-et-couleurs-de-lignes-du-reseau-ferre-ratp.html?tx_icsoddatastore_pi1[page]=1&tx_icsoddatastore_pi1[returnID]=38">RATP</a></li>
<li>Contour de Paris: <a href="http://professionnels.ign.fr/geofla">IGN</a></li>
<li>Fait avec <a href="http://d3js.org">D3.js</a></li>
</ul>
</div>
<div class="infos_station">
<h3><span></span></h3>
<div><i class="icon-user"></i> Trafic entrant : <span class='trafic'></span> personnes / an</div>
<div><i class="icon-certificate"></i> Rang : <span class='rank'></span> / 301</div>
<div><i class="icon-map-marker"></i> Latitude : <span class='latitude'></span></div>
<div><i class="icon-map-marker"></i> Longitude : <span class='longitude'></span></div>
</div>
<div class="infos_line">
<h3><span></span></h3>
<div><i class="icon-user"></i><i class="icon-user"></i><i class="icon-user"></i> Trafic entrant cumulé : <span class='trafic'></span> personnes / an</div>
<ul></ul>
</div>
</div>
<script>
var width = 100,
height = 100;
var svg = d3.select("#map-container").append("svg")
// The viewport
.attr("viewBox", "-100 -100 200 200")
// Width and height of the svg (will be resized)
.attr("preserveAspectRatio", "xMidYMid meet")
.attr("id", "map")
;
var viewport = svg.append("g")
.attr("id", "viewport")
.attr("transform", "scale(1.5)")
.call(d3.behavior.zoom()
.scale(1.5)
.scaleExtent([0.9, 3])
.on("zoom", function() {
viewport.attr("transform",
"translate(" + d3.event.translate + ")" +
" scale(" + d3.event.scale + ")"
);
})
)
var background = viewport.append("rect")
.attr("class", "background")
.attr("x", -1000)
.attr("y", -1000)
.attr("width", 2000)
.attr("height", 2000)
//.on("click", click)
;
var container = viewport.append("g").attr("id", "container");
function color(d, inv) {
var color;
if (d.lines.length == 1) {
var l = d.lines[0];
if (l.toString().indexOf("bis") !== -1)
color = colors[parseInt(l)];
else
color = colors[l];
} else {
color = inv ? "0,0,0" : "255,255,255";
}
return "rgb(" + color + ")";
}
d3.json("ratp.json", function(data) {
container_paris = container.append("g").attr("id", "paris");
container_map = container.append("g").attr("class", "map");
container_lines = container_map.append("g").attr("id", "lines");
container_stations = container_map.append("g").attr("id", "stations");
freq = d3.map(data.freq).values();
lines = data.lines;
var median_x = d3.median(freq, function(e) { return e.latitude; });
var median_y = d3.median(freq, function(e) { return e.longitude; });
// https://github.com/mbostock/d3/wiki/Geo-Projections#wiki-center
var projection = d3.geo.mercator()
.translate([0, 0])
.scale(50000)
.center([median_x, median_y])
;
// Function to project the paris borders in drawing coordinates
var line = d3.svg.line(paris)
.interpolate("linear-closed")
.x(function(d) { return projection(d)[0]; })
.y(function(d) { return projection(d)[1]; })
;
// Create Paris' borders
container_paris.append("path")
.attr("d", line(paris))
.attr("class", "paris")
//.on("click", click)
;
// Stuff needed to scale stations depending on their trafic
var get_trafic = function(e) { return e.trafic; };
var min = d3.min(freq, get_trafic);
var max = d3.max(freq, get_trafic);
var median = d3.median(freq, get_trafic);
var scale = d3.scale.log()
.domain([min, median, max])
.range([0.2, 1.2, 4])
;
// Create the stations by first creating a group
var stations =
container_stations.selectAll(".station")
.data(freq, function(d) { return d.key; })
.enter()
.append("g")
// Translate the group (helpers.js)
.attr("transform", transform(projection))
// helpers.js
.attr("class", station_classes)
// Sort the points by trafic to have
// bigger stations behind (helpers.js)
.sort(sort_stations)
.on("mouseover", select_station)
.on("mouseout", deselect_station)
;
// Then append an arc for each part
stations.selectAll(".station_part")
.data(gen_pie(scale))
.enter()
.append("path")
.attr("d", draw_arc) // helpers.js
.attr("class", station_part_classes) // helpers.js
;
var lines =
container_lines.selectAll(".line")
.data(lines)
.enter()
.append("g")
.attr("class", line_class)
;
lines.selectAll(".line_branch")
.data(gen_branch)
.enter()
.append("path")
.attr("class", branch_class)
.attr("d", draw_line(data, projection))
.on("mouseover", select_line)
.on("mouseout", deselect_line)
;
});
</script>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-21325121-6']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</body>
</html>