2
D3版本4.2.2如何重置/清除d3刷子?
我有一個圖表,我希望用戶能夠跟上刷選擇放大英寸我想在結束事件中清除或重置筆刷,以便用戶看不到舊筆刷。
當前打字稿代碼:
let brushGroup = this.svg.append('g')
.attr('class', 'brush');
let b = brushX()
.on('start',() => {
console.log('start brush');
brushGroup.style('opacity', 100);
})
.on('end',() => {
console.log('end brush', event.selection);
// remove and display none destroy the brush, so use opacity
brushGroup.style('opacity', 0);
this.updateDateRange(this.xScale.invert(event.selection[0]),
this.xScale.invert(event.selection[1]));
});
brushGroup.call(b);
console.log(brushGroup);
display: none
防止未來刷啓動事件brushGroup.remove()
也破壞了刷- 不透明的作品,但刷仍然存在(鼠標光標會變成上懸停)
那麼清除或重置畫筆的正確方法是什麼?
- 我應該把它移動到0,0嗎?
- 我應該摧毀舊的刷子,並創建一個新的每一次?
我決定只刪除並重新創建結束事件中的brushGroup(克元件)各一次。這很好,但如果有更好的方法,我仍然很好奇。 – Arlo