作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在以下链接所示的 d3js 气泡图中:http://www.nytimes.com/interactive/2012/09/06/us/politics/convention-word-counts.html?_r=0# !
单击时气泡会突出显示。我想在我的 d3js 气泡图中实现该功能。有谁知道该怎么做?提前致谢 。
最佳答案
当您单击气泡时,g-selected
类将添加到节点中。这会改变
.g-node .g-democrat {
fill: #c5d7ea;
}
.g-node .g-republican {
fill: #f9caca;
}
到
.g-node.g-selected .g-democrat {
fill: #99c0e5;
stroke: #6081a3;
stroke-width: 1.5px;
}
.g-node.g-selected .g-republican {
fill: #fda4a7;
stroke: #af5e61;
stroke-width: 1.5px;
}
向单击的元素添加类非常简单。该类是使用 selection.classed
方法添加的。
node.classed("g-selected", function(d) { return d === topic; });
如果您正在查看the source ,查看 updateActiveTopic
函数。
您的 fiddle 中的代码比您链接的示例要简单得多。我会更改创建圆形元素的部分,以便它使用 css,而不是内联样式,即
circle {
fill: green;
}
而不是
.style("fill", function (d, i) {
return "green";
})
现在,您将向圆圈添加点击处理程序:
circle.on("click", function(d) {
// remove selected class from all circles that have it
circle.classed('selected', false);
//add the selected class to the element that was clicked
d3.select(this).classed('selected', true)
});
以及选择圆圈时突出显示圆圈的样式
circle.selected {
fill: blue;
stroke: black;
stroke-width: 1.5px;
}
请参阅fiddle完整的示例。
关于javascript - d3js 气泡图中的气泡突出显示功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33671132/
有没有一种方法可以“标记”对象的属性,使它们在反射中“突出”? 例如: class A { int aa, b; string s1, s2; public int AA
我是一名优秀的程序员,十分优秀!