module.tsx 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import React, { PureComponent } from 'react';
  2. import Gauge from 'app/viz/Gauge';
  3. import { NullValueMode, PanelOptionsProps, PanelProps, Threshold } from 'app/types';
  4. import { getTimeSeriesVMs } from 'app/viz/state/timeSeries';
  5. import ValueOptions from './ValueOptions';
  6. import GaugeOptions from './GaugeOptions';
  7. import Thresholds from './Thresholds';
  8. export interface OptionsProps {
  9. decimals: number;
  10. prefix: string;
  11. showThresholdLabels: boolean;
  12. showThresholdMarkers: boolean;
  13. stat: string;
  14. suffix: string;
  15. unit: string;
  16. thresholds: Threshold[];
  17. minValue: number;
  18. maxValue: number;
  19. }
  20. export const defaultProps = {
  21. options: {
  22. minValue: 0,
  23. maxValue: 100,
  24. prefix: '',
  25. showThresholdMarkers: true,
  26. showThresholdLabels: false,
  27. suffix: '',
  28. },
  29. };
  30. interface Props extends PanelProps<OptionsProps> {}
  31. class GaugePanel extends PureComponent<Props> {
  32. render() {
  33. const { timeSeries, width, height } = this.props;
  34. const vmSeries = getTimeSeriesVMs({
  35. timeSeries: timeSeries,
  36. nullValueMode: NullValueMode.Ignore,
  37. });
  38. return <Gauge timeSeries={vmSeries} {...this.props.options} width={width} height={height} />;
  39. }
  40. }
  41. class Options extends PureComponent<PanelOptionsProps<OptionsProps>> {
  42. static defaultProps = defaultProps;
  43. render() {
  44. return (
  45. <div>
  46. <ValueOptions onChange={this.props.onChange} options={this.props.options} />
  47. <GaugeOptions onChange={this.props.onChange} options={this.props.options} />
  48. <Thresholds onChange={this.props.onChange} options={this.props.options} />
  49. </div>
  50. );
  51. }
  52. }
  53. export { GaugePanel as Panel, Options as PanelOptions, defaultProps as PanelDefaults };