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

fix: Make params types more precise for UnitSpecs #8304

Merged
merged 2 commits into from Jul 21, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
118 changes: 22 additions & 96 deletions build/vega-lite-schema.json
Expand Up @@ -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"
},
Expand Down Expand Up @@ -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"
},
Expand Down Expand Up @@ -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"
},
Expand Down Expand Up @@ -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"
},
Expand Down Expand Up @@ -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"
},
Expand Down Expand Up @@ -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"
},
Expand Down Expand Up @@ -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"
},
Expand Down Expand Up @@ -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"
},
Expand Down Expand Up @@ -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"
},
Expand Down Expand Up @@ -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"
},
Expand Down Expand Up @@ -29478,6 +29408,16 @@
],
"type": "object"
},
"TopLevelParameter": {
"anyOf": [
{
"$ref": "#/definitions/VariableParameter"
},
{
"$ref": "#/definitions/TopLevelSelectionParameter"
}
]
},
"TopLevelSelectionParameter": {
"additionalProperties": false,
"properties": {
Expand Down Expand Up @@ -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"
},
Expand Down Expand Up @@ -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"
},
Expand Down
2 changes: 1 addition & 1 deletion src/normalize/index.ts
Expand Up @@ -48,7 +48,7 @@ const topLevelSelectionNormalizer = new TopLevelSelectionsNormalizer();
* And push top-level selection definitions down to unit specs.
*/
function normalizeGenericSpec(
spec: NonNormalizedSpec | FacetedUnitSpec<Field> | RepeatSpec,
spec: NonNormalizedSpec | FacetedUnitSpec<Field, any> | RepeatSpec,
config: Config<SignalRef> = {}
) {
const normParams = {config};
Expand Down
4 changes: 3 additions & 1 deletion src/spec/toplevel.ts
Expand Up @@ -16,6 +16,8 @@ export type Padding = number | {top?: number; bottom?: number; left?: number; ri

export type Datasets = Dict<InlineDataset>;

export type TopLevelParameter = VariableParameter | TopLevelSelectionParameter;

export type TopLevel<S extends BaseSpec> = S &
TopLevelProperties & {
/**
Expand Down Expand Up @@ -72,7 +74,7 @@ export interface TopLevelProperties<ES extends ExprRef | SignalRef = ExprRef | S
/**
* Dynamic variables or selections that parameterize a visualization.
*/
params?: (VariableParameter | TopLevelSelectionParameter)[];
params?: TopLevelParameter[];
}

export type FitType = 'fit' | 'fit-x' | 'fit-y';
Expand Down
15 changes: 9 additions & 6 deletions src/spec/unit.ts
Expand Up @@ -3,16 +3,15 @@ import {CompositeEncoding, FacetedCompositeEncoding} from '../compositemark';
import {Encoding} from '../encoding';
import {ExprRef} from '../expr';
import {AnyMark, Mark, MarkDef} from '../mark';
import {VariableParameter} from '../parameter';
import {Projection} from '../projection';
import {SelectionParameter} from '../selection';
import {Field} from './../channeldef';
import {BaseSpec, DataMixins, FrameMixins, GenericCompositionLayout, ResolveMixins} from './base';
import {TopLevel} from './toplevel';
import {TopLevel, TopLevelParameter} from './toplevel';
/**
* Base interface for a unit (single-view) specification.
*/
export interface GenericUnitSpec<E extends Encoding<any>, M> extends BaseSpec {
export interface GenericUnitSpec<E extends Encoding<any>, 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).
Expand All @@ -33,7 +32,7 @@ export interface GenericUnitSpec<E extends Encoding<any>, 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[];
}

/**
Expand All @@ -51,12 +50,16 @@ export type UnitSpecWithFrame<F extends Field> = GenericUnitSpec<CompositeEncodi
/**
* Unit spec that can have a composite mark and row or column channels (shorthand for a facet spec).
*/
export type FacetedUnitSpec<F extends Field> = GenericUnitSpec<FacetedCompositeEncoding<F>, AnyMark> &
export type FacetedUnitSpec<F extends Field, P = SelectionParameter> = GenericUnitSpec<
FacetedCompositeEncoding<F>,
AnyMark,
P
> &
ResolveMixins &
GenericCompositionLayout &
FrameMixins;

export type TopLevelUnitSpec<F extends Field> = TopLevel<FacetedUnitSpec<F>> & DataMixins;
export type TopLevelUnitSpec<F extends Field> = TopLevel<FacetedUnitSpec<F, TopLevelParameter>> & DataMixins;

export function isUnitSpec(spec: BaseSpec): spec is FacetedUnitSpec<any> | NormalizedUnitSpec {
return 'mark' in spec;
Expand Down
2 changes: 1 addition & 1 deletion test/compile/selection/parse.test.ts
Expand Up @@ -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',
Expand Down
4 changes: 2 additions & 2 deletions test/compile/selection/scales.test.ts
Expand Up @@ -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'},
Expand Down