What is the correct argument for d3.brushSelection ()?

I'm trying to get selection values ​​for a one-dimensional brush, but it's hard for me to figure out what should be the argument for d3.brushSelection (). I see that the documentation says that the argument must be node, but I don’t know exactly what that means. Is this supposed to be the specific HTML element that the brush is invoked on, or the svg element that contains the brush? I have tried both and both return null.

var xBrush = d3.brushX()
  .extent([[0,0], [xWidth,xHeight]])
  .on("brush", brushed);

xChart.append("g")
  .attr("class", "brush")
  .call(xBrush);

If so, how do I create my brush, how can I get the selection value? Thank.

+4
source share
1 answer

The node required in the argument for d3.brushSelectionis the element gmatching your brush.

So, you can access the selection either through

d3.brushSelection(d3.select(".brush").node())

, ,

var xBrush = d3.brushX()
  .extent([[0,0], [xWidth,xHeight]])
  .on("brush", brushed);

var theBrush = xChart.append("g")
  .attr("class", "brush")
  .call(xBrush);

d3.brushSelection(theBrush.node());

, , null.

+3

Source: https://habr.com/ru/post/1648585/


All Articles