Skip to content

Commit d516b19

Browse files
committed
detect root if it's a figure
1 parent ee1c090 commit d516b19

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

src/marks/brush.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export class Brush extends Mark {
2525
{x: X, y: Y, picker: J},
2626
{marginLeft, width, marginRight, marginTop, height, marginBottom}
2727
) {
28-
let svg;
28+
let root;
2929
const {onbrush} = this;
3030
const g = create("svg:g");
3131
const data = this.data;
@@ -52,13 +52,13 @@ export class Brush extends Mark {
5252

5353
if (typeof onbrush === "function") {
5454
onbrush(event, dots);
55-
} else if (svg) {
56-
svg.value = dots;
57-
svg.dispatchEvent(new CustomEvent('input'));
55+
} else if (root) {
56+
root.value = dots;
57+
root.dispatchEvent(new CustomEvent('input'));
5858
}
59-
if (svg) {
59+
if (root) {
6060
if (sourceEvent && type === "start") {
61-
for (const {b, g} of svg.__brushes) {
61+
for (const {b, g} of root.__brushes) {
6262
if (b !== brush) g.call(b.clear);
6363
}
6464
}
@@ -73,12 +73,13 @@ export class Brush extends Mark {
7373
* - register the multiple brushes (for faceting)
7474
*/
7575
setTimeout(() => {
76-
svg = g.node().ownerSVGElement;
77-
if (!svg.__brushes) svg.__brushes = [];
78-
svg.__brushes.push({b: brush, g});
76+
const svg = g.node().ownerSVGElement;
77+
root = svg.parentElement?.nodeName === "FIGURE" ? svg.parentElement : svg;
78+
if (!root.__brushes) root.__brushes = [];
79+
root.__brushes.push({b: brush, g});
7980

8081
// initial setup works only on one facet
81-
if (svg.__brushes.length === 1) {
82+
if (root.__brushes.length === 1) {
8283
if (this.initialSelection) {
8384
const s = this.initialSelection;
8485
if (X && Y) {

0 commit comments

Comments
 (0)