GaugePanel.tsx 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Libraries
  2. import React, { PureComponent } from 'react';
  3. // Services & Utils
  4. import { config } from 'app/core/config';
  5. // Components
  6. import { Gauge } from '@grafana/ui';
  7. // Types
  8. import { GaugeOptions } from './types';
  9. import { DisplayValue, PanelProps, getSingleStatDisplayValues, VizRepeater } from '@grafana/ui';
  10. export class GaugePanel extends PureComponent<PanelProps<GaugeOptions>> {
  11. renderValue = (value: DisplayValue, width: number, height: number): JSX.Element => {
  12. const { options } = this.props;
  13. return (
  14. <Gauge
  15. value={value}
  16. width={width}
  17. height={height}
  18. thresholds={options.thresholds}
  19. showThresholdLabels={options.showThresholdLabels}
  20. showThresholdMarkers={options.showThresholdMarkers}
  21. minValue={options.minValue}
  22. maxValue={options.maxValue}
  23. theme={config.theme}
  24. />
  25. );
  26. };
  27. getValues = (): DisplayValue[] => {
  28. return getSingleStatDisplayValues({
  29. valueMappings: this.props.options.valueMappings,
  30. thresholds: this.props.options.thresholds,
  31. valueOptions: this.props.options.valueOptions,
  32. data: this.props.data,
  33. theme: config.theme,
  34. replaceVariables: this.props.replaceVariables,
  35. });
  36. };
  37. render() {
  38. const { height, width, options, data, renderCounter } = this.props;
  39. return (
  40. <VizRepeater
  41. getValues={this.getValues}
  42. renderValue={this.renderValue}
  43. width={width}
  44. height={height}
  45. source={data}
  46. renderCounter={renderCounter}
  47. orientation={options.orientation}
  48. />
  49. );
  50. }
  51. }