suggestions.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { VisualizationSuggestionsBuilder } from '@grafana/data';
  2. import { SuggestionName } from 'app/types/suggestions';
  3. import { TimelineFieldConfig, TimelineOptions } from './types';
  4. export class StatTimelineSuggestionsSupplier {
  5. getSuggestionsForData(builder: VisualizationSuggestionsBuilder) {
  6. const { dataSummary: ds } = builder;
  7. if (!ds.hasData) {
  8. return;
  9. }
  10. // This panel needs a time field and a string or number field
  11. if (!ds.hasTimeField || (!ds.hasStringField && !ds.hasNumberField)) {
  12. return;
  13. }
  14. // If there are many series then they won't fit on y-axis so this panel is not good fit
  15. if (ds.numberFieldCount >= 30) {
  16. return;
  17. }
  18. // Probably better ways to filter out this by inspecting the types of string values so view this as temporary
  19. if (ds.preferredVisualisationType === 'logs') {
  20. return;
  21. }
  22. const list = builder.getListAppender<TimelineOptions, TimelineFieldConfig>({
  23. name: '',
  24. pluginId: 'state-timeline',
  25. options: {},
  26. fieldConfig: {
  27. defaults: {
  28. custom: {},
  29. },
  30. overrides: [],
  31. },
  32. });
  33. list.append({ name: SuggestionName.StateTimeline });
  34. }
  35. }