Skip to content

Commit

Permalink
Copy PR #191. Thanks to @guillaumeduboc
Browse files Browse the repository at this point in the history
  • Loading branch information
Denis Bardadym committed Dec 27, 2024
1 parent 8bb980c commit 2200fe7
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 86 deletions.
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(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
2 changes: 0 additions & 2 deletions src/style/_base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ main {

padding: 5px;

white-space: nowrap;

font-size: 0.875rem;

background-color: var(--background-color);
Expand Down
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(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
24 changes: 8 additions & 16 deletions test/__snapshots__/e2e-rolldown.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ main {
border: 2px solid;
border-radius: 5px;
padding: 5px;
white-space: nowrap;
font-size: 0.875rem;
background-color: var(--background-color);
color: var(--text-color);
Expand Down Expand Up @@ -4781,7 +4780,6 @@ main {
border: 2px solid;
border-radius: 5px;
padding: 5px;
white-space: nowrap;
font-size: 0.875rem;
background-color: var(--background-color);
color: var(--text-color);
Expand Down Expand Up @@ -9793,11 +9791,11 @@ var drawChart = (function (exports) {
const boundingRect = ref.current.getBoundingClientRect();
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 Expand Up @@ -10323,7 +10321,6 @@ main {
border: 2px solid;
border-radius: 5px;
padding: 5px;
white-space: nowrap;
font-size: 0.875rem;
background-color: var(--background-color);
color: var(--text-color);
Expand Down Expand Up @@ -15328,7 +15325,6 @@ main {
border: 2px solid;
border-radius: 5px;
padding: 5px;
white-space: nowrap;
font-size: 0.875rem;
background-color: var(--background-color);
color: var(--text-color);
Expand Down Expand Up @@ -18717,11 +18713,11 @@ var drawChart = (function (exports) {
const boundingRect = ref.current.getBoundingClientRect();
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 Expand Up @@ -20282,7 +20278,6 @@ main {
border: 2px solid;
border-radius: 5px;
padding: 5px;
white-space: nowrap;
font-size: 0.875rem;
background-color: var(--background-color);
color: var(--text-color);
Expand Down Expand Up @@ -24987,7 +24982,6 @@ main {
border: 2px solid;
border-radius: 5px;
padding: 5px;
white-space: nowrap;
font-size: 0.875rem;
background-color: var(--background-color);
color: var(--text-color);
Expand Down Expand Up @@ -29999,11 +29993,11 @@ var drawChart = (function (exports) {
const boundingRect = ref.current.getBoundingClientRect();
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 Expand Up @@ -30529,7 +30523,6 @@ main {
border: 2px solid;
border-radius: 5px;
padding: 5px;
white-space: nowrap;
font-size: 0.875rem;
background-color: var(--background-color);
color: var(--text-color);
Expand Down Expand Up @@ -35534,7 +35527,6 @@ main {
border: 2px solid;
border-radius: 5px;
padding: 5px;
white-space: nowrap;
font-size: 0.875rem;
background-color: var(--background-color);
color: var(--text-color);
Expand Down Expand Up @@ -38923,11 +38915,11 @@ var drawChart = (function (exports) {
const boundingRect = ref.current.getBoundingClientRect();
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
24 changes: 8 additions & 16 deletions test/__snapshots__/e2e.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ main {
border: 2px solid;
border-radius: 5px;
padding: 5px;
white-space: nowrap;
font-size: 0.875rem;
background-color: var(--background-color);
color: var(--text-color);
Expand Down Expand Up @@ -4781,7 +4780,6 @@ main {
border: 2px solid;
border-radius: 5px;
padding: 5px;
white-space: nowrap;
font-size: 0.875rem;
background-color: var(--background-color);
color: var(--text-color);
Expand Down Expand Up @@ -9793,11 +9791,11 @@ var drawChart = (function (exports) {
const boundingRect = ref.current.getBoundingClientRect();
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 Expand Up @@ -10324,7 +10322,6 @@ main {
border: 2px solid;
border-radius: 5px;
padding: 5px;
white-space: nowrap;
font-size: 0.875rem;
background-color: var(--background-color);
color: var(--text-color);
Expand Down Expand Up @@ -15329,7 +15326,6 @@ main {
border: 2px solid;
border-radius: 5px;
padding: 5px;
white-space: nowrap;
font-size: 0.875rem;
background-color: var(--background-color);
color: var(--text-color);
Expand Down Expand Up @@ -18718,11 +18714,11 @@ var drawChart = (function (exports) {
const boundingRect = ref.current.getBoundingClientRect();
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 Expand Up @@ -20283,7 +20279,6 @@ main {
border: 2px solid;
border-radius: 5px;
padding: 5px;
white-space: nowrap;
font-size: 0.875rem;
background-color: var(--background-color);
color: var(--text-color);
Expand Down Expand Up @@ -24988,7 +24983,6 @@ main {
border: 2px solid;
border-radius: 5px;
padding: 5px;
white-space: nowrap;
font-size: 0.875rem;
background-color: var(--background-color);
color: var(--text-color);
Expand Down Expand Up @@ -30000,11 +29994,11 @@ var drawChart = (function (exports) {
const boundingRect = ref.current.getBoundingClientRect();
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 Expand Up @@ -30531,7 +30525,6 @@ main {
border: 2px solid;
border-radius: 5px;
padding: 5px;
white-space: nowrap;
font-size: 0.875rem;
background-color: var(--background-color);
color: var(--text-color);
Expand Down Expand Up @@ -35536,7 +35529,6 @@ main {
border: 2px solid;
border-radius: 5px;
padding: 5px;
white-space: nowrap;
font-size: 0.875rem;
background-color: var(--background-color);
color: var(--text-color);
Expand Down Expand Up @@ -38925,11 +38917,11 @@ var drawChart = (function (exports) {
const boundingRect = ref.current.getBoundingClientRect();
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
24 changes: 8 additions & 16 deletions test/__snapshots__/gh59.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ main {
border: 2px solid;
border-radius: 5px;
padding: 5px;
white-space: nowrap;
font-size: 0.875rem;
background-color: var(--background-color);
color: var(--text-color);
Expand Down Expand Up @@ -4786,7 +4785,6 @@ main {
border: 2px solid;
border-radius: 5px;
padding: 5px;
white-space: nowrap;
font-size: 0.875rem;
background-color: var(--background-color);
color: var(--text-color);
Expand Down Expand Up @@ -9798,11 +9796,11 @@ var drawChart = (function (exports) {
const boundingRect = ref.current.getBoundingClientRect();
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 Expand Up @@ -10340,7 +10338,6 @@ main {
border: 2px solid;
border-radius: 5px;
padding: 5px;
white-space: nowrap;
font-size: 0.875rem;
background-color: var(--background-color);
color: var(--text-color);
Expand Down Expand Up @@ -15345,7 +15342,6 @@ main {
border: 2px solid;
border-radius: 5px;
padding: 5px;
white-space: nowrap;
font-size: 0.875rem;
background-color: var(--background-color);
color: var(--text-color);
Expand Down Expand Up @@ -18734,11 +18730,11 @@ var drawChart = (function (exports) {
const boundingRect = ref.current.getBoundingClientRect();
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 Expand Up @@ -20299,7 +20295,6 @@ main {
border: 2px solid;
border-radius: 5px;
padding: 5px;
white-space: nowrap;
font-size: 0.875rem;
background-color: var(--background-color);
color: var(--text-color);
Expand Down Expand Up @@ -25007,7 +25002,6 @@ main {
border: 2px solid;
border-radius: 5px;
padding: 5px;
white-space: nowrap;
font-size: 0.875rem;
background-color: var(--background-color);
color: var(--text-color);
Expand Down Expand Up @@ -30019,11 +30013,11 @@ var drawChart = (function (exports) {
const boundingRect = ref.current.getBoundingClientRect();
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 Expand Up @@ -30557,7 +30551,6 @@ main {
border: 2px solid;
border-radius: 5px;
padding: 5px;
white-space: nowrap;
font-size: 0.875rem;
background-color: var(--background-color);
color: var(--text-color);
Expand Down Expand Up @@ -35562,7 +35555,6 @@ main {
border: 2px solid;
border-radius: 5px;
padding: 5px;
white-space: nowrap;
font-size: 0.875rem;
background-color: var(--background-color);
color: var(--text-color);
Expand Down Expand Up @@ -38951,11 +38943,11 @@ var drawChart = (function (exports) {
const boundingRect = ref.current.getBoundingClientRect();
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
Loading

0 comments on commit 2200fe7

Please sign in to comment.