module.tsx 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import React, { PureComponent } from 'react';
  2. import Gauge from 'app/viz/Gauge';
  3. import { getTimeSeriesVMs } from 'app/viz/state/timeSeries';
  4. import ValueOptions from './ValueOptions';
  5. import GaugeOptions from './GaugeOptions';
  6. import Thresholds from './Thresholds';
  7. import ValueMappings from './ValueMappings';
  8. import { PanelOptionsProps, PanelProps, NullValueMode } from '@grafana/ui';
  9. import { BasicGaugeColor, RangeMap, Threshold, ValueMap } from 'app/types';
  10. export interface OptionsProps {
  11. baseColor: string;
  12. decimals: number;
  13. mappings: Array<RangeMap | ValueMap>;
  14. maxValue: number;
  15. minValue: number;
  16. prefix: string;
  17. showThresholdLabels: boolean;
  18. showThresholdMarkers: boolean;
  19. stat: string;
  20. suffix: string;
  21. thresholds: Threshold[];
  22. unit: string;
  23. }
  24. export interface OptionModuleProps {
  25. onChange: (item: any) => void;
  26. options: OptionsProps;
  27. }
  28. export const defaultProps = {
  29. options: {
  30. baseColor: BasicGaugeColor.Green,
  31. minValue: 0,
  32. maxValue: 100,
  33. prefix: '',
  34. showThresholdMarkers: true,
  35. showThresholdLabels: false,
  36. suffix: '',
  37. decimals: 0,
  38. stat: '',
  39. unit: '',
  40. mappings: [],
  41. thresholds: [],
  42. },
  43. };
  44. interface Props extends PanelProps<OptionsProps> {}
  45. class GaugePanel extends PureComponent<Props> {
  46. render() {
  47. const { timeSeries, width, height } = this.props;
  48. const vmSeries = getTimeSeriesVMs({
  49. timeSeries: timeSeries,
  50. nullValueMode: NullValueMode.Ignore,
  51. });
  52. return <Gauge timeSeries={vmSeries} {...this.props.options} width={width} height={height} />;
  53. }
  54. }
  55. class Options extends PureComponent<PanelOptionsProps<OptionsProps>> {
  56. static defaultProps = defaultProps;
  57. render() {
  58. const { onChange, options } = this.props;
  59. return (
  60. <div>
  61. <div className="form-section">
  62. <ValueOptions onChange={onChange} options={options} />
  63. <GaugeOptions onChange={onChange} options={options} />
  64. <Thresholds onChange={onChange} options={options} />
  65. </div>
  66. <div className="form-section">
  67. <ValueMappings onChange={onChange} options={options} />
  68. </div>
  69. </div>
  70. );
  71. }
  72. }
  73. export { GaugePanel as Panel, Options as PanelOptions, defaultProps as PanelDefaults };