grafana/public/app/plugins/panel/gauge/module.tsx
2018-12-03 09:37:45 +01:00

66 lines
1.7 KiB
TypeScript

import React, { PureComponent } from 'react';
import Gauge from 'app/viz/Gauge';
import { NullValueMode, PanelOptionsProps, PanelProps, Threshold } from 'app/types';
import { getTimeSeriesVMs } from 'app/viz/state/timeSeries';
import ValueOptions from './ValueOptions';
import GaugeOptions from './GaugeOptions';
import Thresholds from './Thresholds';
export interface OptionsProps {
decimals: number;
prefix: string;
showThresholdLabels: boolean;
showThresholdMarkers: boolean;
stat: string;
suffix: string;
unit: string;
thresholds: Threshold[];
}
export interface OptionModuleProps {
onChange: (item: any) => void;
options: OptionsProps;
}
export const defaultProps = {
options: {
minValue: 0,
maxValue: 100,
prefix: '',
showThresholdMarkers: true,
showThresholdLabels: false,
suffix: '',
},
};
interface Props extends PanelProps<OptionsProps> {}
class GaugePanel extends PureComponent<Props> {
render() {
const { timeSeries, width, height } = this.props;
const vmSeries = getTimeSeriesVMs({
timeSeries: timeSeries,
nullValueMode: NullValueMode.Ignore,
});
return <Gauge timeSeries={vmSeries} {...this.props.options} width={width} height={height} />;
}
}
class Options extends PureComponent<PanelOptionsProps<OptionsProps>> {
static defaultProps = defaultProps;
render() {
return (
<div>
<ValueOptions onChange={this.props.onChange} options={this.props.options} />
<GaugeOptions onChange={this.props.onChange} options={this.props.options} />
<Thresholds onChange={this.props.onChange} options={this.props.options} />
</div>
);
}
}
export { GaugePanel as Panel, Options as PanelOptions, defaultProps as PanelDefaults };