MAIDR JavaScript API
    Preparing search index...

    Function watchViewport

    • Calls onViewportChange whenever cached viewport coordinates may have gone stale.

      Two events say so. scroll is watched in the capture phase because a scroll event does not bubble: a chart inside its own scrolling container fires on that container and nothing else, and only a capture-phase listener on window sees it. resize covers the window changing shape, which moves a responsive chart's marks without scrolling anything.

      A redraw or a live-data update needs no event here: it replaces the trace, and the new one measures for itself.

      Parameters

      • onViewportChange: () => void

        Called on each scroll or resize

      Returns () => void

      A function that stops watching; safe to call more than once, and a no-op where there is no window (server-side rendering, a node test)