Skip to content

Commit 11b60dd

Browse files
committed
Make facet supports T as we probably don't want a wildcard for type
1 parent 4b7c053 commit 11b60dd

File tree

2 files changed

+29
-14
lines changed

2 files changed

+29
-14
lines changed

src/constraint/field.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
ScaleType,
99
scaleTypeSupportProperty
1010
} from 'vega-lite/build/src/scale';
11+
import {isLocalSingleTimeUnit, isUtcSingleTimeUnit} from 'vega-lite/build/src/timeunit';
1112
import * as TYPE from 'vega-lite/build/src/type';
1213
import {QueryConfig} from '../config';
1314
import {getEncodingNestedProp, Property, SCALE_PROPS} from '../property';
@@ -89,7 +90,19 @@ export const FIELD_CONSTRAINTS: EncodingConstraintModel<FieldQuery>[] = [
8990
...toFieldDef(fieldQ, {schema, props: ['bin', 'timeUnit', 'type']})
9091
};
9192

92-
return channelCompatibility(fieldDef, fieldQ.channel as Channel).compatible;
93+
const {compatible} = channelCompatibility(fieldDef, fieldQ.channel as Channel);
94+
95+
if (compatible) {
96+
return true;
97+
} else {
98+
// In VL, facet's field def must be discrete (O/N), but in CompassQL we can relax this a bit.
99+
const isFacet = fieldQ.channel === 'row' || fieldQ.channel === 'column';
100+
101+
if (isFacet && (isLocalSingleTimeUnit(fieldDef.timeUnit) || isUtcSingleTimeUnit(fieldDef.timeUnit))) {
102+
return true;
103+
}
104+
return false;
105+
}
93106
}
94107
},
95108
{
@@ -242,7 +255,7 @@ export const FIELD_CONSTRAINTS: EncodingConstraintModel<FieldQuery>[] = [
242255
},
243256
{
244257
name: 'typeMatchesPrimitiveType',
245-
description: 'Data type should be supported by field\'s primitive type.',
258+
description: "Data type should be supported by field's primitive type.",
246259
properties: [Property.FIELD, Property.TYPE],
247260
allowWildcardForProperties: false,
248261
strict: true,
@@ -278,7 +291,7 @@ export const FIELD_CONSTRAINTS: EncodingConstraintModel<FieldQuery>[] = [
278291
},
279292
{
280293
name: 'typeMatchesSchemaType',
281-
description: 'Enumerated data type of a field should match the field\'s type in the schema.',
294+
description: "Enumerated data type of a field should match the field's type in the schema.",
282295
properties: [Property.FIELD, Property.TYPE],
283296
allowWildcardForProperties: false,
284297
strict: false,

test/constraint/field.test.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -384,15 +384,17 @@ describe('constraints/field', () => {
384384
});
385385

386386
it(channel + ' supports timeUnit temporal dimension.', () => {
387-
const encQ: EncodingQuery = {channel: channel, field: 'T', type: TYPE.ORDINAL, timeUnit: TimeUnit.MONTH};
388-
assert.isTrue(
389-
FIELD_CONSTRAINT_INDEX['channelFieldCompatible'].satisfy(
390-
encQ,
391-
schema,
392-
new PropIndex<Wildcard<any>>(),
393-
CONSTRAINT_MANUALLY_SPECIFIED_CONFIG
394-
)
395-
);
387+
for (const type of [TYPE.ORDINAL, TYPE.TEMPORAL]) {
388+
const encQ: EncodingQuery = {channel: channel, field: 'T', type, timeUnit: TimeUnit.MONTH};
389+
assert.isTrue(
390+
FIELD_CONSTRAINT_INDEX['channelFieldCompatible'].satisfy(
391+
encQ,
392+
schema,
393+
new PropIndex<Wildcard<any>>(),
394+
CONSTRAINT_MANUALLY_SPECIFIED_CONFIG
395+
)
396+
);
397+
}
396398
});
397399

398400
it(channel + ' supports binned quantitative dimension.', () => {
@@ -493,7 +495,7 @@ describe('constraints/field', () => {
493495
);
494496
});
495497

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

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

0 commit comments

Comments
 (0)