diff --git a/public/app/plugins/panel/flamegraph/components/FlameGraph/FlameGraph.tsx b/public/app/plugins/panel/flamegraph/components/FlameGraph/FlameGraph.tsx
index dd450a5b2f3..61da4958353 100644
--- a/public/app/plugins/panel/flamegraph/components/FlameGraph/FlameGraph.tsx
+++ b/public/app/plugins/panel/flamegraph/components/FlameGraph/FlameGraph.tsx
@@ -161,8 +161,15 @@ const FlameGraph = ({
);
if (barIndex !== -1 && !isNaN(levelIndex) && !isNaN(barIndex)) {
- tooltipRef.current.style.left = e.clientX + 10 + 'px';
tooltipRef.current.style.top = e.clientY + 'px';
+ if (document.documentElement.clientWidth - e.clientX < 400) {
+ tooltipRef.current.style.right = document.documentElement.clientWidth - e.clientX + 15 + 'px';
+ tooltipRef.current.style.left = 'auto';
+ } else {
+ tooltipRef.current.style.left = e.clientX + 15 + 'px';
+ tooltipRef.current.style.right = 'auto';
+ }
+
setTooltipItem(levels[levelIndex][barIndex]);
}
}
diff --git a/public/app/plugins/panel/flamegraph/components/FlameGraph/FlameGraphTooltip.tsx b/public/app/plugins/panel/flamegraph/components/FlameGraph/FlameGraphTooltip.tsx
index 55811867d10..55f3f8cce3a 100644
--- a/public/app/plugins/panel/flamegraph/components/FlameGraph/FlameGraphTooltip.tsx
+++ b/public/app/plugins/panel/flamegraph/components/FlameGraph/FlameGraphTooltip.tsx
@@ -1,7 +1,8 @@
import { css } from '@emotion/css';
import React, { LegacyRef } from 'react';
-import { useStyles2, Tooltip } from '@grafana/ui';
+import { GrafanaTheme2 } from '@grafana/data';
+import { useStyles2 } from '@grafana/ui';
import { FlameGraphDataContainer, LevelItem } from './dataTransform';
@@ -19,26 +20,18 @@ const FlameGraphTooltip = ({ data, tooltipRef, item, totalTicks }: Props) => {
if (item) {
const tooltipData = getTooltipData(data, item, totalTicks);
content = (
- {data.getLabel(item.itemIndex)}
- {tooltipData.unitTitle}
-
- Total: {tooltipData.unitValue} ({tooltipData.percentValue}%)
-
- Self: {tooltipData.unitSelf} ({tooltipData.percentSelf}%)
-
- Samples: {tooltipData.samples}
-
{data.getLabel(item.itemIndex)}
+
+ {tooltipData.unitTitle}
+
+ Total: {tooltipData.unitValue} ({tooltipData.percentValue}%)
+
+ Self: {tooltipData.unitSelf} ({tooltipData.percentSelf}%)
+
+ Samples: {tooltipData.samples}
+