Skip to content

Instantly share code, notes, and snippets.

@philmein23
Last active June 19, 2017 04:02
Show Gist options
  • Save philmein23/7a12e6ca0174f93cc7748c6488de8219 to your computer and use it in GitHub Desktop.
Save philmein23/7a12e6ca0174f93cc7748c6488de8219 to your computer and use it in GitHub Desktop.
fresh block
license: mit
label population country x y
San Francisco 750000 USA -122.431 37.773
Fresno 500000 USA -119.772 36.746
Lahore 12500000 Pakistan 74.329 31.582
Karachi 13000000 Pakistan 67.005 24.946
Rome 2500000 Italy 12.492 41.890
Naples 1000000 Italy 14.305 40.853
Rio 12300000 Brazil -42.864 -22.752
Sao Paolo 12300000 Brazil -46.330 -23.944
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<script src="https://d3js.org/d3.v4.min.js"></script>
<style>
body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; }
</style>
</head>
<body>
<svg></svg>
<script>
// Feel free to change or delete any of the code you see in this editor!
d3.csv('cities.csv', (error, data) => {
if (error) return console.log(error);
dataViz(data);
})
function dataViz(incomingData) {
var maxPopulation = d3.max(incomingData, d => parseInt(d.population))
var yScale = d3.scaleLinear().domain([0, maxPopulation]).range([0,460])
d3.select('svg').attr('style', 'height: 480px; width: 600px;')
d3.select('svg').selectAll('rect')
.data(incomingData)
.enter()
.append('rect')
.attr("width", 50)
.attr("height", d => yScale(parseInt(d.population)))
.attr('x', (d,i) => i * 73)
.attr('y', d => 480 - yScale(parseInt(d.population)))
.style('fill', '#606060')
.style("stroke", "#9A8B7A")
.style("stroke-width", "1px")
}
// var svg = d3.select("body").append("svg")
// .attr("width", 960)
// .attr("height", 500)
// svg.append("text")
// .text("Edit the code below to change me!")
// .attr("y", 200)
// .attr("x", 120)
// .style("font-size", 36)
// .style("font-family", "monospace")
</script>
</body>
{
"tweets": [
{"user": "Al", "content": "I really love seafood.", "timestamp": " Mon Dec 23 2013 21:30 GMT-0800 (PST)", "retweets": ["Raj","Pris","Roy"], "favorites": ["Sam"]},
{"user": "Al", "content": "I take that back, this doesn't taste so good.", "timestamp": "Mon Dec 23 2013 21:55 GMT-0800 (PST)", "retweets": ["Roy"], "favorites": []},
{"user": "Al", "content": "From now on, I'm only eating cheese sandwiches.", "timestamp": "Mon Dec 23 2013 22:22 GMT-0800 (PST)", "retweets": [], "favorites": ["Roy","Sam"]},
{"user": "Roy", "content": "Great workout!", "timestamp": " Mon Dec 23 2013 7:20 GMT-0800 (PST)", "retweets": [], "favorites": []},
{"user": "Roy", "content": "Spectacular oatmeal!", "timestamp": " Mon Dec 23 2013 7:23 GMT-0800 (PST)", "retweets": [], "favorites": []},
{"user": "Roy", "content": "Amazing traffic!", "timestamp": " Mon Dec 23 2013 7:47 GMT-0800 (PST)", "retweets": [], "favorites": []},
{"user": "Roy", "content": "Just got a ticket for texting and driving!", "timestamp": " Mon Dec 23 2013 8:05 GMT-0800 (PST)", "retweets": [], "favorites": ["Sam", "Sally", "Pris"]},
{"user": "Pris", "content": "Going to have some boiled eggs.", "timestamp": " Mon Dec 23 2013 18:23 GMT-0800 (PST)", "retweets": [], "favorites": ["Sally"]},
{"user": "Pris", "content": "Maybe practice some gymnastics.", "timestamp": " Mon Dec 23 2013 19:47 GMT-0800 (PST)", "retweets": [], "favorites": ["Sally"]},
{"user": "Sam", "content": "@Roy Let's get lunch", "timestamp": " Mon Dec 23 2013 11:05 GMT-0800 (PST)", "retweets": ["Pris"], "favorites": ["Sally", "Pris"]}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment