rveciana - d3-trail-layout-example

D3 Trail Layout example

Open raw page in new tab

This is my first example using the D3 trail layout made by Benjamin Schmidt. There is no complete hellow world example yet in the official docs, so I created this one.

<!DOCTYPE html>
<meta charset="utf-8">

<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="pathlayout.js"></script>
var width = 600,
    height = 500;

var points = [{"x":0,"y":0}, {"x":200,"y":200}, {"x":0,"y":400}, {"x":200,"y":100}];
var svg = d3.select("body").append("svg")
    .attr("width", width)
    .attr("height", height);

var trail = d3.layout.trail().coordType('xy');

var trail_layout = trail.data(points).layout();

paths = svg.selectAll("line").data(trail_layout);

.attr("x1",function(d) {return d.x1}) 
.attr("y1",function(d) {return d.y1}) 
.attr("y2",function(d) {return d.y2}) 
.attr("x2",function(d) {return d.x2})