-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstateGDPmap.js
87 lines (77 loc) · 3.05 KB
/
stateGDPmap.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
function districtMap(districts, disputed) {
var width = 800, height = 700, scale = 1200;
var propTag = 'Literacy', ttName = 'Literacy Rate', unit = '%';
function render(selection) {
selection.each(function() {
d3.select(this).select("svg").remove();
var svg = d3.select(this).append("svg")
.attr("width", width)
.attr("height", height);
d3.select(this).select("#tooltip").remove();
d3.select(this).append("div").attr("id", "tooltip").style("opacity", 0);
var projection = d3.geo.mercator()
.center([83, 23])
.scale(scale)
.translate([width / 2, height / 2]);
var path = d3.geo.path().projection(projection);
svg.selectAll(".district")
.data(districts.features)
.enter().append("path")
.attr("class", "district")
.style("fill", function(d) { return d.color; })
.attr("d", path)
.on("mouseover", function(d) {
d3.select("#tooltip").transition()
.duration(200)
.style("opacity", .9);
d3.select("#tooltip").html("<h3>"+(d.id)+"</h3><h4>("+(d.properties.NAME_1)+")</h4><table>"+
"<tr><td>"+ttName+"</td><td>"+(d.properties[propTag])+unit+"</td></tr>"+
"</table>")
.style("left", (d3.event.pageX-document.getElementById('map').offsetLeft + 20) + "px")
.style("top", (d3.event.pageY-document.getElementById('map').offsetTop - 60) + "px");
})
.on("mouseout", function(d) {
d3.select("#tooltip").transition()
.duration(500)
.style("opacity", 0);
});
svg.selectAll(".disputed")
.data(disputed.features)
.enter().append("path")
.attr("class", "disputed")
.style("fill", function(d) { return d.color; })
.attr("d", path);
});
} // render
render.height = function(value) {
if (!arguments.length) return height;
height = value;
return render;
};
render.width = function(value) {
if (!arguments.length) return width;
width = value;
return render;
};
render.scale = function(value) {
if (!arguments.length) return scale;
scale = value;
return render;
};
render.propTag = function(value) {
if (!arguments.length) return propTag;
propTag = value;
return render;
};
render.ttName = function(value) {
if (!arguments.length) return ttName;
ttName = value;
return render;
};
render.unit = function(value) {
if (!arguments.length) return unit;
unit = value;
return render;
};
return render;
} // districtMap