utils.ts 703 B

1234567891011121314151617181920212223242526272829
  1. import { DataFrame, FieldType } from '@grafana/data';
  2. import {
  3. histogramFrameBucketMinFieldName,
  4. histogramFrameBucketMaxFieldName,
  5. } from '@grafana/data/src/transformations/transformers/histogram';
  6. export function originalDataHasHistogram(frames?: DataFrame[]): boolean {
  7. if (frames?.length !== 1) {
  8. return false;
  9. }
  10. const frame = frames[0];
  11. if (frame.fields.length < 3) {
  12. return false;
  13. }
  14. if (
  15. frame.fields[0].name !== histogramFrameBucketMinFieldName ||
  16. frame.fields[1].name !== histogramFrameBucketMaxFieldName
  17. ) {
  18. return false;
  19. }
  20. for (const field of frame.fields) {
  21. if (field.type !== FieldType.number) {
  22. return false;
  23. }
  24. }
  25. return true;
  26. }