vgplot: programatically enable/disable
Mosaic clients can be programatically enabled/disabled via #721 (example code using IntersectionObserver).
This same control in vgplot would be helpful for dashboard optimisation - so that out -of-view or collapsed charts can be prevented from updating.
I'm not sure if this is a suitable workaround if you wanted to avoid creating custom clients, but I tried this:
- define a custom API context with separate coordinator for plots or groups of plots you want to hide:
const qcAPI = vg.createAPIContext({
coordinator: new vg.Coordinator(vg.socketConnector())
});
- use the API context for your disable-able plot:
const percentMT = qcAPI.plot(
qcAPI.densityY(qcAPI.from('cells', { filterBy: $densityFilter }), {
x: 'percent_mt',
fill: 'sample',
opacity: 0.25,
tip: true,
title: 'sample',
normalize: 'max',
}),
qcAPI.name('percentMT'),
qcAPI.colorRange(tableau20),
qcAPI.colorDomain(samples),
qcAPI.intervalX({ as: $percentMTBrush }),
qcAPI.xLabel(umapCategories.percent_mt.title),
qcAPI.yAxis(null),
qcAPI.width(containerWidth),
qcAPI.height(88),
);
if (percentMTRef.current) percentMTRef.current.replaceChildren(percentMT);
- clear the API context whenever you hide the plot and/or on effect cleanup:
useEffect(() => { // plot qc if any dependences change
if (!showQCDist) return;
plotQC();
return () => {
if (percentMTRef.current) percentMTRef.current.replaceChildren(qcAPI.plot(qcAPI.name('percentMT')));
qcAPI.context.coordinator.clear({ clients: true, cache: true });
}
}, [samples, showQCDist]);
...
onClick={() => {
if (showQCDist) { // reset brushes on hide only
handleReset();
if (percentMTRef.current) percentMTRef.current.replaceChildren(qcAPI.plot(qcAPI.name('percentMT')));
qcAPI.context.coordinator.clear({ clients: true, cache: true });
}
setShowQCDist(!showQCDist);
}}
That's an interesting workaround Sam - thanks for sharing!
It's pretty brute force because it clears the client of the plot you are hiding (which resets the plot if you want to reenable), but it at least improves selection/query speed of my visible plots by a lot..