Skip to content

Commit

Permalink
Make facet supports T as we probably don't want a wildcard for type
Browse files Browse the repository at this point in the history
  • Loading branch information
kanitw committed May 27, 2019
1 parent 4b7c053 commit 11b60dd
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 14 deletions.
19 changes: 16 additions & 3 deletions src/constraint/field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
ScaleType,
scaleTypeSupportProperty
} from 'vega-lite/build/src/scale';
import {isLocalSingleTimeUnit, isUtcSingleTimeUnit} from 'vega-lite/build/src/timeunit';
import * as TYPE from 'vega-lite/build/src/type';
import {QueryConfig} from '../config';
import {getEncodingNestedProp, Property, SCALE_PROPS} from '../property';
Expand Down Expand Up @@ -89,7 +90,19 @@ export const FIELD_CONSTRAINTS: EncodingConstraintModel<FieldQuery>[] = [
...toFieldDef(fieldQ, {schema, props: ['bin', 'timeUnit', 'type']})
};

return channelCompatibility(fieldDef, fieldQ.channel as Channel).compatible;
const {compatible} = channelCompatibility(fieldDef, fieldQ.channel as Channel);

if (compatible) {
return true;
} else {
// In VL, facet's field def must be discrete (O/N), but in CompassQL we can relax this a bit.
const isFacet = fieldQ.channel === 'row' || fieldQ.channel === 'column';

if (isFacet && (isLocalSingleTimeUnit(fieldDef.timeUnit) || isUtcSingleTimeUnit(fieldDef.timeUnit))) {
return true;
}
return false;
}
}
},
{
Expand Down Expand Up @@ -242,7 +255,7 @@ export const FIELD_CONSTRAINTS: EncodingConstraintModel<FieldQuery>[] = [
},
{
name: 'typeMatchesPrimitiveType',
description: 'Data type should be supported by field\'s primitive type.',
description: "Data type should be supported by field's primitive type.",
properties: [Property.FIELD, Property.TYPE],
allowWildcardForProperties: false,
strict: true,
Expand Down Expand Up @@ -278,7 +291,7 @@ export const FIELD_CONSTRAINTS: EncodingConstraintModel<FieldQuery>[] = [
},
{
name: 'typeMatchesSchemaType',
description: 'Enumerated data type of a field should match the field\'s type in the schema.',
description: "Enumerated data type of a field should match the field's type in the schema.",
properties: [Property.FIELD, Property.TYPE],
allowWildcardForProperties: false,
strict: false,
Expand Down
24 changes: 13 additions & 11 deletions test/constraint/field.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,15 +384,17 @@ describe('constraints/field', () => {
});

it(channel + ' supports timeUnit temporal dimension.', () => {
const encQ: EncodingQuery = {channel: channel, field: 'T', type: TYPE.ORDINAL, timeUnit: TimeUnit.MONTH};
assert.isTrue(
FIELD_CONSTRAINT_INDEX['channelFieldCompatible'].satisfy(
encQ,
schema,
new PropIndex<Wildcard<any>>(),
CONSTRAINT_MANUALLY_SPECIFIED_CONFIG
)
);
for (const type of [TYPE.ORDINAL, TYPE.TEMPORAL]) {
const encQ: EncodingQuery = {channel: channel, field: 'T', type, timeUnit: TimeUnit.MONTH};
assert.isTrue(
FIELD_CONSTRAINT_INDEX['channelFieldCompatible'].satisfy(
encQ,
schema,
new PropIndex<Wildcard<any>>(),
CONSTRAINT_MANUALLY_SPECIFIED_CONFIG
)
);
}
});

it(channel + ' supports binned quantitative dimension.', () => {
Expand Down Expand Up @@ -493,7 +495,7 @@ describe('constraints/field', () => {
);
});

it(channel + ' does not support ordinal dimension.', () => {
it(channel + ' supports ordinal dimension.', () => {
const encQ: EncodingQuery = {channel: channel, field: 'O', type: TYPE.ORDINAL};
assert.isTrue(
FIELD_CONSTRAINT_INDEX['channelFieldCompatible'].satisfy(
Expand All @@ -505,7 +507,7 @@ describe('constraints/field', () => {
);
});

it(channel + ' does not support nominal dimension.', () => {
it(channel + ' does not support nominal dimension.', () => {
const encQ: EncodingQuery = {channel: channel, field: 'N', type: TYPE.NOMINAL};
assert.isFalse(
FIELD_CONSTRAINT_INDEX['channelFieldCompatible'].satisfy(
Expand Down

0 comments on commit 11b60dd

Please sign in to comment.