From 14bc982e9cf4c936e1537f813c9b3b25fbbfba63 Mon Sep 17 00:00:00 2001 From: Guillaume Duboc Date: Sat, 2 Mar 2024 12:11:53 +0100 Subject: [PATCH] fix: ensure tooltip is in view --- src/flamegraph/tooltip.tsx | 4 ++-- src/network/tooltip.tsx | 4 ++-- src/style/_base.scss | 4 +--- src/treemap/tooltip.tsx | 4 ++-- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/flamegraph/tooltip.tsx b/src/flamegraph/tooltip.tsx index 953e62c..4ee7ef3 100644 --- a/src/flamegraph/tooltip.tsx +++ b/src/flamegraph/tooltip.tsx @@ -130,12 +130,12 @@ export const Tooltip: FunctionalComponent = ({ if (pos.left + boundingRect.width > window.innerWidth) { // Shifting horizontally - pos.left = window.innerWidth - boundingRect.width; + pos.left = Math.max(0,window.innerWidth - boundingRect.width); } if (pos.top + boundingRect.height > window.innerHeight) { // Flipping vertically - pos.top = mouseCoords.y - Tooltip_marginY - boundingRect.height; + pos.top = Math.max(0,mouseCoords.y - Tooltip_marginY - boundingRect.height); } setStyle(pos); diff --git a/src/network/tooltip.tsx b/src/network/tooltip.tsx index 36c1031..fdd1f04 100644 --- a/src/network/tooltip.tsx +++ b/src/network/tooltip.tsx @@ -50,12 +50,12 @@ export const Tooltip: FunctionalComponent = ({ node, visible }) => if (pos.left + boundingRect.width > window.innerWidth) { // Shifting horizontally - pos.left = window.innerWidth - boundingRect.width; + pos.left = Math.max(window.innerWidth - boundingRect.width); } if (pos.top + boundingRect.height > window.innerHeight) { // Flipping vertically - pos.top = mouseCoords.y - Tooltip_marginY - boundingRect.height; + pos.top = Math.max(mouseCoords.y - Tooltip_marginY - boundingRect.height); } setStyle(pos); diff --git a/src/style/_base.scss b/src/style/_base.scss index 978e894..71a43cd 100644 --- a/src/style/_base.scss +++ b/src/style/_base.scss @@ -60,8 +60,6 @@ main { padding: 5px; - white-space: nowrap; - font-size: 0.875rem; background-color: var(--background-color); @@ -139,4 +137,4 @@ main { .node { cursor: pointer; -} \ No newline at end of file +} diff --git a/src/treemap/tooltip.tsx b/src/treemap/tooltip.tsx index 953e62c..4eddbc7 100644 --- a/src/treemap/tooltip.tsx +++ b/src/treemap/tooltip.tsx @@ -130,12 +130,12 @@ export const Tooltip: FunctionalComponent = ({ if (pos.left + boundingRect.width > window.innerWidth) { // Shifting horizontally - pos.left = window.innerWidth - boundingRect.width; + pos.left = Math.max(window.innerWidth - boundingRect.width); } if (pos.top + boundingRect.height > window.innerHeight) { // Flipping vertically - pos.top = mouseCoords.y - Tooltip_marginY - boundingRect.height; + pos.top = Math.max(mouseCoords.y - Tooltip_marginY - boundingRect.height); } setStyle(pos);