Javascript D3js力定向图-删除动画
我正在努力与你合作。现在我能够很好地写这个图,但是因为我的图有2000个节点,所以感觉非常滞后。因此,我决定删除开始动画,但仍然找不到一种方法来做到这一点。我已经看了,并试图解决,但它仍然不工作 有没有办法消除动画,或者有没有其他办法减少延迟 这是我的密码:Javascript D3js力定向图-删除动画,javascript,d3.js,graph,force-layout,Javascript,D3.js,Graph,Force Layout,我正在努力与你合作。现在我能够很好地写这个图,但是因为我的图有2000个节点,所以感觉非常滞后。因此,我决定删除开始动画,但仍然找不到一种方法来做到这一点。我已经看了,并试图解决,但它仍然不工作 有没有办法消除动画,或者有没有其他办法减少延迟 这是我的密码: <!DOCTYPE html> <meta charset="utf-8"> <style> .links line { stroke: #999; stroke-opacity: 0.6; }
<!DOCTYPE html>
<meta charset="utf-8">
<style>
.links line {
stroke: #999;
stroke-opacity: 0.6;
}
.nodes circle {
stroke: #fff;
stroke-width: 1.5px;
}
</style>
<svg width="2000" height="1500"></svg>
<script src="https://d3js.org/d3.v4.min.js"></script>
<script>
var svg = d3.select("svg"),
width = +svg.attr("width"),
height = +svg.attr("height");
var color = d3.scaleOrdinal(d3.schemeCategory20);
var simulation = d3.forceSimulation()
.force("link", d3.forceLink().id(function(d) { return d.id; }))
.force("center", d3.forceCenter(width / 2, height / 2));
d3.json("force.json", function(error, graph) {
if (error) throw error;
// Taken from related answer: https://stackoverflow.com/a/44113223/4235784
let filteredNodes = graph.nodes.filter(
function(n) { return this.has(n.id); },
graph.links.reduce((set, {source:s, target:t}) =>
s !== t ? set.add(s).add(t) : set,
new Set()
)
);
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); });
var node = svg.append("g")
.attr("class", "nodes")
.selectAll("circle")
.data(filteredNodes)
.enter().append("circle")
.attr("r", 5)
.attr("fill", function(d) { return color(d.group); });
node.append("title")
.text(function(d) { return d.name; });
simulation
.nodes(graph.nodes)
.on("tick", ticked);
simulation.force("link")
.links(graph.links);
function ticked() {
link
.attr("x1", function(d) { return d.source.x; })
.attr("y1", function(d) { return d.source.y; })
.attr("x2", function(d) { return d.target.x; })
.attr("y2", function(d) { return d.target.y; });
node
.attr("cx", function(d) { return d.x; })
.attr("cy", function(d) { return d.y; });
}
});
</script>
您是否阅读了链接到的静力布局附带的文本?为了避免冻结用户界面,可能需要计算web worker中的强制导向布局。这甚至链接到工作示例。是的,我已经看到了链接,但我不理解它。我对这些东西还是新手。你读过你链接到的静态力布局的文本吗?为了避免冻结用户界面,可能需要计算web worker中的强制导向布局。这甚至链接到工作示例。是的,我已经看到了链接,但我不理解它。我对这些东西还是新手。