From ee3b438269f93aff1bf6958d6874550c75d4e867 Mon Sep 17 00:00:00 2001 From: Peter Holmberg Date: Fri, 16 Nov 2018 16:41:01 +0100 Subject: [PATCH] format value --- public/app/viz/Gauge.tsx | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/public/app/viz/Gauge.tsx b/public/app/viz/Gauge.tsx index cf934e77c43..200ee635b9a 100644 --- a/public/app/viz/Gauge.tsx +++ b/public/app/viz/Gauge.tsx @@ -3,6 +3,7 @@ import $ from 'jquery'; import { withSize } from 'react-sizeme'; import { TimeSeriesVMs } from 'app/types'; import config from '../core/config'; +import kbn from '../core/utils/kbn'; interface Props { timeSeries: TimeSeriesVMs; @@ -37,17 +38,15 @@ export class Gauge extends PureComponent { this.draw(); } + formatValue(value) { + const { unit } = this.props; + + const formatFunc = kbn.valueFormats[unit.value]; + return formatFunc(value); + } + draw() { - const { - maxValue, - minValue, - showThresholdLables, - size, - showThresholdMarkers, - timeSeries, - thresholds, - unit, - } = this.props; + const { maxValue, minValue, showThresholdLables, size, showThresholdMarkers, timeSeries, thresholds } = this.props; const width = size.width; const height = size.height; @@ -98,7 +97,7 @@ export class Gauge extends PureComponent { value: { color: fontColor, formatter: () => { - return `${Math.round(timeSeries[0].stats.avg)} ${unit.label}`; + return this.formatValue(timeSeries[0].stats.avg); }, font: { size: fontSize,