Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Community colors
- var comm_colors = [ "red", "blue", "green", "yellow", "purple" ];
- // CSV
- function parse_add_csv(cts){
- var new_cts = cts
- console.log('parsing csv');
- d3.csv("data/communities.csv", function(comms)
- { csv = comms.map(function(d)
- {
- return {"community": d.community, "label": d.BoroCT2010} ;
- })
- csv.forEach(function(d, i) {
- new_cts.forEach(function(e, j) {
- if (d.label === e.properties.BoroCT2010) {
- e.properties.community = parseInt(d.community)
- }
- })
- })
- })
- return new_cts
- }
- d3.json("data/nyct2010_17a3_topo.json", function(error, nyb) {
- console.log('tracts uploaded, v3')
- var ctss = topojson.feature(nyb, nyb.objects.nyct2010_17a3).features;
- ctss = parse_add_csv(ctss); // match data from csv by BoroCT2010
- cts.selectAll(".tract")
- .data(ctss)
- .enter().append("path")
- .attr("class", "tract")
- .attr("d", path)
- .attr("id", function(d) {
- return d.properties.BoroCT2010;})
- .attr("nhd_name", function(d) {
- return d.properties.NTAName;})
- .style('fill', function(d){
- console.log(comm_colors[d.properties.community])
- return comm_colors[d.properties.community];})
- .on("mouseover", handleMouseOver)
- .on("mouseout", handleMouseOut)
- .style('fill', function(d) {return
- comm_colors[d.properties.community]});
- })
- .style('fill', function(d){
- console.log(comm_colors[d.properties.community])
- return comm_colors[d.properties.community];})
- d3.json("data/nyct2010_17a3_topo.json", function(error, nyb){
- d3.csv("data/communities.csv", function(comms){
- //here goes all code that uses both 'nyb' and 'comms'
- })
- })
Add Comment
Please, Sign In to add comment