diff --git a/packages/grafana-ui/src/components/uPlot/plugins/ZoomPlugin.tsx b/packages/grafana-ui/src/components/uPlot/plugins/ZoomPlugin.tsx index 4a729bace9c..d870da797b8 100644 --- a/packages/grafana-ui/src/components/uPlot/plugins/ZoomPlugin.tsx +++ b/packages/grafana-ui/src/components/uPlot/plugins/ZoomPlugin.tsx @@ -1,4 +1,6 @@ -import { useEffect, useLayoutEffect, useState } from 'react'; +import { useEffect, useLayoutEffect, useRef, useState } from 'react'; + +import { TimeRange } from '@grafana/data'; import { UPlotConfigBuilder } from '../config/UPlotConfigBuilder'; import { PlotSelection } from '../types'; @@ -7,6 +9,7 @@ import { pluginLog } from '../utils'; interface ZoomPluginProps { onZoom: (range: { from: number; to: number }) => void; config: UPlotConfigBuilder; + timeRange: TimeRange; } // min px width that triggers zoom @@ -15,9 +18,14 @@ const MIN_ZOOM_DIST = 5; /** * @alpha */ -export const ZoomPlugin = ({ onZoom, config }: ZoomPluginProps) => { +export const ZoomPlugin = ({ onZoom, config, timeRange }: ZoomPluginProps) => { const [selection, setSelection] = useState(null); + const refTimeRange = useRef(timeRange); + useEffect(() => { + refTimeRange.current = timeRange; + }, [timeRange]); + useEffect(() => { if (selection) { pluginLog('ZoomPlugin', false, 'selected', selection); @@ -48,6 +56,20 @@ export const ZoomPlugin = ({ onZoom, config }: ZoomPluginProps) => { /* @ts-ignore */ u.setSelect({ left: 0, width: 0 }, false); }); + + config.setCursor({ + bind: { + dblclick: () => () => { + const frTs = refTimeRange.current.from.valueOf(); + const toTs = refTimeRange.current.to.valueOf(); + const pad = (toTs - frTs) / 2; + + onZoom({ from: frTs - pad, to: toTs + pad }); + + return null; + }, + }, + }); }, [config]); return null; diff --git a/public/app/plugins/panel/candlestick/CandlestickPanel.tsx b/public/app/plugins/panel/candlestick/CandlestickPanel.tsx index a8964f0c6ad..71443fa8448 100644 --- a/public/app/plugins/panel/candlestick/CandlestickPanel.tsx +++ b/public/app/plugins/panel/candlestick/CandlestickPanel.tsx @@ -260,7 +260,7 @@ export const CandlestickPanel = ({ return ( <> - + - + diff --git a/public/app/plugins/panel/status-history/StatusHistoryPanel.tsx b/public/app/plugins/panel/status-history/StatusHistoryPanel.tsx index be421751558..1cb0152c335 100644 --- a/public/app/plugins/panel/status-history/StatusHistoryPanel.tsx +++ b/public/app/plugins/panel/status-history/StatusHistoryPanel.tsx @@ -215,7 +215,7 @@ export const StatusHistoryPanel = ({ return ( <> - + {renderTooltip(alignedFrame)} diff --git a/public/app/plugins/panel/timeseries/TimeSeriesPanel.tsx b/public/app/plugins/panel/timeseries/TimeSeriesPanel.tsx index c5d26d01a71..f201cbeed76 100644 --- a/public/app/plugins/panel/timeseries/TimeSeriesPanel.tsx +++ b/public/app/plugins/panel/timeseries/TimeSeriesPanel.tsx @@ -88,7 +88,7 @@ export const TimeSeriesPanel = ({ return ( <> - + {options.tooltip.mode === TooltipDisplayMode.None || (