From a76ee5d37b7fda3f8a38db8d33c6a7b490ac666a Mon Sep 17 00:00:00 2001 From: dileepyelleti Date: Fri, 23 Apr 2021 18:07:53 +0530 Subject: [PATCH 1/2] fix(dataZoom): type fix for startValue and endValue. close #14412 --- src/component/dataZoom/AxisProxy.ts | 4 ++-- src/component/dataZoom/DataZoomModel.ts | 17 +++++++++++++---- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/component/dataZoom/AxisProxy.ts b/src/component/dataZoom/AxisProxy.ts index e9c997d9af..2d7b0f8a52 100644 --- a/src/component/dataZoom/AxisProxy.ts +++ b/src/component/dataZoom/AxisProxy.ts @@ -139,8 +139,8 @@ class AxisProxy { calculateDataWindow(opt?: { start?: number end?: number - startValue?: number - endValue?: number + startValue?: number | string | Date + endValue?: number | string | Date }) { const dataExtent = this._dataExtent; const axisModel = this.getAxisModel(); diff --git a/src/component/dataZoom/DataZoomModel.ts b/src/component/dataZoom/DataZoomModel.ts index 17b1005484..4657da9348 100644 --- a/src/component/dataZoom/DataZoomModel.ts +++ b/src/component/dataZoom/DataZoomModel.ts @@ -101,11 +101,11 @@ export interface DataZoomOption extends ComponentOption { /** * Start value. If startValue specified, start is ignored */ - startValue?: number + startValue?: number | string | Date /** * End value. If endValue specified, end is ignored. */ - endValue?: number + endValue?: number | string | Date /** * Min span percent, 0 - 100 * The range of dataZoom can not be smaller than that. @@ -506,9 +506,12 @@ class DataZoomModel extends Compon setCalculatedRange(opt: RangeOption): void { const option = this.option; - each(['start', 'startValue', 'end', 'endValue'] as const, function (name) { + each(['start', 'end'] as const, function (name) { option[name] = opt[name]; }); + each(['startValue', 'endValue'] as const, function (name) { + option[name] = opt[name]; + }); } getPercentRange(): number[] { @@ -588,7 +591,13 @@ class DataZoomModel extends Compon function retrieveRawOption(option: T) { const ret = {} as T; each( - ['start', 'end', 'startValue', 'endValue', 'throttle'] as const, + ['start', 'end', 'throttle'] as const, + function (name) { + option.hasOwnProperty(name) && (ret[name] = option[name]); + } + ); + each( + ['startValue', 'endValue'] as const, function (name) { option.hasOwnProperty(name) && (ret[name] = option[name]); } From 23a2f7f1de9f2c15df154490b72b1a5918616142 Mon Sep 17 00:00:00 2001 From: dileepyelleti Date: Tue, 11 May 2021 19:42:31 +0530 Subject: [PATCH 2/2] fix: code review comments --- src/component/dataZoom/DataZoomModel.ts | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/src/component/dataZoom/DataZoomModel.ts b/src/component/dataZoom/DataZoomModel.ts index 4657da9348..6ed6ccda0a 100644 --- a/src/component/dataZoom/DataZoomModel.ts +++ b/src/component/dataZoom/DataZoomModel.ts @@ -506,12 +506,9 @@ class DataZoomModel extends Compon setCalculatedRange(opt: RangeOption): void { const option = this.option; - each(['start', 'end'] as const, function (name) { - option[name] = opt[name]; + each(['start', 'startValue', 'end', 'endValue'] as const, function (name) { + (option as any)[name] = opt[name]; }); - each(['startValue', 'endValue'] as const, function (name) { - option[name] = opt[name]; - }); } getPercentRange(): number[] { @@ -591,15 +588,9 @@ class DataZoomModel extends Compon function retrieveRawOption(option: T) { const ret = {} as T; each( - ['start', 'end', 'throttle'] as const, + ['start', 'end', 'startValue', 'endValue', 'throttle'] as const, function (name) { - option.hasOwnProperty(name) && (ret[name] = option[name]); - } - ); - each( - ['startValue', 'endValue'] as const, - function (name) { - option.hasOwnProperty(name) && (ret[name] = option[name]); + option.hasOwnProperty(name) && ((ret as any)[name] = option[name]); } ); return ret;