Skip to content

Commit

Permalink
feat: Improve color scheme type (vega#9015)
Browse files Browse the repository at this point in the history
Co-authored-by: GitHub Actions Bot <[email protected]>
  • Loading branch information
2 people authored and BradyJ27 committed Oct 19, 2023
1 parent ca9f418 commit fade349
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
6 changes: 3 additions & 3 deletions build/vega-lite-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -21936,7 +21936,7 @@
"scheme": {
"anyOf": [
{
"type": "string"
"$ref": "#/definitions/ColorScheme"
},
{
"$ref": "#/definitions/SchemeParams"
Expand Down Expand Up @@ -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": [
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

0 comments on commit fade349

Please sign in to comment.