Skip to content

Commit

Permalink
[XY axis] Fixes the values inside bar charts (#106198) (#106370)
Browse files Browse the repository at this point in the history
* [XY axis] Fixes the values inside bar charts

* Apply PR comments
  • Loading branch information
stratoula authored Jul 21, 2021
1 parent f4276af commit 5270b83
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
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;
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
7 changes: 6 additions & 1 deletion src/plugins/vis_type_xy/public/utils/render_all_series.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,12 @@ export const renderAllSeries = (
minBarHeight={2}
displayValueSettings={{
showValueLabel,
overflowConstraints: [LabelOverflowConstraint.ChartEdges],
isValueContainedInElement: false,
isAlternatingValueLabel: false,
overflowConstraints: [
LabelOverflowConstraint.ChartEdges,
LabelOverflowConstraint.BarGeometry,
],
}}
/>
);
Expand Down

0 comments on commit 5270b83

Please sign in to comment.