Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Improve color scheme type #9015

Merged
merged 8 commits into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions build/vega-lite-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -21912,7 +21912,7 @@
"scheme": {
"anyOf": [
{
"type": "string"
"$ref": "#/definitions/ColorScheme"
},
{
"$ref": "#/definitions/SchemeParams"
Expand Down Expand Up @@ -22468,8 +22468,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": [
Expand Down
5 changes: 3 additions & 2 deletions src/scale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -610,7 +611,7 @@ export interface Scale<ES extends ExprRef | SignalRef = ExprRef | SignalRef> {
*
* 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.
Expand Down
4 changes: 2 additions & 2 deletions test/compile/scale/range.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.', () => {
Expand Down