mirror of
https://github.com/olehomelchenko/astrolabe.git
synced 2026-08-08 02:02:33 +00:00
Implement fit-mode rendering contract with container sizing and pane re-fit
This commit is contained in:
@@ -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'));
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user