| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- // Libraries
- import React, { PureComponent } from 'react';
- // Services & Utils
- import { config } from 'app/core/config';
- // Components
- import { BarGauge, VizRepeater, getFieldDisplayValues, FieldDisplay, DataLinksContextMenu } from '@grafana/ui';
- // Types
- import { BarGaugeOptions } from './types';
- import { PanelProps } from '@grafana/ui';
- import { getFieldLinksSupplier } from 'app/features/panel/panellinks/linkSuppliers';
- export class BarGaugePanel extends PureComponent<PanelProps<BarGaugeOptions>> {
- renderValue = (value: FieldDisplay, width: number, height: number): JSX.Element => {
- const { options } = this.props;
- const { field, display } = value;
- return (
- <DataLinksContextMenu links={getFieldLinksSupplier(value)}>
- {({ openMenu, targetClassName }) => {
- return (
- <BarGauge
- value={display}
- width={width}
- height={height}
- orientation={options.orientation}
- thresholds={field.thresholds}
- theme={config.theme}
- itemSpacing={this.getItemSpacing()}
- displayMode={options.displayMode}
- minValue={field.min}
- maxValue={field.max}
- onClick={openMenu}
- className={targetClassName}
- />
- );
- }}
- </DataLinksContextMenu>
- );
- };
- getValues = (): FieldDisplay[] => {
- const { data, options, replaceVariables } = this.props;
- return getFieldDisplayValues({
- ...options,
- replaceVariables,
- theme: config.theme,
- data: data.series,
- });
- };
- getItemSpacing(): number {
- if (this.props.options.displayMode === 'lcd') {
- return 2;
- }
- return 10;
- }
- render() {
- const { height, width, options, data, renderCounter } = this.props;
- return (
- <VizRepeater
- source={data}
- getValues={this.getValues}
- renderValue={this.renderValue}
- renderCounter={renderCounter}
- width={width}
- height={height}
- itemSpacing={this.getItemSpacing()}
- orientation={options.orientation}
- />
- );
- }
- }
|