Skip to content

Instantly share code, notes, and snippets.

@tortillaj
Last active July 24, 2016 15:53
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 tortillaj/d96fa350b500788b017d7565ffdde286 to your computer and use it in GitHub Desktop.
Save tortillaj/d96fa350b500788b017d7565ffdde286 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/ekC3czs.png"}
var margin = {top: 100, right: 50, bottom: 100, left: 50},
width = 900 - margin.left - margin.right,
height = 500 - margin.top - margin.bottom;
var tree = d3.layout.tree()
.separation(function(a, b) { return a.parent === b.parent ? 1 : 1.2; })
.children(function(d) { return d.children; })
.size([width, height]);
var svg = d3.select("svg")
.attr("class", "org-chart")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
var nodes = tree.nodes(getData());
var node = svg.selectAll(".org-chart__employee")
.data(nodes)
.enter()
.append("g");
node.append("rect")
.attr("width", 140)
.attr("height", 80)
.attr("fill", "tan")
.attr("x", function(d) { return d.x - 70; })
.attr("y", function(d) { return height - d.y - 40; });
node.append("text")
.attr("font-size", "16px")
.attr("fill", "black")
.attr("x", function(d) { return d.x; })
.attr("y", function(d) { return height - d.y - 15; })
.style("text-anchor", "middle")
.text(function(d) { return d.name; });
function connect(d, i) {
console.log(d, i);
return "M" + d.source.x + "," + (height - d.source.y)
+ "V" + (height - (8*d.source.y + 4*d.target.y)/7)
+ "H" + d.target.x
+ "V" + (height - d.target.y);
}
function getData() {
return {
uid: 10,
name: "James",
email: "james@email.com",
photo: "http://place-hoff.com/50/50",
children: [
{
uid: 11,
name: "Tom",
email: "tom@email.com",
photo: "http://place-hoff.com/50/50"
},
{
uid: 12,
name: "Fred",
email: "fred@email.com",
photo: "http://place-hoff.com/50/50"
},
{
uid: 13,
name: "Betty",
email: "betty@email.com",
photo: "http://place-hoff.com/50/50"
}
],
parents: [
{
uid: 9,
name: "Jack",
email: "jack@email.com",
photo: "http://place-hoff.com/50/50"
},
{
uid: 8,
name: "Beth",
email: "beth@email.com",
photo: "http://place-hoff.com/50/50"
}
]
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment