123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- import { VisualizationSuggestionsBuilder, VisualizationSuggestionScore } from '@grafana/data';
- import { config } from '@grafana/runtime';
- import { SuggestionName } from 'app/types/suggestions';
- import { prepareCandlestickFields } from './fields';
- import { CandlestickOptions, defaultPanelOptions } from './models.gen';
- export class CandlestickSuggestionsSupplier {
- getSuggestionsForData(builder: VisualizationSuggestionsBuilder) {
- const { dataSummary } = builder;
- if (
- !builder.data?.series ||
- !dataSummary.hasData ||
- dataSummary.timeFieldCount < 1 ||
- dataSummary.numberFieldCount < 2 ||
- dataSummary.numberFieldCount > 10
- ) {
- return;
- }
- const info = prepareCandlestickFields(builder.data.series, defaultPanelOptions, config.theme2);
- if (!info) {
- return;
- }
- // Regular timeseries
- if (info.open === info.high && info.open === info.low) {
- return;
- }
- const list = builder.getListAppender<CandlestickOptions, {}>({
- name: '',
- pluginId: 'candlestick',
- options: {},
- fieldConfig: {
- defaults: {
- custom: {},
- },
- overrides: [],
- },
- });
- list.append({
- name: SuggestionName.Candlestick,
- options: defaultPanelOptions,
- fieldConfig: {
- defaults: {},
- overrides: [],
- },
- score: info.autoOpenClose ? VisualizationSuggestionScore.Good : VisualizationSuggestionScore.Best,
- });
- }
- }
|