import { isNumber } from 'lodash'; import React, { PureComponent } from 'react'; import { DisplayValueAlignmentFactors, FieldDisplay, getDisplayValueAlignmentFactors, getFieldDisplayValues, PanelProps, FieldConfig, DisplayProcessor, DisplayValue, VizOrientation, } from '@grafana/data'; import { BarGauge, DataLinksContextMenu, VizRepeater, VizRepeaterRenderValueProps } from '@grafana/ui'; import { DataLinksContextMenuApi } from '@grafana/ui/src/components/DataLinks/DataLinksContextMenu'; import { config } from 'app/core/config'; import { BarGaugeOptions } from './types'; export class BarGaugePanel extends PureComponent> { renderComponent = ( valueProps: VizRepeaterRenderValueProps, menuProps: DataLinksContextMenuApi ): JSX.Element => { const { options, fieldConfig } = this.props; const { value, alignmentFactors, orientation, width, height, count } = valueProps; const { field, display, view, colIndex } = value; const { openMenu, targetClassName } = menuProps; let processor: DisplayProcessor | undefined = undefined; if (view && isNumber(colIndex)) { processor = view.getFieldDisplayProcessor(colIndex); } return ( 1 ? alignmentFactors : undefined} showUnfilled={options.showUnfilled} /> ); }; renderValue = (valueProps: VizRepeaterRenderValueProps): JSX.Element => { const { value, orientation } = valueProps; const { hasLinks, getLinks } = value; if (hasLinks && getLinks) { return (
{(api) => this.renderComponent(valueProps, api)}
); } return this.renderComponent(valueProps, {}); }; getValues = (): FieldDisplay[] => { const { data, options, replaceVariables, fieldConfig, timeZone } = this.props; return getFieldDisplayValues({ fieldConfig, reduceOptions: options.reduceOptions, replaceVariables, theme: config.theme2, data: data.series, timeZone, }); }; getItemSpacing(): number { if (this.props.options.displayMode === 'lcd') { return 2; } return 10; } render() { const { height, width, options, data, renderCounter } = this.props; return ( ); } } export function clearNameForSingleSeries(count: number, field: FieldConfig, display: DisplayValue): DisplayValue { if (count === 1 && !field.displayName) { return { ...display, title: undefined, }; } return display; }