123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- import { VisualizationSuggestionsBuilder, VizOrientation } from '@grafana/data';
- import { BarGaugeDisplayMode } from '@grafana/ui';
- import { SuggestionName } from 'app/types/suggestions';
- import { BarGaugeOptions } from './types';
- export class BarGaugeSuggestionsSupplier {
- getSuggestionsForData(builder: VisualizationSuggestionsBuilder) {
- const { dataSummary } = builder;
- if (!dataSummary.hasData || !dataSummary.hasNumberField) {
- return;
- }
- const list = builder.getListAppender<BarGaugeOptions, {}>({
- 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: [],
- },
- });
- }
- }
- }
|