2019-02-15 05:55:35 -06:00
|
|
|
// Libraries
|
|
|
|
import React, { PureComponent } from 'react';
|
|
|
|
|
|
|
|
// Services & Utils
|
2019-02-20 08:07:30 -06:00
|
|
|
import { config } from 'app/core/config';
|
2019-02-15 05:55:35 -06:00
|
|
|
|
2019-04-05 05:59:29 -05:00
|
|
|
// Components
|
|
|
|
import { BarGauge, VizRepeater, getSingleStatDisplayValues } from '@grafana/ui/src/components';
|
|
|
|
|
2019-02-15 05:55:35 -06:00
|
|
|
// Types
|
|
|
|
import { BarGaugeOptions } from './types';
|
2019-04-05 05:59:29 -05:00
|
|
|
import { PanelProps, DisplayValue } from '@grafana/ui/src/types';
|
2019-03-13 02:26:06 -05:00
|
|
|
|
2019-03-14 16:47:01 -05:00
|
|
|
export class BarGaugePanel extends PureComponent<PanelProps<BarGaugeOptions>> {
|
|
|
|
renderValue = (value: DisplayValue, width: number, height: number): JSX.Element => {
|
2019-03-13 13:12:11 -05:00
|
|
|
const { options } = this.props;
|
2019-02-15 05:55:35 -06:00
|
|
|
|
2019-02-20 08:07:30 -06:00
|
|
|
return (
|
|
|
|
<BarGauge
|
|
|
|
value={value}
|
|
|
|
width={width}
|
|
|
|
height={height}
|
|
|
|
orientation={options.orientation}
|
|
|
|
thresholds={options.thresholds}
|
|
|
|
theme={config.theme}
|
2019-04-05 05:59:29 -05:00
|
|
|
itemSpacing={this.getItemSpacing()}
|
2019-03-14 12:48:12 -05:00
|
|
|
displayMode={options.displayMode}
|
2019-02-20 08:07:30 -06:00
|
|
|
/>
|
|
|
|
);
|
2019-03-14 16:47:01 -05:00
|
|
|
};
|
2019-02-15 05:55:35 -06:00
|
|
|
|
2019-04-05 05:59:29 -05:00
|
|
|
getValues = (): DisplayValue[] => {
|
2019-04-16 15:23:34 -05:00
|
|
|
const { data, options, replaceVariables } = this.props;
|
2019-03-28 08:57:49 -05:00
|
|
|
return getSingleStatDisplayValues({
|
2019-04-16 15:23:34 -05:00
|
|
|
...options,
|
|
|
|
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-02-15 05:55:35 -06:00
|
|
|
|
2019-04-05 05:59:29 -05:00
|
|
|
getItemSpacing(): number {
|
|
|
|
if (this.props.options.displayMode === 'lcd') {
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 10;
|
|
|
|
}
|
|
|
|
|
2019-03-14 16:47:01 -05:00
|
|
|
render() {
|
2019-03-19 11:26:15 -05:00
|
|
|
const { height, width, options, data, renderCounter } = this.props;
|
2019-04-16 15:23:34 -05:00
|
|
|
|
2019-02-23 04:31:35 -06:00
|
|
|
return (
|
2019-04-05 05:59:29 -05:00
|
|
|
<VizRepeater
|
|
|
|
source={data}
|
|
|
|
getValues={this.getValues}
|
2019-03-14 16:47:01 -05:00
|
|
|
renderValue={this.renderValue}
|
2019-04-05 05:59:29 -05:00
|
|
|
renderCounter={renderCounter}
|
2019-03-14 16:47:01 -05:00
|
|
|
width={width}
|
|
|
|
height={height}
|
2019-04-05 05:59:29 -05:00
|
|
|
itemSpacing={this.getItemSpacing()}
|
2019-03-19 08:07:48 -05:00
|
|
|
orientation={options.orientation}
|
2019-03-14 16:47:01 -05:00
|
|
|
/>
|
2019-02-23 04:31:35 -06:00
|
|
|
);
|
2019-02-15 05:55:35 -06:00
|
|
|
}
|
|
|
|
}
|