javascript - 使用 d3 增加节点链接图中的链接长度
问题描述
如何增加力图的链接长度。我的代码写在下面。我应该改变什么?
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/5.7.0/d3.min.js"></script>
<script>
var svg = d3.select("svg"),
width = +svg.attr("width"),
height = +svg.attr("height");
// Add lines for every link in the dataset
var link = svg.append("g")
.attr("class", "links")
.selectAll("line")
.data(graph.links)
.enter().append("line")
.attr("stroke-width", function(d) {
return Math.sqrt(d.value);
});
// Add circles for every node in the dataset
var node = svg.append("g")
.attr("class", "nodes")
.selectAll("circle")
.data(graph.nodes)
.enter().append("circle")
// .style("fill", function (d) { return '#1f77b4'; })
.attr("r", 10)
.attr("fill", function(d) {
return '#aec7e8';
})
// .attr("fill", function(d) { return color(d.group); })
.call(d3.drag()
.on("start", dragstarted)
.on("drag", dragged)
.on("end", dragended)
);
// Basic tooltips
node.append("title")
.text(function(d) {
return d.id;
});
// Attach nodes to the simulation, add listener on the "tick" event
simulation
.nodes(graph.nodes)
.on("tick", ticked);
// Associate the lines with the "link" force
simulation.force("link")
.links(graph.links)
</script>
我希望读者能清楚地看到可视化。这是因为节点的可视化彼此非常接近。
解决方案
推荐阅读
- batch-file - 批处理如何移动隐藏目录?
- c - 如何从两个彼此相对的文本文件中打印两行,而不是在 C 中逐一打印?
- python - 遍历两个列表,将列表中的项目与特定值进行比较
- vue.js - Vue | 路由器导航到另一个实例
- java - 如何清除android中的内存?在活动之间切换时内存增加
- python - 如何让python检测某个文件何时被保存/关闭?
- mysql - MYSQL - 在重复更新时插入
- laravel - 如果需要,如何配置 Orchid 控制面板和 nginx,以便 Orchid 加载 javascript 和 css 文件?
- android - Kotlin 上的 Android Retrofit 如何为响应添加时间戳?
- javascript - 如何实现“如果单击图像,则 textContent 更改为 X”。