GaugePanel.tsx 1.5 KB

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