Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[XY axis] Fixes the values inside bar charts #106198

Merged
merged 3 commits into from
Jul 21, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 5 additions & 13 deletions src/plugins/vis_type_xy/public/components/xy_settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,15 @@ type XYSettingsProps = Pick<
legendPosition: Position;
};

function getValueLabelsStyling(isHorizontal: boolean) {
const VALUE_LABELS_MAX_FONTSIZE = 15;
function getValueLabelsStyling() {
const VALUE_LABELS_MAX_FONTSIZE = 12;
const VALUE_LABELS_MIN_FONTSIZE = 10;
stratoula marked this conversation as resolved.
Show resolved Hide resolved
const VALUE_LABELS_VERTICAL_OFFSET = -10;
const VALUE_LABELS_HORIZONTAL_OFFSET = 10;

return {
displayValue: {
fontSize: { min: VALUE_LABELS_MIN_FONTSIZE, max: VALUE_LABELS_MAX_FONTSIZE },
fill: { textInverted: true, textBorder: 2 },
alignment: isHorizontal
? {
vertical: VerticalAlignment.Middle,
}
: { horizontal: HorizontalAlignment.Center },
offsetX: isHorizontal ? VALUE_LABELS_HORIZONTAL_OFFSET : 0,
offsetY: isHorizontal ? 0 : VALUE_LABELS_VERTICAL_OFFSET,
fill: { textInverted: false, textContrast: true },
alignment: { horizontal: HorizontalAlignment.Center, vertical: VerticalAlignment.Middle },
},
};
}
Expand All @@ -103,7 +95,7 @@ export const XYSettings: FC<XYSettingsProps> = ({
const theme = themeService.useChartsTheme();
const baseTheme = themeService.useChartsBaseTheme();
const dimmingOpacity = getUISettings().get<number | undefined>('visualization:dimmingOpacity');
const valueLabelsStyling = getValueLabelsStyling(rotation === 90 || rotation === -90);
const valueLabelsStyling = getValueLabelsStyling();

const themeOverrides: PartialTheme = {
markSizeRatio,
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/vis_type_xy/public/utils/render_all_series.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ export const renderAllSeries = (
minBarHeight={2}
displayValueSettings={{
showValueLabel,
isValueContainedInElement: true,
stratoula marked this conversation as resolved.
Show resolved Hide resolved
isAlternatingValueLabel: false,
overflowConstraints: [LabelOverflowConstraint.ChartEdges],
stratoula marked this conversation as resolved.
Show resolved Hide resolved
}}
/>
Expand Down