Last active
August 29, 2015 14:01
-
-
Save jtauber/1ff0675ba73244997e0a to your computer and use it in GitHub Desktop.
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
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> | |
<style> | |
.node { | |
fill: #333; | |
cursor: pointer; | |
} | |
</style> | |
</head> | |
<body> | |
<script src="http://d3js.org/d3.v3.min.js"></script> | |
<script> | |
var width = 960, | |
height = 500; | |
var fill = d3.scale.category20(); | |
var force = d3.layout.force() | |
.size([width, height]) | |
.nodes([ | |
{word: "I"}, | |
{word: "need"}, | |
{word: "to"}, | |
{word: "ensure"}, | |
{word: "these"}, | |
{word: "words"}, | |
{word: "don't"}, | |
{word: "overlap"}, | |
]) | |
.gravity(0.05) | |
.charge(-200) | |
.on("tick", tick); | |
var svg = d3.select("body").append("svg") | |
.attr("width", width) | |
.attr("height", height); | |
var node = svg.selectAll(".node") | |
.data(force.nodes()); | |
node.enter().insert("text") | |
.attr("class", "node") | |
.call(force.drag); | |
force.start(); | |
function tick() { | |
node.attr("x", function(d) { return d.x; }) | |
.attr("y", function(d) { return d.y; }) | |
.text(function(d) { return d.word; }); | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment