Skip to content

Commit

Permalink
fix: ensure tooltip is in view
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaumeduboc committed Mar 2, 2024
1 parent dec8398 commit 14bc982
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/flamegraph/tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,12 @@ export const Tooltip: FunctionalComponent<TooltipProps> = ({

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);
Expand Down
4 changes: 2 additions & 2 deletions src/network/tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ export const Tooltip: FunctionalComponent<TooltipProps> = ({ 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);
Expand Down
4 changes: 1 addition & 3 deletions src/style/_base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ main {

padding: 5px;

white-space: nowrap;

font-size: 0.875rem;

background-color: var(--background-color);
Expand Down Expand Up @@ -139,4 +137,4 @@ main {

.node {
cursor: pointer;
}
}
4 changes: 2 additions & 2 deletions src/treemap/tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,12 @@ export const Tooltip: FunctionalComponent<TooltipProps> = ({

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);
Expand Down

0 comments on commit 14bc982

Please sign in to comment.