Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/transforms/dodge.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ function dodge(y, x, anchor, padding, r, options) {
if (!channels[x]) throw new Error(`missing channel: ${x}`);
({[x]: X} = applyPosition(channels, scales, context));
const cr = R ? undefined : r !== undefined ? number(r) : this.r !== undefined ? this.r : 3;
if (cr !== undefined && !(cr > 0)) throw new Error(`invalid dodge radius: ${cr}`);
if (R) R = valueof(R.value, scales[R.scale] || identity, Float64Array);
let [ky, ty] = anchor(dimensions);
const compare = ky ? compareAscending : compareSymmetric;
Expand Down
12 changes: 12 additions & 0 deletions test/transforms/dodge-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import * as Plot from "@observablehq/plot";
import assert from "assert";
import it from "../jsdom.js";

it("dodgeY throws on non-positive constant r", () => {
assert.throws(() => Plot.dot([1, 2, 3], Plot.dodgeY({x: Plot.identity, r: -1})).plot(), /invalid dodge radius/);
assert.throws(() => Plot.dot([1, 2, 3], Plot.dodgeY({x: Plot.identity, r: 0})).plot(), /invalid dodge radius/);
});

it("dodgeX throws on non-positive constant r", () => {
assert.throws(() => Plot.dot([1, 2, 3], Plot.dodgeX({y: Plot.identity, r: -1})).plot(), /invalid dodge radius/);
});
Loading