Skip to content

Commit d0e41cb

Browse files
committed
error if projection and band-requiring channels
1 parent 4b561a4 commit d0e41cb

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/scales.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -307,9 +307,9 @@ function inferScaleType(key, channels, {type, domain, range, scheme, pivot, proj
307307
if (key === "fx" || key === "fy") return "band";
308308

309309
// If a projection is specified, the x- and y-scales are disabled; these
310-
// channels will be projected rather than scaled. TODO Throw an error if these
311-
// scales are specified in conjunction with a projection.
312-
if ((key === "x" || key === "y") && projection != null) return;
310+
// channels will be projected rather than scaled. (But still check that none
311+
// of the associated channels are incompatible with a projection.)
312+
if ((key === "x" || key === "y") && projection != null) type = "projection";
313313

314314
// If a channel dictates a scale type, make sure that it is consistent with
315315
// the user-specified scale type (if any) and all other channels. For example,
@@ -321,6 +321,7 @@ function inferScaleType(key, channels, {type, domain, range, scheme, pivot, proj
321321
}
322322

323323
// If the scale, a channel, or user specified a (consistent) type, return it.
324+
if (type === "projection") return;
324325
if (type !== undefined) return type;
325326

326327
// If there’s no data (and no type) associated with this scale, don’t create a scale.

test/marks/cell-test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,7 @@ it("cellY() defaults y to identity and x to null", () => {
125125
);
126126
assert.strictEqual(cell.channels.y.type, "band");
127127
});
128+
129+
it("cell() is incompatible with a projection", () => {
130+
assert.throws(() => Plot.cell([]).plot({projection: "equal-earth"}), /scale incompatible with channel: projection !== band/);
131+
});

0 commit comments

Comments
 (0)