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
|
2020-03-27 06:38:46 -05:00
|
|
|
import { Gauge, DataLinksContextMenu, VizRepeater, VizRepeaterRenderValueProps } from '@grafana/ui';
|
2019-01-18 04:58:29 -06:00
|
|
|
|
|
|
|
// Types
|
|
|
|
import { GaugeOptions } from './types';
|
2019-10-31 04:48:05 -05:00
|
|
|
import { FieldDisplay, getFieldDisplayValues, VizOrientation, PanelProps } from '@grafana/data';
|
2019-01-09 10:00:10 -06:00
|
|
|
|
2019-03-14 16:47:01 -05:00
|
|
|
export class GaugePanel extends PureComponent<PanelProps<GaugeOptions>> {
|
2020-03-27 06:38:46 -05:00
|
|
|
renderValue = (valueProps: VizRepeaterRenderValueProps<FieldDisplay>): JSX.Element => {
|
2019-03-13 13:12:11 -05:00
|
|
|
const { options } = this.props;
|
2020-03-27 06:38:46 -05:00
|
|
|
const { value, width, height } = valueProps;
|
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 (
|
2020-04-20 00:37:38 -05:00
|
|
|
<DataLinksContextMenu links={value.getLinks}>
|
2019-08-28 01:50:43 -05:00
|
|
|
{({ openMenu, targetClassName }) => {
|
|
|
|
return (
|
|
|
|
<Gauge
|
|
|
|
value={display}
|
|
|
|
width={width}
|
|
|
|
height={height}
|
2019-12-28 19:32:58 -06:00
|
|
|
field={field}
|
2019-08-28 01:50:43 -05:00
|
|
|
showThresholdLabels={options.showThresholdLabels}
|
|
|
|
showThresholdMarkers={options.showThresholdMarkers}
|
|
|
|
theme={config.theme}
|
|
|
|
onClick={openMenu}
|
|
|
|
className={targetClassName}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}}
|
|
|
|
</DataLinksContextMenu>
|
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[] => {
|
2020-04-27 08:28:06 -05:00
|
|
|
const { data, options, replaceVariables, fieldConfig, timeZone } = this.props;
|
2019-05-04 03:08:48 -05:00
|
|
|
return getFieldDisplayValues({
|
2020-03-19 05:50:31 -05:00
|
|
|
fieldConfig,
|
2020-03-28 17:11:50 -05:00
|
|
|
reduceOptions: options.reduceOptions,
|
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-12-13 10:36:49 -06:00
|
|
|
autoMinMax: true,
|
2020-04-27 08:28:06 -05:00
|
|
|
timeZone,
|
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}
|
2020-04-04 09:57:06 -05:00
|
|
|
autoGrid={true}
|
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
|
|
|
}
|
|
|
|
}
|