From de80ba471156d6ef3c310cf4b7ffbdef93db6996 Mon Sep 17 00:00:00 2001 From: Timothy Mugo Date: Tue, 11 Aug 2026 20:54:52 +0300 Subject: [PATCH 1/7] feat: add tooltip visibility control on scroll --- .../dvz-ui/src/embeddable/chart/Tooltip.jsx | 42 ++++++++++++++++--- .../src/embeddable/common/ChartTooltip.jsx | 2 +- .../src/scss/themes/default/_charts.scss | 5 ++- 3 files changed, 42 insertions(+), 7 deletions(-) diff --git a/packages/dvz-ui/src/embeddable/chart/Tooltip.jsx b/packages/dvz-ui/src/embeddable/chart/Tooltip.jsx index 197bb7ec..799d13da 100644 --- a/packages/dvz-ui/src/embeddable/chart/Tooltip.jsx +++ b/packages/dvz-ui/src/embeddable/chart/Tooltip.jsx @@ -22,6 +22,18 @@ const clampShift = (start, end, viewportSize, overshoot = 0) => { return 0; }; +const isNivoTooltipWrapper = (el) => { + if (!el) { + return false; + } + + const inlineStyle = (el.getAttribute("style") || "").toLowerCase(); + return ( + inlineStyle.includes("position: absolute") && + inlineStyle.includes("pointer-events: none") + ); +}; + // Nudges an already-positioned tooltip back inside the viewport via a // corrective transform, without touching the chart library's own positioning // (chart libraries like nivo can place tooltips past the screen edge). @@ -30,18 +42,33 @@ export const clampTooltipToViewport = (el) => { return; } + const wrapper = isNivoTooltipWrapper(el.parentElement) ? el.parentElement : null; + // Reset so we measure relative to the library's original position. el.style.transform = ""; + if (wrapper) { + // Keep the library transform untouched; only reset our corrective translate. + wrapper.style.translate = "0px 0px"; + } const rect = el.getBoundingClientRect(); const { innerWidth: viewportWidth, innerHeight: viewportHeight } = window; const mobileOvershoot = viewportWidth < 768 ? 12 : 40; // extra room on narrow viewports + const isSmallDevice = viewportWidth < 768; - const shiftX = clampShift(rect.left, rect.right, viewportWidth, mobileOvershoot); + // On small devices, anchor the tooltip from the left edge so it grows to the + // right and never expands the page width. + const shiftX = isSmallDevice + ? VIEWPORT_EDGE_MARGIN - rect.left + : clampShift(rect.left, rect.right, viewportWidth, mobileOvershoot); const shiftY = clampShift(rect.top, rect.bottom, viewportHeight); if (shiftX || shiftY) { - el.style.transform = `translate(${Math.round(shiftX)}px, ${Math.round(shiftY)}px)`; + if (wrapper) { + wrapper.style.translate = `${Math.round(shiftX)}px ${Math.round(shiftY)}px`; + } else { + el.style.transform = `translate(${Math.round(shiftX)}px, ${Math.round(shiftY)}px)`; + } } }; @@ -79,8 +106,13 @@ export const useClampTooltipToViewport = (deps = []) => { const tick = (frame) => { clampTooltipToViewport(el); - unchangedFrames = el.style.transform === lastTransform ? unchangedFrames + 1 : 0; - lastTransform = el.style.transform; + const wrapper = isNivoTooltipWrapper(el.parentElement) ? el.parentElement : null; + const activeTransform = wrapper + ? `${wrapper.style.transform}|${wrapper.style.translate}` + : el.style.transform; + + unchangedFrames = activeTransform === lastTransform ? unchangedFrames + 1 : 0; + lastTransform = activeTransform; const settled = unchangedFrames >= SETTLE_FRAMES || frame >= MAX_BURST_FRAMES; frameId = settled ? null : window.requestAnimationFrame(() => tick(frame + 1)); @@ -206,7 +238,7 @@ const Tooltip = ({ tooltip, d, intl, tooltipEnableMarkdown }) => { } // Must run before any early return below (rules of hooks). - const tooltipRef = useClampTooltipToViewport([str, tooltipEnableMarkdown]); + const tooltipRef = useClampTooltipToViewport([d, str, tooltipEnableMarkdown]); if (!str) { return
; diff --git a/packages/dvz-ui/src/embeddable/common/ChartTooltip.jsx b/packages/dvz-ui/src/embeddable/common/ChartTooltip.jsx index 660f82e1..1ed314ba 100644 --- a/packages/dvz-ui/src/embeddable/common/ChartTooltip.jsx +++ b/packages/dvz-ui/src/embeddable/common/ChartTooltip.jsx @@ -51,7 +51,7 @@ const ChartTooltip = ({tooltip, d, intl, tooltipEnableMarkdown}) => { } // Must run on every render, before any conditional early return. - const tooltipRef = useClampTooltipToViewport([str, tooltipEnableMarkdown]) + const tooltipRef = useClampTooltipToViewport([d, str, tooltipEnableMarkdown]) if (data) { if (tooltipEnableMarkdown) { diff --git a/packages/dvz-ui/src/scss/themes/default/_charts.scss b/packages/dvz-ui/src/scss/themes/default/_charts.scss index fecaeef7..e1023f3c 100644 --- a/packages/dvz-ui/src/scss/themes/default/_charts.scss +++ b/packages/dvz-ui/src/scss/themes/default/_charts.scss @@ -417,7 +417,10 @@ } .chart.tooltip { - max-width: 500px !important; + max-width: min(500px, calc(100vw - 16px)) !important; + z-index: 2001 !important; + overflow-wrap: anywhere; + word-break: break-word; padding: 15px; border-radius: 4px; opacity: 1; From b87b23a4cc4be0ad890bccf2fd3b3d36a3fde02d Mon Sep 17 00:00:00 2001 From: Timothy Mugo Date: Thu, 13 Aug 2026 12:09:04 +0300 Subject: [PATCH 2/7] feat: add tooltip hiding functionality on scroll --- .../dvz-ui/src/embeddable/chart/Tooltip.jsx | 36 +++++++++++++++++-- .../src/embeddable/common/ChartTooltip.jsx | 5 +-- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/packages/dvz-ui/src/embeddable/chart/Tooltip.jsx b/packages/dvz-ui/src/embeddable/chart/Tooltip.jsx index 799d13da..9e988eb1 100644 --- a/packages/dvz-ui/src/embeddable/chart/Tooltip.jsx +++ b/packages/dvz-ui/src/embeddable/chart/Tooltip.jsx @@ -1,4 +1,4 @@ -import React, { useLayoutEffect, useRef } from "react"; +import React, { useEffect, useLayoutEffect, useRef, useState } from "react"; import ReactMarkdown from "react-markdown"; import remarkGfm from "remark-gfm"; import rehypeRaw from "rehype-raw"; @@ -143,6 +143,37 @@ export const useClampTooltipToViewport = (deps = []) => { return ref; }; +// Hides sticky/touch-triggered tooltips when the user scrolls. +export const useHideTooltipOnScroll = (resetDeps = []) => { + const [isHidden, setIsHidden] = useState(false); + + useEffect(() => { + setIsHidden(false); + }, resetDeps); + + useEffect(() => { + if (typeof window === "undefined") { + return undefined; + } + + const hide = () => setIsHidden(true); + const show = () => setIsHidden(false); + + // Capture phase catches scrolling on nested containers too. + window.addEventListener("scroll", hide, true); + window.addEventListener("touchmove", hide, { passive: true }); + window.addEventListener("pointerdown", show, true); + + return () => { + window.removeEventListener("scroll", hide, true); + window.removeEventListener("touchmove", hide); + window.removeEventListener("pointerdown", show, true); + }; + }, []); + + return isHidden; +}; + const applyFormat = (expresion, str, style, isPercent, intl, container) => { // Fall back to the raw string when intl isn't available (e.g. SSR). if (!intl || !intl.formatNumber) { @@ -239,8 +270,9 @@ const Tooltip = ({ tooltip, d, intl, tooltipEnableMarkdown }) => { // Must run before any early return below (rules of hooks). const tooltipRef = useClampTooltipToViewport([d, str, tooltipEnableMarkdown]); + const hideOnScroll = useHideTooltipOnScroll([d, str]); - if (!str) { + if (!str || hideOnScroll) { return
; } diff --git a/packages/dvz-ui/src/embeddable/common/ChartTooltip.jsx b/packages/dvz-ui/src/embeddable/common/ChartTooltip.jsx index 1ed314ba..05f8c993 100644 --- a/packages/dvz-ui/src/embeddable/common/ChartTooltip.jsx +++ b/packages/dvz-ui/src/embeddable/common/ChartTooltip.jsx @@ -3,7 +3,7 @@ import ReactMarkdown from 'react-markdown' import remarkGfm from 'remark-gfm' import rehypeRaw from 'rehype-raw' import template from 'string-template'; -import { useClampTooltipToViewport } from "../chart/Tooltip"; +import { useClampTooltipToViewport, useHideTooltipOnScroll } from "../chart/Tooltip"; const percentExpresion = /(\+?\%)[\(]([A-z0-9,.,-]+)\)/gi const numericExpresion = /(\+?\#)[\(]([A-z0-9,.,-]+)\)/gi @@ -52,8 +52,9 @@ const ChartTooltip = ({tooltip, d, intl, tooltipEnableMarkdown}) => { // Must run on every render, before any conditional early return. const tooltipRef = useClampTooltipToViewport([d, str, tooltipEnableMarkdown]) + const hideOnScroll = useHideTooltipOnScroll([d, str]) - if (data) { + if (data && !hideOnScroll) { if (tooltipEnableMarkdown) { return (
From d93fdc6663432d624ade3dccb34a07f029bc6152 Mon Sep 17 00:00:00 2001 From: Timothy Mugo Date: Thu, 13 Aug 2026 23:06:58 +0300 Subject: [PATCH 3/7] feat: re-implement chart tooltip using floating-ui to fix mobile viewport issues. --- packages/dvz-ui/package.json | 3 + .../dvz-ui/src/embeddable/chart/Tooltip.jsx | 251 ++++++++---------- .../src/embeddable/common/ChartTooltip.jsx | 31 ++- pnpm-lock.yaml | 63 ++++- 4 files changed, 182 insertions(+), 166 deletions(-) diff --git a/packages/dvz-ui/package.json b/packages/dvz-ui/package.json index 448d7d07..f6df8c7e 100644 --- a/packages/dvz-ui/package.json +++ b/packages/dvz-ui/package.json @@ -43,6 +43,8 @@ }, "dependencies": { "@artsy/fresnel": "^8.1.0", + "@floating-ui/react": "^0.27.20", + "@floating-ui/react-dom": "^2.1.9", "@nivo/bar": "^0.96.0", "@nivo/bump": "^0.96.0", "@nivo/colors": "^0.96.0", @@ -108,6 +110,7 @@ "@types/papaparse": "^5.3.16", "@types/react": "^18.3.11", "@types/react-dom": "^18.3.1", + "@types/string-template": "^1.0.7", "@types/topojson-client": "^3.1.5", "@types/uuid": "^10.0.0", "@vitejs/plugin-react-swc": "^3.9.0", diff --git a/packages/dvz-ui/src/embeddable/chart/Tooltip.jsx b/packages/dvz-ui/src/embeddable/chart/Tooltip.jsx index 9e988eb1..c2611abe 100644 --- a/packages/dvz-ui/src/embeddable/chart/Tooltip.jsx +++ b/packages/dvz-ui/src/embeddable/chart/Tooltip.jsx @@ -1,8 +1,9 @@ -import React, { useEffect, useLayoutEffect, useRef, useState } from "react"; +import React, { useCallback, useEffect, useState } from "react"; import ReactMarkdown from "react-markdown"; import remarkGfm from "remark-gfm"; import rehypeRaw from "rehype-raw"; import template from 'string-template'; +import { useFloating, autoUpdate, offset, flip, shift, FloatingPortal } from "@floating-ui/react"; const percentExpresion = /(\+?\%)[\(]([A-z0-9,.,-]+)\)/gi; const numericExpresion = /(\+?\#)[\(]([A-z0-9,.,-]+)\)/gi; @@ -11,17 +12,8 @@ const compactExpresion = /(\+?\#C)[\(]([A-z0-9,.,-]+)\)/gi; // Minimum gap (px) to keep between the tooltip and the viewport edge. const VIEWPORT_EDGE_MARGIN = 8; -// Shift needed to bring [start, end] inside [0, viewportSize]; 0 if it already fits. -const clampShift = (start, end, viewportSize, overshoot = 0) => { - if (start < VIEWPORT_EDGE_MARGIN) { - return VIEWPORT_EDGE_MARGIN - start; - } - if (end > viewportSize - VIEWPORT_EDGE_MARGIN) { - return viewportSize - VIEWPORT_EDGE_MARGIN - end - overshoot; - } - return 0; -}; - +// Chart libraries like nivo render our tooltip inside their own +// absolutely-positioned wrapper div, placed near the hovered point. const isNivoTooltipWrapper = (el) => { if (!el) { return false; @@ -34,116 +26,50 @@ const isNivoTooltipWrapper = (el) => { ); }; -// Nudges an already-positioned tooltip back inside the viewport via a -// corrective transform, without touching the chart library's own positioning -// (chart libraries like nivo can place tooltips past the screen edge). -export const clampTooltipToViewport = (el) => { - if (!el || typeof window === "undefined") { - return; - } - - const wrapper = isNivoTooltipWrapper(el.parentElement) ? el.parentElement : null; - - // Reset so we measure relative to the library's original position. - el.style.transform = ""; - if (wrapper) { - // Keep the library transform untouched; only reset our corrective translate. - wrapper.style.translate = "0px 0px"; - } - - const rect = el.getBoundingClientRect(); - const { innerWidth: viewportWidth, innerHeight: viewportHeight } = window; - const mobileOvershoot = viewportWidth < 768 ? 12 : 40; // extra room on narrow viewports - const isSmallDevice = viewportWidth < 768; - - // On small devices, anchor the tooltip from the left edge so it grows to the - // right and never expands the page width. - const shiftX = isSmallDevice - ? VIEWPORT_EDGE_MARGIN - rect.left - : clampShift(rect.left, rect.right, viewportWidth, mobileOvershoot); - const shiftY = clampShift(rect.top, rect.bottom, viewportHeight); - - if (shiftX || shiftY) { - if (wrapper) { - wrapper.style.translate = `${Math.round(shiftX)}px ${Math.round(shiftY)}px`; - } else { - el.style.transform = `translate(${Math.round(shiftX)}px, ${Math.round(shiftY)}px)`; - } - } -}; - -// Frames with an unchanged correction before we consider the tooltip settled. -const SETTLE_FRAMES = 6; -// Safety cap on a burst's length (~1s at 60fps) in case position never settles. -const MAX_BURST_FRAMES = 60; - -/** - * Keeps a tooltip inside the viewport, re-clamping every frame for a short - * burst whenever it might have moved (mount, resize, scroll) and stopping - * once the correction settles. The burst is needed because animated wrappers - * (e.g. nivo + react-spring) can still be mid-animation when we first measure. +/** + * Positions a tooltip bubble with floating-ui: anchored to wherever the host + * chart library already placed its wrapper, and kept clear of the viewport + * edges via the `shift`/`flip` middleware. Render the bubble through + * so its `fixed` positioning escapes the host wrapper's own + * transform (nivo animates that transform with react-spring). */ -export const useClampTooltipToViewport = (deps = []) => { - const ref = useRef(null); - - useLayoutEffect(() => { - const el = ref.current; - if (!el || typeof window === "undefined" || !window.requestAnimationFrame) { - clampTooltipToViewport(el); - return undefined; - } - - let frameId = null; - - const startBurst = () => { - if (frameId != null) { - window.cancelAnimationFrame(frameId); - } - - let lastTransform = null; - let unchangedFrames = 0; - - const tick = (frame) => { - clampTooltipToViewport(el); - - const wrapper = isNivoTooltipWrapper(el.parentElement) ? el.parentElement : null; - const activeTransform = wrapper - ? `${wrapper.style.transform}|${wrapper.style.translate}` - : el.style.transform; - - unchangedFrames = activeTransform === lastTransform ? unchangedFrames + 1 : 0; - lastTransform = activeTransform; - - const settled = unchangedFrames >= SETTLE_FRAMES || frame >= MAX_BURST_FRAMES; - frameId = settled ? null : window.requestAnimationFrame(() => tick(frame + 1)); - }; - - tick(0); - }; - - startBurst(); - - const resizeObserver = typeof ResizeObserver !== "undefined" ? new ResizeObserver(startBurst) : null; - resizeObserver?.observe(el); - - // Capture phase catches scroll on any ancestor, not just the window. - window.addEventListener("scroll", startBurst, true); - window.addEventListener("resize", startBurst); - - return () => { - if (frameId != null) { - window.cancelAnimationFrame(frameId); +export const useTooltipPosition = () => { + const { refs, floatingStyles } = useFloating({ + placement: "top", + strategy: "fixed", + // The reference (nivo's wrapper) moves via a transform, not a resize/ + // layout change, so we need frame-by-frame tracking rather than the + // default scroll/resize-only observers. + whileElementsMounted: (referenceEl, floatingEl, update) => + autoUpdate(referenceEl, floatingEl, update, { animationFrame: true }), + middleware: [offset(8), flip(), shift({ padding: VIEWPORT_EDGE_MARGIN })], + }); + + // The theme's `.chart.tooltip` styling (background, border, padding, ...) + // is compiled scoped under `#root`/`.edit-post-visual-editor`. FloatingPortal + // defaults to `document.body`, which escapes that scope and drops the + // styling, so anchor the portal to whichever of those ancestors we find. + const [portalRoot, setPortalRoot] = useState(undefined); + + const anchorRef = useCallback( + (node) => { + if (!node) { + return; } - resizeObserver?.disconnect(); - window.removeEventListener("scroll", startBurst, true); - window.removeEventListener("resize", startBurst); - }; - }, deps); + const wrapper = isNivoTooltipWrapper(node.parentElement) ? node.parentElement : node; + refs.setReference(wrapper); + setPortalRoot(wrapper.closest("#root, .edit-post-visual-editor") || undefined); + }, + [refs] + ); - return ref; + return { anchorRef, floatingRef: refs.setFloating, floatingStyles, portalRoot }; }; -// Hides sticky/touch-triggered tooltips when the user scrolls. +// Hides sticky/touch-triggered tooltips the instant the user scrolls, touches +// to scroll, or taps anywhere (used to dismiss the tooltip). Listeners are +// passive/capturing so they never block scrolling and fire on nested +// scroll containers, not just the window. export const useHideTooltipOnScroll = (resetDeps = []) => { const [isHidden, setIsHidden] = useState(false); @@ -157,17 +83,15 @@ export const useHideTooltipOnScroll = (resetDeps = []) => { } const hide = () => setIsHidden(true); - const show = () => setIsHidden(false); - // Capture phase catches scrolling on nested containers too. - window.addEventListener("scroll", hide, true); - window.addEventListener("touchmove", hide, { passive: true }); - window.addEventListener("pointerdown", show, true); + window.addEventListener("scroll", hide, { capture: true, passive: true }); + window.addEventListener("touchmove", hide, { capture: true, passive: true }); + window.addEventListener("pointerdown", hide, { capture: true, passive: true }); return () => { - window.removeEventListener("scroll", hide, true); - window.removeEventListener("touchmove", hide); - window.removeEventListener("pointerdown", show, true); + window.removeEventListener("scroll", hide, { capture: true }); + window.removeEventListener("touchmove", hide, { capture: true }); + window.removeEventListener("pointerdown", hide, { capture: true }); }; }, []); @@ -269,30 +193,67 @@ const Tooltip = ({ tooltip, d, intl, tooltipEnableMarkdown }) => { } // Must run before any early return below (rules of hooks). - const tooltipRef = useClampTooltipToViewport([d, str, tooltipEnableMarkdown]); const hideOnScroll = useHideTooltipOnScroll([d, str]); + // Explicit, event-driven visibility -- independent of nivo's own hover + // detection -- so the tooltip reacts to mouse/touch events on itself + // instead of relying solely on the chart library re-rendering it. + const [isHovered, setIsHovered] = useState(true); + const { anchorRef, floatingRef, floatingStyles, portalRoot } = useTooltipPosition(); - if (!str || hideOnScroll) { - return
; - } + // A new/changed data point should always start out visible. + useEffect(() => { + setIsHovered(true); + }, [d, str]); - if (tooltipEnableMarkdown) { - return ( -
- -
- ); - } else { - return ( -
-
-
- ); + if (!str) { + return
; } + + const isVisible = isHovered && !hideOnScroll; + + const show = () => setIsHovered(true); + const hide = () => setIsHovered(false); + const handleTouchStart = () => setIsHovered(true); + const handleTouchEnd = (event) => { + // Prevent the emulated mouse events that follow a tap from immediately + // hiding the tooltip we just opened via touch. + event.preventDefault(); + }; + + const content = tooltipEnableMarkdown ? ( + + ) : ( +
+ ); + + return ( +
+ +
+ {content} +
+
+
+ ); }; export default Tooltip; diff --git a/packages/dvz-ui/src/embeddable/common/ChartTooltip.jsx b/packages/dvz-ui/src/embeddable/common/ChartTooltip.jsx index 05f8c993..beaa6fc2 100644 --- a/packages/dvz-ui/src/embeddable/common/ChartTooltip.jsx +++ b/packages/dvz-ui/src/embeddable/common/ChartTooltip.jsx @@ -3,7 +3,8 @@ import ReactMarkdown from 'react-markdown' import remarkGfm from 'remark-gfm' import rehypeRaw from 'rehype-raw' import template from 'string-template'; -import { useClampTooltipToViewport, useHideTooltipOnScroll } from "../chart/Tooltip"; +import { FloatingPortal } from "@floating-ui/react"; +import { useTooltipPosition, useHideTooltipOnScroll } from "../chart/Tooltip"; const percentExpresion = /(\+?\%)[\(]([A-z0-9,.,-]+)\)/gi const numericExpresion = /(\+?\#)[\(]([A-z0-9,.,-]+)\)/gi @@ -51,25 +52,23 @@ const ChartTooltip = ({tooltip, d, intl, tooltipEnableMarkdown}) => { } // Must run on every render, before any conditional early return. - const tooltipRef = useClampTooltipToViewport([d, str, tooltipEnableMarkdown]) + const { anchorRef, floatingRef, floatingStyles, portalRoot } = useTooltipPosition() const hideOnScroll = useHideTooltipOnScroll([d, str]) if (data && !hideOnScroll) { - if (tooltipEnableMarkdown) { - return ( -
- - -
- ) - } else { - return ( -
-
-
) - } - + const content = tooltipEnableMarkdown + ? + :
+ return ( +
+ +
+ {content} +
+
+
+ ) } else { return
} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f31122c5..b8141232 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -124,6 +124,12 @@ importers: '@artsy/fresnel': specifier: ^8.1.0 version: 8.1.0(react@18.3.1) + '@floating-ui/react': + specifier: ^0.27.20 + version: 0.27.20(react-dom@18.3.1(react@18.3.1))(react@18.3.1) + '@floating-ui/react-dom': + specifier: ^2.1.9 + version: 2.1.9(react-dom@18.3.1(react@18.3.1))(react@18.3.1) '@nivo/bar': specifier: ^0.96.0 version: 0.96.0(react-dom@18.3.1(react@18.3.1))(react@18.3.1) @@ -314,6 +320,9 @@ importers: '@types/react-dom': specifier: ^18.3.1 version: 18.3.1 + '@types/string-template': + specifier: ^1.0.7 + version: 1.0.7 '@types/topojson-client': specifier: ^3.1.5 version: 3.1.5 @@ -975,15 +984,30 @@ packages: '@floating-ui/core@1.7.0': resolution: {integrity: sha512-FRdBLykrPPA6P76GGGqlex/e7fbe0F1ykgxHYNXQsH/iTEtjMj/f9bpY5oQqbjt5VgZvgz/uKXbGuROijh3VLA==} + '@floating-ui/core@1.8.0': + resolution: {integrity: sha512-0CIZ5itps/8x7BG8dEIhs53BvCUH2PCoogtakwRTut+Arm58sJooJ0AuZhLw2HJYIR5cMLNPBSS728sPho2khQ==} + '@floating-ui/dom@1.7.0': resolution: {integrity: sha512-lGTor4VlXcesUMh1cupTUTDoCxMb0V6bm3CnxHzQcw8Eaf1jQbgQX4i02fYgT0vJ82tb5MZ4CZk1LRGkktJCzg==} - '@floating-ui/react-dom@2.1.2': - resolution: {integrity: sha512-06okr5cgPzMNBy+Ycse2A6udMi4bqwW/zgBF/rwjcNqWkyr82Mcg8b0vjX8OJpZFy/FKjJmw6wV7t44kK6kW7A==} + '@floating-ui/dom@1.8.0': + resolution: {integrity: sha512-yXSrzeHZBTZadLOlfyhCkJHNeLJnHRnRInwdZ40L7ZiaAtrBwoYlsDrX3v5zB1Utk7CLfzcOVnVVWoXEky7Ceg==} + + '@floating-ui/react-dom@2.1.9': + resolution: {integrity: sha512-JDjEFGCpImxDCA7JJKviA0M9+RtmJdj0m/NVU5IMgBK+AmZouAQQ7/+2GLH0GXXY0YMw9oXPB8hKdbPYg5QLYg==} peerDependencies: react: '>=16.8.0' react-dom: '>=16.8.0' + '@floating-ui/react@0.27.20': + resolution: {integrity: sha512-CMqMy7OaXl9W0eq1Uy7L7i2Y/anPvHmFmESd2CEw0t5YvZhcVCeo4MBevAmswRllX7Y2dEidA4ozGPunLSTQpw==} + peerDependencies: + react: '>=17.0.0' + react-dom: '>=17.0.0' + + '@floating-ui/utils@0.2.12': + resolution: {integrity: sha512-HpCo8tmWzLVad5s2d19EhAz5zqrrQ6s69qd6moPMQvkOuSwDT1YgRfWSVuc4ennqrgv3OHppiOGMQ7oC13yIww==} + '@floating-ui/utils@0.2.9': resolution: {integrity: sha512-MDWhGtE+eHw5JW7lq4qhc5yRLS11ERl1c7Z6Xd0a58DozHES6EnNNwUWbMiG4J9Cgj053Bhk8zvlhFYKVhULwg==} @@ -2172,6 +2196,9 @@ packages: '@types/react@18.3.11': resolution: {integrity: sha512-r6QZ069rFTjrEYgFdOck1gK7FLVsgJE7tTz0pQBczlBNUhBNk0MQH4UbnFSwjpQLMkLzgqvBBa+qGpLje16eTQ==} + '@types/string-template@1.0.7': + resolution: {integrity: sha512-sQWEsTbB0pKCc1eAC9mwTKftyXuWfSZVfDTskhlQLE/xTtuevqOlFG/t4Djf/VFbRdt7PROaovoqpWfZWhMRfA==} + '@types/topojson-client@3.1.5': resolution: {integrity: sha512-C79rySTyPxnQNNguTZNI1Ct4D7IXgvyAs3p9HPecnl6mNrJ5+UhvGNYcZfpROYV2lMHI48kJPxwR+F9C6c7nmw==} @@ -5083,6 +5110,9 @@ packages: resolution: {integrity: sha512-GTt8rSKje5FilG+wEdfCkOcLL7LWqpMlr2c3LRuKt/YXxcJ52aGSbGBAdI4L3aaqfrBt6y711El53ItyH1NWzg==} engines: {node: '>=16.0.0'} + tabbable@6.5.0: + resolution: {integrity: sha512-wieBHXygIm7OyQOu5hQlkk62/WyCFYGlWg7L6/ZCUZwx0o398Zkn4pVmMyfYhfMG8kGrj/Krt8eIk6UKC6VzwA==} + tailwind-merge@3.3.0: resolution: {integrity: sha512-fyW/pEfcQSiigd5SNn0nApUOxx0zB/dm6UDU/rEwc2c3sX2smWUNbapHv+QRqLGVp9GWX3THIa7MUGPo+YkDzQ==} @@ -6128,17 +6158,36 @@ snapshots: dependencies: '@floating-ui/utils': 0.2.9 + '@floating-ui/core@1.8.0': + dependencies: + '@floating-ui/utils': 0.2.12 + '@floating-ui/dom@1.7.0': dependencies: '@floating-ui/core': 1.7.0 '@floating-ui/utils': 0.2.9 - '@floating-ui/react-dom@2.1.2(react-dom@18.3.1(react@18.3.1))(react@18.3.1)': + '@floating-ui/dom@1.8.0': dependencies: - '@floating-ui/dom': 1.7.0 + '@floating-ui/core': 1.8.0 + '@floating-ui/utils': 0.2.12 + + '@floating-ui/react-dom@2.1.9(react-dom@18.3.1(react@18.3.1))(react@18.3.1)': + dependencies: + '@floating-ui/dom': 1.8.0 react: 18.3.1 react-dom: 18.3.1(react@18.3.1) + '@floating-ui/react@0.27.20(react-dom@18.3.1(react@18.3.1))(react@18.3.1)': + dependencies: + '@floating-ui/react-dom': 2.1.9(react-dom@18.3.1(react@18.3.1))(react@18.3.1) + '@floating-ui/utils': 0.2.12 + react: 18.3.1 + react-dom: 18.3.1(react@18.3.1) + tabbable: 6.5.0 + + '@floating-ui/utils@0.2.12': {} + '@floating-ui/utils@0.2.9': {} '@fluentui/react-component-event-listener@0.63.1(react-dom@18.3.1(react@18.3.1))(react@18.3.1)': @@ -6804,7 +6853,7 @@ snapshots: '@radix-ui/react-popper@1.2.7(@types/react-dom@18.3.1)(@types/react@18.3.11)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)': dependencies: - '@floating-ui/react-dom': 2.1.2(react-dom@18.3.1(react@18.3.1))(react@18.3.1) + '@floating-ui/react-dom': 2.1.9(react-dom@18.3.1(react@18.3.1))(react@18.3.1) '@radix-ui/react-arrow': 1.1.7(@types/react-dom@18.3.1)(@types/react@18.3.11)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) '@radix-ui/react-compose-refs': 1.1.2(@types/react@18.3.11)(react@18.3.1) '@radix-ui/react-context': 1.1.2(@types/react@18.3.11)(react@18.3.1) @@ -7531,6 +7580,8 @@ snapshots: '@types/prop-types': 15.7.14 csstype: 3.1.3 + '@types/string-template@1.0.7': {} + '@types/topojson-client@3.1.5': dependencies: '@types/geojson': 7946.0.16 @@ -11019,6 +11070,8 @@ snapshots: sync-message-port@1.1.3: {} + tabbable@6.5.0: {} + tailwind-merge@3.3.0: {} term-size@2.2.1: {} From 8534e63fe3cc2be00951c76fa3ae7ab06f3be061 Mon Sep 17 00:00:00 2001 From: Timothy Mugo Date: Thu, 13 Aug 2026 23:10:58 +0300 Subject: [PATCH 4/7] feat: add lodash.debounce and its type definitions for improved performance --- packages/dvz-ui/package.json | 2 ++ .../embeddable/big-filter/BigNumberGroup.jsx | 4 ++-- pnpm-lock.yaml | 18 ++++++++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/packages/dvz-ui/package.json b/packages/dvz-ui/package.json index f6df8c7e..aa23f0db 100644 --- a/packages/dvz-ui/package.json +++ b/packages/dvz-ui/package.json @@ -71,6 +71,7 @@ "html-react-parser": "^5.2.6", "immutable": "^5.1.3", "lodash": "^4.17.21", + "lodash.debounce": "^4.0.8", "lodash.isequal": "^4.5.0", "papaparse": "^5.5.3", "pure-react-carousel": "^1.32.0", @@ -105,6 +106,7 @@ "@types/d3-shape": "^3.1.7", "@types/file-saver": "^2.0.7", "@types/lodash": "^4.17.16", + "@types/lodash.debounce": "^4.0.9", "@types/lodash.isequal": "^4.5.8", "@types/node": "^22.15.18", "@types/papaparse": "^5.3.16", diff --git a/packages/dvz-ui/src/embeddable/big-filter/BigNumberGroup.jsx b/packages/dvz-ui/src/embeddable/big-filter/BigNumberGroup.jsx index 726ae724..c15fe4c3 100644 --- a/packages/dvz-ui/src/embeddable/big-filter/BigNumberGroup.jsx +++ b/packages/dvz-ui/src/embeddable/big-filter/BigNumberGroup.jsx @@ -2,7 +2,7 @@ import React, { useEffect, useState, useCallback, useRef } from 'react'; import { Container, Grid } from "semantic-ui-react"; import { BigNumberItem } from './BigNumberItem'; import { decode } from '../utils/parseUtils'; -import _ from 'lodash'; +import debounce from 'lodash.debounce'; const BigNumberGroup = (props) => { const { @@ -74,7 +74,7 @@ const BigNumberGroup = (props) => { } const debouncedApplyFilter = useRef( - _.debounce((newFilters, type) => { + debounce((newFilters, type) => { if (newFilters.length == 0) { onSetFilter({ app, group, parent, param: type, value: [] }); onUnSetFilter({ app, group: blockName, parent, param: type }); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b8141232..12823513 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -208,6 +208,9 @@ importers: lodash: specifier: ^4.17.21 version: 4.17.21 + lodash.debounce: + specifier: ^4.0.8 + version: 4.0.8 lodash.isequal: specifier: ^4.5.0 version: 4.5.0 @@ -305,6 +308,9 @@ importers: '@types/lodash': specifier: ^4.17.16 version: 4.17.16 + '@types/lodash.debounce': + specifier: ^4.0.9 + version: 4.0.9 '@types/lodash.isequal': specifier: ^4.5.8 version: 4.5.8 @@ -2155,6 +2161,9 @@ packages: '@types/json-schema@7.0.15': resolution: {integrity: sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==} + '@types/lodash.debounce@4.0.9': + resolution: {integrity: sha512-Ma5JcgTREwpLRwMM+XwBR7DaWe96nC38uCBDFKZWbNKD+osjVzdpnUSwBcqCptrp16sSOLBAUb50Car5I0TCsQ==} + '@types/lodash.isequal@4.5.8': resolution: {integrity: sha512-uput6pg4E/tj2LGxCZo9+y27JNyB2OZuuI/T5F+ylVDYuqICLG2/ktjxx0v6GvVntAf8TvEzeQLcV0ffRirXuA==} @@ -3880,6 +3889,9 @@ packages: lodash-es@4.17.21: resolution: {integrity: sha512-mKnC+QJ9pWVzv+C4/U3rRsHapFfHvQFoFB92e52xeyGMcX6/OlIl78je1u8vePzYZSkkogMPJ2yjxxsb89cxyw==} + lodash.debounce@4.0.8: + resolution: {integrity: sha512-FT1yDzDYEoYWhnSGnpE/4Kj1fLZkDFyqRb7fNt6FdYOSxlUWAtp42Eh6Wb0rGIv/m9Bgo7x4GhQbm5Ys4SG5ow==} + lodash.isequal@4.5.0: resolution: {integrity: sha512-pDo3lu8Jhfjqls6GkMgpahsF9kCyayhgykjyLMNFTKWrpVdAQtYyB4muAMWozBB4ig/dtWAmsMxLEI8wuz+DYQ==} deprecated: This package is deprecated. Use require('node:util').isDeepStrictEqual instead. @@ -7537,6 +7549,10 @@ snapshots: '@types/json-schema@7.0.15': {} + '@types/lodash.debounce@4.0.9': + dependencies: + '@types/lodash': 4.17.16 + '@types/lodash.isequal@4.5.8': dependencies: '@types/lodash': 4.17.16 @@ -9520,6 +9536,8 @@ snapshots: lodash-es@4.17.21: {} + lodash.debounce@4.0.8: {} + lodash.isequal@4.5.0: {} lodash.merge@4.6.2: {} From 80c7bff955d40035d5b2d0d8f750c26eb2c16e8b Mon Sep 17 00:00:00 2001 From: Timothy Mugo Date: Thu, 13 Aug 2026 23:45:03 +0300 Subject: [PATCH 5/7] chore: add changeset and fix some deps --- .changeset/green-schools-poke.md | 15 +++++++++++++++ packages/dvz-ui/src/embeddable/chart/Radar.jsx | 1 - packages/dvz-ui/src/utils/semanticUtils.ts | 6 ++---- 3 files changed, 17 insertions(+), 5 deletions(-) create mode 100644 .changeset/green-schools-poke.md diff --git a/.changeset/green-schools-poke.md b/.changeset/green-schools-poke.md new file mode 100644 index 00000000..4a23543e --- /dev/null +++ b/.changeset/green-schools-poke.md @@ -0,0 +1,15 @@ +--- +"@devgateway/dvz-ui-react": minor +--- + +Fix chart tooltips: migrate to floating-ui for proper scroll detection and positioning + +- Implemented `useTooltipPosition()` hook using @floating-ui/react with automatic viewport boundary detection (flip/shift middleware) +- Added `useHideTooltipOnScroll()` hook for instant tooltip dismissal on scroll/touch events +- Fixed theme scope styling by anchoring FloatingPortal to nearest `#root` or `.edit-post-visual-editor` ancestor +- Enabled frame-by-frame position tracking via autoUpdate with animationFrame option (required for Nivo's react-spring animations) +- Added independent hover/touch state management for better control over tooltip visibility +- Applied changes to Tooltip.jsx (Bar, Line, Pie charts) and ChartTooltip.jsx (Sankey, GroupedBars) + +**Breaking changes:** None. Internal implementation detail; public API unchanged. +**Related:** Addresses off-screen tooltips, scroll persistence diff --git a/packages/dvz-ui/src/embeddable/chart/Radar.jsx b/packages/dvz-ui/src/embeddable/chart/Radar.jsx index 8e0c769d..5f61e101 100644 --- a/packages/dvz-ui/src/embeddable/chart/Radar.jsx +++ b/packages/dvz-ui/src/embeddable/chart/Radar.jsx @@ -3,7 +3,6 @@ import { injectIntl } from "react-intl"; import { ResponsiveRadar } from "@nivo/radar"; import Legends from "./Legends.jsx"; import deviceType from "@/utils/deviceType.js"; -import _ from "lodash"; const DEFAULT_COLOR = "none"; diff --git a/packages/dvz-ui/src/utils/semanticUtils.ts b/packages/dvz-ui/src/utils/semanticUtils.ts index 327013ac..2689aeeb 100644 --- a/packages/dvz-ui/src/utils/semanticUtils.ts +++ b/packages/dvz-ui/src/utils/semanticUtils.ts @@ -1,5 +1,3 @@ -import _ from 'lodash' - export const htmlInputAttrs = [ // REACT 'selected', @@ -97,9 +95,9 @@ export const partitionHTMLProps = (props: object, options: { htmlProps?: string[ const inputProps = {} const rest = {} - _.forEach(props, (val, prop) => { + Object.entries(props).forEach(([prop, val]) => { const possibleAria = includeAria && (/^aria-.*$/.test(prop) || prop === 'role') - const target = _.includes(htmlProps, prop) || possibleAria ? inputProps : rest + const target = htmlProps.includes(prop) || possibleAria ? inputProps : rest target[prop] = val }) From f8dda30179d53554df6afc95e6d7f480cfa2948b Mon Sep 17 00:00:00 2001 From: Timothy Mugo Gachengo <55899373+timothygachengo@users.noreply.github.com> Date: Thu, 13 Aug 2026 23:54:50 +0300 Subject: [PATCH 6/7] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- packages/dvz-ui/src/embeddable/chart/Tooltip.jsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/dvz-ui/src/embeddable/chart/Tooltip.jsx b/packages/dvz-ui/src/embeddable/chart/Tooltip.jsx index c2611abe..c0bb7f2b 100644 --- a/packages/dvz-ui/src/embeddable/chart/Tooltip.jsx +++ b/packages/dvz-ui/src/embeddable/chart/Tooltip.jsx @@ -49,7 +49,7 @@ export const useTooltipPosition = () => { // is compiled scoped under `#root`/`.edit-post-visual-editor`. FloatingPortal // defaults to `document.body`, which escapes that scope and drops the // styling, so anchor the portal to whichever of those ancestors we find. - const [portalRoot, setPortalRoot] = useState(undefined); + const [portalRoot, setPortalRoot] = useState(null); const anchorRef = useCallback( (node) => { @@ -58,7 +58,7 @@ export const useTooltipPosition = () => { } const wrapper = isNivoTooltipWrapper(node.parentElement) ? node.parentElement : node; refs.setReference(wrapper); - setPortalRoot(wrapper.closest("#root, .edit-post-visual-editor") || undefined); + setPortalRoot(wrapper.closest("#root, .edit-post-visual-editor") || wrapper.ownerDocument.body); }, [refs] ); From 4fb466437eba24584e88dca6e6f49d0cadb91cc9 Mon Sep 17 00:00:00 2001 From: Timothy Mugo Gachengo <55899373+timothy-mugo@users.noreply.github.com> Date: Tue, 3 Nov 2026 16:59:55 +0300 Subject: [PATCH 7/7] Remove onMouseOut handler from Tooltip component Remove redundant onMouseOut event handler. Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- packages/dvz-ui/src/embeddable/chart/Tooltip.jsx | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/dvz-ui/src/embeddable/chart/Tooltip.jsx b/packages/dvz-ui/src/embeddable/chart/Tooltip.jsx index c0bb7f2b..a686b92d 100644 --- a/packages/dvz-ui/src/embeddable/chart/Tooltip.jsx +++ b/packages/dvz-ui/src/embeddable/chart/Tooltip.jsx @@ -245,7 +245,6 @@ const Tooltip = ({ tooltip, d, intl, tooltipEnableMarkdown }) => { }} onMouseEnter={show} onMouseLeave={hide} - onMouseOut={hide} onTouchStart={handleTouchStart} onTouchEnd={handleTouchEnd} >