Skip to content

Commit

Permalink
fix: selection compatibility normalizer should run first (#7160)
Browse files Browse the repository at this point in the history
  • Loading branch information
arvind committed Jan 6, 2021
1 parent c10f44e commit 55d6238
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/normalize/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function normalizeGenericSpec(
) {
const normParams = {config};
return topLevelSelectionNormalizer.map(
selectionCompatNormalizer.map(coreNormalizer.map(spec, normParams), normParams),
coreNormalizer.map(selectionCompatNormalizer.map(spec, normParams), normParams),
normParams
);
}
Expand Down
12 changes: 9 additions & 3 deletions src/normalize/selectioncompat.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import {Field} from '../channeldef';
import {SelectionDef} from '../selection';
import {NormalizedUnitSpec} from '../spec';
import {FacetedUnitSpec, LayerSpec, UnitSpec} from '../spec';
import {SpecMapper} from '../spec/map';
import {NormalizerParams} from './base';

export class SelectionCompatibilityNormalizer extends SpecMapper<NormalizerParams, NormalizedUnitSpec> {
public mapUnit(spec: NormalizedUnitSpec) {
export class SelectionCompatibilityNormalizer extends SpecMapper<
NormalizerParams,
FacetedUnitSpec<Field>,
LayerSpec<Field>,
UnitSpec<Field>
> {
public mapUnit(spec: UnitSpec<Field>) {
const selections = (spec as any).selection;
const params: SelectionDef[] = [];

Expand Down
27 changes: 27 additions & 0 deletions test/normalize/selectioncompat.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {normalize} from '../../src';
import {SelectionCompatibilityNormalizer} from '../../src/normalize/selectioncompat';
import {NormalizedUnitSpec} from '../../src/spec';

Expand Down Expand Up @@ -85,4 +86,30 @@ describe('SelectionCompatibilityNormalizer', () => {
expect(normedUnit.params[0]).toHaveProperty('value', {x: [55, 160], y: [13, 37]});
expect(normedUnit.params[1]).toHaveProperty('bind', 'scales');
});

it('should be the first normalizer run', () => {
const spec: any = {
data: {url: 'data/cars.json'},
selection: {
brush: {
type: 'interval',
init: {x: [55, 160], y: [13, 37]}
}
},
mark: {type: 'line', point: true},
encoding: {
row: {field: 'Origin', type: 'nominal'},
x: {field: 'Horsepower', type: 'quantitative'},
y: {field: 'Miles_per_Gallon', type: 'quantitative'},
color: {
condition: {selection: 'brush', field: 'Cylinders', type: 'ordinal'},
value: 'grey'
}
}
};

const normalized = normalize(spec) as any;
expect(normalized.spec.layer[0]).toHaveProperty('params');
expect(normalized.spec.layer[0].params[0].name).toBe('brush');
});
});

0 comments on commit 55d6238

Please sign in to comment.