Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix annotations refresh #17

Merged
merged 2 commits into from
Oct 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change Log

## 1.5.0 (2024-10-21)

### Features / Enhancements

- Fix annotations refresh (#17)

## 1.4.0 (2024-10-01)

### Features / Enhancements
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -81,5 +81,5 @@
"test:ci": "jest --maxWorkers 4 --coverage",
"upgrade": "npm upgrade --save"
},
"version": "1.4.0"
"version": "1.5.0"
}
18 changes: 17 additions & 1 deletion src/plugins/AnnotationsPlugin.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useCallback, useEffect, useLayoutEffect, useRef } from 'react';
import React, { useCallback, useEffect, useLayoutEffect, useReducer, useRef } from 'react';
import uPlot from 'uplot';

import { colorManipulator, DataFrame, DataFrameFieldIndex, DataFrameView } from '@grafana/data';
@@ -20,6 +20,8 @@ export const AnnotationsPlugin = ({ annotations, timeZone, config }: Annotations

const annotationsRef = useRef<Array<DataFrameView<AnnotationsDataFrameViewDTO>>>();

const [_, forceUpdate] = useReducer((x) => x + 1, 0);

// Update annotations views when new annotations came
useEffect(() => {
const views: Array<DataFrameView<AnnotationsDataFrameViewDTO>> = [];
@@ -100,6 +102,20 @@ export const AnnotationsPlugin = ({ annotations, timeZone, config }: Annotations
});
}, [config, theme]);

// ensure annos are re-drawn whenever they change
useEffect(() => {
if (plotInstance.current) {
plotInstance.current.redraw();

// this forces a second redraw after uPlot is updated (in the Plot.tsx didUpdate) with new data/scales
// and ensures the anno marker positions in the dom are re-rendered in correct places
// (this is temp fix until uPlot integrtion is refactored)
setTimeout(() => {
forceUpdate();
}, 0);
}
}, [annotations]);

const mapAnnotationToXYCoords = useCallback((frame: DataFrame, dataFrameFieldIndex: DataFrameFieldIndex) => {
const view = new DataFrameView<AnnotationsDataFrameViewDTO>(frame);
const annotation = view.get(dataFrameFieldIndex.fieldIndex);

Unchanged files with check annotations Beta

textarea.focus();
textarea.select();
try {
const successful = document.execCommand('copy');

Check warning on line 101 in src/@grafana/ui/src/components/VizTooltip/VizTooltipRow.tsx

GitHub Actions / build

'execCommand' is deprecated. [MDN Reference](https://developer.mozilla.org/docs/Web/API/Document/execCommand)
if (successful) {
setCopiedText({ [`${type}`]: text });
setShowCopySuccess(true);
el.value = string;
document.body.appendChild(el);
el.select();
document.execCommand('copy');

Check warning on line 223 in src/app/core/utils/explore.ts

GitHub Actions / build

'execCommand' is deprecated. [MDN Reference](https://developer.mozilla.org/docs/Web/API/Document/execCommand)
document.body.removeChild(el);
};
};
const getExemplarMarkerStyles = (theme: GrafanaTheme2) => {
const bg = theme.isDark ? theme.v1.palette.dark2 : theme.v1.palette.white;

Check warning on line 220 in src/plugins/ExemplarMarker.tsx

GitHub Actions / build

'v1' is deprecated. Will be removed in a future version

Check warning on line 220 in src/plugins/ExemplarMarker.tsx

GitHub Actions / build

'v1' is deprecated. Will be removed in a future version
const headerBg = theme.isDark ? theme.v1.palette.dark9 : theme.v1.palette.gray5;

Check warning on line 221 in src/plugins/ExemplarMarker.tsx

GitHub Actions / build

'v1' is deprecated. Will be removed in a future version

Check warning on line 221 in src/plugins/ExemplarMarker.tsx

GitHub Actions / build

'v1' is deprecated. Will be removed in a future version
const shadowColor = theme.isDark ? theme.v1.palette.black : theme.v1.palette.white;

Check warning on line 222 in src/plugins/ExemplarMarker.tsx

GitHub Actions / build

'v1' is deprecated. Will be removed in a future version

Check warning on line 222 in src/plugins/ExemplarMarker.tsx

GitHub Actions / build

'v1' is deprecated. Will be removed in a future version
const tableBgOdd = theme.isDark ? theme.v1.palette.dark3 : theme.v1.palette.gray6;

Check warning on line 223 in src/plugins/ExemplarMarker.tsx

GitHub Actions / build

'v1' is deprecated. Will be removed in a future version

Check warning on line 223 in src/plugins/ExemplarMarker.tsx

GitHub Actions / build

'v1' is deprecated. Will be removed in a future version
return {
markerWrapper: css({