Built with blockbuilder.org
Last active
April 28, 2017 00:23
-
-
Save li01012/3fcc794fdebb6218e60e8df20f92b559 to your computer and use it in GitHub Desktop.
project 2.0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
license: mit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<meta charset="utf-8"> | |
<title>N. of Death caused by </title> | |
<style> | |
body { | |
position: absolute; | |
margin: 0px; | |
} | |
svg { | |
background-color: #4682b4; | |
} | |
.info { | |
font-family: sans-serif; | |
color: #000; | |
position: absolute; | |
top: 450px; | |
left: 800px; | |
} | |
path { | |
fill: #555555; | |
stroke: #aaaaaa; | |
} | |
</style> | |
<script src="https://d3js.org/d3.v4.min.js"></script> | |
<script src="https://d3js.org/topojson.v2.min.js"></script> | |
<body> | |
<script> | |
var width = 960, height = 500; | |
var data; // declare a global variable | |
var svg = d3.select("body").append("svg") | |
.attr("width", width) | |
.attr("height", height) | |
.on("mousemove", mousemoved); | |
// Add a <div> element to label the mouse position | |
var info = d3.select("body").append("div") | |
.attr("class", "info"); | |
var projection = d3.geoAlbersUsa(); | |
var path = d3.geoPath() | |
.projection(projection); | |
var url = "https://umbcvis.github.io/classes/class-03/us.json" | |
var YTS = "https://raw.githubusercontent.com/li01012/classes/master/Project/Youth_Tobacco_Survey__YTS__Data.csv" | |
d3.json(url, plotStates); | |
function plotStates(error, json) { | |
data = json.objects.us.geometries.map(function(d) { return topojson.feature(json, d); }) | |
svg.selectAll("path") | |
.data(data) | |
.enter() | |
.append("path") | |
.attr("d", path); | |
} | |
} | |
}); | |
//d3.csv("YTS", function(d) { | |
//data = csv.objects.features.map(function(d)) {return console.log(rows)} | |
// }); | |
d3.csv(YTS) | |
function | |
function mousemoved() { | |
info.text(formatLocation(projection.invert(d3.mouse(this)), projection.scale())); | |
} | |
function formatLocation(p, k) { | |
var format = d3.format("." + Math.floor(Math.log(k) / 2 - 2) + "f"); | |
return (p[1] < 0 ? format(-p[1]) + "°S" : format(p[1]) + "°N") + " " | |
+ (p[0] < 0 ? format(-p[0]) + "°W" : format(p[0]) + "°E"); | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment