[英]D3 brush extent disappears from chart when dragged beyond extent
I've put together a chart in D3 that uses a vertically-sliding brush with a circular handle, plus a horizontal line to show intersection with a curve: 我在D3中整理了一个图表,该图表使用具有圆柄的垂直滑动笔刷以及一条水平线来显示与曲线的交点:
. 。 .
。 .
。 but the brush extent, handle and line all disappear from the chart when I drag the handle past point of extent = 0:
但是当我将鼠标指针拖到范围= 0时,画笔范围,手柄和线都从图表中消失了:
I've disabled the upper brush handle since this is a one-directional tool, but I suspect that may be the problem. 由于这是一种单向工具,因此我已禁用了上刷柄,但我怀疑这可能是问题所在。 I've also tried changing the margins to expose ">100% of the brush height", but the elements still disappear in the same way.
我还尝试过更改边距以显示“> 100%的笔刷高度”,但是元素仍然以相同的方式消失。 Have I improperly defined the brush parameters or is this worth filing a ticket in the D3 repo?
我是否定义了画笔参数不正确,还是值得在D3存储库中提交票证?
Here's the complete example: http://bl.ocks.org/wboykinm/1a2806d828cb3fa64c4d 这是完整的示例: http : //bl.ocks.org/wboykinm/1a2806d828cb3fa64c4d
Thanks! 谢谢!
This is because at that point your brush has an extent of 0 and thus is empty. 这是因为此时您的笔刷的范围为0,因此为空。 If you look at the source code , an empty brush will have its
display
set to none
. 如果您查看源代码 ,则空画笔将其
display
设置为none
。 You can see this at play if you inspect the g
element with class of .resize.s
with the browser developer tools. 如果使用浏览器开发人员工具检查类
.resize.s
的g
元素,则可以在运行时看到这一点。
One possible fix is to add this to a brushend
listener: 一种可能的解决方法是将其添加到
brushend
侦听器:
// Add the brush to the Y axis, set to 10% of the extent
var brush = d3.svg.brush()
.y(y)
.extent([0,0.1])
.on("brushend", function(){
brushg.selectAll(".resize.s")
.style("display","inline")
});
Here is a PLUNK with this solution. 这是带有此解决方案的PLUNK 。
You may not have to deal with this once you start really working with the brush in your chart. 一旦真正开始使用图表中的画笔,您可能就不必处理此问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.