flotPairs.ts 858 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // Types
  2. import { NullValueMode, DataFrame, GraphSeriesValue } from '@grafana/data';
  3. export interface FlotPairsOptions {
  4. series: DataFrame;
  5. xIndex: number;
  6. yIndex: number;
  7. nullValueMode?: NullValueMode;
  8. }
  9. export function getFlotPairs({ series, xIndex, yIndex, nullValueMode }: FlotPairsOptions): GraphSeriesValue[][] {
  10. const rows = series.rows;
  11. const ignoreNulls = nullValueMode === NullValueMode.Ignore;
  12. const nullAsZero = nullValueMode === NullValueMode.AsZero;
  13. const pairs: any[][] = [];
  14. for (let i = 0; i < rows.length; i++) {
  15. const x = rows[i][xIndex];
  16. let y = rows[i][yIndex];
  17. if (y === null) {
  18. if (ignoreNulls) {
  19. continue;
  20. }
  21. if (nullAsZero) {
  22. y = 0;
  23. }
  24. }
  25. // X must be a value
  26. if (x === null) {
  27. continue;
  28. }
  29. pairs.push([x, y]);
  30. }
  31. return pairs;
  32. }