API Reference@grafana/dataPanelPlugin

PanelPlugin class

Signature

export declare class PanelPlugin<TOptions = any, TFieldConfigOptions extends object = any> extends GrafanaPlugin<PanelPluginMeta> 

Import

import { PanelPlugin } from '@grafana/data';

Constructors

ConstructorModifiersDescription
constructor(panel)Constructs a new instance of the PanelPlugin class

Properties

PropertyModifiersTypeDescription
angularPanelCtrlanyLegacy angular ctrl. If this exists it will be used instead of the panel
dataSupportPanelPluginDataSupport
defaults{}
editorComponentClass<PanelEditorProps<TOptions>>
fieldConfigDefaultsFieldConfigSource<TFieldConfigOptions>
fieldConfigRegistryFieldConfigOptionsRegistry
noPaddingboolean
onPanelMigrationPanelMigrationHandler<TOptions>
onPanelTypeChangedPanelTypeChangedHandler<TOptions>
panelComponentType<PanelProps<TOptions>> | null

Methods

MethodModifiersDescription
hasPluginId(pluginId)
setDataSupport(support)Tells Grafana if the plugin should subscribe to annotation and alertState results.
setDefaults(defaults)
setEditor(editor)
setMigrationHandler(handler)This function is called before the panel first loads if the current version is different than the version that was saved.This is a good place to support any changes to the options model
setNoPadding()
setPanelChangeHandler(handler)This function is called when the visualization was changed. This passes in the panel model for previous visualisation options inspection and panel model updates.This is useful for supporting PanelModel API updates when changing between Angular and React panels.
setPanelOptions(builder)Enables panel options editor creation
useFieldConfig(config)Allows specifying which standard field config options panel should use and defining default values

constructor(panel)

Constructs a new instance of the PanelPlugin class

Signature

constructor(panel: ComponentType<PanelProps<TOptions>> | null);

Parameters

ParameterTypeDescription
panelComponentType<PanelProps<TOptions>> | null

angularPanelCtrl property

Legacy angular ctrl. If this exists it will be used instead of the panel

Signature

angularPanelCtrl?: any;

dataSupport property

Signature

dataSupport: PanelPluginDataSupport;

defaults property

Signature

get defaults(): {};

editor property

Signature

editor?: ComponentClass<PanelEditorProps<TOptions>>;

fieldConfigDefaults property

Signature

get fieldConfigDefaults(): FieldConfigSource<TFieldConfigOptions>;

fieldConfigRegistry property

Signature

get fieldConfigRegistry(): FieldConfigOptionsRegistry;

noPadding property

Signature

noPadding?: boolean;

onPanelMigration property

Signature

onPanelMigration?: PanelMigrationHandler<TOptions>;

onPanelTypeChanged property

Signature

onPanelTypeChanged?: PanelTypeChangedHandler<TOptions>;

panel property

Signature

panel: ComponentType<PanelProps<TOptions>> | null;

hasPluginId method

Signature

hasPluginId(pluginId: string): boolean;

Parameters

ParameterTypeDescription
pluginIdstring

Returns:

boolean

setDataSupport method

Tells Grafana if the plugin should subscribe to annotation and alertState results.

Signature

setDataSupport(support: Partial<PanelPluginDataSupport>): this;

Parameters

ParameterTypeDescription
supportPartial<PanelPluginDataSupport>

Returns:

this

Example


import { ShapePanel } from './ShapePanel';

interface ShapePanelOptions {}

export const plugin = new PanelPlugin<ShapePanelOptions>(ShapePanel)
    .useFieldConfig({})
    ...
    ...
    .setDataSupport({
      annotations: true,
      alertStates: true,
    });

setDefaults method

Signature

setDefaults(defaults: TOptions): this;

Parameters

ParameterTypeDescription
defaultsTOptions

Returns:

this

setEditor method

Signature

setEditor(editor: ComponentClass<PanelEditorProps<TOptions>>): this;

Parameters

ParameterTypeDescription
editorComponentClass<PanelEditorProps<TOptions>>

Returns:

this

setMigrationHandler method

This function is called before the panel first loads if the current version is different than the version that was saved.

This is a good place to support any changes to the options model

Signature

setMigrationHandler(handler: PanelMigrationHandler<TOptions>): this;

Parameters

ParameterTypeDescription
handlerPanelMigrationHandler<TOptions>

Returns:

this

setNoPadding method

Signature

setNoPadding(): this;

Returns:

this

setPanelChangeHandler method

This function is called when the visualization was changed. This passes in the panel model for previous visualisation options inspection and panel model updates.

This is useful for supporting PanelModel API updates when changing between Angular and React panels.

Signature

setPanelChangeHandler(handler: PanelTypeChangedHandler): this;

Parameters

ParameterTypeDescription
handlerPanelTypeChangedHandler

Returns:

this

setPanelOptions method

Enables panel options editor creation

Signature

setPanelOptions(builder: PanelOptionsSupplier<TOptions>): this;

Parameters

ParameterTypeDescription
builderPanelOptionsSupplier<TOptions>

Returns:

this

Example


import { ShapePanel } from './ShapePanel';

interface ShapePanelOptions {}

export const plugin = new PanelPlugin<ShapePanelOptions>(ShapePanel)
  .setPanelOptions(builder => {
    builder
      .addSelect({
        id: 'shape',
        name: 'Shape',
        description: 'Select shape to render'
        settings: {
          options: [
            {value: 'circle', label: 'Circle' },
            {value: 'square', label: 'Square },
            {value: 'triangle', label: 'Triangle }
           ]
        },
      })
  })

useFieldConfig method

Allows specifying which standard field config options panel should use and defining default values

Signature

useFieldConfig(config?: SetFieldConfigOptionsArgs<TFieldConfigOptions>): this;

Parameters

ParameterTypeDescription
configSetFieldConfigOptionsArgs<TFieldConfigOptions>

Returns:

this

Example


import { ShapePanel } from './ShapePanel';

interface ShapePanelOptions {}

// when plugin should use all standard options
export const plugin = new PanelPlugin<ShapePanelOptions>(ShapePanel)
 .useFieldConfig();

// when plugin should only display specific standard options
// note, that options will be displayed in the order they are provided
export const plugin = new PanelPlugin<ShapePanelOptions>(ShapePanel)
 .useFieldConfig({
   standardOptions: [FieldConfigProperty.Min, FieldConfigProperty.Max]
  });

// when standard option's default value needs to be provided
export const plugin = new PanelPlugin<ShapePanelOptions>(ShapePanel)
 .useFieldConfig({
   standardOptions: [FieldConfigProperty.Min, FieldConfigProperty.Max],
   standardOptionsDefaults: {
     [FieldConfigProperty.Min]: 20,
     [FieldConfigProperty.Max]: 100
   }
 });

// when custom field config options needs to be provided
export const plugin = new PanelPlugin<ShapePanelOptions>(ShapePanel)
 .useFieldConfig({
   useCustomConfig: builder => {
     builder
      .addNumberInput({
        id: 'shapeBorderWidth',
        name: 'Border width',
        description: 'Border width of the shape',
        settings: {
          min: 1,
          max: 5,
        },
      })
      .addSelect({
        id: 'displayMode',
        name: 'Display mode',
        description: 'How the shape shout be rendered'
        settings: {
        options: [{value: 'fill', label: 'Fill' }, {value: 'transparent', label: 'Transparent }]
      },
    })
  },
 });