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

[Dashboard] Fix Lens and TSVB chart tooltip positioning relative to global headers #94247

Merged
merged 14 commits into from
Apr 5, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@
"@cypress/webpack-preprocessor": "^5.5.0",
"@elastic/apm-rum": "^5.6.1",
"@elastic/apm-rum-react": "^1.2.5",
"@elastic/charts": "25.1.0",
"@elastic/charts": "25.2.0",
"@elastic/eslint-config-kibana": "link:packages/elastic-eslint-config-kibana",
"@elastic/eslint-plugin-eui": "0.0.2",
"@elastic/github-checks-reporter": "0.0.20b3",
Expand Down
10 changes: 9 additions & 1 deletion src/plugins/vis_type_xy/public/components/xy_settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ type XYSettingsProps = Pick<
legendPosition: Position;
};

const KBN_HEADER_OFFSET = 98;
Copy link
Contributor

Choose a reason for hiding this comment

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

This constant should be available from

import euiLightVars from '@elastic/eui/dist/eui_theme_light.json';
KBN_HEADER_OFFSET = 2* euiLightVarseuiHeaderHeightCompensation

(same for Lens)

Copy link
Contributor Author

@nickofthyme nickofthyme Mar 10, 2021

Choose a reason for hiding this comment

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

Thanks @flash1293 I'll pull from that value.

Also is there an easy way to tell what app you are in or better yet if the header is visible? Other than a querySelector. I'd like to only add this padding when the tooltip is visible. Like canvas for instance may use an xy chart on full screen where the padding is not necessary.

Screen.Recording.2021-03-10.at.07.50.29.AM.mp4

Copy link
Contributor

Choose a reason for hiding this comment

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

That's a good point - core.chrome.getIsVisible$ should give you an observable with this information. The biggest challenge is to pass it through to the right places :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That worked perfectly! Thanks! 🙏

xy charts in canvas

Screen.Recording.2021-03-10.at.09.04.54.AM.mp4

Lens charts in dashboard

Screen.Recording.2021-03-10.at.09.39.54.AM.mp4


function getValueLabelsStyling(isHorizontal: boolean) {
const VALUE_LABELS_MAX_FONTSIZE = 15;
const VALUE_LABELS_MIN_FONTSIZE = 10;
Expand Down Expand Up @@ -148,13 +150,19 @@ export const XYSettings: FC<XYSettingsProps> = ({
: headerValueFormatter &&
(tooltip.detailedTooltip ? undefined : ({ value }: any) => headerValueFormatter(value));

const boudaryProps = {
boundary: document.body,
boundaryPadding: { top: KBN_HEADER_OFFSET },
};

const tooltipProps: TooltipProps = tooltip.detailedTooltip
? {
...tooltip,
...boudaryProps,
customTooltip: tooltip.detailedTooltip(headerFormatter),
headerFormatter: undefined,
}
: { ...tooltip, headerFormatter };
: { ...tooltip, ...boudaryProps, headerFormatter };

return (
<Settings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { VisualizationContainer } from '../visualization_container';
import { CHART_NAMES, DEFAULT_PERCENT_DECIMALS } from './constants';
import { PieExpressionProps } from './types';
import { getSliceValue, getFilterContext } from './render_helpers';
import { EmptyPlaceholder } from '../shared_components';
import { EmptyPlaceholder, KBN_HEADER_OFFSET } from '../shared_components';
import './visualization.scss';
import { desanitizeFilterContext } from '../utils';
import {
Expand Down Expand Up @@ -260,6 +260,10 @@ export function PieComponent(
>
<Chart>
<Settings
tooltip={{
boundary: document.body,
boundaryPadding: { top: KBN_HEADER_OFFSET },
}}
debugState={window._echDebugStateFlag ?? false}
// Legend is hidden in many scenarios
// - Tiny preview
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/lens/public/shared_components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ export * from './empty_placeholder';
export { ToolbarPopoverProps, ToolbarPopover } from './toolbar_popover';
export { LegendSettingsPopover } from './legend_settings_popover';
export { PalettePicker } from './palette_picker';

export const KBN_HEADER_OFFSET = 98;
4 changes: 3 additions & 1 deletion x-pack/plugins/lens/public/xy_visualization/expression.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ import {
PaletteRegistry,
SeriesLayer,
} from '../../../../../src/plugins/charts/public';
import { EmptyPlaceholder } from '../shared_components';
import { EmptyPlaceholder, KBN_HEADER_OFFSET } from '../shared_components';
import { desanitizeFilterContext } from '../utils';
import { fittingFunctionDefinitions, getFitOptions } from './fitting_functions';
import { getAxesConfiguration } from './axes_configuration';
Expand Down Expand Up @@ -548,6 +548,8 @@ export function XYChart({
baseTheme={chartBaseTheme}
tooltip={{
headerFormatter: (d) => safeXAccessorLabelRenderer(d.value),
boundary: document.body,
boundaryPadding: { top: KBN_HEADER_OFFSET },
}}
rotation={shouldRotate ? 90 : 0}
xDomain={xDomain}
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1349,10 +1349,10 @@
dependencies:
object-hash "^1.3.0"

"@elastic/charts@25.1.0":
version "25.1.0"
resolved "https://registry.yarnpkg.com/@elastic/charts/-/charts-25.1.0.tgz#8859e07c9822696b3f9b12ae46a18e3316f623fd"
integrity sha512-4IFmyhg3dG7VjP0C9DbMBBAxAtai/HPdG/4Z5UMdGYGoZiJwS+fo50irQtvD3H5Lm6OSS8Xk9hmCVPx8KmdiUg==
"@elastic/charts@25.2.0":
version "25.2.0"
resolved "https://registry.yarnpkg.com/@elastic/charts/-/charts-25.2.0.tgz#82ec02e7d7998ab3da26edb9f18dcb4b9304b4b0"
integrity sha512-E3QUxt8vklGH8ThZ1yBl+Nb0cLikJnrai5AcZcSSKioiSRlBoIfam7BWWHKl3p2GFOlEs7mGid82BnZDnY6EUw==
dependencies:
"@popperjs/core" "^2.4.0"
chroma-js "^2.1.0"
Expand Down