【发布时间】:2018-08-10 01:30:37
【问题描述】:
TL;DR:你如何移动d3.select('#a_brush')?
问题
我在<g> 群组中有画笔,名为axes。每个<g> 轴包含一个d3 轴和一个d3 画笔。在axes 的更新选择中,我想更新 d3 轴和画笔。
axes.each(function (d) { d3.select(this).select('.axis').call(d3.axisBottom(d[1])) });
axes.each(function (d) { d3.select(this).select('.brush').call(brush.move, f(d)) });
在上面,axes 是一个更新选择。假设f(d) 产生一个合适的数组。两行中的第一行有效,但第二行抛出:
Uncaught TypeError: Cannot read property 'move' of undefined
这可能是因为我在任何地方都没有保存名为画笔的变量。我希望直接在选择上调用.move 方法,而不必保存画笔变量。
在选择中移动画笔的合适命名是什么
axes.each(function (d) { d3.select(this).select('.brush') ?? ... somehow move the brush to f(d) ...
注意事项
- d3 brush.move() docs
-
"Click-to-Recenter Brush" Block 和 Brush & Zoom 有一个
.call(brush.move和一个保存的brush变量。 -
Brush Snapping III 和 Brush Snapping II
有
d3.select(this).call(d3.event.target.move,但我可能不会从任何最近的 d3 事件中移动画笔。
【问题讨论】:
标签: javascript d3.js