GaugePanel.tsx 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. const { data, options, replaceVariables } = this.props;
  29. return getSingleStatDisplayValues({
  30. ...options,
  31. replaceVariables,
  32. theme: config.theme,
  33. data: data.series,
  34. });
  35. };
  36. render() {
  37. const { height, width, options, data, renderCounter } = this.props;
  38. return (
  39. <VizRepeater
  40. getValues={this.getValues}
  41. renderValue={this.renderValue}
  42. width={width}
  43. height={height}
  44. source={data}
  45. renderCounter={renderCounter}
  46. orientation={options.orientation}
  47. />
  48. );
  49. }
  50. }