From 7b1dffac5343911eb991eafa60247a30312c9337 Mon Sep 17 00:00:00 2001 From: Yongjie Zhao Date: Wed, 1 Sep 2021 14:47:05 +0100 Subject: [PATCH] fix: bignumber format by time formatter (#1307) * feat: bignumber format by time formatter * fix ut * rename control label --- .../src/BigNumber/BigNumber.tsx | 13 ++++--- .../src/BigNumber/transformProps.ts | 7 +++- .../src/BigNumberTotal/controlPanel.ts | 37 ++++++++++++++++++- .../test/transformProps.test.ts | 2 +- 4 files changed, 49 insertions(+), 10 deletions(-) diff --git a/plugins/legacy-preset-chart-big-number/src/BigNumber/BigNumber.tsx b/plugins/legacy-preset-chart-big-number/src/BigNumber/BigNumber.tsx index eff8f5a8ea..266026b73d 100644 --- a/plugins/legacy-preset-chart-big-number/src/BigNumber/BigNumber.tsx +++ b/plugins/legacy-preset-chart-big-number/src/BigNumber/BigNumber.tsx @@ -76,7 +76,7 @@ type BigNumberVisProps = { height: number; bigNumber?: number | null; bigNumberFallback?: TimeSeriesDatum; - formatNumber: NumberFormatter; + headerFormatter: NumberFormatter | TimeFormatter; formatTime: TimeFormatter; fromDatetime?: number; toDatetime?: number; @@ -98,7 +98,7 @@ class BigNumberVis extends React.PureComponent { static defaultProps = { className: '', - formatNumber: defaultNumberFormatter, + headerFormatter: defaultNumberFormatter, formatTime: smartDateVerboseFormatter, headerFontSize: PROPORTION.HEADER, kickerFontSize: PROPORTION.KICKER, @@ -173,8 +173,8 @@ class BigNumberVis extends React.PureComponent { } renderHeader(maxHeight: number) { - const { bigNumber, formatNumber, width } = this.props; - const text = bigNumber === null ? t('No data') : formatNumber(bigNumber); + const { bigNumber, headerFormatter, width } = this.props; + const text = bigNumber === null ? t('No data') : headerFormatter(bigNumber); const container = this.createTemporaryContainer(); document.body.append(container); @@ -246,7 +246,7 @@ class BigNumberVis extends React.PureComponent { mainColor, subheader, startYAxisAtZero, - formatNumber, + headerFormatter, formatTime, fromDatetime, timeRangeFixed, @@ -283,7 +283,8 @@ class BigNumberVis extends React.PureComponent { { }, }; const transformed = transformProps(propsWithDatasource); - expect(transformed.formatNumber(transformed.bigNumber)).toStrictEqual('1.23'); + expect(transformed.headerFormatter(transformed.bigNumber)).toStrictEqual('1.23'); }); }); });