我有一个d3演示文稿,展示了世界地球仪。当我将鼠标悬停在某个国家/地区上时,如果代码尚无标题,则希望代码附加标题。否则,代码会将标题后的标题追加到同一路径。如何检查路径是否有标题?
function pathOver(d) {
var thisID = d.properties.id;
if (!d3.select('path#' +thisID).attr('title')) { //this doesn't work
d3.select('path#' +thisID).append('title').text(function(d){return d.properties.name});
}
}
选择标题,然后查看所选内容是否为空:
if(d3.select('path#' + thisID).selectAll('title').empty()) {
d3.select('path#' +thisID).append('title').text(function(d){return d.properties.name});
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句