Skip to content

Commit

Permalink
fix: unescape paths in binned timeunits
Browse files Browse the repository at this point in the history
  • Loading branch information
lsh committed Sep 12, 2023
1 parent 76e5460 commit 34ecf2e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/compile/data/timeunit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
18 changes: 18 additions & 0 deletions test/compile/data/timeunit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: []},
Expand Down

0 comments on commit 34ecf2e

Please sign in to comment.