Skip to content

Commit a8c46fe

Browse files
committed
{selection} sets the initial position of the brush
1 parent a8b4a0e commit a8c46fe

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/marks/brush.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export class Brush extends Mark {
1111
{
1212
x = first,
1313
y = second,
14+
selection,
1415
transform,
1516
...style
1617
} = {}
@@ -25,6 +26,7 @@ export class Brush extends Mark {
2526
transform
2627
);
2728
Style(this, style);
29+
this.initialSelection = selection;
2830
}
2931
render(
3032
I,
@@ -78,7 +80,20 @@ export class Brush extends Mark {
7880
svg = g.node().ownerSVGElement;
7981
if (!svg.__brushes) svg.__brushes = [];
8082
svg.__brushes.push({b: brush, g});
81-
g.call(brush.clear);
83+
if (this.initialSelection) {
84+
const s = this.initialSelection;
85+
if (x && y) {
86+
const [x0, x1] = extent([x(s[0][0]), x(s[1][0])]);
87+
const [y0, y1] = extent([y(s[0][1]), y(s[1][1])]);
88+
g.call(brush.move, [[x0, y0], [x1, y1]]);
89+
} else if (x) {
90+
g.call(brush.move, extent(s.map(x)));
91+
} else if (y) {
92+
g.call(brush.move, extent(s.map(y)));
93+
}
94+
} else {
95+
g.call(brush.clear);
96+
}
8297
}, 1);
8398

8499
return g.node();

0 commit comments

Comments
 (0)