diff --git a/src/scales.js b/src/scales.js index 5bc4865f04..a94ab7ef78 100644 --- a/src/scales.js +++ b/src/scales.js @@ -376,10 +376,16 @@ function formatScaleType(type) { return typeof type === "symbol" ? type.description : type; } +function maybeScaleType(type) { + return typeof type === "string" ? `${type}`.toLowerCase() : type; +} + // A special type symbol when the x and y scales are replaced with a projection. const typeProjection = {toString: () => "projection"}; function inferScaleType(key, channels, {type, domain, range, scheme, pivot, projection}) { + type = maybeScaleType(type); + // The facet scales are always band scales; this cannot be changed. if (key === "fx" || key === "fy") return "band"; @@ -391,7 +397,8 @@ function inferScaleType(key, channels, {type, domain, range, scheme, pivot, proj // If a channel dictates a scale type, make sure that it is consistent with // the user-specified scale type (if any) and all other channels. For example, // barY requires x to be a band scale and disallows any other scale type. - for (const {type: t} of channels) { + for (const channel of channels) { + const t = maybeScaleType(channel.type); if (t === undefined) continue; else if (type === undefined) type = t; else if (type !== t) throw new Error(`scale incompatible with channel: ${type} !== ${t}`); diff --git a/test/scales/scales-test.js b/test/scales/scales-test.js index faa4ab6d1b..08558d732d 100644 --- a/test/scales/scales-test.js +++ b/test/scales/scales-test.js @@ -37,6 +37,12 @@ it("Plot does not throw an error if a quantile scale has a non-monotonic domain" }); }); +it("Scale types are lowercased", () => { + assert.strictEqual(Plot.scale({x: {type: "UTC"}}).type, "utc"); + assert.strictEqual(Plot.scale({color: {type: "OrDiNaL"}}).type, "ordinal"); + assert.strictEqual(Plot.scale({fx: {type: "BAND"}}).type, "band"); +}); + it("Plot.scale(description) returns a standalone scale", () => { const color = Plot.scale({color: {type: "linear"}}); scaleEqual(color, {