mirror of
https://github.com/grafana/grafana.git
synced 2025-02-11 16:15:42 -06:00
* Make suggestion cards support img & text mode instead of only preview * Generic solution for non data panels * minor review tweaks
88 lines
2.2 KiB
TypeScript
88 lines
2.2 KiB
TypeScript
import { ThresholdsMode, VisualizationSuggestionsBuilder } from '@grafana/data';
|
|
import { SuggestionName } from 'app/types/suggestions';
|
|
import { GaugeOptions } from './types';
|
|
|
|
export class GaugeSuggestionsSupplier {
|
|
getSuggestionsForData(builder: VisualizationSuggestionsBuilder) {
|
|
const { dataSummary } = builder;
|
|
|
|
if (!dataSummary.hasData || !dataSummary.hasNumberField) {
|
|
return;
|
|
}
|
|
|
|
// for many fields / series this is probably not a good fit
|
|
if (dataSummary.numberFieldCount >= 50) {
|
|
return;
|
|
}
|
|
|
|
const list = builder.getListAppender<GaugeOptions, {}>({
|
|
name: SuggestionName.Gauge,
|
|
pluginId: 'gauge',
|
|
options: {},
|
|
fieldConfig: {
|
|
defaults: {
|
|
thresholds: {
|
|
steps: [
|
|
{ value: -Infinity, color: 'green' },
|
|
{ value: 70, color: 'orange' },
|
|
{ value: 85, color: 'red' },
|
|
],
|
|
mode: ThresholdsMode.Percentage,
|
|
},
|
|
custom: {},
|
|
},
|
|
overrides: [],
|
|
},
|
|
cardOptions: {
|
|
previewModifier: (s) => {
|
|
if (s.options!.reduceOptions.values) {
|
|
s.options!.reduceOptions.limit = 2;
|
|
}
|
|
},
|
|
},
|
|
});
|
|
|
|
if (dataSummary.hasStringField && dataSummary.frameCount === 1 && dataSummary.rowCountTotal < 10) {
|
|
list.append({
|
|
name: SuggestionName.Gauge,
|
|
options: {
|
|
reduceOptions: {
|
|
values: true,
|
|
calcs: [],
|
|
},
|
|
},
|
|
});
|
|
list.append({
|
|
name: SuggestionName.GaugeNoThresholds,
|
|
options: {
|
|
reduceOptions: {
|
|
values: true,
|
|
calcs: [],
|
|
},
|
|
showThresholdMarkers: false,
|
|
},
|
|
});
|
|
} else {
|
|
list.append({
|
|
name: SuggestionName.Gauge,
|
|
options: {
|
|
reduceOptions: {
|
|
values: false,
|
|
calcs: ['lastNotNull'],
|
|
},
|
|
},
|
|
});
|
|
list.append({
|
|
name: SuggestionName.GaugeNoThresholds,
|
|
options: {
|
|
reduceOptions: {
|
|
values: false,
|
|
calcs: ['lastNotNull'],
|
|
},
|
|
showThresholdMarkers: false,
|
|
},
|
|
});
|
|
}
|
|
}
|
|
}
|