mirror of
https://github.com/grafana/grafana.git
synced 2025-02-16 18:34:52 -06:00
* kindsys: Adapt to new PanelCfg schema interface * building locally * Remove Panel prefix in cue files * Regenerate * Update imports * fixup! Merge branch 'remove-panel-prefix' into sdboyer/redundant-panelcfg-prefixes * Fix formatting --------- Co-authored-by: Ryan McKinley <ryantxu@gmail.com> Co-authored-by: Tania B <yalyna.ts@gmail.com>
116 lines
2.9 KiB
TypeScript
116 lines
2.9 KiB
TypeScript
import { VisualizationSuggestionsBuilder, VizOrientation } from '@grafana/data';
|
|
import { BarGaugeDisplayMode } from '@grafana/ui';
|
|
import { SuggestionName } from 'app/types/suggestions';
|
|
|
|
import { Options } from './panelcfg.gen';
|
|
|
|
export class BarGaugeSuggestionsSupplier {
|
|
getSuggestionsForData(builder: VisualizationSuggestionsBuilder) {
|
|
const { dataSummary } = builder;
|
|
|
|
if (!dataSummary.hasData || !dataSummary.hasNumberField) {
|
|
return;
|
|
}
|
|
|
|
const list = builder.getListAppender<Options, {}>({
|
|
name: '',
|
|
pluginId: 'bargauge',
|
|
options: {},
|
|
fieldConfig: {
|
|
defaults: {
|
|
custom: {},
|
|
},
|
|
overrides: [],
|
|
},
|
|
});
|
|
|
|
// This is probably not a good option for many numeric fields
|
|
if (dataSummary.numberFieldCount > 50) {
|
|
return;
|
|
}
|
|
|
|
// To use show individual row values we also need a string field to give each value a name
|
|
if (dataSummary.hasStringField && dataSummary.frameCount === 1 && dataSummary.rowCountTotal < 30) {
|
|
list.append({
|
|
name: SuggestionName.BarGaugeBasic,
|
|
options: {
|
|
reduceOptions: {
|
|
values: true,
|
|
calcs: [],
|
|
},
|
|
displayMode: BarGaugeDisplayMode.Basic,
|
|
orientation: VizOrientation.Horizontal,
|
|
},
|
|
fieldConfig: {
|
|
defaults: {
|
|
color: {
|
|
mode: 'continuous-GrYlRd',
|
|
},
|
|
},
|
|
overrides: [],
|
|
},
|
|
});
|
|
|
|
list.append({
|
|
name: SuggestionName.BarGaugeLCD,
|
|
options: {
|
|
reduceOptions: {
|
|
values: true,
|
|
calcs: [],
|
|
},
|
|
displayMode: BarGaugeDisplayMode.Lcd,
|
|
orientation: VizOrientation.Horizontal,
|
|
},
|
|
fieldConfig: {
|
|
defaults: {
|
|
color: {
|
|
mode: 'continuous-GrYlRd',
|
|
},
|
|
},
|
|
overrides: [],
|
|
},
|
|
});
|
|
} else {
|
|
list.append({
|
|
name: SuggestionName.BarGaugeBasic,
|
|
options: {
|
|
displayMode: BarGaugeDisplayMode.Basic,
|
|
orientation: VizOrientation.Horizontal,
|
|
reduceOptions: {
|
|
values: false,
|
|
calcs: ['lastNotNull'],
|
|
},
|
|
},
|
|
fieldConfig: {
|
|
defaults: {
|
|
color: {
|
|
mode: 'continuous-GrYlRd',
|
|
},
|
|
},
|
|
overrides: [],
|
|
},
|
|
});
|
|
|
|
list.append({
|
|
name: SuggestionName.BarGaugeLCD,
|
|
options: {
|
|
displayMode: BarGaugeDisplayMode.Lcd,
|
|
orientation: VizOrientation.Horizontal,
|
|
reduceOptions: {
|
|
values: false,
|
|
calcs: ['lastNotNull'],
|
|
},
|
|
},
|
|
fieldConfig: {
|
|
defaults: {
|
|
color: {
|
|
mode: 'continuous-GrYlRd',
|
|
},
|
|
},
|
|
overrides: [],
|
|
},
|
|
});
|
|
}
|
|
}
|
|
}
|