简体   繁体   English

D3圆包布局中嵌套圆的工具提示

[英]Tooltips for nested circles in D3 circle pack layout

I'm banging my head here. 我在这里敲我的头。 I want to display tooltips for the leaf nodes in a structure such as Zoomable Pack Layout . 我想在Zoomable Pack Layout等结构中显示叶节点的工具提示。 The leaf nodes are the brown ones. 叶节点是棕色节点。 If I used the standard code for tooltips: 如果我使用工具提示的标准代码:

vis.selectAll("circle")
    .data(nodes)
   .enter()
    .append("svg:circle")
    .attr("class", function(d) {
        return d.children ? "parent" : "child";
    })
    .attr("cx", function(d) {
        return d.x;
    })
    .attr("cy", function(d) {
        return d.y;
    })
    .attr("r", function(d) {
        return d.r;
    })
    .on("click", function(d) {
        zoom(node == d ? root : d);
    })
    .append("svg:title")
    .text("test");          \\ Browser uses this for tooltips

I get tooltips on the primary circles but not on the leaf nodes. 我在主要圆圈上获得了工具提示,但在叶子节点上没有。 I tried: 我试过了:

.append("svg:title")
.text(function(d) {
    if(d.size){return 'test';}
});

...hoping that by returning something only when a varaible contained by leaf nodes is present may prevent the parent nodes from showing a tooltip but I'm afraid all it did was allow a hidden tooltip taht silently prevents anything from displaying. ...希望只有当叶子节点包含的变量存在时返回一些东西可能会阻止父节点显示工具提示,但我担心它所做的一切都是允许隐藏的工具提示默默地阻止任何显示。

Any thoughts? 有什么想法吗? I figure I either need to stack the svg:circles so that the leaf nodes are in front of the others or attach svg:titles only to the leaf nodes but I'm not sure how to do that. 我想我要么堆叠svg:circles,以便叶节点在其他节点前面,或者只将svg:titles附加到叶节点,但我不知道如何做到这一点。

Here is a fiddle of the tooltips: Fiddle 这是工具提示的小提琴小提琴

The problem is in fact not the code, but the CSS that prevents the leaf node circles from receiving pointer events. 问题实际上不是代码,而是阻止叶节点圈接收指针事件的CSS。 Simply remove 只需删除

circle.child {
  pointer-events: none;
}

and it works fine. 它工作正常。 Complete example here . 在这里完成示例。

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

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