2

Hi excuse the newbie nature of this question (and code snippet).

I want to set the extent of a brush. I firstly, I better make sure that my definition of "extent" is correct.

It seems that in most brush examples (such as this: http://bl.ocks.org/mbostock/6232620 ) when the user is initially presented with the brush -- a region is not selected.

I would like to set an initial region...so that the user can already see a selection.

I figure that this selected region is called the "extent".

I have defined my brush as follows:

var the_brush = d3.brushX().extent([[0, 0], [width, height]]).handleSize(50).on("brush", brushed);

And then attach it to an svg element using the following:

svg.append("g").attr("class", "brush").call(the_brush);

The height and width are initially defined as 50 and 880 respectively.

I then figure that I should be able to experiment in Chrome console to redefine the extent such that a shaded area is displayed.

I use this command (in the Chrome console):

the_brush.extent([200, 0], [500, 50])

But a function is returned.

Mmmm I am obviously missing something quite fundamentially here...by what..?

I hope it is clear from my question...my actual objective. That is when the user first opens the page that (s)he is presented with a brush widget that already has a portion selected.

There is a hacky (but working) copy of the code here

My question is similar to a previous question here

But I do not think that the previous solution is applicaton to D3 version 4.

Thanks.

Community
  • 1
  • 1
markthekoala
  • 1,065
  • 1
  • 11
  • 24
  • that is correct, brush.extent will return a function, which when called on the selection will set the brush positions. – Chirag Kothari Oct 10 '16 at 03:32
  • Thanks very much @ChiragKothari. Okay so I try to do the following in Chrome console: fn_new_brush = the_brush.extent([200, 0], [500, 50]) d3.select("g.brush").call(fn_new_brush) Nothing changes. And lots of errors are recorded. Mmm I am thinking that actually that extent is the incorrect method. This seems to simplly define what region can contain a brush...but it does not seem to determine what is initially displayed.... – markthekoala Oct 10 '16 at 04:23
  • There is a copy of the working code [link](http://plnkr.co/edit/ZTN3rYNwEKxJWNdoIxNK?p=preview). My question is very similar to a previous question [here](http://stackoverflow.com/questions/24350893/how-to-set-d3-brush-extent-right?rq=1) But I suspect that the solution no longer applies to version 4. – markthekoala Oct 10 '16 at 06:55
  • https://stackoverflow.com/questions/42781226/d3-js-v3-to-v4-brush-changes – Abhishek2k6 Feb 21 '18 at 11:17

0 Answers0