first commit

This commit is contained in:
dev-chiefworks
2022-05-31 16:21:53 -04:00
commit f76abffdcd
5978 changed files with 1078901 additions and 0 deletions
+168
View File
@@ -0,0 +1,168 @@
/* ------------------------------------------------------------------------------
*
* # D3.js - basic tree layout
*
* Demo of tree layout setup with .json data source
*
* Version: 1.0
* Latest update: August 1, 2015
*
* ---------------------------------------------------------------------------- */
$(function () {
// Initialize chart
treeBasic('#d3-tree-basic', 800);
// Chart setup
function treeBasic(element, height) {
// Basic setup
// ------------------------------
// Define main variables
var d3Container = d3.select(element),
margin = {top: 0, right: 0, bottom: 0, left: 40},
width = d3Container.node().getBoundingClientRect().width - margin.left - margin.right,
height = height - margin.top - margin.bottom - 5;
// Create chart
// ------------------------------
// Add SVG element
var container = d3Container.append("svg");
// Add SVG group
var svg = container
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
// Construct chart layout
// ------------------------------
// Tree
var tree = d3.layout.tree()
.size([height, width - 180]);
// Diagonal projection
var diagonal = d3.svg.diagonal()
.projection(function(d) { return [d.y, d.x]; });
// Load data
// ------------------------------
d3.json("assets/demo_data/d3/tree/tree_data_basic.json", function(error, json) {
var nodes = tree.nodes(json),
links = tree.links(nodes);
// Links
// ------------------------------
// Append link group
var linkGroup = svg.append("g")
.attr("class", "d3-tree-link-group");
// Append link path
var link = linkGroup.selectAll(".d3-tree-link")
.data(links)
.enter()
.append("path")
.attr("class", "d3-tree-link")
.attr("d", diagonal)
.style("fill", "none")
.style("stroke", "#ddd")
.style("stroke-width", 1.5);
// Nodes
// ------------------------------
// Append node group
var nodeGroup = svg.append("g")
.attr("class", "d3-tree-node-group");
// Append node
var node = nodeGroup.selectAll(".d3-tree-node")
.data(nodes)
.enter()
.append("g")
.attr("class", "d3-tree-node")
.attr("transform", function(d) { return "translate(" + d.y + "," + d.x + ")"; });
// Append node circles
node.append("circle")
.attr("r", 4.5)
.attr("class", "d3-tree-circle")
.style("fill", "#fff")
.style("stroke", "#2196F3")
.style("stroke-width", 1.5);
// Append node text
node.append("text")
.attr("dx", function(d) { return d.children ? -12 : 12; })
.attr("dy", 4)
.style("text-anchor", function(d) { return d.children ? "end" : "start"; })
.style("font-size", 12)
.text(function(d) { return d.name; });
// Resize chart
// ------------------------------
// Call function on window resize
$(window).on('resize', resize);
// Call function on sidebar width change
$('.sidebar-control').on('click', resize);
// Resize function
//
// Since D3 doesn't support SVG resize by default,
// we need to manually specify parts of the graph that need to
// be updated on window resize
function resize() {
// Layout variables
width = d3Container.node().getBoundingClientRect().width - margin.left - margin.right,
nodes = tree.nodes(json),
links = tree.links(nodes);
// Layout
// -------------------------
// Main svg width
container.attr("width", width + margin.left + margin.right);
// Width of appended group
svg.attr("width", width + margin.left + margin.right);
// Tree size
tree.size([height, width - 180]);
// Chart elements
// -------------------------
// Link paths
svg.selectAll(".d3-tree-link").attr("d", diagonal)
// Node paths
svg.selectAll(".d3-tree-node").attr("transform", function(d) { return "translate(" + d.y + "," + d.x + ")"; });
}
});
}
});
+327
View File
@@ -0,0 +1,327 @@
/* ------------------------------------------------------------------------------
*
* # D3.js - bracket tree layout
*
* Demo of double sided bracket layout setup with pan and zoom
*
* Version: 1.0
* Latest update: August 1, 2015
*
* ---------------------------------------------------------------------------- */
$(function () {
// Initialize chart
brackets('#d3-tree-bracket', 600);
// Chart setup
function brackets(element, height) {
// Basic setup
// ------------------------------
// Define main variables
var d3Container = d3.select(element),
margin = {top: 0, right: 0, bottom: 0, left: 0},
width = d3Container.node().getBoundingClientRect().width - margin.left - margin.right,
halfWidth = width / 2,
height = height - margin.top - margin.bottom - 5,
i = 0,
duration = 500,
root;
// Create chart
// ------------------------------
// Add SVG element
var container = d3Container.append("svg");
// Add SVG group
var svg = container
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
// Get children
var getChildren = function(d) {
var a = [];
if(d.winners) for(var i = 0; i < d.winners.length; i++){
d.winners[i].isRight = false;
d.winners[i].parent = d;
a.push(d.winners[i]);
}
if(d.challengers) for(var i = 0; i < d.challengers.length; i++){
d.challengers[i].isRight = true;
d.challengers[i].parent = d;
a.push(d.challengers[i]);
}
return a.length?a:null;
};
// Add zoom behavior
// ------------------------------
// Add zoom with scale
var zoom = d3.behavior.zoom()
.scaleExtent([1,2])
.on('zoom', function(){
svg.attr("transform", "translate(" + d3.event.translate + ") scale(" + d3.event.scale + ")");
});
// Initialize zoom
container.call(zoom);
// Construct chart layout
// ------------------------------
// Tree
var tree = d3.layout.tree()
.size([height, width]);
// Diagonal projection
var diagonal = d3.svg.diagonal()
.projection(function(d) { return [d.y, d.x]; });
// Helper functions
// ------------------------------
// Connector
var elbow = function (d, i){
var source = calcLeft(d.source),
target = calcLeft(d.target),
hy = (target.y-source.y) / 2;
if(d.isRight) hy = -hy;
return "M" + source.y + "," + source.x + "H" + (source.y + hy) + "V" + target.x + "H" + target.y;
};
var connector = elbow;
// Calculate horizontal position
var calcLeft = function(d) {
var l = d.y;
if(!d.isRight) {
l = d.y-halfWidth;
l = halfWidth - l;
}
return {x : d.x, y : l};
};
var toArray = function(item, arr){
arr = arr || [];
var i = 0,
l = item.children?item.children.length : 0;
arr.push(item);
for(; i < l; i++) {
toArray(item.children[i], arr);
}
return arr;
};
// Load data
// ------------------------------
d3.json("assets/demo_data/d3/tree/tree_bracket.json", function(json) {
root = json;
root.x0 = height / 2;
root.y0 = width / 2;
// Add tree layout
var t1 = d3.layout.tree().size([height, halfWidth]).children(function(d){return d.winners;}),
t2 = d3.layout.tree().size([height, halfWidth]).children(function(d){return d.challengers;});
t1.nodes(root);
t2.nodes(root);
// Rebuild children nodes
var rebuildChildren = function(node){
node.children = getChildren(node);
if(node.children) node.children.forEach(rebuildChildren);
}
rebuildChildren(root);
root.isRight = false;
update(root);
});
// Layout setup
// ------------------------------
// Update nodes
function update(source) {
// Compute the new tree layout.
var nodes = toArray(source);
// Normalize for fixed-depth.
nodes.forEach(function(d) { d.y = d.depth * 180 + halfWidth; });
// Update the nodes…
var node = svg.selectAll("g.node")
.data(nodes, function(d) { return d.id || (d.id = ++i); });
// Stash the old positions for transition.
nodes.forEach(function(d) {
var p = calcLeft(d);
d.x0 = p.x;
d.y0 = p.y;
});
// Enter nodes
// ------------------------------
// Enter any new nodes at the parent's previous position.
var nodeEnter = node.enter().append("g")
.attr("class", "node")
.attr("transform", function(d) { return "translate(" + source.y0 + "," + source.x0 + ")"; })
.on("click", click);
// Add node circles
nodeEnter.append("circle")
.attr("r", 1e-6)
.style("stroke", "#546E7A")
.style("stroke-width", 1.5)
.style("cursor", "pointer")
.style("fill", function(d) { return d._children ? "#546E7A" : "#fff"; });
// Add node text
nodeEnter.append("text")
.attr("dy", function(d) { return d.isRight?18:-12;})
.attr("text-anchor", "middle")
.text(function(d) { return d.name; })
.style("font-size", 12)
.style("fill-opacity", 1e-6);
// Update nodes
// ------------------------------
// Transition nodes to their new position.
var nodeUpdate = node.transition()
.duration(duration)
.attr("transform", function(d) { p = calcLeft(d); return "translate(" + p.y + "," + p.x + ")"; });
// Update circle
nodeUpdate.select("circle")
.attr("r", 4.5)
.style("fill", function(d) { return d._children ? "#546E7A" : "#fff"; });
// Update text
nodeUpdate.select("text")
.style("fill-opacity", 1);
// Exit nodes
// ------------------------------
// Transition exiting nodes to the parent's new position.
var nodeExit = node.exit().transition()
.duration(duration)
.attr("transform", function(d) { p = calcLeft(d.parent||source); return "translate(" + p.y + "," + p.x + ")"; })
.remove();
// Update circles
nodeExit.select("circle")
.attr("r", 1e-6);
// Update text
nodeExit.select("text")
.style("fill-opacity", 1e-6);
// Links
// ------------------------------
// Update the links
var link = svg.selectAll("path.link")
.data(tree.links(nodes), function(d) { return d.target.id; });
// Enter any new links at the parent's previous position
link.enter().insert("path", "g")
.attr("class", "link")
.style("stroke", "#546E7A")
.style("fill", "none")
.style("stroke-width", 1.5)
.attr("d", function(d) {
var o = {x: source.x0, y: source.y0};
return connector({source: o, target: o});
});
// Transition links to their new position
link.transition()
.duration(duration)
.attr("d", connector);
// Transition exiting nodes to the parent's new position
link.exit().transition()
.duration(duration)
.attr("d", function(d) {
var o = calcLeft(d.source||source);
if(d.source.isRight) o.y -= halfWidth - (d.target.y - d.source.y);
else o.y += halfWidth - (d.target.y - d.source.y);
return connector({source: o, target: o});
})
.remove();
// Toggle children on click.
function click(d) {
if (d.children) {
d._children = d.children;
d.children = null;
} else {
d.children = d._children;
d._children = null;
}
update(source);
}
// Resize chart
// ------------------------------
// Call function on window resize
$(window).on('resize', resize);
// Call function on sidebar width change
$('.sidebar-control').on('click', resize);
// Resize function
//
// Since D3 doesn't support SVG resize by default,
// we need to manually specify parts of the graph that need to
// be updated on window resize
function resize() {
// Layout variables
width = d3Container.node().getBoundingClientRect().width - margin.left - margin.right,
// Layout
// -------------------------
// Main svg width
container.attr("width", width + margin.left + margin.right);
// Width of appended group
svg.attr("width", width + margin.left + margin.right);
}
}
}
});
+282
View File
@@ -0,0 +1,282 @@
/* ------------------------------------------------------------------------------
*
* # D3.js - collapsible tree layout
*
* Demo of tree layout setup with collapsible nodes
*
* Version: 1.0
* Latest update: August 1, 2015
*
* ---------------------------------------------------------------------------- */
$(function () {
// Initialize chart
treeCollapsible('#d3-tree-collapsible', 800);
// Chart setup
function treeCollapsible(element, height) {
// Basic setup
// ------------------------------
// Define main variables
var d3Container = d3.select(element),
margin = {top: 0, right: 0, bottom: 0, left: 40},
width = d3Container.node().getBoundingClientRect().width - margin.left - margin.right,
height = height - margin.top - margin.bottom - 5,
i = 0,
root;
// Create chart
// ------------------------------
// Add SVG element
var container = d3Container.append("svg");
// Add SVG group
var svg = container
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
// Construct chart layout
// ------------------------------
// Tree
var tree = d3.layout.tree()
.size([height, width - 180]);
// Diagonal projection
var diagonal = d3.svg.diagonal()
.projection(function(d) { return [d.y, d.x]; });
// Load data
// ------------------------------
d3.json("assets/demo_data/d3/tree/tree_data_collapsible.json", function(error, json) {
root = json;
root.x0 = height/2;
root.y0 = 0;
// Toggle nodes function
function toggleAll(d) {
if (d.children) {
d.children.forEach(toggleAll);
toggle(d);
}
}
// Initialize the display to show a few nodes
root.children.forEach(toggleAll);
toggle(root.children[1]);
toggle(root.children[1].children[2]);
toggle(root.children[9]);
toggle(root.children[9].children[0]);
update(root);
});
// Layout setup
// ------------------------------
// Update nodes
function update(source) {
// Set duration
var duration = d3.event && d3.event.altKey ? 5000 : 500;
// Compute the new tree layout.
var nodes = tree.nodes(root).reverse();
// Normalize for fixed-depth.
//nodes.forEach(function(d) { d.y = d.depth * 250; });
// Update the nodes…
var node = svg.selectAll(".d3-tree-node")
.data(nodes, function(d) { return d.id || (d.id = ++i); });
// Enter nodes
// ------------------------------
// Enter any new nodes at the parent's previous position.
var nodeEnter = node.enter().append("g")
.attr("class", "d3-tree-node")
.attr("transform", function(d) { return "translate(" + source.y0 + "," + source.x0 + ")"; })
.on("click", function(d) { toggle(d); update(d); });
// Add node circles
nodeEnter.append("circle")
.attr("r", 1e-6)
.style("fill", "#fff")
.style("stroke", "#2196F3")
.style("stroke-width", 1.5)
.style("cursor", "pointer")
.style("fill", function(d) { return d._children ? "#2196F3" : "#fff"; });
// Add nodes text
nodeEnter.append("text")
.attr("x", function(d) { return d.children || d._children ? -10 : 10; })
.attr("dy", ".35em")
.style("text-anchor", function(d) { return d.children || d._children ? "end" : "start"; })
.style("font-size", 12)
.style("fill-opacity", 1e-6)
.text(function(d) { return d.name; });
// Update nodes
// ------------------------------
// Transition nodes to their new position.
var nodeUpdate = node.transition()
.duration(duration)
.attr("transform", function(d) { return "translate(" + d.y + "," + d.x + ")"; });
// Update circle
nodeUpdate.select("circle")
.attr("r", 4.5)
.style("fill", function(d) { return d._children ? "#2196F3" : "#fff"; });
// Update text
nodeUpdate.select("text")
.style("fill-opacity", 1);
// Exit nodes
// ------------------------------
// Transition exiting nodes to the parent's new position.
var nodeExit = node.exit()
.transition()
.duration(duration)
.attr("transform", function(d) { return "translate(" + source.y + "," + source.x + ")"; })
.remove();
// Update circles
nodeExit.select("circle")
.attr("r", 1e-6);
// Update text
nodeExit.select("text")
.style("fill-opacity", 1e-6);
// Links
// ------------------------------
// Update the links…
var link = svg.selectAll(".d3-tree-link")
.data(tree.links(nodes), function(d) { return d.target.id; });
// Enter any new links at the parent's previous position.
link.enter().insert("path", "g")
.attr("class", "d3-tree-link")
.style("fill", "none")
.style("stroke", "#ddd")
.style("stroke-width", 1.5)
.attr("d", function(d) {
var o = {x: source.x0, y: source.y0};
return diagonal({source: o, target: o});
})
.transition()
.duration(duration)
.attr("d", diagonal);
// Transition links to their new position.
link.transition()
.duration(duration)
.attr("d", diagonal);
// Transition exiting nodes to the parent's new position.
link.exit().transition()
.duration(duration)
.attr("d", function(d) {
var o = {x: source.x, y: source.y};
return diagonal({source: o, target: o});
})
.remove();
// Stash the old positions for transition.
nodes.forEach(function(d) {
d.x0 = d.x;
d.y0 = d.y;
});
// Resize chart
// ------------------------------
// Call function on window resize
$(window).on('resize', resize);
// Call function on sidebar width change
$('.sidebar-control, .d3-tree-node circle').on('click', resize);
// Resize function
//
// Since D3 doesn't support SVG resize by default,
// we need to manually specify parts of the graph that need to
// be updated on window resize
function resize() {
// Layout variables
width = d3Container.node().getBoundingClientRect().width - margin.left - margin.right,
nodes = tree.nodes(root),
links = tree.links(nodes);
// Layout
// -------------------------
// Main svg width
container.attr("width", width + margin.left + margin.right);
// Width of appended group
svg.attr("width", width + margin.left + margin.right);
// Tree size
tree.size([height, width - 180]);
diagonal.projection(function(d) { return [d.y, d.x]; });
// Chart elements
// -------------------------
// Link paths
svg.selectAll(".d3-tree-link").attr("d", diagonal)
// Node paths
svg.selectAll(".d3-tree-node").attr("transform", function(d) { return "translate(" + d.y + "," + d.x + ")"; });
}
}
// Toggle childrens
function toggle(d) {
if (d.children) {
d._children = d.children;
d.children = null;
}
else {
d.children = d._children;
d._children = null;
}
}
}
});
+168
View File
@@ -0,0 +1,168 @@
/* ------------------------------------------------------------------------------
*
* # D3.js - cluster dendrogram
*
* Demo of cluster dendrogram setup in cartesian orientation
*
* Version: 1.0
* Latest update: August 1, 2015
*
* ---------------------------------------------------------------------------- */
$(function () {
// Initialize chart
treeCluster('#d3-tree-dendrogram', 800);
// Chart setup
function treeCluster(element, height) {
// Basic setup
// ------------------------------
// Define main variables
var d3Container = d3.select(element),
margin = {top: 0, right: 0, bottom: 0, left: 40},
width = d3Container.node().getBoundingClientRect().width - margin.left - margin.right,
height = height - margin.top - margin.bottom - 5;
// Create chart
// ------------------------------
// Add SVG element
var container = d3Container.append("svg");
// Add SVG group
var svg = container
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
// Construct chart layout
// ------------------------------
// Cluster
var cluster = d3.layout.cluster()
.size([height, width - 180]);
// Diagonal projection
var diagonal = d3.svg.diagonal()
.projection(function(d) { return [d.y, d.x]; });
// Load data
// ------------------------------
d3.json("assets/demo_data/d3/tree/tree_data_dendrogram.json", function(error, root) {
var nodes = cluster.nodes(root),
links = cluster.links(nodes);
// Links
// ------------------------------
// Append link group
var linkGroup = svg.append("g")
.attr("class", "d3-tree-link-group");
// Append link path
var link = linkGroup.selectAll(".d3-tree-link")
.data(links)
.enter()
.append("path")
.attr("class", "d3-tree-link")
.style("fill", "none")
.style("stroke", "#ddd")
.style("stroke-width", 1.5)
.attr("d", diagonal);
// Nodes
// ------------------------------
// Append node group
var nodeGroup = svg.append("g")
.attr("class", "d3-tree-node-group");
// Append node
var node = nodeGroup.selectAll(".d3-tree-node")
.data(nodes)
.enter()
.append("g")
.attr("class", "d3-tree-node")
.attr("transform", function(d) { return "translate(" + d.y + "," + d.x + ")"; })
// Append node circles
node.append("circle")
.style("fill", "#fff")
.style("stroke", "#2196F3")
.style("stroke-width", 1.5)
.attr("r", 4.5);
// Append node text
var text = node.append("text")
.attr("dx", function(d) { return d.children ? -10 : 10; })
.attr("dy", 4)
.style("text-anchor", function(d) { return d.children ? "end" : "start"; })
.style("font-size", 12)
.style("background-color", "#fff")
.text(function(d) { return d.name; });
// Resize chart
// ------------------------------
// Call function on window resize
$(window).on('resize', resize);
// Call function on sidebar width change
$('.sidebar-control').on('click', resize);
// Resize function
//
// Since D3 doesn't support SVG resize by default,
// we need to manually specify parts of the graph that need to
// be updated on window resize
function resize() {
// Layout variables
width = d3Container.node().getBoundingClientRect().width - margin.left - margin.right,
nodes = cluster.nodes(root),
links = cluster.links(nodes);
// Layout
// -------------------------
// Main svg width
container.attr("width", width + margin.left + margin.right);
// Width of appended group
svg.attr("width", width + margin.left + margin.right);
// Tree size
cluster.size([height, width - 180]);
// Chart elements
// -------------------------
// Link paths
svg.selectAll(".d3-tree-link").attr("d", diagonal)
// Node paths
svg.selectAll(".d3-tree-node").attr("transform", function(d) { return "translate(" + d.y + "," + d.x + ")"; });
}
});
}
});
+105
View File
@@ -0,0 +1,105 @@
/* ------------------------------------------------------------------------------
*
* # D3.js - radial dendrogram layout
*
* Demo of radial dendrogram layout setup with .json data source
*
* Version: 1.0
* Latest update: August 1, 2015
*
* ---------------------------------------------------------------------------- */
$(function () {
// Initialize chart
dendrogramRadial('#d3-dendrogram-radial', 900);
// Chart setup
function dendrogramRadial(element, diameter) {
// Basic setup
// ------------------------------
// Define main variables
var d3Container = d3.select(element);
// Create chart
// ------------------------------
// Add SVG element
var container = d3Container.append("svg");
// Add SVG group
var svg = container
.attr("width", diameter)
.attr("height", diameter)
.append("g")
.attr("transform", "translate(" + (diameter / 2) + "," + (diameter / 2) + ")");
// Construct chart layout
// ------------------------------
// Cluster
var cluster = d3.layout.cluster()
.size([360, (diameter / 2) - 150]);
// Diagonal projection
var diagonal = d3.svg.diagonal.radial()
.projection(function(d) { return [d.y, d.x / 180 * Math.PI]; });
// Load data
// ------------------------------
d3.json("assets/demo_data/d3/tree/tree_data_dendrogram_radial.json", function(error, root) {
var nodes = cluster.nodes(root);
// Links
// ------------------------------
// Append link paths
var link = svg.selectAll(".d3-tree-link")
.data(cluster.links(nodes))
.enter()
.append("path")
.attr("class", "d3-tree-link")
.attr("d", diagonal)
.style("fill", "none")
.style("stroke", "#ddd")
.style("stroke-width", 1.5);
// Nodes
// ------------------------------
// Append node group
var node = svg.selectAll(".d3-tree-node")
.data(nodes)
.enter()
.append("g")
.attr("class", "d3-tree-node")
.attr("transform", function(d) { return "rotate(" + (d.x - 90) + ")translate(" + d.y + ")"; })
// Append circles
node.append("circle")
.attr("r", 4.5)
.style("fill", "#fff")
.style("stroke", "#2196F3")
.style("stroke-width", 1.5);
// Append text
node.append("text")
.attr("dy", ".31em")
.attr("text-anchor", function(d) { return d.x < 180 ? "start" : "end"; })
.attr("transform", function(d) { return d.x < 180 ? "translate(8)" : "rotate(180)translate(-8)"; })
.style("font-size", 12)
.text(function(d) { return d.name; });
});
}
});
+108
View File
@@ -0,0 +1,108 @@
/* ------------------------------------------------------------------------------
*
* # D3.js - radial tree layout
*
* Demo of radial tree layout setup with .json data source
*
* Version: 1.0
* Latest update: August 1, 2015
*
* ---------------------------------------------------------------------------- */
$(function () {
// Initialize chart
treeRadial('#d3-tree-radial', 900);
// Chart setup
function treeRadial(element, diameter) {
// Basic setup
// ------------------------------
// Define main variables
var d3Container = d3.select(element);
// Create chart
// ------------------------------
// Add SVG element
var container = d3Container.append("svg");
// Add SVG group
var svg = container
.attr("width", diameter)
.attr("height", diameter - 140)
.append("g")
.attr("transform", "translate(" + (diameter / 2) + "," + (diameter / 2) + ")");
// Construct chart layout
// ------------------------------
// Tree
var tree = d3.layout.tree()
.size([360, (diameter / 2) - 110])
.separation(function(a, b) { return (a.parent == b.parent ? 1 : 2) / a.depth; });
// Diagonal projection
var diagonal = d3.svg.diagonal.radial()
.projection(function(d) { return [d.y, d.x / 180 * Math.PI]; });
// Load data
// ------------------------------
d3.json("assets/demo_data/d3/tree/tree_data_radial.json", function(error, root) {
var nodes = tree.nodes(root),
links = tree.links(nodes);
// Links
// ------------------------------
// Append link paths
var link = svg.selectAll(".d3-tree-link")
.data(links)
.enter()
.append("path")
.attr("class", "d3-tree-link")
.attr("d", diagonal)
.style("fill", "none")
.style("stroke", "#ddd")
.style("stroke-width", 1.5);
// Nodes
// ------------------------------
// Append node group
var node = svg.selectAll(".d3-tree-node")
.data(nodes)
.enter()
.append("g")
.attr("class", "d3-tree-node")
.attr("transform", function(d) { return "rotate(" + (d.x - 90) + ")translate(" + d.y + ")"; })
// Append circles
node.append("circle")
.attr("r", 4.5)
.style("fill", "#fff")
.style("stroke", "#2196F3")
.style("stroke-width", 1.5);
// Append text
node.append("text")
.attr("dy", ".31em")
.attr("text-anchor", function(d) { return d.x < 180 ? "start" : "end"; })
.attr("transform", function(d) { return d.x < 180 ? "translate(8)" : "rotate(180)translate(-8)"; })
.style("font-size", 12)
.text(function(d) { return d.name; });
});
}
});