@@ -28,7 +28,7 @@ export class Lasso extends Mark {
28
28
29
29
// The lasso polygons follow the even-odd rule in css, matching the way
30
30
// they are computed by polygonContains.
31
- render ( index , scales , { x : X , y : Y } , dimensions ) {
31
+ render ( index , { x , y } , { x : X , y : Y } , dimensions ) {
32
32
const margin = 5 ;
33
33
const { ariaLabel, ariaDescription, ariaHidden, fill, fillOpacity, stroke, strokeWidth} = this ;
34
34
const { marginLeft, width, marginRight, marginTop, height, marginBottom} = dimensions ;
@@ -53,9 +53,15 @@ export class Lasso extends Mark {
53
53
. data ( polygons )
54
54
. join ( "path" )
55
55
. attr ( "d" , path ) ;
56
- const activePolygons = polygons . find ( polygon => polygon . length > 2 ) ;
57
- const S = ! activePolygons ? null
58
- : index . filter ( i => polygons . some ( polygon => polygon . length > 2 && polygonContains ( polygon , [ X [ i ] , Y [ i ] ] ) ) ) ;
56
+ let S = null ;
57
+ let activePolygons = polygons . filter ( polygon => polygon . length > 2 ) ;
58
+ if ( activePolygons . length > 0 ) {
59
+ let bw ;
60
+ if ( x . bandwidth && ( bw = x . bandwidth ( ) / 2 ) ) activePolygons = activePolygons . map ( polygon => polygon . map ( p => [ p [ 0 ] - bw , p [ 1 ] ] ) ) ;
61
+ if ( y . bandwidth && ( bw = y . bandwidth ( ) / 2 ) ) activePolygons = activePolygons . map ( polygon => polygon . map ( p => [ p [ 0 ] , p [ 1 ] - bw ] ) ) ;
62
+ S = index . filter ( i => activePolygons . some ( polygon => polygonContains ( polygon , [ X [ i ] , Y [ i ] ] ) ) ) ;
63
+
64
+ }
59
65
if ( ! selectionEquals ( node [ selection ] , S ) ) {
60
66
node [ selection ] = S ;
61
67
node . dispatchEvent ( new Event ( "input" , { bubbles : true } ) ) ;
0 commit comments