From e301e9df3454f9d38b427d43390d2489ff61231f Mon Sep 17 00:00:00 2001 From: serenajiang Date: Tue, 4 May 2021 14:52:49 -0700 Subject: [PATCH] fix(legacy-plugin-chart-sankey): ensure tooltip position is within chart (#1092) --- .../plugins/legacy-plugin-chart-sankey/src/Sankey.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/superset-frontend/temporary_superset_ui/superset-ui/plugins/legacy-plugin-chart-sankey/src/Sankey.js b/superset-frontend/temporary_superset_ui/superset-ui/plugins/legacy-plugin-chart-sankey/src/Sankey.js index f7a2ee0305e5a..34a5bbfc7e9ac 100644 --- a/superset-frontend/temporary_superset_ui/superset-ui/plugins/legacy-plugin-chart-sankey/src/Sankey.js +++ b/superset-frontend/temporary_superset_ui/superset-ui/plugins/legacy-plugin-chart-sankey/src/Sankey.js @@ -115,9 +115,11 @@ function Sankey(element, props) { tooltip .html(() => getTooltipHtml(d)) .transition() - .duration(200) - .style('left', `${d3.event.offsetX + 10}px`) - .style('top', `${d3.event.offsetY + 10}px`) + .duration(200); + const { height: tooltipHeight, width: tooltipWidth } = tooltip.node().getBoundingClientRect(); + tooltip + .style('left', `${Math.min(d3.event.offsetX + 10, width - tooltipWidth)}px`) + .style('top', `${Math.min(d3.event.offsetY + 10, height - tooltipHeight)}px`) .style('position', 'absolute') .style('opacity', 0.95); }