javascript - 更新 d3 强制有向图链接不起作用
问题描述
我正在尝试更新我的力有向图,但只有节点在更新(而不是链接)。我基本上是在尝试使用 css 类更新链接的颜色,但它没有设置。每当有内容更新时,都会调用更新函数。
我的代码有点复杂,所以我只是粘贴了它的要点:
let update = () => {
// [...]
// Update nodes and their css classes works perfectly
// But updating link css class is not updating at all
link = link
.data(links)
.join(enter => {
return enter
.append("path")
.attr("class", d => {
return "someclass"; // <-- This is not constant!
});
},
update => {
return update
}
);
this._simulation.nodes(nodes);
this._simulation.force("link").links(links);
this._simulation.alpha(1).restart();
};
请特别注意该return "someclass";
行。返回的字符串可能会更改,但不会应用该类。
这不起作用有什么明显的原因吗?
使用以下版本:
d3:6.7.0,d3-力:2.1.1
解决方案
推荐阅读
- google-cloud-platform - Hive 直线转换到 Google Dataproc
- react-native - 如何在本机反应中编写自定义闪存消息
- googlemock - Gmock ReturnRef 不返回正确的值
- java - intellij中的maven编译器
- antlr4 - 正则表达式评论
- java - 在休眠中创建多个子实体时,如何仅创建一次父实体?
- amazon-web-services - 关于海王星数据的导出
- python - 如何在oddo 12中创建新公司时自动创建销售点会话?
- linux - Shell脚本循环文件,应用命令并将每个输出保存到新文件
- tls1.2 - Knative:启用自动 TLS 证书配置 - 不起作用