Skip to content

Instantly share code, notes, and snippets.

@repustate
Created December 3, 2013 20:18
Show Gist options
  • Save repustate/7776799 to your computer and use it in GitHub Desktop.
Save repustate/7776799 to your computer and use it in GitHub Desktop.
Insert markers for tweets based on lat/long. Colour coded based on sentiment.
d3.json('/media/js/points.json', function(err, json) {
svg.select('#points')
.selectAll('circle')
.data(json)
.enter()
.append("circle")
.attr("r",4)
.style('fill-opacity', 0.7)
.style('display', function(d) {
if (d.dd == base_date.getDate() && d.mm == base_date.getMonth()+1) {
return ''
}
return 'none'
})
.style('fill', function(d) {
key = d.mm+'-'+d.dd
if (!sentiment[key]) {
sentiment[key] = {pos:0, neg:0}
}
if (d.sentiment == 'pos') {
sentiment[key]['pos'] += 1
return 'blue'
} else {
sentiment[key]['neg'] += 1
return 'red'
}
})
.style('stroke', '#fff')
.attr("transform", function(d) {return "translate(" + projection([d.lng, d.lat]) + ")";})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment