[ Launch: Simple word cloud ] 7405896 by jefffriesen
-
-
Save jefffriesen/7405896 to your computer and use it in GitHub Desktop.
Simple word cloud
This file contains hidden or 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
{"description":"Simple word cloud","endpoint":"","display":"svg","public":true,"require":[{"name":"wordcloud","url":"https://raw.github.com/jasondavies/d3-cloud/master/d3.layout.cloud.js"}],"fileconfigs":{"inlet.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"wordcloud.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"_.md":{"default":true,"vim":false,"emacs":false,"fontSize":12},"config.json":{"default":true,"vim":false,"emacs":false,"fontSize":12}},"fullscreen":false,"play":false,"loop":false,"restart":false,"autoinit":true,"pause":true,"loop_type":"pingpong","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01,"thumbnail":"http://i.imgur.com/kjsCIbB.png"} |
This file contains hidden or 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 fill = d3.scale.category20(); | |
d3.layout.cloud().size([300, 300]) | |
.words([ | |
"Hello", "world", "normally", "you", "want", "more", "words", | |
"than", "this"].map(function(d) { | |
return {text: d, size: 10 + Math.random() * 90}; | |
})) | |
.padding(5) | |
.rotate(function() { return ~~(Math.random() * 2) * 90; }) | |
.font("Impact") | |
.fontSize(function(d) { return d.size; }) | |
.on("end", draw) | |
.start(); | |
function draw(words) { | |
var svg = d3.select("svg") | |
.attr("width", 300) | |
.attr("height", 300) | |
.append("g") | |
.attr("transform", "translate(150,150)") | |
.selectAll("text") | |
.data(words) | |
.enter().append("text") | |
.style("font-size", function(d) { return d.size + "px"; }) | |
.style("font-family", "Impact") | |
.style("fill", function(d, i) { return fill(i); }) | |
.attr("text-anchor", "middle") | |
.attr("transform", function(d) { | |
//return "translate(" + [d.x, d.y] + ")rotate(" + d.rotate + ")"; | |
return "translate(" + [d.x, d.y] + ")"; | |
}) | |
.text(function(d) { return d.text; }); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment