forked from datapublica/ratp-trafic-map
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmouse.helpers.js
52 lines (48 loc) · 1.77 KB
/
mouse.helpers.js
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
function numberWithCommas(x) {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, " ");
}
var select_station = function(station) {
svg.selectAll(".line_branch, .station")
.classed("active", false);
$(station.lines).each(function(i, e) {
svg.selectAll(".line_branch.line_" + e + ", .station.line_" + e )
.classed("active", true);
});
$(".help").hide();
$(".infos_station").show();
$(".infos_station h3 span").html(station.name);
$(".infos_station .trafic").html(numberWithCommas(station.trafic));
$(".infos_station .latitude").html(station.latitude);
$(".infos_station .longitude").html(station.longitude);
$(".infos_station .rank").html(station.rank);
}
var deselect_station = function(station) {
svg.selectAll(".line_branch, .station")
.classed("active", true);
$(".help").show();
$(".infos_station").hide();
}
var select_line = function(line) {
svg.selectAll(".line_branch, .station")
.classed("active", false);
svg.selectAll(".line_branch.line_" + line.key + ", .station.line_" + line.key )
.classed("active", true);
$(".help").hide();
$(".infos_line").show();
$(".infos_line h3 span").html("Ligne <span class='sign line_" + line.key + "'>" + line.key + "</line>");
var sum = 0;
var ul = $(".infos_line ul");
ul.empty();
$(svg.selectAll(".station.line_" + line.key).sort(function(x1, x2) { return x1.trafic < x2.trafic }).data()).each(function(i, e) {
ul.append('<li>' + e.name + " : " +
'' + numberWithCommas(e.trafic) + "</li>");
sum += e.trafic;
});
$(".infos_line .trafic").html(numberWithCommas(sum));
}
var deselect_line = function(line) {
svg.selectAll(".line_branch, .station")
.classed("active", true);
$(".help").show();
$(".infos_line").hide();
}