|
|
@@ -1,13 +1,35 @@
|
|
|
// Libraries
|
|
|
-import React, { CSSProperties } from 'react';
|
|
|
+import React, { PureComponent, CSSProperties } from 'react';
|
|
|
|
|
|
// Types
|
|
|
import { SingleStatOptions } from './types';
|
|
|
-import { DisplayValue } from '@grafana/ui/src/utils/displayValue';
|
|
|
-import { SingleStatBase } from './SingleStatBase';
|
|
|
|
|
|
-export class SingleStatPanel extends SingleStatBase<SingleStatOptions> {
|
|
|
- renderStat(value: DisplayValue, width: number, height: number) {
|
|
|
+import { processSingleStatPanelData, DisplayValue, PanelProps } from '@grafana/ui';
|
|
|
+import { config } from 'app/core/config';
|
|
|
+import { getDisplayProcessor } from '@grafana/ui';
|
|
|
+import { ProcessedValuesRepeater } from './ProcessedValuesRepeater';
|
|
|
+
|
|
|
+export const getSingleStatValues = (props: PanelProps<SingleStatOptions>): DisplayValue[] => {
|
|
|
+ const { panelData, replaceVariables, options } = props;
|
|
|
+ const { valueOptions, valueMappings } = options;
|
|
|
+ const processor = getDisplayProcessor({
|
|
|
+ unit: valueOptions.unit,
|
|
|
+ decimals: valueOptions.decimals,
|
|
|
+ mappings: valueMappings,
|
|
|
+ thresholds: options.thresholds,
|
|
|
+
|
|
|
+ prefix: replaceVariables(valueOptions.prefix),
|
|
|
+ suffix: replaceVariables(valueOptions.suffix),
|
|
|
+ theme: config.theme,
|
|
|
+ });
|
|
|
+ return processSingleStatPanelData({
|
|
|
+ panelData: panelData,
|
|
|
+ stat: valueOptions.stat,
|
|
|
+ }).map(stat => processor(stat.value));
|
|
|
+};
|
|
|
+
|
|
|
+export class SingleStatPanel extends PureComponent<PanelProps<SingleStatOptions>> {
|
|
|
+ renderValue = (value: DisplayValue, width: number, height: number): JSX.Element => {
|
|
|
const style: CSSProperties = {};
|
|
|
style.margin = '0 auto';
|
|
|
style.fontSize = '250%';
|
|
|
@@ -21,5 +43,24 @@ export class SingleStatPanel extends SingleStatBase<SingleStatOptions> {
|
|
|
<div style={style}>{value.text}</div>
|
|
|
</div>
|
|
|
);
|
|
|
+ };
|
|
|
+
|
|
|
+ getProcessedValues = (): DisplayValue[] => {
|
|
|
+ return getSingleStatValues(this.props);
|
|
|
+ };
|
|
|
+
|
|
|
+ render() {
|
|
|
+ const { height, width, options, panelData } = this.props;
|
|
|
+ const { orientation } = options;
|
|
|
+ return (
|
|
|
+ <ProcessedValuesRepeater
|
|
|
+ getProcessedValues={this.getProcessedValues}
|
|
|
+ renderValue={this.renderValue}
|
|
|
+ width={width}
|
|
|
+ height={height}
|
|
|
+ source={panelData}
|
|
|
+ orientation={orientation}
|
|
|
+ />
|
|
|
+ );
|
|
|
}
|
|
|
}
|