Closed insertmike closed 1 year ago
Have you had a look at the dispatched events? Specifically, init
and draw
should help you here. Also, scatter.draw()
returns a promise that resolves once the points have been drawn.
So a very quick fix would be
const hasDrawn = useRef(false);
useEffect(() => {
hasDrawn.current = false;
if (!scatter) return;
scatter.draw(points)
.then(() => { hasDrawn.current = true; })
.catch(() => { hasDrawn.current = false; })
}, [points]);
useEffect(() => {
if (!scatter || !hasDrawn.current) return;
if (selected && selected.length > 0) {
scatter.select(selected);
scatterPlot.zoomToPoints(selected);
}
}, [selected]);
But apart from that I agree that zoomToPoints
should not fail when the points have not been drawn yet. :)
@flekschas
Have you had a look at the dispatched events? Specifically, init and draw should help you here. Also, scatter.draw() returns a promise that resolves once the points have been drawn. So a very quick fix would be ...
That's a good proposal, thank you! However, I was thinking whether it makes sense to delegate this to the scatter itself? A READ_ONLY property. What do you think?
@insertmike Sure, we can simply allow getting isPointsDrawn
in the get()
function.
Abstract
zoomToPoints
break plot if called before initializedContext:
Suppose a client is developing application, which has the following workflow:
As the order of effects is not guaranteed, nor there is no way of direct checking whether the points have been drawn, if
zoomToPoints
is invoked beforeKDBush
is initialized, it results in the following error:It is possible to have a workaround by trying out to check whether
Scatter
returns points when queried, but this is not a solution. Scatter should not throw runtime error when trying to perform this action while trying.The problem arises because code is trying to access searchIndex but it is undefined in the meantime.
Proposal
There is a couple of things we can do here. I will list my proposal with (MR) and propose additional improvements that we can make to make it nicer.
searchIndex
is defined whenzoomToPoints
is called and return (Could throw a warning too). Otherwise. - This complies with the following improvements as makes the library more robust. It couFurther Improvements
@flekschas Can you share your thoughts on the following ones?