diff --git a/src/scales.js b/src/scales.js index ef76725ab7..2512b9b67c 100644 --- a/src/scales.js +++ b/src/scales.js @@ -2,6 +2,7 @@ import {registry, position, radius} from "./scales/index.js"; import {ScaleDiverging, ScaleLinear, ScalePow, ScaleLog, ScaleSymlog} from "./scales/quantitative.js"; import {ScaleTime, ScaleUtc} from "./scales/temporal.js"; import {ScaleOrdinal, ScalePoint, ScaleBand} from "./scales/ordinal.js"; +import {ScaleIdentity} from "./scales/identity.js"; export function Scales(channels, {inset, round, nice, align, padding, ...options} = {}) { const scales = {}; @@ -43,6 +44,7 @@ function Scale(key, channels = [], options = {}) { case "time": return ScaleTime(key, channels, options); case "point": return ScalePoint(key, channels, options); case "band": return ScaleBand(key, channels, options); + case "identity": return ScaleIdentity(key, channels, options); case undefined: return; default: throw new Error(`unknown scale type: ${options.type}`); } diff --git a/src/scales/identity.js b/src/scales/identity.js new file mode 100644 index 0000000000..10a76f769e --- /dev/null +++ b/src/scales/identity.js @@ -0,0 +1,21 @@ +import {scaleIdentity} from "d3-scale"; +import {ScaleO} from "./ordinal.js"; +import {ScaleQ} from "./quantitative.js"; + +export function ScaleIdentity(key, channels, options) { + let type = "quantitative"; + for (const c of channels) { + for (const v of c.value) { + if (typeof v === "string") { + type = "ordinal"; + break; + } + } + } + switch (type) { + case "ordinal": + return ScaleO(Object.assign(x => x, { domain: () => {} }), channels, options); + case "quantitative": + return ScaleQ(key, scaleIdentity(), channels, options); + } +} diff --git a/test/identity-scale-test.html b/test/identity-scale-test.html new file mode 100644 index 0000000000..7ae033ab76 --- /dev/null +++ b/test/identity-scale-test.html @@ -0,0 +1,28 @@ + + + + + +