suggestions.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import { VisualizationSuggestionsBuilder, VisualizationSuggestionScore } from '@grafana/data';
  2. import { config } from '@grafana/runtime';
  3. import { SuggestionName } from 'app/types/suggestions';
  4. import { prepareCandlestickFields } from './fields';
  5. import { CandlestickOptions, defaultPanelOptions } from './models.gen';
  6. export class CandlestickSuggestionsSupplier {
  7. getSuggestionsForData(builder: VisualizationSuggestionsBuilder) {
  8. const { dataSummary } = builder;
  9. if (
  10. !builder.data?.series ||
  11. !dataSummary.hasData ||
  12. dataSummary.timeFieldCount < 1 ||
  13. dataSummary.numberFieldCount < 2 ||
  14. dataSummary.numberFieldCount > 10
  15. ) {
  16. return;
  17. }
  18. const info = prepareCandlestickFields(builder.data.series, defaultPanelOptions, config.theme2);
  19. if (!info) {
  20. return;
  21. }
  22. // Regular timeseries
  23. if (info.open === info.high && info.open === info.low) {
  24. return;
  25. }
  26. const list = builder.getListAppender<CandlestickOptions, {}>({
  27. name: '',
  28. pluginId: 'candlestick',
  29. options: {},
  30. fieldConfig: {
  31. defaults: {
  32. custom: {},
  33. },
  34. overrides: [],
  35. },
  36. });
  37. list.append({
  38. name: SuggestionName.Candlestick,
  39. options: defaultPanelOptions,
  40. fieldConfig: {
  41. defaults: {},
  42. overrides: [],
  43. },
  44. score: info.autoOpenClose ? VisualizationSuggestionScore.Good : VisualizationSuggestionScore.Best,
  45. });
  46. }
  47. }