diff --git a/src/compile/data/timeunit.ts b/src/compile/data/timeunit.ts index cea3ced5e5..99a1602f77 100644 --- a/src/compile/data/timeunit.ts +++ b/src/compile/data/timeunit.ts @@ -170,7 +170,9 @@ export class TimeUnitNode extends DataFlowNode { as: [as, `${as}_end`] }); } else if (f) { - const {field, timeUnit} = f; + const {field: escapedField, timeUnit} = f; + // since this is a expression, we want the unescaped field name + const field = escapedField.replaceAll('\\.', '.'); const smallestUnit = getSmallestTimeUnitPart(timeUnit?.unit); const {part, step} = getDateTimePartAndStep(smallestUnit, timeUnit.step); transforms.push({ diff --git a/test/compile/data/timeunit.test.ts b/test/compile/data/timeunit.test.ts index 37e8bf0d56..93524e7496 100644 --- a/test/compile/data/timeunit.test.ts +++ b/test/compile/data/timeunit.test.ts @@ -70,6 +70,24 @@ describe('compile/data/timeunit', () => { ]); }); + it('should return the proper field escaping with binnedyearmonth', () => { + const model = parseUnitModel({ + data: {values: []}, + mark: 'bar', + encoding: { + x: {field: 'a\\.b', type: 'temporal', timeUnit: 'binnedyearmonth'} + } + }); + + expect(assembleFromEncoding(model)).toEqual([ + { + type: 'formula', + expr: `timeOffset('month', datum['a.b'], 1)`, + as: 'a.b_end' + } + ]); + }); + it('should return a unit offset transforms for text with bandPosition', () => { const model = parseUnitModel({ data: {values: []},