Skip to content

Commit 41048e1

Browse files
committed
add an onbrush option which receives the D3 brush event (?) and the selected data
defaults to sending a customEvent to the figure
1 parent 8372bb1 commit 41048e1

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/marks/brush.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export class Brush extends Mark {
1212
y = second,
1313
selection,
1414
transform,
15+
onbrush,
1516
...style
1617
} = {}
1718
) {
@@ -26,6 +27,7 @@ export class Brush extends Mark {
2627
);
2728
Style(this, style);
2829
this.initialSelection = selection;
30+
this.onbrush = onbrush;
2931
}
3032
render(
3133
I,
@@ -34,6 +36,7 @@ export class Brush extends Mark {
3436
{marginLeft, width, marginRight, marginTop, height, marginBottom}
3537
) {
3638
let svg;
39+
const {onbrush} = this;
3740
const g = create("svg:g");
3841
const data = this.data;
3942

@@ -62,10 +65,14 @@ export class Brush extends Mark {
6265
}
6366
}
6467
const dots = selection ? Array.from(index, i => J[i]) : data;
65-
66-
if (svg) {
68+
69+
if (typeof onbrush === "function") {
70+
onbrush(event, dots);
71+
} else if (svg) {
6772
svg.value = dots;
6873
svg.dispatchEvent(new CustomEvent('input'));
74+
}
75+
if (svg) {
6976
if (sourceEvent && type === "start") {
7077
for (const {b, g} of svg.__brushes) {
7178
if (b !== brush) g.call(b.clear);

0 commit comments

Comments
 (0)