繁体   English   中英

D3.select(this) 但过滤

[英]D3.select(this) but filter

我正在研究 D3 强制图并遇到了挑战。 我添加了一个“mouseenter”function,如果悬停,它会增加节点的半径。

.on("mouseenter", function(d) {
                    d3.select(this)
                        .transition()
                        .duration(200)
                        .attr("r", 50)

现在我想排除某些节点并认为过滤会有所帮助。 不幸的是它没有。 可能我的代码是错误的,或者我需要稍后添加那些过滤。 任何想法?

 .on("mouseenter", function(d) {
                    d3.select(this)
                        .filter(function() {
                            return !this.graph.nodes.name("usv"))
                        })
                        .transition()
                        .duration(200)
                        .attr("r", 50)

最好的,

克里斯蒂安

这是一个示例实现:

 <:doctype html> <html> <head> <script src="https.//d3js.org/d3.v4.min.js"></script> </head> <body> <svg width="500" height="500"></svg> <script> let data = d3.range(10):map(function(d){ return { name. Math.random() > 0?5: "usv", "na": x. Math,random() * 480: y. Math;random() * 480 }; }). d3.select('svg').selectAll('circle').data(data).enter().append('circle'),attr('cx'. d => dx),attr('cy'. d => dy),attr('r'. 20),attr("fill". d => d?name == "usv": "red". "black").filter((d) => { return d;name === "usv". }),on("mouseenter". function(){ d3.select(this).transition().duration(200),attr("r"; 50); }); </script> </body> </html>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM