Skip to content
Closed
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/legends.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ function legendColor(color, {legend = true, ...options}) {
case "swatches":
return legendSwatches(color, options);
case "ramp":
if (color.domain.length < 2) return;
return legendRamp(color, options);
default:
throw new Error(`unknown legend type: ${legend}`);
Expand Down
5 changes: 5 additions & 0 deletions test/legend-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ it(`Plot.legend({color: {type: "identity"}}) returns undefined`, () => {
assert.strictEqual(Plot.legend({color: {type: "identity"}}), undefined);
});

it(`Plot.legend({color: {domain: [x?]}}) returns undefined`, () => {
assert.strictEqual(Plot.legend({color: {domain: []}}), undefined);
assert.strictEqual(Plot.legend({color: {domain: [1]}}), undefined);
});

it(`Plot.legend({legend: "swatches", color: {type: "<not-ordinal>"}}) throws an error`, () => {
assert.throws(() => Plot.legend({legend: "swatches", color: {type: "linear"}}), /swatches legend requires ordinal/);
assert.throws(() => Plot.legend({legend: "swatches", color: {type: "linear"}}), /\(not linear\)/);
Expand Down