suggestions.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import { FieldColorModeId, VisualizationSuggestionsBuilder } from '@grafana/data';
  2. import { SuggestionName } from 'app/types/suggestions';
  3. import { StatusPanelOptions, StatusFieldConfig } from './types';
  4. export class StatusHistorySuggestionsSupplier {
  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. // if there a lot of data points for each series then this is not a good match
  19. if (ds.rowCountMax > 100) {
  20. return;
  21. }
  22. // Probably better ways to filter out this by inspecting the types of string values so view this as temporary
  23. if (ds.preferredVisualisationType === 'logs') {
  24. return;
  25. }
  26. const list = builder.getListAppender<StatusPanelOptions, StatusFieldConfig>({
  27. name: '',
  28. pluginId: 'status-history',
  29. options: {},
  30. fieldConfig: {
  31. defaults: {
  32. color: {
  33. mode: FieldColorModeId.ContinuousGrYlRd,
  34. },
  35. custom: {},
  36. },
  37. overrides: [],
  38. },
  39. cardOptions: {
  40. previewModifier: (s) => {
  41. s.options!.colWidth = 0.7;
  42. },
  43. },
  44. });
  45. list.append({ name: SuggestionName.StatusHistory });
  46. }
  47. }