2021-10-25 06:55:06 -05:00
|
|
|
import { VisualizationSuggestionsBuilder } from '@grafana/data';
|
|
|
|
import { SuggestionName } from 'app/types/suggestions';
|
2022-04-22 08:33:13 -05:00
|
|
|
|
2021-10-25 06:55:06 -05:00
|
|
|
import { TimelineFieldConfig, TimelineOptions } from './types';
|
|
|
|
|
|
|
|
export class StatTimelineSuggestionsSupplier {
|
|
|
|
getSuggestionsForData(builder: VisualizationSuggestionsBuilder) {
|
2021-11-15 08:13:01 -06:00
|
|
|
const { dataSummary: ds } = builder;
|
2021-10-25 06:55:06 -05:00
|
|
|
|
2021-11-15 08:13:01 -06:00
|
|
|
if (!ds.hasData) {
|
2021-10-25 06:55:06 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This panel needs a time field and a string or number field
|
2021-11-15 08:13:01 -06:00
|
|
|
if (!ds.hasTimeField || (!ds.hasStringField && !ds.hasNumberField)) {
|
2021-10-25 06:55:06 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If there are many series then they won't fit on y-axis so this panel is not good fit
|
2021-11-15 08:13:01 -06:00
|
|
|
if (ds.numberFieldCount >= 30) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Probably better ways to filter out this by inspecting the types of string values so view this as temporary
|
|
|
|
if (ds.preferredVisualisationType === 'logs') {
|
2021-10-25 06:55:06 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const list = builder.getListAppender<TimelineOptions, TimelineFieldConfig>({
|
|
|
|
name: '',
|
|
|
|
pluginId: 'state-timeline',
|
|
|
|
options: {},
|
|
|
|
fieldConfig: {
|
|
|
|
defaults: {
|
|
|
|
custom: {},
|
|
|
|
},
|
|
|
|
overrides: [],
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
list.append({ name: SuggestionName.StateTimeline });
|
|
|
|
}
|
|
|
|
}
|