From b604a9fcd47f8f63acbdd39cd256b833d2473633 Mon Sep 17 00:00:00 2001 From: Ovilia Date: Thu, 19 Jun 2025 14:24:12 +0800 Subject: [PATCH 1/2] fix(dataZoom): fix dataZoom for single data relates #16978 --- src/component/dataZoom/SliderZoomView.ts | 8 +- test/dataZoom-timeAxis.html | 224 +++++++++++++++++++++++ 2 files changed, 228 insertions(+), 4 deletions(-) create mode 100644 test/dataZoom-timeAxis.html diff --git a/src/component/dataZoom/SliderZoomView.ts b/src/component/dataZoom/SliderZoomView.ts index 7069065601..40e2522c4c 100644 --- a/src/component/dataZoom/SliderZoomView.ts +++ b/src/component/dataZoom/SliderZoomView.ts @@ -376,7 +376,7 @@ class SliderZoomView extends DataZoomView { data !== this._shadowData || otherDim !== this._shadowDim || size[0] !== oldSize[0] || size[1] !== oldSize[1] ) { - const thisDataExtent = data.getDataExtent(info.thisDim); + const thisScaleExtent = info.thisAxis.scale.getExtent(); let otherDataExtent = data.getDataExtent(otherDim); // Nice extent. const otherOffset = (otherDataExtent[1] - otherDataExtent[0]) * 0.3; @@ -389,8 +389,8 @@ class SliderZoomView extends DataZoomView { const areaPoints = [[size[0], 0], [0, 0]]; const linePoints: number[][] = []; - const step = thisShadowExtent[1] / (data.count() - 1); - const normalizationConstant = size[0] / (thisDataExtent[1] - thisDataExtent[0]); + const step = thisShadowExtent[1] / (Math.max(1, data.count() - 1)); + const normalizationConstant = size[0] / (thisScaleExtent[1] - thisScaleExtent[0]); const isTimeAxis = info.thisAxis.type === 'time'; let thisCoord = -step; @@ -407,7 +407,7 @@ class SliderZoomView extends DataZoomView { } thisCoord = isTimeAxis - ? (+thisValue - thisDataExtent[0]) * normalizationConstant + ? (+thisValue - thisScaleExtent[0]) * normalizationConstant : thisCoord + step; // FIXME diff --git a/test/dataZoom-timeAxis.html b/test/dataZoom-timeAxis.html new file mode 100644 index 0000000000..7e33d9aa63 --- /dev/null +++ b/test/dataZoom-timeAxis.html @@ -0,0 +1,224 @@ + + + + + + + + + + + + + + + + + + + + + +
+
+ + + + + + + + + + + + + + From f5c8bf64a8ac9ac0457e6c93e5bd7211bf893e78 Mon Sep 17 00:00:00 2001 From: Ovilia Date: Thu, 19 Jun 2025 14:36:01 +0800 Subject: [PATCH 2/2] fix(dataZoom): revert unnecessary changes --- src/component/dataZoom/SliderZoomView.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/component/dataZoom/SliderZoomView.ts b/src/component/dataZoom/SliderZoomView.ts index 40e2522c4c..b460ffee72 100644 --- a/src/component/dataZoom/SliderZoomView.ts +++ b/src/component/dataZoom/SliderZoomView.ts @@ -376,7 +376,7 @@ class SliderZoomView extends DataZoomView { data !== this._shadowData || otherDim !== this._shadowDim || size[0] !== oldSize[0] || size[1] !== oldSize[1] ) { - const thisScaleExtent = info.thisAxis.scale.getExtent(); + const thisDataExtent = data.getDataExtent(info.thisDim); let otherDataExtent = data.getDataExtent(otherDim); // Nice extent. const otherOffset = (otherDataExtent[1] - otherDataExtent[0]) * 0.3; @@ -390,7 +390,7 @@ class SliderZoomView extends DataZoomView { const areaPoints = [[size[0], 0], [0, 0]]; const linePoints: number[][] = []; const step = thisShadowExtent[1] / (Math.max(1, data.count() - 1)); - const normalizationConstant = size[0] / (thisScaleExtent[1] - thisScaleExtent[0]); + const normalizationConstant = size[0] / (thisDataExtent[1] - thisDataExtent[0]); const isTimeAxis = info.thisAxis.type === 'time'; let thisCoord = -step; @@ -407,7 +407,7 @@ class SliderZoomView extends DataZoomView { } thisCoord = isTimeAxis - ? (+thisValue - thisScaleExtent[0]) * normalizationConstant + ? (+thisValue - thisDataExtent[0]) * normalizationConstant : thisCoord + step; // FIXME