Menu

Important: This documentation is about an older version. It's relevant only to the release noted, many of the features and functions have been updated or replaced. Please view the current version.

Enterprise Open source

PanelPlugin class

Signature

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

Import

typescript
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
defaults{} | null
editorComponentClass<PanelEditorProps<TOptions>>
fieldConfigDefaultsFieldConfigSource<TFieldConfigOptions>
fieldConfigRegistryFieldConfigOptionsRegistry
noPaddingboolean
onPanelMigrationPanelMigrationHandler<TOptions>
onPanelTypeChangedPanelTypeChangedHandler<TOptions>
optionEditorsPanelOptionEditorsRegistry
panelComponentType<PanelProps<TOptions>> | null

Methods

MethodModifiersDescription
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

typescript
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

typescript
angularPanelCtrl?: any;

defaults property

Signature

typescript
get defaults(): {} | null;

editor property

Signature

typescript
editor?: ComponentClass<PanelEditorProps<TOptions>>;

fieldConfigDefaults property

Signature

typescript
get fieldConfigDefaults(): FieldConfigSource<TFieldConfigOptions>;

fieldConfigRegistry property

Signature

typescript
get fieldConfigRegistry(): FieldConfigOptionsRegistry;

noPadding property

Signature

typescript
noPadding?: boolean;

onPanelMigration property

Signature

typescript
onPanelMigration?: PanelMigrationHandler<TOptions>;

onPanelTypeChanged property

Signature

typescript
onPanelTypeChanged?: PanelTypeChangedHandler<TOptions>;

optionEditors property

Signature

typescript
get optionEditors(): PanelOptionEditorsRegistry;

panel property

Signature

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

setDefaults method

Signature

typescript
setDefaults(defaults: TOptions): this;

Parameters

ParameterTypeDescription
defaultsTOptions

Returns:

this

setEditor method

Signature

typescript
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

typescript
setMigrationHandler(handler: PanelMigrationHandler): this;

Parameters

ParameterTypeDescription
handlerPanelMigrationHandler

Returns:

this

setNoPadding method

Signature

typescript
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

typescript
setPanelChangeHandler(handler: PanelTypeChangedHandler): this;

Parameters

ParameterTypeDescription
handlerPanelTypeChangedHandler

Returns:

this

setPanelOptions method

Enables panel options editor creation

Signature

typescript
setPanelOptions(builder: (builder: PanelOptionsEditorBuilder<TOptions>) => void): this;

Parameters

ParameterTypeDescription
builder(builder: PanelOptionsEditorBuilder<TOptions>) => void

Returns:

this

Example

typescript

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

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

Parameters

ParameterTypeDescription
configSetFieldConfigOptionsArgs<TFieldConfigOptions>

Returns:

this

Example

typescript

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 }]
      },
    })
  },
 });