You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Since we want to support brushing histograms, we needed two additional features:
* an **interval** option for snapping the brush on gesture end.
* support for X1/X2 channels in renderFilter, for rect marks.
(This will require some work to merge with #2363)
Copy file name to clipboardExpand all lines: docs/interactions/brush.md
+97-12Lines changed: 97 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -44,6 +44,40 @@ Plot.plot({
44
44
45
45
The brush mark does not require data. When added to a plot, it renders a [brush](https://d3js.org/d3-brush) overlay covering the frame. The user can click and drag to create a rectangular selection, drag the selection to reposition it, or drag an edge or corner to resize it. Clicking outside the selection clears it.
Similarly, the **brushY** mark operates on the *y* axis.
80
+
47
81
## Input events
48
82
49
83
The brush dispatches an [*input* event](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/input_event) whenever the selection changes. The plot’s value (`plot.value`) is set to a [BrushValue](#brushvalue) object when a selection is active, or null when the selection is cleared. This allows you to use a plot as an [Observable view](https://observablehq.com/@observablehq/views), or to register an *input* event listener to react to the brush.
The **filter** function on the brush value tests whether a data point falls inside the selection. Its signature depends on whether the plot uses faceting:
93
+
The **filter** function on the brush value tests whether a data point falls inside the selection. Its signature depends on whether the plot uses faceting, and on the brush’s dimension:
@@ -199,7 +233,7 @@ The brush value dispatched on [_input_ events](#input-events). When the brush is
199
233
- **filter** - a function to test whether a point is inside the selection
200
234
- **pending** - `true` during interaction; absent when committed
201
235
202
-
By convention, *x1* < *x2* and *y1* < *y2*.
236
+
By convention, *x1* < *x2* and *y1* < *y2*. The brushX mark does not dispatch *y1* and *y2*; similarly, the brushY mark does not dispatch *x1* and *x2*.
203
237
204
238
The **pending** property indicates the user is still interacting with the brush. To skip intermediate values and react only to committed selections:
205
239
@@ -248,7 +282,11 @@ Returns mark options that hide the mark by default and, during brushing, show on
248
282
brush.move({x1:36, x2:48, y1:15, y2:20})
249
283
```
250
284
251
-
Programmatically sets the brush selection in data space. The *value* must have **x1**, **x2**, **y1**, and **y2** properties. For faceted plots, include **fx** or **fy** to target a specific facet. Pass null to clear the selection.
285
+
Programmatically sets the brush selection in data space. For a 2D brush, the *value* must have **x1**, **x2**, **y1**, and **y2** properties; for brushX, **x1** and **x2**; for brushY, **y1** and **y2**. For faceted plots, include **fx** or **fy** to target a specific facet. Pass null to clear the selection.
For projected plots, the coordinates are in pixels (consistent with the [BrushValue](#brushvalue)), so you need to project the two corners of the brush beforehand. In the future Plot might expose its *projection* to facilitate this. Please upvote [this issue](https://github.com/observablehq/plot/issues/1191) to help prioritize this feature.
300
+
301
+
## brushX(*options*) {#brushX}
302
+
303
+
```js
304
+
constbrush=Plot.brushX()
305
+
```
306
+
307
+
Returns a new horizontal brush mark that selects along the *x* axis. The available *options* are:
308
+
309
+
- **interval** - an interval to snap the brush to on release; a number for quantitative scales (_e.g._, `100`), a time interval name for temporal scales (_e.g._, `"month"`), or an object with *floor* and *offset* methods
310
+
311
+
When an **interval** is set, the selection snaps to interval boundaries on release, and the filter rounds values before testing, for consistency with binned marks using the same interval. (Use the same interval in the bin transform so the brush aligns with bin edges.)
0 commit comments