Created
August 24, 2014 23:00
-
-
Save dviramontes/590a07c71ff4863ac41b to your computer and use it in GitHub Desktop.
// source http://jsbin.com/watiki/2
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> | |
<html> | |
<head> | |
<script src="http://code.jquery.com/jquery.min.js"></script> | |
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet" type="text/css" /> | |
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script> | |
<script src="http://cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.min.js"></script> | |
<script src="http://code.jquery.com/jquery-git2.js"></script> | |
<script src="http://d3js.org/d3.v3.min.js"></script> | |
<meta charset="utf-8"> | |
<title>JS Bin</title> | |
<style id="jsbin-css"> | |
svg { | |
margin: 0 auto; | |
} | |
</style> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
var height, main, url, width, withData; | |
url = 'http://feeds.delicious.com/v2/json/tags/dviramontes'; | |
width = 400; | |
height = 200; | |
withData = function(data) { | |
return main(data); | |
}; | |
$.ajax(url, { | |
crossDomain: true, | |
dataType: 'jsonp' | |
}).error(function(xhr, status, error) { | |
return alert(error.message); | |
}).success(withData); | |
main = function(data) { | |
var group, svg, tags, theme; | |
tags = _.map(data, function(d, i) { | |
return { | |
tag: i, | |
"count": d | |
}; | |
}); | |
theme = d3.scale.linear().domain([1, 20]).range(['#67001f', '#b2182b', '#d6604d', '#f4a582', "#fddbc7", "#ffffff", "#e0e0e0", "#bababa", "#878787", "#4d4d4d", "#1a1a1a"]); | |
svg = d3.select('body').append('svg'); | |
svg.attr('width', width).attr('height', height).style({ | |
"border": "2px red solid" | |
}); | |
group = svg.append('g').attr('transform', 'translate(' + 0 + ',' + height / 2 + ')'); | |
return group.selectAll('circle').data(tags).enter().append('circle').attr('cx', function(d, i) { | |
return i; | |
}).attr('cy', 0).attr('r', function(d, i) { | |
return d.count; | |
}).attr('fill', function(d, i) { | |
return theme(i); | |
}); | |
}; | |
</script> | |
<script id="jsbin-source-css" type="text/css">svg { | |
margin : 0 auto; | |
}</script> | |
<script id="jsbin-source-javascript" type="text/javascript">url = 'http://feeds.delicious.com/v2/json/tags/dviramontes' | |
width = 400 | |
height = 200 | |
withData = (data) -> | |
main data | |
$.ajax(url, | |
crossDomain : true | |
dataType: 'jsonp') | |
.error((xhr, status, error) -> | |
alert(error.message)) | |
.success(withData) | |
main = (data) -> | |
tags = _.map data, (d,i) -> tag: i, "count":d | |
theme = d3.scale.linear() | |
.domain([1,20]) | |
.range(['#67001f' | |
'#b2182b' | |
'#d6604d' | |
'#f4a582' | |
"#fddbc7" | |
"#ffffff" | |
"#e0e0e0" | |
"#bababa" | |
"#878787" | |
"#4d4d4d" | |
"#1a1a1a"]) | |
svg = d3.select('body') | |
.append('svg') | |
svg | |
.attr 'width', width | |
.attr 'height', height | |
.style "border" : "2px red solid" | |
group = svg.append('g') | |
.attr('transform', 'translate('+0 + ',' + height/2 + ')') | |
group | |
.selectAll('circle') | |
.data(tags) | |
.enter() | |
.append('circle') | |
.attr('cx', (d,i) -> i) | |
.attr('cy', 0) | |
.attr('r', (d,i) -> d.count) | |
.attr('fill', (d,i) -> theme(i)) | |
</script></body> | |
</html> |
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
svg { | |
margin: 0 auto; | |
} |
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
var height, main, url, width, withData; | |
url = 'http://feeds.delicious.com/v2/json/tags/dviramontes'; | |
width = 400; | |
height = 200; | |
withData = function(data) { | |
return main(data); | |
}; | |
$.ajax(url, { | |
crossDomain: true, | |
dataType: 'jsonp' | |
}).error(function(xhr, status, error) { | |
return alert(error.message); | |
}).success(withData); | |
main = function(data) { | |
var group, svg, tags, theme; | |
tags = _.map(data, function(d, i) { | |
return { | |
tag: i, | |
"count": d | |
}; | |
}); | |
theme = d3.scale.linear().domain([1, 20]).range(['#67001f', '#b2182b', '#d6604d', '#f4a582', "#fddbc7", "#ffffff", "#e0e0e0", "#bababa", "#878787", "#4d4d4d", "#1a1a1a"]); | |
svg = d3.select('body').append('svg'); | |
svg.attr('width', width).attr('height', height).style({ | |
"border": "2px red solid" | |
}); | |
group = svg.append('g').attr('transform', 'translate(' + 0 + ',' + height / 2 + ')'); | |
return group.selectAll('circle').data(tags).enter().append('circle').attr('cx', function(d, i) { | |
return i; | |
}).attr('cy', 0).attr('r', function(d, i) { | |
return d.count; | |
}).attr('fill', function(d, i) { | |
return theme(i); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment