Skip to content

Commit 561ef05

Browse files
ssharif6kanitw
authored andcommitted
Add format support & fix test
1 parent 5cbd7f9 commit 561ef05

File tree

4 files changed

+20
-2
lines changed

4 files changed

+20
-2
lines changed

src/property.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const ENCODING_TOPLEVEL_PROP_INDEX: Flag<EncodingTopLevelProp> = {
5050
aggregate: 1, autoCount: 1, bin: 1, timeUnit: 1, hasFn: 1,
5151
sort: 1, stack: 1,
5252
field: 1, type: 1,
53-
scale: 1, axis: 1, legend: 1,
53+
format: 1, scale: 1, axis: 1, legend: 1,
5454
value: 1
5555
};
5656

@@ -174,6 +174,9 @@ export namespace Property {
174174
export const TRANSFORM: 'transform' = 'transform';
175175
// Layout
176176
export const STACK: 'stack' = 'stack';
177+
178+
export const FORMAT: 'format' = 'format';
179+
177180
// TODO: sub parts of stack
178181

179182
// Encoding Properties

src/query/encoding.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ export interface FieldQueryBase {
102102

103103
axis?: boolean | AxisQuery | SHORT_WILDCARD;
104104
legend?: boolean | LegendQuery | SHORT_WILDCARD;
105+
106+
format?: string;
105107
}
106108

107109
export type FieldQuery = EncodingQueryBase & FieldQueryBase;
@@ -119,7 +121,7 @@ export type ScaleQuery = FlatQueryWithEnableFlag<Scale>;
119121
export type AxisQuery = FlatQueryWithEnableFlag<Axis>;
120122
export type LegendQuery = FlatQueryWithEnableFlag<Legend>;
121123

122-
const DEFAULT_PROPS = [Property.AGGREGATE, Property.BIN, Property.TIMEUNIT, Property.FIELD, Property.TYPE, Property.SCALE, Property.SORT, Property.AXIS, Property.LEGEND, Property.STACK];
124+
const DEFAULT_PROPS = [Property.AGGREGATE, Property.BIN, Property.TIMEUNIT, Property.FIELD, Property.TYPE, Property.SCALE, Property.SORT, Property.AXIS, Property.LEGEND, Property.STACK, Property.FORMAT];
123125

124126
export interface ConversionParams {
125127
schema?: Schema;

src/wildcard.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ export const DEFAULT_NAME = {
107107
sort: 'so',
108108
stack: 'st',
109109
scale: 's',
110+
format: 'f',
110111
axis: 'ax',
111112
legend: 'l',
112113
value: 'v',
@@ -164,6 +165,7 @@ export type EnumIndex =
164165
{
165166
sort: (SortField<string> | SortOrder)[],
166167
stack: StackOffset[],
168+
format: string[],
167169
scale: boolean[],
168170
axis: boolean[],
169171
legend: boolean[],
@@ -282,6 +284,7 @@ export const DEFAULT_ENUM_INDEX: EnumIndex = {
282284
stack: ['zero', 'normalize', 'center', null],
283285
value: [undefined],
284286

287+
format: [undefined],
285288
scale: [true],
286289
axis: DEFAULT_BOOLEAN_ENUM,
287290
legend: DEFAULT_BOOLEAN_ENUM,

test/query/encoding.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ describe('query/encoding', () => {
2424
{type: 'quantitative'}
2525
);
2626
});
27+
28+
it('return correct fieldDef for Text FieldQuery with format', () => {
29+
assert.deepEqual(
30+
toFieldDef(
31+
{format: '.3f', channel: 'text', field: 'Q', type: 'quantitative'},
32+
{props: ['field', 'format', 'type'], wildcardMode: 'skip'}
33+
),
34+
{format: '.3f', field: 'Q', type: 'quantitative'}
35+
);
36+
});
2737
});
2838

2939
describe('toValueDef', () => {

0 commit comments

Comments
 (0)