Container: Add load / render / redraw lifecycle events - #782
Conversation
rokotyan
left a comment
There was a problem hiding this comment.
I like the idea! But there're a couple things I'm concerned about.
| componentWidth: number, | ||
| componentHeight: number, | ||
| ) => void; | ||
| onRenderComplete?: (payload: SingleContainerRenderPayload) => void; |
There was a problem hiding this comment.
Switching to a payload object will be a breaking change, so we won't be able to do it till we release version 2.0. We'll need to stick to arguments
There was a problem hiding this comment.
Reverted the TS-core onRenderComplete to positional args; wrappers build XYContainerRenderPayload / SingleContainerRenderPayload internally before emitting. No breaking change for existing TS / React / Solid users.
|
|
||
| | Event | When it fires | | ||
| | -------- | --------------------------------------------------- | | ||
| | `load` | Once, after the chart's first render completes. | |
There was a problem hiding this comment.
Do you think we really need three of these events instead of just one? I think the users can track whether it was the first render themselves if they need to. Could you give a couple of use cases to justify that?
There was a problem hiding this comment.
I was inspired by Highcharts (chart.events.load / render / redraw). Since I'm currently migrating from it, I have a couple of moments where I use these. Use cases I had in mind:
load— the big one. Fires once, perfect for prefetching chart settings, hydrating a "chart settings" panel, logging first-paint time, kicking off a fade-in, and hiding a skeleton. A userland boolean works, but every team ends up rewriting it and getting it subtly wrong (re-mounts, keyed components, hot reload, props that retrigger updates without a true "first paint").redraw— react only to data/prop updates without the noisy first paint. e.g. block a "chart settings" toggle button while a redraw is in flight, refit an overlay, restore scroll, re-sync an external legend.render— superset, blocks UI on every paint (first + redraw). Useful when you want a generic "chart is busy" gate around the whole lifecycle without branching on first vs subsequent.
Cost on our side is one boolean per container, so emitting all three is essentially free. Happy to drop redraw if it really feels redundant — but I'd push hard to keep load since it's the one consumers actually trip over. WDYT?
77e8c54 to
9fc7d32
Compare
e670bb6 to
d296e97
Compare
e2cd852 to
90afba4
Compare
ab7c00b to
d6f6b43
Compare
697d19e to
814d70e
Compare
814d70e to
e3b15c1
Compare
Wanted a reliable way to know when a chart actually finished drawing — for logging first-paint times and reacting to renders downstream. The only existing hook was the
onRenderCompletefunction-prop callback, which feels foreign in Vue/Svelte/Angular where events are the idiom. The usual workaround isawait nextTick()+ a couple ofrequestAnimationFrames, but that's a guess, not a real signal from unovis.So I wired up
load(first render),render(every render),redraw(every render except first) onVisXYContainerandVisSingleContainer— Highcharts-style. Vue gets@load, Svelteon:load, Angular(load). React/Solid keeponRenderComplete(function-prop callbacks are idiomatic there).While at it, refactored the underlying
XYContainer.onRenderComplete/SingleContainer.onRenderCompletefrom 7 positional args to a single payload object — that wayXYContainerRenderPayload/SingleContainerRenderPayloadlive once in@unovis/tsand everyone imports them. This is a small breaking change for anyone passingonRenderCompletedirectly to the TS class or to React/Solid wrappers.Verified
pnpm checkfor Vue/Svelte,ng buildfor Angular, and the TS package rebuilds clean.