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

Don't include extra encoding for composite mark in the main Encoding #4528

Merged
merged 3 commits into from
Feb 10, 2019
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
1,526 changes: 761 additions & 765 deletions build/vega-lite-schema.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"deploy:gh": "scripts/deploy-gh.sh",
"deploy:schema": "scripts/deploy-schema.sh",
"preschema": "npm run prebuild",
"schema": "node --stack-size=2800 ./node_modules/.bin/ts-json-schema-generator --no-type-check --path tsconfig.json --type TopLevelSpec > build/vega-lite-schema.json && npm run renameschema && cp build/vega-lite-schema.json _data/",
"schema": "node --stack-size=4000 ./node_modules/.bin/ts-json-schema-generator --no-type-check --path tsconfig.json --type TopLevelSpec > build/vega-lite-schema.json && npm run renameschema && cp build/vega-lite-schema.json _data/",
"renameschema": "scripts/rename-schema.sh",
"presite": "npm run prebuild && npm run data && npm run build:site && npm run build:toc && npm run build:versions && scripts/create-example-pages",
"site": "bundle exec jekyll serve --incremental",
Expand Down
8 changes: 2 additions & 6 deletions scripts/check-schema.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
#!/usr/bin/env bash

if grep 'Generic.*Spec<' ./build/vega-lite-schema.json
if grep 'Generic[^U].*Spec<' ./build/vega-lite-schema.json
then
echo "Generic*Spec in the schema have not been replaced."
exit 1
elif grep 'UnitSpec<Encoding' ./build/vega-lite-schema.json
then
echo "UnitSpec<...> in the schema have not been replaced."
echo "Non-Unit Generic Spec in the schema have not been replaced."
exit 1
elif grep '<Field>' ./build/vega-lite-schema.json
then
Expand Down
5 changes: 1 addition & 4 deletions scripts/rename-schema.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
#!/usr/bin/env bash

perl -pi -e s,'<Field>','',g build/vega-lite-schema.json
perl -pi -e s,'<Field\,','<',g build/vega-lite-schema.json
perl -pi -e s,'<StandardType>','',g build/vega-lite-schema.json

perl -pi -e s,'CompositeEncoding','Encoding',g build/vega-lite-schema.json
perl -pi -e s,'FacetedCompositeUnitSpec','FacetedUnitSpec',g build/vega-lite-schema.json
perl -pi -e s,'ExtendedLayerSpec','LayerSpec',g build/vega-lite-schema.json
perl -pi -e s,'GenericLayerSpec<CompositeUnitSpec>','LayerSpec',g build/vega-lite-schema.json
perl -pi -e s,'Generic(.*)<FacetedUnitSpec\,LayerSpec>','\1',g build/vega-lite-schema.json

perl -pi -e s,'GenericUnitSpec<EncodingWithFacet\,AnyMark>','FacetedCompositeUnitSpecAlias',g build/vega-lite-schema.json
perl -pi -e s,'GenericUnitSpec<Encoding\,AnyMark>','CompositeUnitSpecAlias',g build/vega-lite-schema.json

perl -pi -e s,'FieldDefWithoutScale','FieldDef',g build/vega-lite-schema.json

