使用Jupyter Notebook中的d3js更新了可折叠图形的答案
在笔记本电脑中启动第一个单元
%%html
.node circle {
cursor: pointer;
stroke: #3182bd;
stroke-width: 1.5px;
}
.node text {
font: 10px sans-serif;
pointer-events: none;
text-anchor: middle;
}
line.link {
fill: none;
stroke: #9ecae1;
stroke-width: 1.5px;
}
笔记本电脑中的第一个电池结束
在笔记本中开始第二个单元格
%%javascript
// We load the d3.js library from the Web.
require.config({paths:
{d3: "http://d3js.org/d3.v3.min"}});
require(["d3"], function(d3) {
// The code in this block is executed when the
// d3.js library has been loaded.
// First, we specify the size of the canvas
// containing the visualization (size of the
//
var width = 960,
height = 500,
root;
// We create a color scale.
var color = d3.scale.category10();
// We create a force-directed dynamic graph layout.
// var force = d3.layout.force()
// .charge(-120)
// .linkDistance(30)
// .size([width, height]);
var force = d3.layout.force()
.linkDistance(80)
.charge(-120)
.gravity(.05)
.size([width, height])
.on("tick", tick);
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
var link = svg.selectAll(".link"),
node = svg.selectAll(".node&#