GaugePanel.tsx 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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, VizOrientation, DataLinksContextMenu } from '@grafana/ui';
  7. // Types
  8. import { GaugeOptions } from './types';
  9. import { PanelProps, VizRepeater } from '@grafana/ui';
  10. import { getFieldLinksSupplier } from 'app/features/panel/panellinks/linkSuppliers';
  11. export class GaugePanel extends PureComponent<PanelProps<GaugeOptions>> {
  12. renderValue = (value: FieldDisplay, width: number, height: number): JSX.Element => {
  13. const { options } = this.props;
  14. const { field, display } = value;
  15. return (
  16. <DataLinksContextMenu links={getFieldLinksSupplier(value)}>
  17. {({ openMenu, targetClassName }) => {
  18. return (
  19. <Gauge
  20. value={display}
  21. width={width}
  22. height={height}
  23. thresholds={field.thresholds}
  24. showThresholdLabels={options.showThresholdLabels}
  25. showThresholdMarkers={options.showThresholdMarkers}
  26. minValue={field.min}
  27. maxValue={field.max}
  28. theme={config.theme}
  29. onClick={openMenu}
  30. className={targetClassName}
  31. />
  32. );
  33. }}
  34. </DataLinksContextMenu>
  35. );
  36. };
  37. getValues = (): FieldDisplay[] => {
  38. const { data, options, replaceVariables } = this.props;
  39. return getFieldDisplayValues({
  40. fieldOptions: options.fieldOptions,
  41. replaceVariables,
  42. theme: config.theme,
  43. data: data.series,
  44. });
  45. };
  46. render() {
  47. const { height, width, data, renderCounter } = this.props;
  48. return (
  49. <VizRepeater
  50. getValues={this.getValues}
  51. renderValue={this.renderValue}
  52. width={width}
  53. height={height}
  54. source={data}
  55. renderCounter={renderCounter}
  56. orientation={VizOrientation.Auto}
  57. />
  58. );
  59. }
  60. }