Skip to content

Instantly share code, notes, and snippets.

@ramnathv
Last active August 29, 2015 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ramnathv/35908ea29a9de4fe20e2 to your computer and use it in GitHub Desktop.
Save ramnathv/35908ea29a9de4fe20e2 to your computer and use it in GitHub Desktop.
Tributary inlet
{"description":"Tributary inlet","endpoint":"","display":"svg","public":true,"require":[],"fileconfigs":{"inlet.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,"ajax-caching":true,"thumbnail":"http://i.imgur.com/uj4pZ7l.png"}
var data = {
"name": "Max",
"children": [
{"name": "Joe",
"children": [
{"name": "Ram"},
{"name": "Nath"}
]
},
{"name": "Jill"}
]
}
var canvas = d3.select("svg")
.attr("width", 500)
.attr("height", 500)
.append("g")
.attr("transform", "translate(50, 50)")
/*
var diagonal = d3.svg.diagonal()
.source({x: 71, y: 60})
.target({x: 318, y: 300})
canvas.append("path")
.attr("fill", "none")
.attr("stroke", "steelblue")
.attr("d", diagonal)
*/
var tree = d3.layout.tree()
.size([400, 196])
var nodes = tree.nodes(data)
var node = canvas.selectAll(".node")
.data(nodes).enter()
.append("g")
.attr("class", "node")
node.append("circle")
.attr("r", 10)
.attr("fill", "steelblue")
.attr("cx", I("x"))
.attr("cy", I("y"))
/*
node.append("rect")
.attr("fill", "none")
.attr("stroke", "steelblue")
.attr("x", I("x"))
.attr("y", I("y"))
.attr("width", 80)
.attr("height", 29)
node.append("text")
.text(I("name"))
.attr("x", I("x"))
.attr("y", I("y"))
.attr("font-size", "14px")
.attr("transform", "translate(29, 20)")
*/
var links = tree.links(nodes)
var diagonal = d3.svg.diagonal()
canvas.selectAll(".link")
.data(links).enter()
.append("path")
.attr("class", "link")
.attr("fill", "none")
.attr("stroke", "#bbb")
.attr("d", diagonal)
function I(x){
return function(d){
return d[x]
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment