Skip to content

Commit 16dbbc9

Browse files
Filmbostock
andauthoredJan 26, 2022
don't crash on Plot.dot({ length: 1 }).plot() (#709)
* don't crash on Plot.dot({ length: 1 }).plot() * Update options.js * Update dot-test.js Co-authored-by: Mike Bostock <[email protected]>
·
v0.6.17v0.4.1
1 parent 180ad4e commit 16dbbc9

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed
 

‎src/options.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ export const zero = () => 0;
2424
export const string = x => x == null ? x : `${x}`;
2525
export const number = x => x == null ? x : +x;
2626
export const boolean = x => x == null ? x : !!x;
27-
export const first = d => d[0];
28-
export const second = d => d[1];
27+
export const first = x => x ? x[0] : undefined;
28+
export const second = x => x ? x[1] : undefined;
2929
export const constant = x => () => x;
3030

3131
// Some channels may allow a string constant to be specified; to differentiate

‎test/marks/dot-test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ it("dot() has the expected defaults", () => {
2222
assert.strictEqual(dot.shapeRendering, undefined);
2323
});
2424

25+
it("dot accepts undefined data", () => {
26+
Plot.dot({length: 1}).initialize();
27+
});
28+
2529
it("dot(data, {r}) allows r to be a constant radius", () => {
2630
const dot = Plot.dot(undefined, {r: 42});
2731
assert.strictEqual(dot.r, 42);

0 commit comments

Comments
 (0)
Please sign in to comment.