2019-01-18 04:58:29 -06:00
|
|
|
// Libraries
|
2019-01-09 10:00:10 -06:00
|
|
|
import React, { PureComponent } from 'react';
|
2019-01-11 01:30:30 -06:00
|
|
|
|
2019-01-18 04:58:29 -06:00
|
|
|
// Services & Utils
|
2019-02-11 04:45:02 -06:00
|
|
|
import { config } from 'app/core/config';
|
2019-01-18 04:58:29 -06:00
|
|
|
|
|
|
|
// Components
|
2019-05-14 09:33:47 -05:00
|
|
|
import { Gauge, FieldDisplay, getFieldDisplayValues, VizOrientation } from '@grafana/ui';
|
2019-01-18 04:58:29 -06:00
|
|
|
|
|
|
|
// Types
|
|
|
|
import { GaugeOptions } from './types';
|
2019-05-04 03:08:48 -05:00
|
|
|
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>> {
|
2019-05-04 03:08:48 -05:00
|
|
|
renderValue = (value: FieldDisplay, width: number, height: number): JSX.Element => {
|
2019-03-13 13:12:11 -05:00
|
|
|
const { options } = this.props;
|
2019-05-04 03:08:48 -05:00
|
|
|
const { field, display } = value;
|
2019-02-01 03:53:58 -06:00
|
|
|
|
2019-02-05 09:34:01 -06:00
|
|
|
return (
|
2019-02-11 04:45:02 -06:00
|
|
|
<Gauge
|
2019-05-04 03:08:48 -05:00
|
|
|
value={display}
|
2019-02-19 08:53:05 -06:00
|
|
|
width={width}
|
|
|
|
height={height}
|
2019-07-12 10:32:39 -05:00
|
|
|
thresholds={field.thresholds}
|
2019-02-19 08:53:05 -06:00
|
|
|
showThresholdLabels={options.showThresholdLabels}
|
|
|
|
showThresholdMarkers={options.showThresholdMarkers}
|
2019-05-04 03:08:48 -05:00
|
|
|
minValue={field.min}
|
|
|
|
maxValue={field.max}
|
2019-02-11 04:45:02 -06:00
|
|
|
theme={config.theme}
|
|
|
|
/>
|
2019-02-05 09:34:01 -06:00
|
|
|
);
|
2019-03-14 16:47:01 -05:00
|
|
|
};
|
2019-02-01 03:53:58 -06:00
|
|
|
|
2019-05-04 03:08:48 -05:00
|
|
|
getValues = (): FieldDisplay[] => {
|
2019-04-16 15:23:34 -05:00
|
|
|
const { data, options, replaceVariables } = this.props;
|
2019-05-04 03:08:48 -05:00
|
|
|
return getFieldDisplayValues({
|
|
|
|
fieldOptions: options.fieldOptions,
|
2019-04-16 15:23:34 -05:00
|
|
|
replaceVariables,
|
2019-03-28 08:57:49 -05:00
|
|
|
theme: config.theme,
|
2019-04-16 15:23:34 -05:00
|
|
|
data: data.series,
|
2019-03-28 08:57:49 -05:00
|
|
|
});
|
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() {
|
2019-05-14 09:33:47 -05:00
|
|
|
const { height, width, data, renderCounter } = this.props;
|
2019-01-15 11:05:55 -06:00
|
|
|
return (
|
2019-04-05 05:59:29 -05:00
|
|
|
<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}
|
2019-03-19 08:07:48 -05:00
|
|
|
renderCounter={renderCounter}
|
2019-05-14 09:33:47 -05:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|