mirror of
https://github.com/grafana/grafana.git
synced 2025-02-15 10:03:33 -06:00
* Table panel: Support multiple data links in default cell * Table panel: Show data links for Image and JSONView cells * Simplify DataLinksContextMenu api * Betterer
84 lines
2.4 KiB
TypeScript
84 lines
2.4 KiB
TypeScript
import React, { PureComponent } from 'react';
|
|
|
|
import { FieldDisplay, getFieldDisplayValues, PanelProps } from '@grafana/data';
|
|
import { DataLinksContextMenu, Gauge, VizRepeater, VizRepeaterRenderValueProps } from '@grafana/ui';
|
|
import { DataLinksContextMenuApi } from '@grafana/ui/src/components/DataLinks/DataLinksContextMenu';
|
|
import { config } from 'app/core/config';
|
|
|
|
import { clearNameForSingleSeries } from '../bargauge/BarGaugePanel';
|
|
|
|
import { PanelOptions } from './models.gen';
|
|
|
|
export class GaugePanel extends PureComponent<PanelProps<PanelOptions>> {
|
|
renderComponent = (
|
|
valueProps: VizRepeaterRenderValueProps<FieldDisplay>,
|
|
menuProps: DataLinksContextMenuApi
|
|
): JSX.Element => {
|
|
const { options, fieldConfig } = this.props;
|
|
const { width, height, count, value } = valueProps;
|
|
const { field, display } = value;
|
|
const { openMenu, targetClassName } = menuProps;
|
|
|
|
return (
|
|
<Gauge
|
|
value={clearNameForSingleSeries(count, fieldConfig.defaults, display)}
|
|
width={width}
|
|
height={height}
|
|
field={field}
|
|
text={options.text}
|
|
showThresholdLabels={options.showThresholdLabels}
|
|
showThresholdMarkers={options.showThresholdMarkers}
|
|
theme={config.theme}
|
|
onClick={openMenu}
|
|
className={targetClassName}
|
|
/>
|
|
);
|
|
};
|
|
|
|
renderValue = (valueProps: VizRepeaterRenderValueProps<FieldDisplay>): JSX.Element => {
|
|
const { value } = valueProps;
|
|
const { getLinks, hasLinks } = value;
|
|
|
|
if (hasLinks && getLinks) {
|
|
return (
|
|
<DataLinksContextMenu links={getLinks}>
|
|
{(api) => {
|
|
return this.renderComponent(valueProps, api);
|
|
}}
|
|
</DataLinksContextMenu>
|
|
);
|
|
}
|
|
|
|
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,
|
|
});
|
|
};
|
|
|
|
render() {
|
|
const { height, width, data, renderCounter, options } = this.props;
|
|
|
|
return (
|
|
<VizRepeater
|
|
getValues={this.getValues}
|
|
renderValue={this.renderValue}
|
|
width={width}
|
|
height={height}
|
|
source={data}
|
|
autoGrid={true}
|
|
renderCounter={renderCounter}
|
|
orientation={options.orientation}
|
|
/>
|
|
);
|
|
}
|
|
}
|