Files
grafana/public/app/plugins/panel/bargauge/BarGaugePanel.tsx
Torkel Ödegaard 8894e2858c StatPanel: ColorMode, GraphMode & JustifyMode changes (#20680)
* StatPanel: Options rethink

* Changed options to string based

* -Fixed tests

* Refactoring moving files

* Refactoring alignment factors

* Added alignment factors

* Added basic test

* Added unit test for layout

* Font size handling

* Font sizing works

* Progress on sizing

* Updated

* Minor update

* Updated

* Updated

* Removed line option

* updated

* Updated

* Updated

* Updated

* Highlight last point

* Fixed tests

* Code refactoring and cleanup

* updated

* Updated snapshot
2019-12-01 17:02:44 +01:00

89 lines
2.3 KiB
TypeScript

// Libraries
import React, { PureComponent } from 'react';
// Services & Utils
import { config } from 'app/core/config';
import { BarGauge, VizRepeater, DataLinksContextMenu } from '@grafana/ui';
import { BarGaugeOptions } from './types';
import {
getFieldDisplayValues,
FieldDisplay,
PanelProps,
getDisplayValueAlignmentFactors,
DisplayValueAlignmentFactors,
} from '@grafana/data';
import { getFieldLinksSupplier } from 'app/features/panel/panellinks/linkSuppliers';
export class BarGaugePanel extends PureComponent<PanelProps<BarGaugeOptions>> {
renderValue = (
value: FieldDisplay,
width: number,
height: number,
alignmentFactors: DisplayValueAlignmentFactors
): 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}
alignmentFactors={alignmentFactors}
/>
);
}}
</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}
getAlignmentFactors={getDisplayValueAlignmentFactors}
getValues={this.getValues}
renderValue={this.renderValue}
renderCounter={renderCounter}
width={width}
height={height}
itemSpacing={this.getItemSpacing()}
orientation={options.orientation}
/>
);
}
}