| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- // Libraries
- import React, { PureComponent } from 'react';
- import {
- PanelEditorProps,
- ThresholdsEditor,
- Threshold,
- PanelOptionsGrid,
- ValueMappingsEditor,
- ValueMapping,
- FieldDisplayOptions,
- FieldDisplayEditor,
- Field,
- FieldPropertiesEditor,
- Switch,
- PanelOptionsGroup,
- } from '@grafana/ui';
- import { GaugeOptions } from './types';
- export class GaugePanelEditor extends PureComponent<PanelEditorProps<GaugeOptions>> {
- labelWidth = 6;
- onToggleThresholdLabels = () =>
- this.props.onOptionsChange({ ...this.props.options, showThresholdLabels: !this.props.options.showThresholdLabels });
- onToggleThresholdMarkers = () =>
- this.props.onOptionsChange({
- ...this.props.options,
- showThresholdMarkers: !this.props.options.showThresholdMarkers,
- });
- onThresholdsChanged = (thresholds: Threshold[]) =>
- this.onDisplayOptionsChanged({
- ...this.props.options.fieldOptions,
- thresholds,
- });
- onValueMappingsChanged = (mappings: ValueMapping[]) =>
- this.onDisplayOptionsChanged({
- ...this.props.options.fieldOptions,
- mappings,
- });
- onDisplayOptionsChanged = (fieldOptions: FieldDisplayOptions) =>
- this.props.onOptionsChange({
- ...this.props.options,
- fieldOptions,
- });
- onDefaultsChange = (field: Partial<Field>) => {
- this.onDisplayOptionsChanged({
- ...this.props.options.fieldOptions,
- defaults: field,
- });
- };
- render() {
- const { options } = this.props;
- const { fieldOptions, showThresholdLabels, showThresholdMarkers } = options;
- return (
- <>
- <PanelOptionsGrid>
- <PanelOptionsGroup title="Display">
- <FieldDisplayEditor
- onChange={this.onDisplayOptionsChanged}
- value={fieldOptions}
- labelWidth={this.labelWidth}
- />
- <Switch
- label="Labels"
- labelClass={`width-${this.labelWidth}`}
- checked={showThresholdLabels}
- onChange={this.onToggleThresholdLabels}
- />
- <Switch
- label="Markers"
- labelClass={`width-${this.labelWidth}`}
- checked={showThresholdMarkers}
- onChange={this.onToggleThresholdMarkers}
- />
- </PanelOptionsGroup>
- <PanelOptionsGroup title="Field">
- <FieldPropertiesEditor showMinMax={true} onChange={this.onDefaultsChange} value={fieldOptions.defaults} />
- </PanelOptionsGroup>
- <ThresholdsEditor onChange={this.onThresholdsChanged} thresholds={fieldOptions.thresholds} />
- </PanelOptionsGrid>
- <ValueMappingsEditor onChange={this.onValueMappingsChanged} valueMappings={fieldOptions.mappings} />
- </>
- );
- }
- }
|