grafana/public/app/plugins/panel/bargauge/BarGaugePanel.tsx

67 lines
1.6 KiB
TypeScript
Raw Normal View History

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
// Components
import { BarGauge, VizRepeater, getSingleStatDisplayValues } from '@grafana/ui/src/components';
2019-02-15 05:55:35 -06:00
// Types
import { BarGaugeOptions } from './types';
import { PanelProps, DisplayValue } from '@grafana/ui/src/types';
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}
itemSpacing={this.getItemSpacing()}
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
getValues = (): DisplayValue[] => {
const { data, options, replaceVariables } = this.props;
return getSingleStatDisplayValues({
...options,
replaceVariables,
theme: config.theme,
data: data.series,
});
2019-03-14 16:47:01 -05:00
};
2019-02-15 05:55:35 -06: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;
return (
<VizRepeater
source={data}
getValues={this.getValues}
2019-03-14 16:47:01 -05:00
renderValue={this.renderValue}
renderCounter={renderCounter}
2019-03-14 16:47:01 -05:00
width={width}
height={height}
itemSpacing={this.getItemSpacing()}
orientation={options.orientation}
2019-03-14 16:47:01 -05:00
/>
);
2019-02-15 05:55:35 -06:00
}
}