series.ts 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. import { Moment } from 'moment';
  2. import { PluginMeta } from './plugins';
  3. export enum LoadingState {
  4. NotStarted = 'NotStarted',
  5. Loading = 'Loading',
  6. Done = 'Done',
  7. Error = 'Error',
  8. }
  9. export interface RawTimeRange {
  10. from: Moment | string;
  11. to: Moment | string;
  12. }
  13. export interface TimeRange {
  14. from: Moment;
  15. to: Moment;
  16. raw: RawTimeRange;
  17. }
  18. export type TimeSeriesValue = string | number | null;
  19. export type TimeSeriesPoints = TimeSeriesValue[][];
  20. export interface TimeSeries {
  21. target: string;
  22. datapoints: TimeSeriesPoints;
  23. unit?: string;
  24. }
  25. /** View model projection of a time series */
  26. export interface TimeSeriesVM {
  27. label: string;
  28. color: string;
  29. data: TimeSeriesValue[][];
  30. stats: TimeSeriesStats;
  31. }
  32. export interface TimeSeriesStats {
  33. total: number;
  34. max: number;
  35. min: number;
  36. logmin: number;
  37. avg: number | null;
  38. current: number | null;
  39. first: number | null;
  40. delta: number;
  41. diff: number | null;
  42. range: number | null;
  43. timeStep: number;
  44. count: number;
  45. allIsNull: boolean;
  46. allIsZero: boolean;
  47. }
  48. export enum NullValueMode {
  49. Null = 'null',
  50. Ignore = 'connected',
  51. AsZero = 'null as zero',
  52. }
  53. /** View model projection of many time series */
  54. export interface TimeSeriesVMs {
  55. [index: number]: TimeSeriesVM;
  56. length: number;
  57. }
  58. export interface DataQueryResponse {
  59. data: TimeSeries[];
  60. }
  61. export interface DataQuery {
  62. refId: string;
  63. [key: string]: any;
  64. }
  65. export interface DataQueryOptions {
  66. timezone: string;
  67. range: TimeRange;
  68. rangeRaw: RawTimeRange;
  69. targets: DataQuery[];
  70. panelId: number;
  71. dashboardId: number;
  72. cacheTimeout?: string;
  73. interval: string;
  74. intervalMs: number;
  75. maxDataPoints: number;
  76. scopedVars: object;
  77. }
  78. export interface DataSourceApi {
  79. interval?: string;
  80. /**
  81. * Imports queries from a different datasource
  82. */
  83. importQueries?(queries: DataQuery[], originMeta: PluginMeta): Promise<DataQuery[]>;
  84. /**
  85. * Initializes a datasource after instantiation
  86. */
  87. init?: () => void;
  88. /**
  89. * Main metrics / data query action
  90. */
  91. query(options: DataQueryOptions): Promise<DataQueryResponse>;
  92. /**
  93. * Test & verify datasource settings & connection details
  94. */
  95. testDatasource(): Promise<any>;
  96. }