@@ -38,18 +38,17 @@ function brushTransform(mode, {selectionMode = "data", ...options}) {
38
38
] ;
39
39
const brush = ( mode === "xy" ? brusher : mode === "x" ? brusherX : brusherY ) ( )
40
40
. extent ( extent )
41
- . on ( "brush start end" , function ( event ) {
42
- const f = select ( this ) . datum ( ) ;
41
+ . on ( "brush start end" , function ( event , d ) {
43
42
const { type, selection} = event ;
44
43
let S = null ;
45
- const [ X , Y ] = selection
46
- ? mode === "xy"
47
- ? transpose ( selection )
48
- : mode === "x"
49
- ? [ selection ]
50
- : [ , selection ]
51
- : [ ] ;
52
- if ( X || Y ) S = f . index ;
44
+ const [ X , Y ] = ! selection
45
+ ? [ ]
46
+ : mode === "xy"
47
+ ? transpose ( selection )
48
+ : mode === "x"
49
+ ? [ selection ]
50
+ : [ , selection ] ;
51
+ if ( X || Y ) S = d . index ;
53
52
if ( X ) {
54
53
const [ x0 , x1 ] = X ;
55
54
S = S . filter ( ( i ) => x0 <= Xm [ i ] && Xl [ i ] <= x1 ) ;
@@ -59,9 +58,9 @@ function brushTransform(mode, {selectionMode = "data", ...options}) {
59
58
S = S . filter ( ( i ) => y0 <= Ym [ i ] && Yl [ i ] <= y1 ) ;
60
59
}
61
60
// Only one facet can be active at a time; clear the others.
62
- if ( type === "start" ) for ( let i = 0 ; i < cancels . length ; ++ i ) if ( i !== ( f . index . fi ?? 0 ) ) cancels [ i ] ( ) ;
61
+ if ( type === "start" ) for ( let i = 0 ; i < cancels . length ; ++ i ) if ( i !== ( d . index . fi ?? 0 ) ) cancels [ i ] ( ) ;
63
62
64
- f . display . replaceWith ( ( f . display = next . call ( this , S ?? [ ] , scales , values , dimensions , context ) ) ) ;
63
+ d . display . replaceWith ( ( d . display = next . call ( this , S ?? [ ] , scales , values , dimensions , context ) ) ) ;
65
64
66
65
// Update the plot’s value if the selection has changed.
67
66
if ( selectionMode === "data" ) {
@@ -102,6 +101,7 @@ function brushTransform(mode, {selectionMode = "data", ...options}) {
102
101
// When the plot is complete, append the target element to the top
103
102
// (z-index), translate it to match the facet’s frame position, and
104
103
// initialize the plot’s value.
104
+ // TODO: cleaner.
105
105
if ( typeof requestAnimationFrame === "function" ) {
106
106
requestAnimationFrame ( ( ) => {
107
107
select ( svg )
0 commit comments