Skip to content

Commit ebfde33

Browse files
authored
feat(ui): Create and use element id for ECharts when using tooltip.appendToBody (#88735)
ECharts has a tooltip option (`appendToBody`) to append the tooltip to `document.body`. This is useful when the charts has a parent container that has e.g. `overflow: hidden` so that the tooltip does not get cutoff. However we have a [custom tooltip positioning function](https://github.com/getsentry/sentry/blob/master/static/app/components/charts/components/tooltip.tsx#L403) that requires a element id to get a reference of the chart (or its container) to properly position the tooltip. If we use `appendToBody` without an `id`, the tooltip does not get displayed near the mouse cursor and instead it's confined within the bounds of the chart. ### Before The crosshairs is where the mouse is (above series both both screenshots) ![image](https://github.com/user-attachments/assets/ab34d439-ee7b-4472-9810-11e4946c13bd) Here the tooltip is not near the series or the mouse ![image](https://github.com/user-attachments/assets/a51e41c6-c55b-4d28-8984-e0cdd169b96c) ### After Notice the tooltips are near the crosshairs ![image](https://github.com/user-attachments/assets/82ac66ab-f894-4900-a606-2ca3dc524be9) ![image](https://github.com/user-attachments/assets/585aeb0b-fb1c-4fec-ab12-1d129f63909c)
1 parent d905eaf commit ebfde33

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

static/app/components/charts/baseChart.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import 'echarts/lib/component/toolbox';
44
import 'echarts/lib/component/brush';
55
import 'zrender/lib/svg/svg';
66

7-
import {useMemo} from 'react';
7+
import {useId, useMemo} from 'react';
88
import type {Theme} from '@emotion/react';
99
import {css, Global, useTheme} from '@emotion/react';
1010
import styled from '@emotion/styled';
@@ -181,6 +181,7 @@ export interface BaseChartProps {
181181
* Chart height
182182
*/
183183
height?: ReactEChartOpts['height'];
184+
184185
/**
185186
* If data is grouped by date; then apply default date formatting to x-axis
186187
* and tooltips.
@@ -478,6 +479,7 @@ function BaseChart({
478479
: false;
479480

480481
const isTooltipPortalled = tooltip?.appendToBody;
482+
const chartId = useId();
481483

482484
const chartOption = useMemo(() => {
483485
const seriesData =
@@ -496,6 +498,7 @@ function BaseChart({
496498
addSecondsToTimeFormat,
497499
utc,
498500
bucketSize,
501+
chartId: isTooltipPortalled ? chartId : undefined,
499502
...tooltip,
500503
className: isTooltipPortalled
501504
? `${tooltip?.className ?? ''} chart-tooltip-portal`
@@ -568,6 +571,7 @@ function BaseChart({
568571
brush,
569572
};
570573
}, [
574+
chartId,
571575
color,
572576
resolvedSeries,
573577
isTooltipPortalled,
@@ -662,7 +666,11 @@ function BaseChart({
662666
}, [style, autoHeightResize, height, width]);
663667

664668
return (
665-
<ChartContainer autoHeightResize={autoHeightResize} data-test-id={dataTestId}>
669+
<ChartContainer
670+
id={isTooltipPortalled ? chartId : undefined}
671+
autoHeightResize={autoHeightResize}
672+
data-test-id={dataTestId}
673+
>
666674
{isTooltipPortalled && <Global styles={getPortalledTooltipStyles({theme})} />}
667675
<ReactEchartsCore
668676
ref={ref}

static/app/views/issueDetails/streamline/eventGraph.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,7 @@ export function EventGraph({
512512
...releaseBubbleGrid,
513513
}}
514514
tooltip={{
515+
appendToBody: true,
515516
formatAxisLabel: (
516517
value,
517518
isTimestamp,

0 commit comments

Comments
 (0)