loadSnapshotData.ts 1.4 KB

1234567891011121314151617181920212223242526272829303132333435
  1. import { applyFieldOverrides, ArrayDataFrame, getDefaultTimeRange, LoadingState, PanelData } from '@grafana/data';
  2. import { config } from 'app/core/config';
  3. import { SnapshotWorker } from '../../query/state/DashboardQueryRunner/SnapshotWorker';
  4. import { getProcessedDataFrames } from '../../query/state/runRequest';
  5. import { getTimeSrv } from '../services/TimeSrv';
  6. import { DashboardModel, PanelModel } from '../state';
  7. import { applyPanelTimeOverrides } from './panel';
  8. export function loadSnapshotData(panel: PanelModel, dashboard: DashboardModel): PanelData {
  9. const data = getProcessedDataFrames(panel.snapshotData);
  10. const worker = new SnapshotWorker();
  11. const options = { dashboard, range: getDefaultTimeRange() };
  12. const annotationEvents = worker.canWork(options) ? worker.getAnnotationsInSnapshot(dashboard, panel.id) : [];
  13. const annotations = [new ArrayDataFrame(annotationEvents)];
  14. const timeData = applyPanelTimeOverrides(panel, getTimeSrv().timeRange());
  15. return {
  16. timeRange: timeData.timeRange,
  17. state: LoadingState.Done,
  18. series: applyFieldOverrides({
  19. data,
  20. fieldConfig: {
  21. defaults: {},
  22. overrides: [],
  23. },
  24. replaceVariables: panel.replaceVariables,
  25. fieldConfigRegistry: panel.plugin!.fieldConfigRegistry,
  26. theme: config.theme2,
  27. timeZone: dashboard.getTimezone(),
  28. }),
  29. annotations,
  30. };
  31. }