From fade34936eeaf497fc679b0d52fa67126c354d21 Mon Sep 17 00:00:00 2001 From: Andrew McNutt Date: Wed, 19 Jul 2023 07:35:04 -0500 Subject: [PATCH] feat: Improve color scheme type (#9015) Co-authored-by: GitHub Actions Bot --- build/vega-lite-schema.json | 6 +++--- src/scale.ts | 5 +++-- test/compile/scale/range.test.ts | 4 ++-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/build/vega-lite-schema.json b/build/vega-lite-schema.json index 465e8258dc0..1615f70b26a 100644 --- a/build/vega-lite-schema.json +++ b/build/vega-lite-schema.json @@ -21936,7 +21936,7 @@ "scheme": { "anyOf": [ { - "type": "string" + "$ref": "#/definitions/ColorScheme" }, { "$ref": "#/definitions/SchemeParams" @@ -22492,8 +22492,8 @@ "type": "array" }, "name": { - "description": "A color scheme name for ordinal scales (e.g., `\"category10\"` or `\"blues\"`).\n\nFor the full list of supported schemes, please refer to the [Vega Scheme](https://vega.github.io/vega/docs/schemes/#reference) reference.", - "type": "string" + "$ref": "#/definitions/ColorScheme", + "description": "A color scheme name for ordinal scales (e.g., `\"category10\"` or `\"blues\"`).\n\nFor the full list of supported schemes, please refer to the [Vega Scheme](https://vega.github.io/vega/docs/schemes/#reference) reference." } }, "required": [ diff --git a/src/scale.ts b/src/scale.ts index f97938c099c..395cf47783f 100644 --- a/src/scale.ts +++ b/src/scale.ts @@ -9,6 +9,7 @@ import { TimeIntervalStep } from 'vega'; import {isString} from 'vega-util'; +import type {ColorScheme} from 'vega-typings'; import * as CHANNEL from './channel'; import {Channel, isColorChannel} from './channel'; import {DateTime} from './datetime'; @@ -458,7 +459,7 @@ export interface SchemeParams { * * For the full list of supported schemes, please refer to the [Vega Scheme](https://vega.github.io/vega/docs/schemes/#reference) reference. */ - name: string | SignalRef; + name: ColorScheme | SignalRef; /** * The extent of the color range to use. For example `[0.2, 1]` will rescale the color scheme such that color values in the range _[0, 0.2)_ are excluded from the scheme. @@ -610,7 +611,7 @@ export interface Scale { * * For the full list of supported schemes, please refer to the [Vega Scheme](https://vega.github.io/vega/docs/schemes/#reference) reference. */ - scheme?: string | SchemeParams | ES; + scheme?: ColorScheme | SchemeParams | ES; /** * The alignment of the steps within the scale range. diff --git a/test/compile/scale/range.test.ts b/test/compile/scale/range.test.ts index a46dc1ce076..ed31590a8df 100644 --- a/test/compile/scale/range.test.ts +++ b/test/compile/scale/range.test.ts @@ -349,11 +349,11 @@ describe('compile/scale', () => { const model = parseUnitModelWithScaleExceptRange({ mark: 'point', encoding: { - color: {field: 'x', type: 'quantitative', scale: {scheme: {name: 'warm', extent: [0.2, 1]}}} + color: {field: 'x', type: 'quantitative', scale: {scheme: {name: 'warmgreys', extent: [0.2, 1]}}} } }); - expect(parseRangeForChannel('color', model)).toEqual(makeExplicit({scheme: 'warm', extent: [0.2, 1]})); + expect(parseRangeForChannel('color', model)).toEqual(makeExplicit({scheme: 'warmgreys', extent: [0.2, 1]})); }); it('should support custom range.', () => {