Skip to content

Commit 109fc72

Browse files
authored
avoid stack overflow with negative radius (#2404)
1 parent f4a989c commit 109fc72

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

src/transforms/dodge.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ function dodge(y, x, anchor, padding, r, options) {
7878
const radius = R ? (i) => R[i] : () => cr;
7979
for (let I of facets) {
8080
const tree = IntervalTree();
81-
I = I.filter(R ? (i) => finite(X[i]) && positive(R[i]) : (i) => finite(X[i]));
81+
I = I.filter(R ? (i) => finite(X[i]) && positive(R[i]) : cr > 0 ? (i) => finite(X[i]) : () => false);
8282
const intervals = new Float64Array(2 * I.length + 2);
8383
for (const i of I) {
8484
const ri = radius(i);
Lines changed: 38 additions & 0 deletions
Loading

test/plots/penguin-dodge.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,11 @@ test(async function penguinDodge() {
99
marks: [Plot.dot(penguins, Plot.dodgeY({x: "body_mass_g"}))]
1010
});
1111
});
12+
13+
test(async function penguinDodgeNegativeRadius() {
14+
const penguins = await d3.csv<any>("data/penguins.csv", d3.autoType);
15+
return Plot.plot({
16+
height: 200,
17+
marks: [Plot.dot(penguins, Plot.dodgeY({x: "body_mass_g", r: -1}))]
18+
});
19+
});

0 commit comments

Comments
 (0)