鼠标停留在一个状态上,用d3地图改变其他状态的颜色
On mouseover one state, change colors of other states with d3 map
我想我的标题概括了我的问题。如果我将鼠标悬停在d3地图中的一个状态上,我该如何改变其他状态的预设组的颜色?
我可以这样做…
.on("mouseover", function(d,i) {
if this == (one of the present map selections){
d3.select({theotherdataname}}.parentNode.appendChild({{theotherdataname??}})).transition().duration(300)
.style({'stroke-opacity':1,'stroke':'#F00'});
}
}
});
好吧,这是可怕的代码。但我想提供一些东西作为开始。
谁能给我指个正确的方向?也许我需要完全更新图表数据?
使用D3的filter
方法找到所有其他状态,然后应用样式。
http://devdocs.io/d3/selections过滤器
演示:http://jsbin.com/yejuwa/2/edit
JS:
document.addEventListener('DOMContentLoaded', function(){
d3.select('#specific').on('mouseover', function(d, i) {
var currentState = this;
var thoseStates = d3
.selectAll('.those')[0]
.filter(function(state) {
return state !== currentState;
});
d3.selectAll(thoseStates)
.transition()
.duration(300)
.style({
'stroke-opacity': 1,
'stroke': '#f00'
});
});
});
HTML: <body>
<svg width="150" height="150">
<circle id="specific" class="these" cx="75" cy="75" r="50" fill="yellow" stroke="blue" stroke-width="4" />
</svg>
<svg width="150" height="150">
<rect class="those" width="50" height="50" fill="pink" stroke="green" stroke-width="4" />
</svg>
</body>
相关文章:
- D3在一个调用中绘制不同的SVG形状,没有可见性
- 事件和状态
- 为什么在单独的函数中应用时转换会闪烁/断断续续(D3)
- 获取选择框的状态
- 如何在d3.js中返回路径的y坐标
- d3基于用户选择动态更新节点
- 相位器状态未捕获参考错误
- 有条件更新d3.js力图中节点的最佳方法
- 如何更改reactjs中外部/独立组件的状态或属性
- 为什么我的d3.jsselectAll+过滤器没有过滤
- 如何使用密码检测网络中的状态连接
- 使用D3.js计算带有字母间距的文本长度
- d3.js保存状态
- 如何获取浏览器's”;背面“;按钮以清除d3.js可视化的先前状态
- 如何在d3.js中的每个状态中添加标签(albersUsa)
- 捕获D3库创建的可视化并将状态存储在DB中
- 如何在g元素中选择特定元素并在D3.js中更改其状态
- 如何在ui-view状态中使用D3
- 鼠标停留在一个状态上,用d3地图改变其他状态的颜色
- 使用d3-js和country topojson文件分别绘制状态