module.tsx 2.2 KB

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