diff --git a/build/vega-lite-schema.json b/build/vega-lite-schema.json index 0e99779025..c169ce5c8f 100644 --- a/build/vega-lite-schema.json +++ b/build/vega-lite-schema.json @@ -7665,14 +7665,7 @@ "params": { "description": "Dynamic variables or selections that parameterize a visualization.", "items": { - "anyOf": [ - { - "$ref": "#/definitions/VariableParameter" - }, - { - "$ref": "#/definitions/TopLevelSelectionParameter" - } - ] + "$ref": "#/definitions/TopLevelParameter" }, "type": "array" }, @@ -9268,14 +9261,7 @@ "params": { "description": "An array of parameters that may either be simple variables, or more complex selections that map user input to data queries.", "items": { - "anyOf": [ - { - "$ref": "#/definitions/VariableParameter" - }, - { - "$ref": "#/definitions/SelectionParameter" - } - ] + "$ref": "#/definitions/SelectionParameter" }, "type": "array" }, @@ -11092,14 +11078,7 @@ "params": { "description": "An array of parameters that may either be simple variables, or more complex selections that map user input to data queries.", "items": { - "anyOf": [ - { - "$ref": "#/definitions/VariableParameter" - }, - { - "$ref": "#/definitions/SelectionParameter" - } - ] + "$ref": "#/definitions/SelectionParameter" }, "type": "array" }, @@ -28440,14 +28419,7 @@ "params": { "description": "Dynamic variables or selections that parameterize a visualization.", "items": { - "anyOf": [ - { - "$ref": "#/definitions/VariableParameter" - }, - { - "$ref": "#/definitions/TopLevelSelectionParameter" - } - ] + "$ref": "#/definitions/TopLevelParameter" }, "type": "array" }, @@ -28584,14 +28556,7 @@ "params": { "description": "Dynamic variables or selections that parameterize a visualization.", "items": { - "anyOf": [ - { - "$ref": "#/definitions/VariableParameter" - }, - { - "$ref": "#/definitions/TopLevelSelectionParameter" - } - ] + "$ref": "#/definitions/TopLevelParameter" }, "type": "array" }, @@ -28714,14 +28679,7 @@ "params": { "description": "Dynamic variables or selections that parameterize a visualization.", "items": { - "anyOf": [ - { - "$ref": "#/definitions/VariableParameter" - }, - { - "$ref": "#/definitions/TopLevelSelectionParameter" - } - ] + "$ref": "#/definitions/TopLevelParameter" }, "type": "array" }, @@ -28872,14 +28830,7 @@ "params": { "description": "Dynamic variables or selections that parameterize a visualization.", "items": { - "anyOf": [ - { - "$ref": "#/definitions/VariableParameter" - }, - { - "$ref": "#/definitions/TopLevelSelectionParameter" - } - ] + "$ref": "#/definitions/TopLevelParameter" }, "type": "array" }, @@ -29045,14 +28996,7 @@ "params": { "description": "Dynamic variables or selections that parameterize a visualization.", "items": { - "anyOf": [ - { - "$ref": "#/definitions/VariableParameter" - }, - { - "$ref": "#/definitions/TopLevelSelectionParameter" - } - ] + "$ref": "#/definitions/TopLevelParameter" }, "type": "array" }, @@ -29223,14 +29167,7 @@ "params": { "description": "Dynamic variables or selections that parameterize a visualization.", "items": { - "anyOf": [ - { - "$ref": "#/definitions/VariableParameter" - }, - { - "$ref": "#/definitions/TopLevelSelectionParameter" - } - ] + "$ref": "#/definitions/TopLevelParameter" }, "type": "array" }, @@ -29411,14 +29348,7 @@ "params": { "description": "Dynamic variables or selections that parameterize a visualization.", "items": { - "anyOf": [ - { - "$ref": "#/definitions/VariableParameter" - }, - { - "$ref": "#/definitions/TopLevelSelectionParameter" - } - ] + "$ref": "#/definitions/TopLevelParameter" }, "type": "array" }, @@ -29478,6 +29408,16 @@ ], "type": "object" }, + "TopLevelParameter": { + "anyOf": [ + { + "$ref": "#/definitions/VariableParameter" + }, + { + "$ref": "#/definitions/TopLevelSelectionParameter" + } + ] + }, "TopLevelSelectionParameter": { "additionalProperties": false, "properties": { @@ -29711,14 +29651,7 @@ "params": { "description": "An array of parameters that may either be simple variables, or more complex selections that map user input to data queries.", "items": { - "anyOf": [ - { - "$ref": "#/definitions/VariableParameter" - }, - { - "$ref": "#/definitions/SelectionParameter" - } - ] + "$ref": "#/definitions/TopLevelParameter" }, "type": "array" }, @@ -30017,14 +29950,7 @@ "params": { "description": "An array of parameters that may either be simple variables, or more complex selections that map user input to data queries.", "items": { - "anyOf": [ - { - "$ref": "#/definitions/VariableParameter" - }, - { - "$ref": "#/definitions/SelectionParameter" - } - ] + "$ref": "#/definitions/SelectionParameter" }, "type": "array" }, diff --git a/src/normalize/index.ts b/src/normalize/index.ts index e9423b06f7..f038a30612 100644 --- a/src/normalize/index.ts +++ b/src/normalize/index.ts @@ -48,7 +48,7 @@ const topLevelSelectionNormalizer = new TopLevelSelectionsNormalizer(); * And push top-level selection definitions down to unit specs. */ function normalizeGenericSpec( - spec: NonNormalizedSpec | FacetedUnitSpec | RepeatSpec, + spec: NonNormalizedSpec | FacetedUnitSpec | RepeatSpec, config: Config = {} ) { const normParams = {config}; diff --git a/src/spec/toplevel.ts b/src/spec/toplevel.ts index 690fe44daf..6a488e2b9b 100644 --- a/src/spec/toplevel.ts +++ b/src/spec/toplevel.ts @@ -16,6 +16,8 @@ export type Padding = number | {top?: number; bottom?: number; left?: number; ri export type Datasets = Dict; +export type TopLevelParameter = VariableParameter | TopLevelSelectionParameter; + export type TopLevel = S & TopLevelProperties & { /** @@ -72,7 +74,7 @@ export interface TopLevelProperties, M> extends BaseSpec { +export interface GenericUnitSpec, M, P = SelectionParameter> extends BaseSpec { /** * A string describing the mark type (one of `"bar"`, `"circle"`, `"square"`, `"tick"`, `"line"`, * `"area"`, `"point"`, `"rule"`, `"geoshape"`, and `"text"`) or a [mark definition object](https://vega.github.io/vega-lite/docs/mark.html#mark-def). @@ -33,7 +32,7 @@ export interface GenericUnitSpec, M> extends BaseSpec { /** * An array of parameters that may either be simple variables, or more complex selections that map user input to data queries. */ - params?: (VariableParameter | SelectionParameter)[]; + params?: P[]; } /** @@ -51,12 +50,16 @@ export type UnitSpecWithFrame = GenericUnitSpec = GenericUnitSpec, AnyMark> & +export type FacetedUnitSpec = GenericUnitSpec< + FacetedCompositeEncoding, + AnyMark, + P +> & ResolveMixins & GenericCompositionLayout & FrameMixins; -export type TopLevelUnitSpec = TopLevel> & DataMixins; +export type TopLevelUnitSpec = TopLevel> & DataMixins; export function isUnitSpec(spec: BaseSpec): spec is FacetedUnitSpec | NormalizedUnitSpec { return 'mark' in spec; diff --git a/test/compile/selection/parse.test.ts b/test/compile/selection/parse.test.ts index 0e04759ad8..2600ebb07c 100644 --- a/test/compile/selection/parse.test.ts +++ b/test/compile/selection/parse.test.ts @@ -306,7 +306,7 @@ describe('Selection', () => { params: [ { name: 'index', - value: {x: {year: 2005, month: 1, date: 1}}, + value: [{x: {year: 2005, month: 1, date: 1}}], select: { type: 'point', on: 'mouseover', diff --git a/test/compile/selection/scales.test.ts b/test/compile/selection/scales.test.ts index 471777ea79..fc16df2144 100644 --- a/test/compile/selection/scales.test.ts +++ b/test/compile/selection/scales.test.ts @@ -11,13 +11,13 @@ describe('Selection + Scales', () => { describe('selectionExtent', () => { it('is assembled from selection parameter', () => { const model = parseConcatModel({ + params: [{name: 'var'}], vconcat: [ { mark: 'area', params: [ {name: 'brush', select: {type: 'interval', encodings: ['x']}}, - {name: 'brush2', select: {type: 'point', fields: ['price'], resolve: 'intersect'}}, - {name: 'var'} + {name: 'brush2', select: {type: 'point', fields: ['price'], resolve: 'intersect'}} ], encoding: { x: {field: 'date', type: 'temporal'},