Skip to content

Commit

Permalink
use the same defaults as Lens (#87991)
Browse files Browse the repository at this point in the history
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
VladLasitsa and kibanamachine authored Jan 15, 2021
1 parent a0b787c commit 5fd0027
Showing 1 changed file with 25 additions and 11 deletions.
36 changes: 25 additions & 11 deletions src/plugins/vis_type_xy/public/components/xy_settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import {
LegendColorPicker,
TooltipProps,
TickFormatter,
VerticalAlignment,
HorizontalAlignment,
} from '@elastic/charts';

import { renderEndzoneTooltip } from '../../../charts/public';
Expand Down Expand Up @@ -70,6 +72,27 @@ type XYSettingsProps = Pick<
legendPosition: Position;
};

function getValueLabelsStyling(isHorizontal: boolean) {
const VALUE_LABELS_MAX_FONTSIZE = 15;
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,
},
};
}

export const XYSettings: FC<XYSettingsProps> = ({
markSizeRatio,
rotation,
Expand All @@ -92,10 +115,7 @@ export const XYSettings: FC<XYSettingsProps> = ({
const theme = themeService.useChartsTheme();
const baseTheme = themeService.useChartsBaseTheme();
const dimmingOpacity = getUISettings().get<number | undefined>('visualization:dimmingOpacity');
const fontSize =
typeof theme.barSeriesStyle?.displayValue?.fontSize === 'number'
? { min: theme.barSeriesStyle?.displayValue?.fontSize }
: theme.barSeriesStyle?.displayValue?.fontSize ?? { min: 8 };
const valueLabelsStyling = getValueLabelsStyling(rotation === 90 || rotation === -90);

const themeOverrides: PartialTheme = {
markSizeRatio,
Expand All @@ -105,13 +125,7 @@ export const XYSettings: FC<XYSettingsProps> = ({
},
},
barSeriesStyle: {
displayValue: {
fontSize,
alignment: {
horizontal: 'center',
vertical: 'middle',
},
},
...valueLabelsStyling,
},
axes: {
axisTitle: {
Expand Down

0 comments on commit 5fd0027

Please sign in to comment.