Skip to content

Commit

Permalink
fix: parse field projections after encodings to prevent duplicates (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
arvind authored Jan 7, 2021
1 parent bafca07 commit f365e1f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/compile/selection/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,6 @@ const project: SelectionCompiler = {
}
}

// TODO: find a possible channel mapping for these fields.
for (const field of fields ?? []) {
const p: SelectionProjection = {type: 'E', field};
p.signals = {...signalName(p, 'data')};
proj.items.push(p);
proj.hasField[field] = p;
}

for (const channel of encodings ?? []) {
const fieldDef = model.fieldDef(channel);
if (fieldDef) {
Expand Down Expand Up @@ -158,6 +150,15 @@ const project: SelectionCompiler = {
}
}

// TODO: find a possible channel mapping for these fields.
for (const field of fields ?? []) {
if (proj.hasField[field]) continue;
const p: SelectionProjection = {type: 'E', field};
p.signals = {...signalName(p, 'data')};
proj.items.push(p);
proj.hasField[field] = p;
}

if (init) {
selCmpt.init = (init as any).map((v: SelectionInitMapping | SelectionInitIntervalMapping) => {
return proj.items.map(p => (v[p.channel] !== undefined ? v[p.channel] : v[p.field]));
Expand Down
14 changes: 14 additions & 0 deletions test/compile/selection/parse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,20 @@ describe('Selection', () => {
}
]);
});

it('does not add duplicate projections', () => {
const component = parseUnitSelection(model, [
{
name: 'one',
select: {type: 'interval', fields: ['Horsepower', 'Miles_per_Gallon'], encodings: ['x', 'y']}
}
]);

expect(component['one'].project.items).toEqual([
{field: 'Horsepower', channel: 'x', type: 'R', signals: {data: 'one_Horsepower', visual: 'one_x'}},
{field: 'Miles_per_Gallon', channel: 'y', type: 'R', signals: {data: 'one_Miles_per_Gallon', visual: 'one_y'}}
]);
});
});

it('materializes a selection', () => {
Expand Down

0 comments on commit f365e1f

Please sign in to comment.