Skip to content

Commit

Permalink
fix: correct y axis title in boxplot when mark.extent isnt set (#9483)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcBaeuerle authored Feb 14, 2025
1 parent 61d927c commit f3dc811
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/compositemark/boxplot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {MarkInvalidMixins} from '../invalid';
import {NormalizerParams} from '../normalize';
import {GenericUnitSpec, NormalizedLayerSpec, NormalizedUnitSpec} from '../spec';
import {AggregatedFieldDef, CalculateTransform, JoinAggregateTransform, Transform} from '../transform';
import {accessWithDatumToUnescapedPath, isEmpty, omit, removePathFromField} from '../util';
import {accessWithDatumToUnescapedPath, removePathFromField} from '../util';
import {CompositeMarkNormalizer} from './base';
import {
compositeMarkContinuousAxis,
Expand Down Expand Up @@ -301,7 +301,6 @@ export function normalizeBoxPlot(

const {scale, axis} = continuousAxisChannelDef;
const title = getTitle(continuousAxisChannelDef);
const axisWithoutTitle = omit(axis, ['title']);

const outlierLayersMixins = partLayerMixins<BoxPlotPartsMixins>(markDef, 'outliers', config.boxplot, {
transform: [{filter: `(${fieldExpr} < ${lowerWhiskerExpr}) || (${fieldExpr} > ${upperWhiskerExpr})`}],
Expand All @@ -312,8 +311,7 @@ export function normalizeBoxPlot(
type: continuousAxisChannelDef.type,
...(title !== undefined ? {title} : {}),
...(scale !== undefined ? {scale} : {}),
// add axis without title since we already added the title above
...(isEmpty(axisWithoutTitle) ? {} : {axis: axisWithoutTitle})
...(axis !== undefined ? {axis} : {})
},
...encodingWithoutSizeColorContinuousAxisAndTooltip,
...(color ? {color} : {}),
Expand Down
23 changes: 23 additions & 0 deletions test/compositemark/boxplot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1166,4 +1166,27 @@ describe('normalizeBoxIQR', () => {
as: `${timeUnit}_${field}`
});
});

it('should produce correct y axis title when mark.extent is not explicitly set', () => {
const normalizedSpec = normalize(
{
data: {url: 'data/population.json'},
mark: {
type: 'boxplot'
},
encoding: {
x: {field: 'age', type: 'quantitative'},
y: {
field: 'people',
type: 'quantitative',
axis: {title: 'Population'}
},
color: {value: 'skyblue'}
}
},
defaultConfig
);
const title = (normalizedSpec as any).layer[0].layer[0].encoding.y.axis.title;
expect(title).toBe('Population');
});
});

0 comments on commit f3dc811

Please sign in to comment.