Skip to content

Commit 8372bb1

Browse files
committed
allow 1-d brush (brushX / brushY) on 2-dimensional charts
1 parent 0b7fe2c commit 8372bb1

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

src/marks/brush.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,25 +38,26 @@ export class Brush extends Mark {
3838
const data = this.data;
3939

4040
// compute the scaled channels
41-
if (x && this.X === undefined) this.X = X.map(x);
42-
if (y && this.Y === undefined) this.Y = Y.map(y);
41+
if (X && this.X === undefined) this.X = X.map(x);
42+
if (Y && this.Y === undefined) this.Y = Y.map(y);
4343
({X, Y} = this);
4444

4545
const bounds = [
4646
[Math.floor(marginLeft), Math.floor(marginTop)],
4747
[Math.ceil(width - marginRight), Math.ceil(height - marginBottom)]
4848
];
49-
const brush = (x && y ? brusher : x ? brusherX : brusherY)()
49+
const brush = (X && Y ? brusher : X ? brusherX : brusherY)()
5050
.extent(bounds)
51-
.on("start brush end", ({type, selection, sourceEvent}) => {
51+
.on("start brush end", (event) => {
52+
const {type, selection, sourceEvent} = event;
5253
let index = filter(I, X, Y);
5354
if (selection) {
54-
if (x) {
55-
const [x0, x1] = y ? [selection[0][0], selection[1][0]] : selection;
55+
if (X) {
56+
const [x0, x1] = Y ? [selection[0][0], selection[1][0]] : selection;
5657
index = index.filter(i => X[i] >= x0 && X[i] <= x1);
5758
}
58-
if (y) {
59-
const [y0, y1] = x ? [selection[0][1], selection[1][1]] : selection;
59+
if (Y) {
60+
const [y0, y1] = X ? [selection[0][1], selection[1][1]] : selection;
6061
index = index.filter(i => Y[i] >= y0 && Y[i] <= y1);
6162
}
6263
}
@@ -89,17 +90,17 @@ export class Brush extends Mark {
8990
if (svg.__brushes.length === 1) {
9091
if (this.initialSelection) {
9192
const s = this.initialSelection;
92-
if (x && y) {
93+
if (X && Y) {
9394
const [x0, x1] = extent([x(s[0][0]), x(s[1][0])]);
9495
const [y0, y1] = extent([y(s[0][1]), y(s[1][1])]);
9596
g.call(brush.move, [
9697
[ max(x0, bounds[0][0]), max(y0, bounds[0][1]) ],
9798
[ min(x1, bounds[1][0]), min(y1, bounds[1][1]) ]
9899
]);
99-
} else if (x) {
100+
} else if (X) {
100101
const [x0, x1] = extent(s.map(x));
101102
g.call(brush.move, [ max(x0, bounds[0][0]), min(x1, bounds[1][0]) ]);
102-
} else if (y) {
103+
} else if (Y) {
103104
const [y0, y1] = extent(s.map(y));
104105
g.call(brush.move, [ max(y0, bounds[0][1]), min(y1, bounds[1][1]) ]);
105106
}

0 commit comments

Comments
 (0)