grafana/public/app/plugins/panel/gauge/GaugePanel.tsx

59 lines
1.5 KiB
TypeScript
Raw Normal View History

2019-01-18 04:58:29 -06:00
// Libraries
2019-01-09 10:00:10 -06:00
import React, { PureComponent } from 'react';
2019-01-18 04:58:29 -06:00
// Services & Utils
import { config } from 'app/core/config';
2019-01-18 04:58:29 -06:00
// Components
import { Gauge, FieldDisplay, getFieldDisplayValues, VizOrientation } from '@grafana/ui';
2019-01-18 04:58:29 -06:00
// Types
import { GaugeOptions } from './types';
import { PanelProps, VizRepeater } from '@grafana/ui';
2019-01-09 10:00:10 -06:00
2019-03-14 16:47:01 -05:00
export class GaugePanel extends PureComponent<PanelProps<GaugeOptions>> {
renderValue = (value: FieldDisplay, width: number, height: number): JSX.Element => {
2019-03-13 13:12:11 -05:00
const { options } = this.props;
const { field, display } = value;
2019-02-05 09:34:01 -06:00
return (
<Gauge
value={display}
width={width}
height={height}
thresholds={field.thresholds}
showThresholdLabels={options.showThresholdLabels}
showThresholdMarkers={options.showThresholdMarkers}
minValue={field.min}
maxValue={field.max}
theme={config.theme}
/>
2019-02-05 09:34:01 -06:00
);
2019-03-14 16:47:01 -05:00
};
getValues = (): FieldDisplay[] => {
const { data, options, replaceVariables } = this.props;
return getFieldDisplayValues({
fieldOptions: options.fieldOptions,
replaceVariables,
theme: config.theme,
data: data.series,
});
2019-03-14 16:47:01 -05:00
};
2019-01-09 10:00:10 -06:00
2019-03-14 16:47:01 -05:00
render() {
const { height, width, data, renderCounter } = this.props;
2019-01-15 11:05:55 -06:00
return (
<VizRepeater
getValues={this.getValues}
2019-03-14 16:47:01 -05:00
renderValue={this.renderValue}
width={width}
height={height}
2019-03-15 17:37:56 -05:00
source={data}
renderCounter={renderCounter}
orientation={VizOrientation.Auto}
2019-03-14 16:47:01 -05:00
/>
2019-01-15 11:05:55 -06:00
);
2019-01-09 10:00:10 -06:00
}
}