Files
grafana/public/app/plugins/panel/bargauge/BarGaugePanel.tsx

79 lines
2.1 KiB
TypeScript
Raw Normal View History

2019-02-15 12:55:35 +01:00
// Libraries
import React, { PureComponent } from 'react';
// Services & Utils
2019-02-20 15:07:30 +01:00
import { config } from 'app/core/config';
2019-02-15 12:55:35 +01:00
// Components
import { BarGauge, VizRepeater, getFieldDisplayValues, FieldDisplay, DataLinksContextMenu } from '@grafana/ui';
2019-02-15 12:55:35 +01:00
// Types
import { BarGaugeOptions } from './types';
import { PanelProps } from '@grafana/ui';
import { getFieldLinksSupplier } from 'app/features/panel/panellinks/linkSuppliers';
2019-03-14 14:47:01 -07:00
export class BarGaugePanel extends PureComponent<PanelProps<BarGaugeOptions>> {
renderValue = (value: FieldDisplay, width: number, height: number): JSX.Element => {
2019-03-13 11:12:11 -07:00
const { options } = this.props;
const { field, display } = value;
2019-02-15 12:55:35 +01:00
2019-02-20 15:07:30 +01:00
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>
2019-02-20 15:07:30 +01:00
);
2019-03-14 14:47:01 -07:00
};
2019-02-15 12:55:35 +01:00
getValues = (): FieldDisplay[] => {
const { data, options, replaceVariables } = this.props;
return getFieldDisplayValues({
...options,
replaceVariables,
theme: config.theme,
data: data.series,
});
2019-03-14 14:47:01 -07:00
};
2019-02-15 12:55:35 +01:00
getItemSpacing(): number {
if (this.props.options.displayMode === 'lcd') {
return 2;
}
return 10;
}
2019-03-14 14:47:01 -07:00
render() {
2019-03-19 09:26:15 -07:00
const { height, width, options, data, renderCounter } = this.props;
return (
<VizRepeater
source={data}
getValues={this.getValues}
2019-03-14 14:47:01 -07:00
renderValue={this.renderValue}
renderCounter={renderCounter}
2019-03-14 14:47:01 -07:00
width={width}
height={height}
itemSpacing={this.getItemSpacing()}
orientation={options.orientation}
2019-03-14 14:47:01 -07:00
/>
);
2019-02-15 12:55:35 +01:00
}
}