Skip to content

Commit 08118dd

Browse files
authored
no scale if no data and no type (#756)
1 parent 1c5f971 commit 08118dd

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

src/scales.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,9 @@ function inferScaleType(key, channels, {type, domain, range, scheme}) {
229229
// If the scale, a channel, or user specified a (consistent) type, return it.
230230
if (type !== undefined) return type;
231231

232+
// If there’s no data (and no type) associated with this scale, don’t create a scale.
233+
if (domain === undefined && !channels.some(({value}) => value !== undefined)) return;
234+
232235
const kind = registry.get(key);
233236

234237
// For color scales, if no range or scheme is specified and all associated

test/plots/empty.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ export default async function() {
55
return Plot.plot({
66
grid: true,
77
inset: 6,
8-
x: {},
9-
y: {},
8+
x: {type: "linear"},
9+
y: {type: "linear"},
1010
marks: [
1111
Plot.frame(),
1212
undefined,

test/scales/scales-test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,13 +1112,13 @@ it("plot(…).scale('opacity') respects the percent option, affecting domain and
11121112
});
11131113

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

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

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

0 commit comments

Comments
 (0)