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: remove normalized spec from schema #6965

Merged
merged 2 commits into from
Nov 15, 2020
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
544 changes: 15 additions & 529 deletions build/vega-lite-schema.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions scripts/rename-schema.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ perl -pi -e s,'<ExprRef>','',g build/vega-lite-schema.json
perl -pi -e s,'\,ExprRef>','>',g build/vega-lite-schema.json

perl -pi -e s,'CompositeEncoding','Encoding',g build/vega-lite-schema.json
perl -pi -e s,'Generic(.*)<FacetedUnitSpec\,LayerSpec\,?.*\,FieldName>','\1',g build/vega-lite-schema.json
perl -pi -e s,'Generic(.*)<FacetedUnitSpec\,LayerSpec\,?.*\,Field>','Normalized\1',g build/vega-lite-schema.json
perl -pi -e s,'Generic(.*)<FacetedUnitSpec\,LayerSpec\,?.*\,Field>','\1',g build/vega-lite-schema.json
perl -pi -e s,'Generic(.*)<NonNormalizedSpec>','\1',g build/vega-lite-schema.json

perl -pi -e s,'ValueDef(.*)<Value>','ValueDef\1',g build/vega-lite-schema.json
perl -pi -e s,'Conditional<(.*)>','Conditional\1',g build/vega-lite-schema.json
Expand Down
2 changes: 1 addition & 1 deletion src/compile/format.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {SignalRef} from 'vega-typings/types';
import {SignalRef} from 'vega';
import {isString} from 'vega-util';
import {isBinning} from '../bin';
import {
Expand Down
2 changes: 1 addition & 1 deletion src/compile/mark/encode/offset.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Utility files for producing Vega ValueRef for marks
*/
import {SignalRef} from 'vega-typings/types';
import {SignalRef} from 'vega';
import {getOffsetChannel, PolarPositionChannel, PositionChannel} from '../../../channel';
import {Mark, MarkDef} from '../../../mark';

Expand Down
2 changes: 1 addition & 1 deletion src/compile/mark/encode/position-range.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {SignalRef} from 'vega-typings/types';
import {SignalRef} from 'vega';
import {getMainRangeChannel, getSecondaryRangeChannel, getSizeChannel, getVgPositionChannel} from '../../../channel';
import {isFieldOrDatumDef} from '../../../channeldef';
import {MarkConfig} from '../../../mark';
Expand Down
2 changes: 1 addition & 1 deletion src/compile/mark/text.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {SignalRef} from 'vega-typings/types';
import {SignalRef} from 'vega';
import {Config} from '../../config';
import {Encoding} from '../../encoding';
import {MarkDef} from '../../mark';
Expand Down
8 changes: 3 additions & 5 deletions src/compositemark/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,18 @@ export function remove(mark: string) {
delete compositeMarkRegistry[mark];
}

export type CompositeEncoding<F extends Field = Field> = Encoding<F> & ErrorExtraEncoding<F>;
export type CompositeEncoding<F extends Field> = Encoding<F> & ErrorExtraEncoding<F>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain why do we remove the default = Field here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found it less confusing to explicitly say the type. It makes me more confident that we didn't miss using string somewhere.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you okay with this?


export type PartialIndex<T extends Encoding<any>> = {
[t in keyof T]?: Partial<T[t]>;
};

export type SharedCompositeEncoding<F extends Field = Field> = PartialIndex<
export type SharedCompositeEncoding<F extends Field> = PartialIndex<
Omit<CompositeEncoding<F>, 'detail' | 'order' | 'tooltip'> // need to omit and cherry pick detail / order / tooltip since they allow array
> &
Pick<Encoding<F>, 'detail' | 'order' | 'tooltip'>;

export type FacetedCompositeEncoding<F extends Field = Field> = Encoding<F> &
ErrorExtraEncoding<F> &
EncodingFacetMapping<F>;
export type FacetedCompositeEncoding<F extends Field> = Encoding<F> & ErrorExtraEncoding<F> & EncodingFacetMapping<F>;

export type CompositeMark = BoxPlot | ErrorBar | ErrorBand;

Expand Down
2 changes: 1 addition & 1 deletion src/normalize/base.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {SignalRef} from 'vega-typings/types';
import {SignalRef} from 'vega';
import {FieldName} from '../channeldef';
import {Config} from '../config';
import {Encoding} from '../encoding';
Expand Down
14 changes: 7 additions & 7 deletions src/normalize/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {PathOverlayNormalizer} from './pathoverlay';
import {replaceRepeaterInEncoding, replaceRepeaterInFacet} from './repeater';
import {RuleForRangedLineNormalizer} from './ruleforrangedline';

export class CoreNormalizer extends SpecMapper<NormalizerParams, FacetedUnitSpec, LayerSpec> {
export class CoreNormalizer extends SpecMapper<NormalizerParams, FacetedUnitSpec<Field>, LayerSpec<Field>> {
private nonFacetUnitNormalizers: NonFacetUnitNormalizer<any>[] = [
boxPlotNormalizer,
errorBarNormalizer,
Expand All @@ -40,7 +40,7 @@ export class CoreNormalizer extends SpecMapper<NormalizerParams, FacetedUnitSpec
new RuleForRangedLineNormalizer()
];

public map(spec: GenericSpec<FacetedUnitSpec, LayerSpec, RepeatSpec, Field>, params: NormalizerParams) {
public map(spec: GenericSpec<FacetedUnitSpec<Field>, LayerSpec<Field>, RepeatSpec, Field>, params: NormalizerParams) {
// Special handling for a faceted unit spec as it can return a facet spec, not just a layer or unit spec like a normal unit spec.
if (isUnitSpec(spec)) {
const hasRow = channelHasField(spec.encoding, ROW);
Expand All @@ -56,7 +56,7 @@ export class CoreNormalizer extends SpecMapper<NormalizerParams, FacetedUnitSpec
}

// This is for normalizing non-facet unit
public mapUnit(spec: UnitSpec, params: NormalizerParams): NormalizedUnitSpec | NormalizedLayerSpec {
public mapUnit(spec: UnitSpec<Field>, params: NormalizerParams): NormalizedUnitSpec | NormalizedLayerSpec {
const {parentEncoding, parentProjection} = params;

const encoding = replaceRepeaterInEncoding(spec.encoding, params.repeater);
Expand Down Expand Up @@ -194,7 +194,7 @@ export class CoreNormalizer extends SpecMapper<NormalizerParams, FacetedUnitSpec
}

protected mapFacet(
spec: GenericFacetSpec<UnitSpec, LayerSpec, Field>,
spec: GenericFacetSpec<UnitSpec<Field>, LayerSpec<Field>, Field>,
params: NormalizerParams
): GenericFacetSpec<NormalizedUnitSpec, NormalizedLayerSpec, FieldName> {
const {facet} = spec;
Expand All @@ -209,7 +209,7 @@ export class CoreNormalizer extends SpecMapper<NormalizerParams, FacetedUnitSpec
}

private mapUnitWithParentEncodingOrProjection(
spec: FacetedUnitSpec,
spec: FacetedUnitSpec<Field>,
params: NormalizerParams
): NormalizedUnitSpec | NormalizedLayerSpec {
const {encoding, projection} = spec;
Expand All @@ -230,7 +230,7 @@ export class CoreNormalizer extends SpecMapper<NormalizerParams, FacetedUnitSpec
);
}

private mapFacetedUnit(spec: FacetedUnitSpec, params: NormalizerParams): NormalizedFacetSpec {
private mapFacetedUnit(spec: FacetedUnitSpec<Field>, params: NormalizerParams): NormalizedFacetSpec {
// New encoding in the inside spec should not contain row / column
// as row/column should be moved to facet
const {row, column, facet, ...encoding} = spec.encoding;
Expand Down Expand Up @@ -312,7 +312,7 @@ export class CoreNormalizer extends SpecMapper<NormalizerParams, FacetedUnitSpec
}

public mapLayer(
spec: LayerSpec,
spec: LayerSpec<Field>,
{parentEncoding, parentProjection, ...otherParams}: NormalizerParams
): NormalizedLayerSpec {
// Special handling for extended layer spec
Expand Down
10 changes: 4 additions & 6 deletions src/normalize/index.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import {SignalRef} from 'vega-typings/types';
import {SignalRef} from 'vega';
import {isString} from 'vega-util';
import {Field} from '../channeldef';
import {Config, initConfig} from '../config';
import * as log from '../log';
import {
FacetedUnitSpec,
GenericSpec,
isLayerSpec,
isUnitSpec,
LayerSpec,
LayoutSizeMixins,
NonNormalizedSpec,
NormalizedSpec,
RepeatSpec,
TopLevelSpec,
UnitSpec
TopLevelSpec
} from '../spec';
import {AutoSizeParams, AutosizeType, TopLevel} from '../spec/toplevel';
import {deepEqual} from '../util';
Expand Down Expand Up @@ -45,7 +43,7 @@ const normalizer = new CoreNormalizer();
* Decompose extended unit specs into composition of pure unit specs.
*/
function normalizeGenericSpec(
spec: GenericSpec<UnitSpec, LayerSpec, RepeatSpec, Field> | FacetedUnitSpec | RepeatSpec,
spec: NonNormalizedSpec | FacetedUnitSpec<Field> | RepeatSpec,
config: Config<SignalRef> = {}
) {
return normalizer.map(spec, {config});
Expand Down
2 changes: 1 addition & 1 deletion src/normalize/pathoverlay.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {SignalRef} from 'vega-typings/types';
import {SignalRef} from 'vega';
import {isObject} from 'vega-util';
import {Config} from '../config';
import {Encoding, normalizeEncoding} from '../encoding';
Expand Down
2 changes: 1 addition & 1 deletion src/parameter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Binding, Expr, InitSignal, NewSignal} from 'vega-typings/types';
import {Binding, Expr, InitSignal, NewSignal} from 'vega';

export interface Parameter {
/**
Expand Down
2 changes: 1 addition & 1 deletion src/predicate.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {SignalRef} from 'vega-typings/types';
import {SignalRef} from 'vega';
import {isArray} from 'vega-util';
import {FieldName, valueExpr, vgField} from './channeldef';
import {DateTime} from './datetime';
Expand Down
23 changes: 13 additions & 10 deletions src/spec/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* - The external specs (no prefix) would allow composite marks, row/column encodings, and mark macros like point/line overlay.
* - The internal specs (with `Normalized` prefix) would only support primitive marks and support no macros/shortcuts.
*/
import {Field} from '../channeldef';
import {FieldName} from '../channeldef';
import {Field, FieldName} from '../channeldef';
import {Encoding} from '../encoding';
import {DataMixins} from './base';
import {GenericConcatSpec, GenericHConcatSpec, GenericVConcatSpec} from './concat';
import {GenericFacetSpec} from './facet';
Expand Down Expand Up @@ -33,8 +33,8 @@ export {FacetedUnitSpec, GenericUnitSpec, isUnitSpec, NormalizedUnitSpec, UnitSp
* Any specification in Vega-Lite.
*/
export type GenericSpec<
U extends GenericUnitSpec<any, any>,
L extends GenericLayerSpec<any>,
U extends GenericUnitSpec<Encoding<F>, any>,
L extends GenericLayerSpec<U>,
R extends RepeatSpec,
F extends Field
> =
Expand All @@ -51,18 +51,21 @@ export type GenericSpec<
*/
export type NormalizedSpec = GenericSpec<NormalizedUnitSpec, NormalizedLayerSpec, never, FieldName>;

export type TopLevelFacetSpec = TopLevel<GenericFacetSpec<UnitSpecWithFrame, LayerSpec, Field>> & DataMixins;
export type TopLevelFacetSpec = TopLevel<GenericFacetSpec<UnitSpecWithFrame<Field>, LayerSpec<Field>, Field>> &
DataMixins;

export type NonNormalizedSpec = GenericSpec<FacetedUnitSpec<Field>, LayerSpec<Field>, RepeatSpec, Field>;

/**
* A Vega-Lite top-level specification.
* This is the root class for all Vega-Lite specifications.
* (The json schema is generated from this type.)
*/
export type TopLevelSpec =
| TopLevelUnitSpec
| TopLevelUnitSpec<Field>
| TopLevelFacetSpec
| TopLevel<LayerSpec>
| TopLevel<LayerSpec<Field>>
| TopLevel<RepeatSpec>
| TopLevel<GenericConcatSpec<GenericSpec<FacetedUnitSpec, LayerSpec, RepeatSpec, Field>>>
| TopLevel<GenericVConcatSpec<GenericSpec<FacetedUnitSpec, LayerSpec, RepeatSpec, Field>>>
| TopLevel<GenericHConcatSpec<GenericSpec<FacetedUnitSpec, LayerSpec, RepeatSpec, Field>>>;
| TopLevel<GenericConcatSpec<NonNormalizedSpec>>
| TopLevel<GenericVConcatSpec<NonNormalizedSpec>>
| TopLevel<GenericHConcatSpec<NonNormalizedSpec>>;
7 changes: 4 additions & 3 deletions src/spec/layer.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {Field} from '../channeldef';
import {SharedCompositeEncoding} from '../compositemark';
import {Projection} from '../projection';
import {BaseSpec, FrameMixins, ResolveMixins} from './base';
Expand All @@ -18,18 +19,18 @@ export interface GenericLayerSpec<U extends GenericUnitSpec<any, any>> extends B
/**
* A full layered plot specification, which may contains `encoding` and `projection` properties that will be applied to underlying unit (single-view) specifications.
*/
export interface LayerSpec extends BaseSpec, FrameMixins, ResolveMixins {
export interface LayerSpec<F extends Field> extends BaseSpec, FrameMixins, ResolveMixins {
/**
* Layer or single view specifications to be layered.
*
* __Note__: Specifications inside `layer` cannot use `row` and `column` channels as layering facet specifications is not allowed. Instead, use the [facet operator](https://vega.github.io/vega-lite/docs/facet.html) and place a layer inside a facet.
*/
layer: (LayerSpec | UnitSpec)[];
layer: (LayerSpec<F> | UnitSpec<F>)[];

/**
* A shared key-value mapping between encoding channels and definition of fields in the underlying layers.
*/
encoding?: SharedCompositeEncoding;
encoding?: SharedCompositeEncoding<F>;

/**
* An object defining properties of the geographic projection shared by underlying layers.
Expand Down
10 changes: 5 additions & 5 deletions src/spec/repeat.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {isArray} from 'vega-util';
import {GenericSpec, LayerSpec} from '.';
import {FieldName} from '../channeldef';
import {LayerSpec, NonNormalizedSpec} from '.';
import {Field} from '../channeldef';
import {BaseSpec, GenericCompositionLayoutWithColumns, ResolveMixins} from './base';
import {FacetedUnitSpec, UnitSpec} from './unit';
import {UnitSpec} from './unit';

export interface RepeatMapping {
/**
Expand Down Expand Up @@ -39,7 +39,7 @@ export interface NonLayerRepeatSpec extends BaseSpec, GenericCompositionLayoutWi
/**
* A specification of the view that gets repeated.
*/
spec: GenericSpec<FacetedUnitSpec, LayerSpec, RepeatSpec, FieldName>;
spec: NonNormalizedSpec;
}

export interface LayerRepeatSpec extends BaseSpec, GenericCompositionLayoutWithColumns, ResolveMixins {
Expand All @@ -53,7 +53,7 @@ export interface LayerRepeatSpec extends BaseSpec, GenericCompositionLayoutWithC
/**
* A specification of the view that gets repeated.
*/
spec: LayerSpec | UnitSpec;
spec: LayerSpec<Field> | UnitSpec<Field>;
}

export function isRepeatSpec(spec: BaseSpec): spec is RepeatSpec {
Expand Down
11 changes: 6 additions & 5 deletions src/spec/unit.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {Field} from './../channeldef';
import {FieldName} from '../channeldef';
import {CompositeEncoding, FacetedCompositeEncoding} from '../compositemark';
import {Encoding} from '../encoding';
Expand Down Expand Up @@ -48,20 +49,20 @@ export type NormalizedUnitSpec = GenericUnitSpec<Encoding<FieldName>, Mark | Mar
/**
* A unit specification, which can contain either [primitive marks or composite marks](https://vega.github.io/vega-lite/docs/mark.html#types).
*/
export type UnitSpec = GenericUnitSpec<CompositeEncoding, AnyMark> & DeprecatedFrameMixins;
export type UnitSpec<F extends Field> = GenericUnitSpec<CompositeEncoding<F>, AnyMark> & DeprecatedFrameMixins;

export type UnitSpecWithFrame = GenericUnitSpec<CompositeEncoding, AnyMark> & FrameMixins;
export type UnitSpecWithFrame<F extends Field> = GenericUnitSpec<CompositeEncoding<F>, AnyMark> & FrameMixins;

/**
* Unit spec that can have a composite mark and row or column channels (shorthand for a facet spec).
*/
export type FacetedUnitSpec = GenericUnitSpec<FacetedCompositeEncoding, AnyMark> &
export type FacetedUnitSpec<F extends Field> = GenericUnitSpec<FacetedCompositeEncoding<F>, AnyMark> &
ResolveMixins &
GenericCompositionLayout &
FrameMixins;

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

export function isUnitSpec(spec: BaseSpec): spec is FacetedUnitSpec | NormalizedUnitSpec {
export function isUnitSpec(spec: BaseSpec): spec is FacetedUnitSpec<any> | NormalizedUnitSpec {
return 'mark' in spec;
}
2 changes: 1 addition & 1 deletion test/channeldef.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {SignalRef} from 'vega-typings/types';
import {SignalRef} from 'vega';
import {COUNTING_OPS} from '../src/aggregate';
import {CHANNELS} from '../src/channel';
import {
Expand Down
2 changes: 1 addition & 1 deletion test/compile/facet.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {SignalRef} from 'vega-typings/types';
import {SignalRef} from 'vega';
import {ROW} from '../../src/channel';
import {FacetModel} from '../../src/compile/facet';
import {assembleLabelTitle} from '../../src/compile/header/assemble';
Expand Down
2 changes: 1 addition & 1 deletion test/compile/mark/encode/offset.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {SignalRef} from 'vega-typings/types';
import {SignalRef} from 'vega';
import {getOffset} from '../../../../src/compile/mark/encode/offset';
import {Mark, MarkDef} from '../../../../src/mark';

Expand Down
3 changes: 2 additions & 1 deletion test/compositemark/errorbar.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {AggregateOp} from 'vega';
import {FieldName} from '../../src/channeldef';
import {ErrorBarCenter, ErrorBarExtent} from '../../src/compositemark/errorbar';
import {defaultConfig} from '../../src/config';
import * as log from '../../src/log';
Expand Down Expand Up @@ -515,7 +516,7 @@ describe('normalizeErrorBar for all possible extents and centers with raw data i

for (const center of centers) {
for (const extent of extents) {
const spec: TopLevelUnitSpec = {
const spec: TopLevelUnitSpec<FieldName> = {
data: {url: 'data/population.json'},
mark: {type, ...(center ? {center} : {}), ...(extent ? {extent} : {})},
encoding: {
Expand Down
2 changes: 1 addition & 1 deletion test/config.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {SignalRef} from 'vega-typings/types';
import {SignalRef} from 'vega';
import {
Config,
defaultConfig,
Expand Down
5 changes: 3 additions & 2 deletions test/normalize/ruleforrangedline.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {FieldName} from '../../src/channeldef';
import * as log from '../../src/log';
import {normalize} from '../../src/normalize';
import {TopLevelUnitSpec} from '../../src/spec/unit';
Expand All @@ -6,7 +7,7 @@ describe('RuleForRangedLineNormalizer', () => {
it(
'correctly normalizes line with rule where there is x2 or y2.',
log.wrap(localLogger => {
const spec: TopLevelUnitSpec = {
const spec: TopLevelUnitSpec<FieldName> = {
data: {url: 'data/stocks.csv', format: {type: 'csv'}},
mark: 'line',
encoding: {
Expand All @@ -26,7 +27,7 @@ describe('RuleForRangedLineNormalizer', () => {
);

it('does not normalize line when there is x2 or y2, but its primary channel is "binned".', () => {
const spec: TopLevelUnitSpec = {
const spec: TopLevelUnitSpec<FieldName> = {
data: {url: 'data/stocks.csv', format: {type: 'csv'}},
mark: 'line',
encoding: {
Expand Down
5 changes: 3 additions & 2 deletions test/util.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {SignalRef} from 'vega-typings/types';
import {SignalRef} from 'vega';
import {Field} from '../src/channeldef';
import {buildModel} from '../src/compile/buildmodel';
import {ConcatModel} from '../src/compile/concat';
import {FacetModel} from '../src/compile/facet';
Expand Down Expand Up @@ -84,7 +85,7 @@ export function parseConcatModel(spec: TopLevel<NormalizedConcatSpec>) {
return new ConcatModel(spec, null, '', initConfig(spec.config));
}

export function assertIsUnitSpec(spec: BaseSpec): asserts spec is FacetedUnitSpec | NormalizedUnitSpec {
export function assertIsUnitSpec(spec: BaseSpec): asserts spec is FacetedUnitSpec<Field> | NormalizedUnitSpec {
if (!isUnitSpec(spec)) {
throw new Error('Spec is not a unit spec!');
}
Expand Down
Loading