From 209619c8c1c0cafdf99ba0b72f51a0a652b4520c Mon Sep 17 00:00:00 2001 From: Adela Almasan <88068998+adela-almasan@users.noreply.github.com> Date: Tue, 19 Dec 2023 12:24:55 -0600 Subject: [PATCH] Heatmap / Status History: Enable annotations rendering (#79483) --- .../plugins/panel/heatmap/HeatmapPanel.tsx | 10 +++ public/app/plugins/panel/heatmap/module.tsx | 3 +- .../status-history/StatusHistoryPanel.tsx | 81 ++++++++++--------- .../plugins/panel/status-history/module.tsx | 3 +- .../timeseries/plugins/AnnotationsPlugin.tsx | 45 ++++++----- 5 files changed, 86 insertions(+), 56 deletions(-) diff --git a/public/app/plugins/panel/heatmap/HeatmapPanel.tsx b/public/app/plugins/panel/heatmap/HeatmapPanel.tsx index 45338861efa..16a884189d3 100644 --- a/public/app/plugins/panel/heatmap/HeatmapPanel.tsx +++ b/public/app/plugins/panel/heatmap/HeatmapPanel.tsx @@ -29,6 +29,8 @@ import { TooltipHoverMode } from '@grafana/ui/src/components/uPlot/plugins/Toolt import { ColorScale } from 'app/core/components/ColorScale/ColorScale'; import { isHeatmapCellsDense, readHeatmapRowsCustomMeta } from 'app/features/transformers/calculateHeatmap/heatmap'; +import { AnnotationsPlugin } from '../timeseries/plugins/AnnotationsPlugin'; + import { ExemplarModalHeader } from './ExemplarModalHeader'; import { HeatmapHoverView } from './HeatmapHoverView'; import { HeatmapHoverView as HeatmapHoverViewOld } from './HeatmapHoverViewOld'; @@ -254,6 +256,14 @@ export const HeatmapPanel = ({ }} /> )} + {data.annotations && ( + + )} )} diff --git a/public/app/plugins/panel/heatmap/module.tsx b/public/app/plugins/panel/heatmap/module.tsx index 0d9b5da6db0..da2d05509f6 100644 --- a/public/app/plugins/panel/heatmap/module.tsx +++ b/public/app/plugins/panel/heatmap/module.tsx @@ -430,4 +430,5 @@ export const plugin = new PanelPlugin(HeatmapPanel) category, }); }) - .setSuggestionsSupplier(new HeatmapSuggestionsSupplier()); + .setSuggestionsSupplier(new HeatmapSuggestionsSupplier()) + .setDataSupport({ annotations: true }); diff --git a/public/app/plugins/panel/status-history/StatusHistoryPanel.tsx b/public/app/plugins/panel/status-history/StatusHistoryPanel.tsx index 377ce3c0231..060694d0e75 100644 --- a/public/app/plugins/panel/status-history/StatusHistoryPanel.tsx +++ b/public/app/plugins/panel/status-history/StatusHistoryPanel.tsx @@ -12,7 +12,7 @@ import { VizTooltipContainer, ZoomPlugin, } from '@grafana/ui'; -import { HoverEvent, addTooltipSupport } from '@grafana/ui/src/components/uPlot/config/addTooltipSupport'; +import { addTooltipSupport, HoverEvent } from '@grafana/ui/src/components/uPlot/config/addTooltipSupport'; import { TooltipHoverMode } from '@grafana/ui/src/components/uPlot/plugins/TooltipPlugin2'; import { CloseButton } from 'app/core/components/CloseButton/CloseButton'; import { TimelineChart } from 'app/core/components/TimelineChart/TimelineChart'; @@ -22,6 +22,7 @@ import { TimelineMode, } from 'app/core/components/TimelineChart/utils'; +import { AnnotationsPlugin } from '../timeseries/plugins/AnnotationsPlugin'; import { OutsideRangePlugin } from '../timeseries/plugins/OutsideRangePlugin'; import { getTimezones } from '../timeseries/utils'; @@ -217,41 +218,49 @@ export const StatusHistoryPanel = ({ }); } - if (config.featureToggles.newVizTooltips) { - return ( - <> - {options.tooltip.mode !== TooltipDisplayMode.None && ( - { - return ( - - ); - }} - /> - )} - - ); - } else { - return ( - <> - - {renderTooltip(alignedFrame)} - - - ); - } + return ( + <> + {data.annotations && ( + + )} + {config.featureToggles.newVizTooltips ? ( + <> + {options.tooltip.mode !== TooltipDisplayMode.None && ( + { + return ( + + ); + }} + /> + )} + + ) : ( + <> + + {renderTooltip(alignedFrame)} + + + )} + + ); }} ); diff --git a/public/app/plugins/panel/status-history/module.tsx b/public/app/plugins/panel/status-history/module.tsx index 0fb5decdfb3..82b06291a11 100644 --- a/public/app/plugins/panel/status-history/module.tsx +++ b/public/app/plugins/panel/status-history/module.tsx @@ -83,4 +83,5 @@ export const plugin = new PanelPlugin(StatusHistoryPanel) commonOptionsBuilder.addLegendOptions(builder, false); commonOptionsBuilder.addTooltipOptions(builder, !config.featureToggles.newVizTooltips); }) - .setSuggestionsSupplier(new StatusHistorySuggestionsSupplier()); + .setSuggestionsSupplier(new StatusHistorySuggestionsSupplier()) + .setDataSupport({ annotations: true }); diff --git a/public/app/plugins/panel/timeseries/plugins/AnnotationsPlugin.tsx b/public/app/plugins/panel/timeseries/plugins/AnnotationsPlugin.tsx index 8d7f9772918..384ec4acd30 100644 --- a/public/app/plugins/panel/timeseries/plugins/AnnotationsPlugin.tsx +++ b/public/app/plugins/panel/timeseries/plugins/AnnotationsPlugin.tsx @@ -11,9 +11,15 @@ interface AnnotationsPluginProps { config: UPlotConfigBuilder; annotations: DataFrame[]; timeZone: TimeZone; + disableCanvasRendering?: boolean; } -export const AnnotationsPlugin = ({ annotations, timeZone, config }: AnnotationsPluginProps) => { +export const AnnotationsPlugin = ({ + annotations, + timeZone, + config, + disableCanvasRendering = false, +}: AnnotationsPluginProps) => { const theme = useTheme2(); const plotInstance = useRef(); @@ -69,35 +75,38 @@ export const AnnotationsPlugin = ({ annotations, timeZone, config }: Annotations ctx.closePath(); }; - for (let i = 0; i < annotationsRef.current.length; i++) { - const annotationsView = annotationsRef.current[i]; - for (let j = 0; j < annotationsView.length; j++) { - const annotation = annotationsView.get(j); + if (!disableCanvasRendering) { + for (let i = 0; i < annotationsRef.current.length; i++) { + const annotationsView = annotationsRef.current[i]; + for (let j = 0; j < annotationsView.length; j++) { + const annotation = annotationsView.get(j); - if (!annotation.time) { - continue; - } + if (!annotation.time) { + continue; + } - let x0 = u.valToPos(annotation.time, 'x', true); - const color = theme.visualization.getColorByName(annotation.color); + let x0 = u.valToPos(annotation.time, 'x', true); + const color = theme.visualization.getColorByName(annotation.color); - renderLine(x0, color); + renderLine(x0, color); - if (annotation.isRegion && annotation.timeEnd) { - let x1 = u.valToPos(annotation.timeEnd, 'x', true); + if (annotation.isRegion && annotation.timeEnd) { + let x1 = u.valToPos(annotation.timeEnd, 'x', true); - renderLine(x1, color); + renderLine(x1, color); - ctx.fillStyle = colorManipulator.alpha(color, 0.1); - ctx.rect(x0, u.bbox.top, x1 - x0, u.bbox.height); - ctx.fill(); + ctx.fillStyle = colorManipulator.alpha(color, 0.1); + ctx.rect(x0, u.bbox.top, x1 - x0, u.bbox.height); + ctx.fill(); + } } } } + ctx.restore(); return; }); - }, [config, theme]); + }, [config, theme, disableCanvasRendering]); const mapAnnotationToXYCoords = useCallback((frame: DataFrame, dataFrameFieldIndex: DataFrameFieldIndex) => { const view = new DataFrameView(frame);