From 41e3b3bea2d91f9da38d65bfee89f321499ea3f9 Mon Sep 17 00:00:00 2001 From: Leon Sorokin Date: Tue, 17 Oct 2023 16:26:31 -0500 Subject: [PATCH] ZoomPlugin: Clear selection in shared-cursor dashboards during zoom (#76719) --- .../components/uPlot/plugins/ZoomPlugin.tsx | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/packages/grafana-ui/src/components/uPlot/plugins/ZoomPlugin.tsx b/packages/grafana-ui/src/components/uPlot/plugins/ZoomPlugin.tsx index 02f539dd3ee..faed1ae95a9 100644 --- a/packages/grafana-ui/src/components/uPlot/plugins/ZoomPlugin.tsx +++ b/packages/grafana-ui/src/components/uPlot/plugins/ZoomPlugin.tsx @@ -51,31 +51,31 @@ export const ZoomPlugin = ({ onZoom, config, withZoomY = false }: ZoomPluginProp } config.addHook('setSelect', (u) => { - if (!maybeZoomAction(u.cursor!.event)) { - return; - } + if (maybeZoomAction(u.cursor!.event)) { + if (withZoomY && yDrag) { + if (u.select.height >= MIN_ZOOM_DIST) { + for (let key in u.scales!) { + if (key !== 'x') { + const maxY = u.posToVal(u.select.top, key); + const minY = u.posToVal(u.select.top + u.select.height, key); - if (withZoomY && yDrag) { - if (u.select.height >= MIN_ZOOM_DIST) { - for (let key in u.scales!) { - if (key !== 'x') { - const maxY = u.posToVal(u.select.top, key); - const minY = u.posToVal(u.select.top + u.select.height, key); - - u.setScale(key, { min: minY, max: maxY }); + u.setScale(key, { min: minY, max: maxY }); + } } + + yZoomed = true; } - yZoomed = true; - } + yDrag = false; + } else { + if (u.select.width >= MIN_ZOOM_DIST) { + const minX = u.posToVal(u.select.left, 'x'); + const maxX = u.posToVal(u.select.left + u.select.width, 'x'); - yDrag = false; - } else { - if (u.select.width >= MIN_ZOOM_DIST) { - const minX = u.posToVal(u.select.left, 'x'); - const maxX = u.posToVal(u.select.left + u.select.width, 'x'); + onZoom({ from: minX, to: maxX }); - onZoom({ from: minX, to: maxX }); + yZoomed = false; + } } }