Implement fit-mode rendering contract with container sizing and pane re-fit

This commit is contained in:
2026-06-05 10:45:41 +03:00
parent f4253f50ca
commit 411bfbc6c2
13 changed files with 552 additions and 73 deletions
+18
View File
@@ -14,6 +14,17 @@ import type { Config } from 'vega-lite';
export interface RenderHandle {
/** Finalize the underlying Vega view and clear the node. */
destroy(): void;
/**
* Re-fit the chart to its container's current size (spec §04 Responsiveness).
*
* Vega-Lite compiles `"container"` sizing to width/height signals that re-read
* `containerSize()` ONLY on a `window:resize` event (nothing observes the
* element, and `view.resize()` alone re-runs layout with the stale size). So a
* pane drag — which fires no window resize — needs us to synthesize that event.
* Doing it this way also means only the container-bound dimensions re-fit
* (fixed ones have no such handler), which is exactly right for Width/Height.
*/
resize(): void;
}
/** Embed a prepared spec into `node`. Non-negotiable: no actions menu, SVG output. */
@@ -33,5 +44,12 @@ export async function renderSpec(
result.view.finalize();
node.replaceChildren();
},
resize() {
// Synthesize the window:resize the container signals listen for (see the
// interface doc). The view re-reads containerSize() and re-renders itself;
// a finalized view has already removed its listener, so this is a safe
// no-op after destroy().
if (typeof window !== 'undefined') window.dispatchEvent(new Event('resize'));
},
};
}