将多个函数应用于d3.js对象,同时输入
这可能会在文档中得到回答,但我还没有解决 基本上我有一些标准的将多个函数应用于d3.js对象,同时输入,d3.js,dry,D3.js,Dry,这可能会在文档中得到回答,但我还没有解决 基本上我有一些标准的d3.js代码如下: group.selectAll('rect') .data(data) .enter().append('svg:rect') .style('fill', colour) .on('mouseover', function(d, i) { chart.currentHoverItem = d }) .on('mouseout', function(d, i) { chart.
d3.js
代码如下:
group.selectAll('rect')
.data(data)
.enter().append('svg:rect')
.style('fill', colour)
.on('mouseover', function(d, i) {
chart.currentHoverItem = d
})
.on('mouseout', function(d, i) {
chart.currentHoverItem = null
})
在我的代码中,我有一些相同的行,它们采用不同的方法。理想情况下,我希望这样做:
var addEvents() {
this.on('mouseover', function(d, i) { ... })
this.on('mouseout', function(d, i) { ... })
}
group.selectAll('rect')
.data(data)
.enter().append('svg:rect')
.apply(addEvents)
干涸此代码的最佳解决方案是什么?您可能正在寻找,请尝试以下方法:
function addEvents(selection) {
selection.on(...);
selection.on(...);
}
group.selectAll('rect')
.data(data)
.enter()
.append('svg:rect')
.call(addEvents);