perl -pi -e s,'ValueDef(.*)\<\(number\|\\\"width\\\"\)\>','XValueDef\1',g build/vega-lite-schema.json
Expand Down
30 changes: 0 additions & 30 deletions src/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ export namespace Channel {
export const Y: 'y' = 'y';
export const X2: 'x2' = 'x2';
export const Y2: 'y2' = 'y2';
export const XERROR: 'xError' = 'xError';
export const YERROR: 'yError' = 'yError';
export const XERROR2: 'xError2' = 'xError2';
export const YERROR2: 'yError2' = 'yError2';

// Geo Position
export const LATITUDE: 'latitude' = 'latitude';
export const LONGITUDE: 'longitude' = 'longitude';
Expand Down Expand Up @@ -62,10 +57,6 @@ export const X = Channel.X;
export const Y = Channel.Y;
export const X2 = Channel.X2;
export const Y2 = Channel.Y2;
export const XERROR = Channel.XERROR;
export const YERROR = Channel.YERROR;
export const XERROR2 = Channel.XERROR2;
export const YERROR2 = Channel.YERROR2;

export const LATITUDE = Channel.LATITUDE;
export const LATITUDE2 = Channel.LATITUDE2;
Expand Down Expand Up @@ -111,10 +102,6 @@ const UNIT_CHANNEL_INDEX: Flag<keyof Encoding<any>> = {
y: 1,
x2: 1,
y2: 1,
xError: 1,
yError: 1,
xError2: 1,
yError2: 1,

...GEOPOSITION_CHANNEL_INDEX,

Expand Down Expand Up @@ -180,10 +167,6 @@ export type SingleDefUnitChannel =
| 'y'
| 'x2'
| 'y2'
| 'xError'
| 'yError'
| 'xError2'
| 'yError2'
| 'longitude'
| 'latitude'
| 'longitude2'
Expand Down Expand Up @@ -237,10 +220,6 @@ const {
// x2 and y2 share the same scale as x and y
x2: _x2,
y2: _y2,
xError: _xError,
yError: _yError,
xError2: _xError2,
yError2: _yError2,
latitude: _latitude,
longitude: _longitude,
latitude2: _latitude2,
Expand Down Expand Up @@ -409,11 +388,6 @@ function getSupportedMark(channel: Channel): SupportedMark {
return {point: 'always', geoshape: 'always'};
case TEXT:
return {text: 'always'};
case XERROR:
case YERROR:
case XERROR2:
case YERROR2:
return {};
}
}

Expand All @@ -429,10 +403,6 @@ export function rangeType(channel: Channel): RangeType {
// X2 and Y2 use X and Y scales, so they similarly have continuous range.
case X2:
case Y2:
case XERROR:
case YERROR:
case XERROR2:
case YERROR2:
return undefined;

case ROW:
Expand Down
4 changes: 0 additions & 4 deletions src/compile/mark/mark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,6 @@ export function pathGroupingFields(mark: Mark, encoding: Encoding<string>): stri
case 'href':
case 'x2':
case 'y2':
case 'xError':
case 'yError':
case 'xError2':
case 'yError2':

case 'latitude':
case 'longitude':
Expand Down
6 changes: 0 additions & 6 deletions src/compositemark/boxplot.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {isNumber, isObject} from 'vega-util';
import {Channel} from '../channel';
import {Config} from '../config';
import {Encoding, extractTransformsFromEncoding} from '../encoding';
import {PositionFieldDef} from '../fielddef';
Expand All @@ -13,7 +12,6 @@ import {
compositeMarkContinuousAxis,
compositeMarkOrient,
CompositeMarkTooltipSummary,
filterUnsupportedChannels,
GenericCompositeMarkDef,
getCompositeMarkTooltip,
makeCompositeAggregatePartFactory,
Expand Down Expand Up @@ -75,14 +73,10 @@ export interface BoxPlotConfigMixins {
boxplot?: BoxPlotConfig;
}

const boxPlotSupportedChannels: Channel[] = ['x', 'y', 'color', 'detail', 'opacity', 'size'];

export function normalizeBoxPlot(
spec: GenericUnitSpec<Encoding<string>, BoxPlot | BoxPlotDef>,
config: Config
): NormalizedLayerSpec {
spec = filterUnsupportedChannels(spec, boxPlotSupportedChannels, BOXPLOT);

// TODO: use selection
const {mark, encoding: _encoding, selection, projection: _p, ...outerSpec} = spec;
const markDef: BoxPlotDef = isMarkDef(mark) ? mark : {type: mark};
Expand Down
34 changes: 9 additions & 25 deletions src/compositemark/common.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {isBoolean, isString} from 'vega-util';
import {CompositeMark, CompositeMarkDef} from '.';
import {Channel} from '../channel';
import {Encoding, fieldDefs, reduce} from '../encoding';
import {Encoding, fieldDefs} from '../encoding';
import {
Field,
FieldDefBase,
Expand All @@ -15,6 +14,7 @@ import {
import * as log from '../log';
import {ColorMixins, GenericMarkDef, isMarkDef, Mark, MarkConfig, MarkDef} from '../mark';
import {GenericUnitSpec, NormalizedUnitSpec} from '../spec';
import {StandardType} from '../type';
import {Orient} from '../vega.schema';

export type PartsMixins<P extends string> = Partial<Record<P, boolean | MarkConfig>>;
Expand Down Expand Up @@ -154,7 +154,13 @@ export function compositeMarkContinuousAxis<M extends CompositeMark>(
spec: GenericUnitSpec<Encoding<string>, CompositeMark | CompositeMarkDef>,
orient: Orient,
compositeMark: M
) {
): {
continuousAxisChannelDef: PositionFieldDef<string>;
continuousAxisChannelDef2: SecondaryFieldDef<string>;
continuousAxisChannelDefError: FieldDefWithoutScale<string, StandardType>;
continuousAxisChannelDefError2: FieldDefWithoutScale<string, StandardType>;
continuousAxis: 'x' | 'y';
} {
const {encoding} = spec;
const continuousAxis: 'x' | 'y' = orient === 'vertical' ? 'y' : 'x';

Expand Down Expand Up @@ -223,25 +229,3 @@ export function compositeMarkOrient<M extends CompositeMark>(
throw new Error('Need a valid continuous axis for ' + compositeMark + 's');
}
}

export function filterUnsupportedChannels<M extends CompositeMark, MD extends GenericCompositeMarkDef<M>>(
spec: GenericUnitSpec<Encoding<string>, M | MD>,
supportedChannels: Channel[],
compositeMark: M
): GenericUnitSpec<Encoding<string>, M | MD> {
return {
...spec,
encoding: reduce(
spec.encoding,
(newEncoding, fieldDef, channel) => {
if (supportedChannels.indexOf(channel) > -1) {
newEncoding[channel] = fieldDef;
} else {
log.warn(log.message.incompatibleChannel(channel, compositeMark));
}
return newEncoding;
},
{}
)
};
}
7 changes: 6 additions & 1 deletion src/compositemark/errorband.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import {Config} from '../config';
import {Encoding} from '../encoding';
import {Field} from '../fielddef';
import * as log from '../log';
import {MarkDef} from '../mark';
import {GenericUnitSpec, NormalizedLayerSpec} from '../spec';
import {Flag, keys} from '../util';
import {Interpolate, Orient} from '../vega.schema';
import {GenericCompositeMarkDef, makeCompositeAggregatePartFactory, PartsMixins} from './common';
import {ErrorBarCenter, ErrorBarExtent, errorBarParams} from './errorbar';
import {ErrorBarCenter, ErrorBarExtent, errorBarParams, ErrorEncoding} from './errorbar';

export type ErrorBandUnitSpec<
EE = {} // extra encoding parameter (for faceted composite unit spec)
> = GenericUnitSpec<ErrorEncoding<Field> & EE, ErrorBand | ErrorBandDef>;

export const ERRORBAND: 'errorband' = 'errorband';
export type ErrorBand = typeof ERRORBAND;
Expand Down
69 changes: 41 additions & 28 deletions src/compositemark/errorbar.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {AggregateOp} from 'vega';
import {Channel} from '../channel';
import {Config} from '../config';
import {Data} from '../data';
import {Encoding, extractTransformsFromEncoding} from '../encoding';
Expand All @@ -10,7 +9,8 @@ import {
isFieldDef,
PositionFieldDef,
SecondaryFieldDef,
title
title,
ValueDef
} from '../fielddef';
import * as log from '../log';
import {isMarkDef, MarkDef} from '../mark';
Expand All @@ -23,7 +23,6 @@ import {
compositeMarkContinuousAxis,
compositeMarkOrient,
CompositeMarkTooltipSummary,
filterUnsupportedChannels,
GenericCompositeMarkDef,
getCompositeMarkTooltip,
makeCompositeAggregatePartFactory,
Expand All @@ -46,6 +45,36 @@ const ERRORBAR_PART_INDEX: Flag<ErrorBarPart> = {
rule: 1
};

export interface ErrorExtraEncoding<F extends Field> {
/**
* Error value of x coordinates for error specified `"errorbar"` and `"errorband"`.
*/
xError?: SecondaryFieldDef<F> | ValueDef<number>;

/**
* Secondary error value of x coordinates for error specified `"errorbar"` and `"errorband"`.
*/
// `xError2` cannot have type as it should have the same type as `xError`
xError2?: SecondaryFieldDef<F> | ValueDef<number>;

/**
* Error value of y coordinates for error specified `"errorbar"` and `"errorband"`.
*/
yError?: SecondaryFieldDef<F> | ValueDef<number>;

/**
* Secondary error value of y coordinates for error specified `"errorbar"` and `"errorband"`.
*/
// `yError2` cannot have type as it should have the same type as `yError`
yError2?: SecondaryFieldDef<F> | ValueDef<number>;
}

export type ErrorEncoding<F extends Field> = Pick<
Encoding<F>,
'x' | 'y' | 'x2' | 'y2' | 'color' | 'detail' | 'opacity'
> &
ErrorExtraEncoding<F>;

export const ERRORBAR_PARTS = keys(ERRORBAR_PART_INDEX);

export type ErrorBarPartsMixins = PartsMixins<ErrorBarPart>;
Expand Down Expand Up @@ -91,7 +120,7 @@ export interface ErrorBarConfigMixins {
}

export function normalizeErrorBar(
spec: GenericUnitSpec<Encoding<string>, ErrorBar | ErrorBarDef>,
spec: GenericUnitSpec<ErrorEncoding<string>, ErrorBar | ErrorBarDef>,
config: Config
): NormalizedLayerSpec {
const {
Expand Down Expand Up @@ -143,7 +172,7 @@ export function normalizeErrorBar(
}

function errorBarOrientAndInputType(
spec: GenericUnitSpec<Encoding<Field>, ErrorBar | ErrorBand | ErrorBarDef | ErrorBandDef>,
spec: GenericUnitSpec<ErrorEncoding<Field>, ErrorBar | ErrorBand | ErrorBarDef | ErrorBandDef>,
compositeMark: ErrorBar | ErrorBand
): {
orient: Orient;
Expand Down Expand Up @@ -237,7 +266,7 @@ function errorBarOrientAndInputType(
}
}

function errorBarIsInputTypeRaw(encoding: Encoding<Field>): boolean {
function errorBarIsInputTypeRaw(encoding: ErrorEncoding<Field>): boolean {
return (
(isFieldDef(encoding.x) || isFieldDef(encoding.y)) &&
!isFieldDef(encoding.x2) &&
Expand All @@ -249,11 +278,11 @@ function errorBarIsInputTypeRaw(encoding: Encoding<Field>): boolean {
);
}

function errorBarIsInputTypeAggregatedUpperLower(encoding: Encoding<Field>): boolean {
function errorBarIsInputTypeAggregatedUpperLower(encoding: ErrorEncoding<Field>): boolean {
return isFieldDef(encoding.x2) || isFieldDef(encoding.y2);
}

function errorBarIsInputTypeAggregatedError(encoding: Encoding<Field>): boolean {
function errorBarIsInputTypeAggregatedError(encoding: ErrorEncoding<Field>): boolean {
return (
isFieldDef(encoding.xError) ||
isFieldDef(encoding.xError2) ||
Expand All @@ -262,33 +291,19 @@ function errorBarIsInputTypeAggregatedError(encoding: Encoding<Field>): boolean
);
}

export const errorBarSupportedChannels: Channel[] = [
'x',
'y',
'x2',
'y2',
'xError',
'yError',
'xError2',
'yError2',
'color',
'detail',
'opacity'
];

export function errorBarParams<
M extends ErrorBar | ErrorBand,
MD extends GenericCompositeMarkDef<M> & (ErrorBarDef | ErrorBandDef)
>(
spec: GenericUnitSpec<Encoding<string>, M | MD>,
spec: GenericUnitSpec<ErrorEncoding<string>, M | MD>,
compositeMark: M,
config: Config
): {
transform: Transform[];
groupby: string[];
continuousAxisChannelDef: PositionFieldDef<string>;
continuousAxis: 'x' | 'y';
encodingWithoutContinuousAxis: Encoding<string>;
encodingWithoutContinuousAxis: ErrorEncoding<string>;
ticksOrient: Orient;
markDef: MD;
outerSpec: {
Expand All @@ -300,10 +315,8 @@ export function errorBarParams<
width?: number;
height?: number;
};
tooltipEncoding: Encoding<string>;
tooltipEncoding: ErrorEncoding<string>;
} {
spec = filterUnsupportedChannels<M, MD>(spec, errorBarSupportedChannels, compositeMark);

// TODO: use selection
const {mark, encoding, selection, projection: _p, ...outerSpec} = spec;
const markDef: MD = isMarkDef(mark) ? mark : ({type: mark} as MD);
Expand Down Expand Up @@ -357,7 +370,7 @@ export function errorBarParams<
const aggregate: AggregatedFieldDef[] = [...oldAggregate, ...errorBarSpecificAggregate];
const groupby: string[] = inputType !== 'raw' ? [] : oldGroupBy;

const tooltipEncoding: Encoding<string> = getCompositeMarkTooltip(
const tooltipEncoding: ErrorEncoding<string> = getCompositeMarkTooltip(
tooltipSummary,
continuousAxisChannelDef,
encodingWithoutContinuousAxis,
Expand Down
Loading