Skip to content
Merged
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
3 changes: 3 additions & 0 deletions src/scales.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,9 @@ function inferScaleType(key, channels, {type, domain, range, scheme}) {
// If the scale, a channel, or user specified a (consistent) type, return it.
if (type !== undefined) return type;

// If there’s no data (and no type) associated with this scale, don’t create a scale.
if (domain === undefined && !channels.some(({value}) => value !== undefined)) return;

const kind = registry.get(key);

// For color scales, if no range or scheme is specified and all associated
Expand Down
4 changes: 2 additions & 2 deletions test/plots/empty.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ export default async function() {
return Plot.plot({
grid: true,
inset: 6,
x: {},
y: {},
x: {type: "linear"},
y: {type: "linear"},
marks: [
Plot.frame(),
undefined,
Expand Down
8 changes: 4 additions & 4 deletions test/scales/scales-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1112,13 +1112,13 @@ it("plot(…).scale('opacity') respects the percent option, affecting domain and
});

it("plot({inset, …}).scale('x') does not allow insets or margins to invert the range", () => {
assert.deepStrictEqual(Plot.plot({x: {inset: 60}, width: 100}).scale("x").range, [80, 80]);
assert.deepStrictEqual(Plot.plot({x: {inset: 30}, margin: 30, width: 100}).scale("x").range, [60, 60]);
assert.deepStrictEqual(Plot.plot({x: {type: "linear", inset: 60}, width: 100}).scale("x").range, [80, 80]);
assert.deepStrictEqual(Plot.plot({x: {type: "linear", inset: 30}, margin: 30, width: 100}).scale("x").range, [60, 60]);
});

it("plot({inset, …}).scale('y') does not allow insets or margins to invert the range", () => {
assert.deepStrictEqual(Plot.plot({y: {inset: 60}, height: 100}).scale("y").range, [80, 80]);
assert.deepStrictEqual(Plot.plot({y: {inset: 30}, margin: 30, height: 100}).scale("y").range, [60, 60]);
assert.deepStrictEqual(Plot.plot({y: {type: "linear", inset: 60}, height: 100}).scale("y").range, [80, 80]);
assert.deepStrictEqual(Plot.plot({y: {type: "linear", inset: 30}, margin: 30, height: 100}).scale("y").range, [60, 60]);
});

it("plot({inset, …}).scale('x').range respects the given top-level inset", () => {
Expand Down