prevent historical graph zoom state from resetting during data updates

This commit is contained in:
Nick Krecklow
2020-06-10 18:42:51 -05:00
parent d33cf682e9
commit 6aeb8b5045
3 changed files with 55 additions and 5 deletions

View File

@ -26,3 +26,27 @@ export function uPlotTooltipPlugin (onHover) {
}
}
}
export function uPlotIsZoomedPlugin (onZoomIn, onZoomOut) {
return {
hooks: {
setSelect: u => {
u._zoomPluginIgnoreNextSetScale = true
if (onZoomIn) {
onZoomIn(u)
}
},
setScale: u => {
if (typeof u._zoomPluginIgnoreNextSetScale !== 'boolean') {
return
}
if (u._zoomPluginIgnoreNextSetScale) {
u._zoomPluginIgnoreNextSetScale = false
} else if (onZoomOut) {
onZoomOut(u)
}
}
}
}
}