-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmap_with_counties.js
More file actions
130 lines (99 loc) · 3.85 KB
/
map_with_counties.js
File metadata and controls
130 lines (99 loc) · 3.85 KB
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
var make_inds_map_with_counties = function(industry) {
try {
document.getElementById('home_page_map').remove()
document.getElementById('tooltip').style.visibility = "hidden";
document.getElementById('header').remove()
}
catch(err) {
//pass
}
document.getElementById('my_p').innerHTML = "Displaying "+industry+" Data From 2012"
var svg = d3.select("svg"),
width = +svg.attr("width"),
height = +svg.attr("height");
var my_map = d3.map();
var name_map = d3.map();
var map_2011 = d3.map();
var path = d3.geoPath();
//var x = d3.scaleLinear()
// .domain([1, 10])
// .rangeRound([600, 860]);
var color = d3.scaleLog()
.base(Math.E)
.domain([Math.exp(0), Math.exp(10)])
.range(["#BBDEFB", "darkblue"]);
var g = svg.append("g")
.attr("class", "key")
.attr("transform", "translate(600,40)");
g.selectAll("rect")
.data([Math.exp(0), Math.exp(2), Math.exp(4), Math.exp(6), Math.exp(8), Math.exp(10), Math.exp(12)])
.enter()
.append("rect")
.attr("height", 8)
.attr("x", function(d, i) { return (i*35); })
.attr("width", 34)
.attr("fill", function(d) { return color(d); })
.attr("text", function(d) { return d});
g.append("text")
.attr("class", "caption")
.attr("x", function(d, i) { return (i*40); })
.attr("y", -6)
.attr("fill", "#000")
.attr("text-anchor", "start")
.attr("font-weight", "bold")
.text("Log Scaled Employment Rate");
g.selectAll("line")
.data([Math.exp(0), Math.exp(2), Math.exp(4), Math.exp(6), Math.exp(8), Math.exp(10), Math.exp(12)])
.enter()
.append("line")
.style("stroke", "black")
.attr("x1", function(d, i) { return (i*35+10); })
.attr("y1", 30)
.attr("x2", function(d, i) { return (i*35+17); })
.attr("y2", 30);
var superscript = "⁰¹²³⁴⁵⁶⁷⁸⁹",
formatPower = function(d) { return (d + "").split("").map(function(c) { return superscript[c]; })}
var keyLaybels = d3.select(".key").selectAll("keyLaybels")
.data([Math.exp(0), Math.exp(2), Math.exp(4), Math.exp(6), Math.exp(8), Math.exp(10), Math.exp(12)])
.enter()
.append("text")
.style('text-anchor','start')
.attr('transform', function(d,i,j) { return 'translate(14,0)' });
keyLaybels.attr("class", "value")
.attr("x", function(d, i) { return i * 35 - 20})
.attr("y", 30)
.attr("dx", -3)
.attr("dy", ".35em")
.attr("text-anchor", "end")
.text(function(d) { return ("e" + formatPower(Math.round(Math.log(d)))).replace(",",""); });
d3.queue()
.defer(d3.json, "https://d3js.org/us-10m.v1.json")
.defer(d3.csv, "/Census-Data-Explorer/data_for_US/"+industry+"_county_emp.csv", function(d) { my_map.set(d.id, +d.rate), name_map.set(d.id, d.name); } )
.await(ready);
function ready(error, us) {
if (error) throw error;
var missing_arr = [];
var missing_fliter = function(d) {
d.forEach(function(element) {
if(typeof(my_map.get(element.id)) == 'undefined')
{ missing_arr.push(element.id) }
})
};
console.log(missing_arr);
missing_fliter(topojson.feature(us, us.objects.counties).features);
svg.append("g")
.attr("class", "counties")
.selectAll("path")
.data(topojson.feature(us, us.objects.counties).features)
.enter().append("path")
.attr("fill", function(d) { return color(my_map.get(d.id))})
.attr("d", path)
.append("title")
.text(function(d) { return name_map.get(d.id) +" \nEmployed in " +industry+": "+my_map.get(d.id); });
svg.append("path")
.datum(topojson.mesh(us, us.objects.states, function(a, b) { return a !== b; }))
.attr("class", "states")
.attr("d", path);
}
}
//make_inds_map_with_counties("Construction")