Skip to content

Commit

Permalink
fix(auto): axis without label (#5338)
Browse files Browse the repository at this point in the history
  • Loading branch information
pearmini authored Jul 24, 2023
1 parent 9bd7bd9 commit 06b73c2
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { G2Spec } from '../../../src';

export function alphabetIntervalAutoPaddingLabelHide(): G2Spec {
return {
type: 'interval',
padding: 'auto',
transform: [{ type: 'sortX', by: 'y', reverse: true }],
data: {
type: 'fetch',
value: 'data/alphabet.csv',
},
encode: {
x: 'letter',
y: 'frequency',
color: 'steelblue',
},
axis: {
y: { labelFormatter: '.0%', label: false },
},
viewStyle: {
viewFill: '#4e79a7',
plotFill: '#f28e2c',
mainFill: '#e15759',
contentFill: '#76b7b2',
},
};
}
1 change: 1 addition & 0 deletions __tests__/plots/static/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,3 +274,4 @@ export { countriesBubbleLegendSize } from './countries-bubble-legend-size';
export { cars2PointOrdinalSize } from './cars2-point-ordinal-size';
export { cars2PointConstantColorSize } from './cars2-point-constant-color-size';
export { alphabetIntervalTitleAuto } from './alphabet-interval-title-auto';
export { alphabetIntervalAutoPaddingLabelHide } from './alphabet-interval-auto-padding-label-hide';
5 changes: 3 additions & 2 deletions src/runtime/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -691,11 +691,10 @@ function computeAxisSize(
// Compute Labels.
const scale = createScale(component, library);
const labelBBoxes = computeLabelsBBox(rest, scale);
const paddingTick = tickLength + labelSpacing;
if (labelBBoxes) {
const maxLabelWidth = max(labelBBoxes, (d) => d.width);
const maxLabelHeight = max(labelBBoxes, (d) => d.height);
const paddingTick = tickLength + labelSpacing;

if (isVertical) {
component.size = maxLabelWidth + paddingTick;
} else {
Expand All @@ -712,6 +711,8 @@ function computeAxisSize(
component.size = maxLabelHeight + paddingTick;
}
}
} else {
component.size = paddingTick;
}

// Compute title.
Expand Down

0 comments on commit 06b73c2

Please sign in to comment.