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

Improve bar value styles on vis_type_xy charts #87991

Merged
merged 2 commits into from
Jan 15, 2021
Merged
Changes from all 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
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,
Comment on lines +83 to +91
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These values should all come from the theme object. This will override all of these properties and ignore the value defined in the theme.

You should be able to add these overrides via the Settings.theme prop already. What is the use case for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I understood we should use defaults from Lens for values styles. These values which I found in Lens we should use in plugin. As we already have 'themeOverrides' variable I think we should add these defaults there. For convenience I created a separate function for this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, sorry 😐. When I looked at this PR I thought this was done in @elastic/charts. Just ignore me and my comment this is perfect!

},
};
}

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