/
script.js
executable file
·122 lines (74 loc) · 2.87 KB
/
script.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
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
/* Author:
*/
var heatmap = null;
var canvas = null;
var context = null;
var myStage = null;
function mapDisplayTooltip(e){
$("#heatmapArea").prepend("<span id='heatmap_tooltip'>Cliquer pour selectionner un député...</span>");
}
function mapHideTooltip(e){
$("#heatmap_tooltip").remove();
}
function seatCanvas(data){
canvas = $("canvas")[0];
context = canvas.getContext("2d");
canvas.addEventListener("mouseover", mapDisplayTooltip, false);
canvas.addEventListener("mouseout", mapHideTooltip, false);
$("canvas").attr("id", "heatmapCanvas");
myStage = new Kinetic("heatmapCanvas", "2d");
myStage.setDrawStage(function(){
$.each(data, function(index, data){
// draw seat circle
myStage.beginRegion();
context.beginPath();
context.arc(data.x, data.y, 6, 0, Math.PI * 2, true);
//context.stroke();
myStage.addRegionEventListener("onmousedown", function(){
$.get("/depute/" + data.id, function(info){
$("#info").html(info)
});
});
myStage.addRegionEventListener("onmouseover", function(){
$("body").css("cursor", "pointer");
});
myStage.addRegionEventListener("onmouseout", function(){
$("body").css("cursor", "default");
});
myStage.closeRegion();
});
});
}
function refreshHeatmap(){
var filters = {};
filters["info"] = $("input:checked").val();
var start_year = $("#start_date td :first span.selected").html();
var start_month = $("#start_date td.month span.selected").parent().attr("title");
filters["start_date"] = Date.parse(start_year + "-" + start_month);
var end_year = $("#end_date td :first span.selected").html();
var end_month = $("#end_date td.month span.selected").parent().attr("title");
filters["end_date"] = Date.parse(end_year + "-" + end_month);
if(filters["start_date"].compareTo(filters["end_date"]) == 1){
$("#heatmapArea").prepend("<span id='heatmap_loading'>erreur sur les dates sélectionnées: la fin est avant le début...</span>");
} else {
if(filters["start_date"].equals(filters["end_date"])){
filters["end_date"].addMonths(1);
}
filters["start_date"] = filters["start_date"].toString('yyyy/MM');
filters["end_date"] = filters["end_date"].toString('yyyy/MM');
$("#heatmapArea").prepend("<span id='heatmap_loading'>chargement...</span>");
$.getJSON("/heatmap", filters, function(map){
heatmap.store.setDataSet(map);
seatCanvas(map['data']);
$("#heatmap_loading").remove();
});
}
}
$(document).ready(function(){
heatmap = h337.create({"element":document.getElementById("heatmapArea"), "radius":8, "visible":true});
$("#radio_info").buttonset();
$("#start_date").monthpicker("2011-03", refreshHeatmap);
$("#end_date").monthpicker("2011-06", refreshHeatmap);
$("input[type=radio]").click(refreshHeatmap);
refreshHeatmap();
});