Skip to content

Commit 36d34dd

Browse files
committed
for band scales, lasso catches the center of the shape
1 parent 84f6f92 commit 36d34dd

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/marks/lasso.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export class Lasso extends Mark {
2828

2929
// The lasso polygons follow the even-odd rule in css, matching the way
3030
// they are computed by polygonContains.
31-
render(index, scales, {x: X, y: Y}, dimensions) {
31+
render(index, {x, y}, {x: X, y: Y}, dimensions) {
3232
const margin = 5;
3333
const {ariaLabel, ariaDescription, ariaHidden, fill, fillOpacity, stroke, strokeWidth} = this;
3434
const {marginLeft, width, marginRight, marginTop, height, marginBottom} = dimensions;
@@ -53,9 +53,15 @@ export class Lasso extends Mark {
5353
.data(polygons)
5454
.join("path")
5555
.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+
}
5965
if (!selectionEquals(node[selection], S)) {
6066
node[selection] = S;
6167
node.dispatchEvent(new Event("input", {bubbles: true}));

0 commit comments

Comments
 (0)