diff --git a/build/vega-lite-schema.json b/build/vega-lite-schema.json index f793af899a2..69e1f5c1ae4 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" }, @@ -11116,14 +11102,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" }, @@ -28464,14 +28443,7 @@ "params": { "description": "Dynamic variables or selections that parameterize a visualization.", "items": { - "anyOf": [ - { - "$ref": "#/definitions/VariableParameter" - }, - { - "$ref": "#/definitions/TopLevelSelectionParameter" - } - ] + "$ref": "#/definitions/TopLevelParameter" }, "type": "array" }, @@ -28608,14 +28580,7 @@ "params": { "description": "Dynamic variables or selections that parameterize a visualization.", "items": { - "anyOf": [ - { - "$ref": "#/definitions/VariableParameter" - }, - { - "$ref": "#/definitions/TopLevelSelectionParameter" - } - ] + "$ref": "#/definitions/TopLevelParameter" }, "type": "array" }, @@ -28738,14 +28703,7 @@ "params": { "description": "Dynamic variables or selections that parameterize a visualization.", "items": { - "anyOf": [ - { - "$ref": "#/definitions/VariableParameter" - }, - { - "$ref": "#/definitions/TopLevelSelectionParameter" - } - ] + "$ref": "#/definitions/TopLevelParameter" }, "type": "array" }, @@ -28896,14 +28854,7 @@ "params": { "description": "Dynamic variables or selections that parameterize a visualization.", "items": { - "anyOf": [ - { - "$ref": "#/definitions/VariableParameter" - }, - { - "$ref": "#/definitions/TopLevelSelectionParameter" - } - ] + "$ref": "#/definitions/TopLevelParameter" }, "type": "array" }, @@ -29069,14 +29020,7 @@ "params": { "description": "Dynamic variables or selections that parameterize a visualization.", "items": { - "anyOf": [ - { - "$ref": "#/definitions/VariableParameter" - }, - { - "$ref": "#/definitions/TopLevelSelectionParameter" - } - ] + "$ref": "#/definitions/TopLevelParameter" }, "type": "array" }, @@ -29247,14 +29191,7 @@ "params": { "description": "Dynamic variables or selections that parameterize a visualization.", "items": { - "anyOf": [ - { - "$ref": "#/definitions/VariableParameter" - }, - { - "$ref": "#/definitions/TopLevelSelectionParameter" - } - ] + "$ref": "#/definitions/TopLevelParameter" }, "type": "array" }, @@ -29447,14 +29384,7 @@ "params": { "description": "Dynamic variables or selections that parameterize a visualization.", "items": { - "anyOf": [ - { - "$ref": "#/definitions/VariableParameter" - }, - { - "$ref": "#/definitions/TopLevelSelectionParameter" - } - ] + "$ref": "#/definitions/TopLevelParameter" }, "type": "array" }, @@ -29526,6 +29456,16 @@ ], "type": "object" }, + "TopLevelParameter": { + "anyOf": [ + { + "$ref": "#/definitions/VariableParameter" + }, + { + "$ref": "#/definitions/TopLevelSelectionParameter" + } + ] + }, "TopLevelSelectionParameter": { "additionalProperties": false, "properties": { @@ -29759,14 +29699,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" }, @@ -30065,14 +29998,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 023a8efe44c..aeccf5f9849 100644 --- a/src/normalize/index.ts +++ b/src/normalize/index.ts @@ -49,7 +49,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 690fe44dafa..6a488e2b9bc 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,13 +50,17 @@ export type UnitSpecWithFrame = GenericUnitSpec = GenericUnitSpec, AnyMark> & +export type FacetedUnitSpec = GenericUnitSpec< + FacetedCompositeEncoding, + AnyMark, + P +> & ResolveMixins & GenericCompositionLayout & FrameMixins & LayoutSizeMixins; -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 0e04759ad8c..2600ebb07ca 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 471777ea794..fc16df21446 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'},