Commit 3208345a authored by Mike Bostock's avatar Mike Bostock
Browse files

Remove force-html example.

parent 626dd3ad
<!DOCTYPE html>
<meta charset="utf-8">
<title>Force-Directed Layout</title>
<style>
div.node {
border-radius: 6px;
width: 12px;
height: 12px;
margin: -6px 0 0 -6px;
position: absolute;
}
div.link {
position: absolute;
border-bottom: solid #999 1px;
height: 0;
-webkit-transform-origin: 0 0;
-moz-transform-origin: 0 0;
-ms-transform-origin: 0 0;
-o-transform-origin: 0 0;
transform-origin: 0 0;
}
</style>
<body>
<script src="../../d3.js"></script>
<script>
var width = 960,
height = 500,
radius = 6,
fill = d3.scale.category20();
var force = d3.layout.force()
.charge(-120)
.linkDistance(30)
.size([width, height]);
var svg = d3.select("body").append("div")
.style("width", width + "px")
.style("height", height + "px");
d3.json("miserables.json", function(error, json) {
var link = svg.selectAll("div.link")
.data(json.links)
.enter().append("div")
.attr("class", "link");
var node = svg.selectAll("div.node")
.data(json.nodes)
.enter().append("div")
.attr("class", "node")
.style("background", function(d) { return fill(d.group); })
.style("border-color", function(d) { return d3.rgb(fill(d.group)).darker(); })
.call(force.drag);
force
.nodes(json.nodes)
.links(json.links)
.on("tick", tick)
.start();
function tick() {
node.style("left", function(d) { return (d.x = Math.max(radius, Math.min(width - radius, d.x))) + "px"; })
.style("top", function(d) { return (d.y = Math.max(radius, Math.min(height - radius, d.y))) + "px"; });
link.style("left", function(d) { return d.source.x + "px"; })
.style("top", function(d) { return d.source.y + "px"; })
.style("width", length)
.style("-webkit-transform", transform)
.style("-moz-transform", transform)
.style("-ms-transform", transform)
.style("-o-transform", transform)
.style("transform", transform);
}
function transform(d) {
return "rotate(" + Math.atan2(d.target.y - d.source.y, d.target.x - d.source.x) * 180 / Math.PI + "deg)";
}
function length(d) {
var dx = d.target.x - d.source.x,
dy = d.target.y - d.source.y;
return Math.sqrt(dx * dx + dy * dy) + "px";
}
});
</script>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment