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

feat: Add timeFormatType field #8320

Merged
merged 16 commits into from
Aug 4, 2022
Prev Previous commit
Next Next commit
fix: address @kanitw's concerns
Lukas Hermann committed Aug 3, 2022
commit af944219a7b8d476899000a6553db674120f5096
7 changes: 6 additions & 1 deletion src/compile/format.ts
Original file line number Diff line number Diff line change
@@ -79,7 +79,12 @@ export function formatSignalRef({
});
}
}
if (type === 'temporal' && config.timeFormatType) {
if (
type === 'temporal' &&
config.timeFormatType &&
isFieldDef(fieldOrDatumDef) &&
fieldOrDatumDef.timeUnit === undefined
) {
return formatCustomType({
fieldOrDatumDef,
format: config.timeFormat,
2 changes: 1 addition & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
@@ -193,7 +193,7 @@ export interface VLOnlyConfig<ES extends ExprRef | SignalRef> {
* [Custom format type](https://vega.github.io/vega-lite/docs/config.html#custom-format-type)
* for `config.timeFormat`.
*
* __Default value:__ `undefined` -- This is equilvalent to call D3-format, which is exposed as [`format` in Vega-Expression](https://vega.github.io/vega/docs/expressions/#format).
* __Default value:__ `undefined` -- This is equilvalent to call D3-time-format, which is exposed as [`timeFormat` in Vega-Expression](https://vega.github.io/vega/docs/expressions/#timeFormat).
* __Note:__ You must also set `customFormatTypes` to `true` and there must *not* be a `timeUnit` defined to use this feature.
*/
timeFormatType?: string;
4 changes: 2 additions & 2 deletions test/compile/format.test.ts
Original file line number Diff line number Diff line change
@@ -231,14 +231,14 @@ describe('Format', () => {
it('should use a custom formatter datumDef if config.timeFormatType is present', () => {
expect(
formatSignalRef({
fieldOrDatumDef: {datum: 200, type: 'temporal'},
fieldOrDatumDef: {field: 'date', type: 'temporal'},
format: undefined,
formatType: undefined,
expr: 'parent',
config: {timeFormat: 'abc', timeFormatType: 'customFormatter', customFormatTypes: true}
})
).toEqual({
signal: 'customFormatter(200, "abc")'
signal: 'customFormatter(parent["date"], "abc")'
});
});