Skip to content

Commit

Permalink
fix: boxplot-temporal-field
Browse files Browse the repository at this point in the history
  • Loading branch information
chanwutk committed Jul 21, 2020
1 parent 1ca8c13 commit 6024ce2
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/compositemark/boxplot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ export function normalizeBoxPlot(

const boxPlotType = getBoxPlotType(extent);
const {
bins,
timeUnits,
transform,
continuousAxisChannelDef,
continuousAxis,
Expand Down Expand Up @@ -300,17 +302,14 @@ export function normalizeBoxPlot(
}
})[0];

const filteredLayersMixinsTransforms = [...bins, ...timeUnits, joinaggregateTransform];
if (outlierLayersMixins && filteredWhiskerSpec) {
filteredLayersMixins = {
transform: [joinaggregateTransform],
transform: filteredLayersMixinsTransforms,
layer: [outlierLayersMixins, filteredWhiskerSpec]
};
} else if (outlierLayersMixins) {
filteredLayersMixins = outlierLayersMixins;
filteredLayersMixins.transform.unshift(joinaggregateTransform);
} else if (filteredWhiskerSpec) {
filteredLayersMixins = filteredWhiskerSpec;
filteredLayersMixins.transform.unshift(joinaggregateTransform);
} else if ((filteredLayersMixins = outlierLayersMixins || filteredWhiskerSpec)) {
filteredLayersMixins.transform.unshift(...filteredLayersMixinsTransforms);
}
}

Expand Down Expand Up @@ -423,6 +422,8 @@ function boxParams(
];

return {
bins,
timeUnits,
transform,
groupby,
aggregate,
Expand Down
27 changes: 27 additions & 0 deletions test/compositemark/boxplot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1070,4 +1070,31 @@ describe('normalizeBoxIQR', () => {
const {tooltip} = normalizedSpecWithTooltip['layer'][0]['layer'][0]['encoding'];
expect(tooltip).toEqual({field: 'year', type: 'quantitative'});
});

it("should include timeUnit transform in filteredLayerMixins' transform", () => {
const field = 'Date';
const timeUnit = 'year';
const normalizedSpec = normalize(
{
data: {url: 'data/population.json'},
mark: 'boxplot',
encoding: {
x: {
field,
type: 'temporal',
timeUnit
},
y: {field: 'Anomaly', type: 'quantitative'}
}
},
defaultConfig
);

const filteredLayerMixins = normalizedSpec['layer'][1];
expect(filteredLayerMixins.transform[0]).toEqual({
timeUnit: {unit: 'year'},
field,
as: `${timeUnit}_${field}`
});
});
});

0 comments on commit 6024ce2

Please sign in to comment.