如何在单击圆圈时调整圆圈的大小?

时间:2014-10-16 22:36:59

标签: javascript d3.js

我是D3的新手,当我点击其中任何一个时,我已经想出了如何调整所有圈子的大小。但是,我想要的只是调整被点击的圆圈的大小。其余的圈子应该保持不变。这就是我所拥有的:

HTML:

<g id="bubble-nodes">
    <rect id="bubble-background"></rect>
    <a class="class="bubble-node">
        <circle r="65"></circle>
    </a>
    ....
</g>

的Javascript / D3:

// this works. It allows me to resize all circles when I click on one of them.
// but, it's not what I want
var resizeCircle = function () {
    var circle = d3.selectAll('circle');
    circle.attr("r", 85);
};

// this is what I want, but it doesn't work. 
// I want to resize the circle I clicked on
var circle = d3
    .selectAll('circle')
    .on("click", function (d) {
        return d.attr("r", 85);
    });

有什么建议吗?

1 个答案:

答案 0 :(得分:0)

这有帮助吗?

var circle = d3
    .selectAll('circle')
    .on('click', function (d) {
        d3.select(this).attr("r", 85);
    });