Skip to content

Commit

Permalink
Fix the pathoverlay normalization to take correct markDef
Browse files Browse the repository at this point in the history
  • Loading branch information
yhoonkim committed Jul 19, 2023
1 parent 538f6e8 commit 98e0ebe
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/normalize/pathoverlay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {isUnitSpec} from '../spec/unit';
import {stack} from '../stack';
import {keys, omit, pick} from '../util';
import {NonFacetUnitNormalizer, NormalizeLayerOrUnit, NormalizerParams} from './base';
import {initMarkdef} from '../compile/mark/init';

type UnitSpecWithPathOverlay = GenericUnitSpec<Encoding<string>, Mark | MarkDef<'line' | 'area' | 'rule' | 'trail'>>;

Expand Down Expand Up @@ -109,6 +110,7 @@ export class PathOverlayNormalizer implements NonFacetUnitNormalizer<UnitSpecWit
const markDef: MarkDef = isMarkDef(mark) ? mark : {type: mark};

const pointOverlay = getPointOverlay(markDef, config[markDef.type], encoding);

const lineOverlay = markDef.type === 'area' && getLineOverlay(markDef, config[markDef.type]);

const layer: NormalizedUnitSpec[] = [
Expand All @@ -130,7 +132,7 @@ export class PathOverlayNormalizer implements NonFacetUnitNormalizer<UnitSpecWit
// FIXME: determine rules for applying selections.

// Need to copy stack config to overlayed layer
const stackProps = stack(markDef, encoding);
const stackProps = stack(initMarkdef(markDef, encoding, config), encoding);

let overlayEncoding = encoding;
if (stackProps) {
Expand Down
36 changes: 36 additions & 0 deletions test/normalize/pathoverlay.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,42 @@ describe('PathOverlayNormalizer', () => {
});
});

it('correctly normalizes default stacked area with overlay line', () => {
const spec: TopLevelSpec = {
data: {url: 'data/movies.json'},
mark: 'area',
encoding: {
x: {field: 'IMDB Rating', type: 'quantitative'},
y: {field: 'Rotten Tomatoes Rating', type: 'quantitative'},
color: {field: 'MPAA RATING', type: 'nominal'}
},
config: {area: {line: {}}}
};
const normalizedSpec = normalize(spec);
expect(normalizedSpec).toEqual({
data: {url: 'data/movies.json'},
layer: [
{
mark: {type: 'area', opacity: 0.7},
encoding: {
x: {field: 'IMDB Rating', type: 'quantitative'},
y: {field: 'Rotten Tomatoes Rating', type: 'quantitative'},
color: {field: 'MPAA RATING', type: 'nominal'}
}
},
{
mark: {type: 'line'},
encoding: {
x: {field: 'IMDB Rating', type: 'quantitative'},
y: {field: 'Rotten Tomatoes Rating', type: 'quantitative', stack: 'zero'},
color: {field: 'MPAA RATING', type: 'nominal'}
}
}
],
config: {area: {line: {}}}
});
});

it('correctly normalizes streamgraph with overlay line', () => {
const spec: TopLevelSpec = {
data: {url: 'data/stocks.csv'},
Expand Down

0 comments on commit 98e0ebe

Please sign in to comment.