From e27004559ce31d046ac3ec410b2c68b290c8f9cc Mon Sep 17 00:00:00 2001 From: Yongjie Zhao Date: Fri, 13 Aug 2021 12:49:09 +0800 Subject: [PATCH 1/3] feat: bignumber format by time formatter --- .../src/BigNumber/BigNumber.tsx | 13 ++++--- .../src/BigNumber/transformProps.ts | 7 +++- .../src/BigNumberTotal/controlPanel.ts | 37 ++++++++++++++++++- 3 files changed, 48 insertions(+), 9 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 { Date: Fri, 13 Aug 2021 14:11:35 +0800 Subject: [PATCH 2/3] fix ut --- .../legacy-preset-chart-big-number/test/transformProps.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/legacy-preset-chart-big-number/test/transformProps.test.ts b/plugins/legacy-preset-chart-big-number/test/transformProps.test.ts index e8f61ef1ce..4402fbeb5f 100644 --- a/plugins/legacy-preset-chart-big-number/test/transformProps.test.ts +++ b/plugins/legacy-preset-chart-big-number/test/transformProps.test.ts @@ -135,7 +135,7 @@ describe('BigNumber', () => { }, }; const transformed = transformProps(propsWithDatasource); - expect(transformed.formatNumber(transformed.bigNumber)).toStrictEqual('1.23'); + expect(transformed.headerFormatter(transformed.bigNumber)).toStrictEqual('1.23'); }); }); }); From 83eebffcb917e3e6df12fd6c38804e775fe72f4a Mon Sep 17 00:00:00 2001 From: Yongjie Zhao Date: Sat, 14 Aug 2021 00:42:01 +0800 Subject: [PATCH 3/3] rename control label --- .../src/BigNumberTotal/controlPanel.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/legacy-preset-chart-big-number/src/BigNumberTotal/controlPanel.ts b/plugins/legacy-preset-chart-big-number/src/BigNumberTotal/controlPanel.ts index 6bc21f3248..2118c55c73 100644 --- a/plugins/legacy-preset-chart-big-number/src/BigNumberTotal/controlPanel.ts +++ b/plugins/legacy-preset-chart-big-number/src/BigNumberTotal/controlPanel.ts @@ -66,7 +66,7 @@ export default { config: { type: 'SelectControl', freeForm: true, - label: t('Timestamp format'), + label: t('Date format'), renderTrigger: true, choices: D3_TIME_FORMAT_OPTIONS, default: '%d-%m-%Y %H:%M:%S',