You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by su...@apache.org on 2025/07/22 09:04:36 UTC

(echarts) branch fix-16266 created (now 18b5db25e)

This is an automated email from the ASF dual-hosted git repository.

sushuang pushed a change to branch fix-16266
in repository https://gitbox.apache.org/repos/asf/echarts.git


      at 18b5db25e fix(scale): Fix that extreme small numbers can not be displayed in Cartesian due to the inappropriate rounding precision.  Close #16266

This branch includes the following new commits:

     new 18b5db25e fix(scale): Fix that extreme small numbers can not be displayed in Cartesian due to the inappropriate rounding precision.  Close #16266

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org


(echarts) 01/01: fix(scale): Fix that extreme small numbers can not be displayed in Cartesian due to the inappropriate rounding precision. Close #16266

Posted by su...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

sushuang pushed a commit to branch fix-16266
in repository https://gitbox.apache.org/repos/asf/echarts.git

commit 18b5db25e01fd40539fab81c9a67d8278909e7ff
Author: 100pah <su...@gmail.com>
AuthorDate: Tue Jul 22 17:03:14 2025 +0800

    fix(scale): Fix that extreme small numbers can not be displayed in Cartesian due to the inappropriate rounding precision.  Close #16266
---
 src/scale/Interval.ts                          | 16 ++++++++++++----
 src/scale/Log.ts                               |  3 ++-
 src/scale/Time.ts                              |  1 +
 src/util/number.ts                             |  5 +++--
 test/runTest/actions/__meta__.json             |  1 +
 test/runTest/actions/scale-extreme-number.json |  1 +
 6 files changed, 20 insertions(+), 7 deletions(-)

diff --git a/src/scale/Interval.ts b/src/scale/Interval.ts
index ebc6ec73a..917aa3f53 100644
--- a/src/scale/Interval.ts
+++ b/src/scale/Interval.ts
@@ -35,7 +35,7 @@ class IntervalScale<SETTING extends ScaleSettingDefault = ScaleSettingDefault> e
     // Step is calculated in adjustExtent.
     protected _interval: number = 0;
     protected _niceExtent: [number, number];
-    private _intervalPrecision: number = 2;
+    protected _intervalPrecision: number = 2;
 
 
     parse(val: ScaleDataValue): number {
@@ -213,9 +213,10 @@ class IntervalScale<SETTING extends ScaleSettingDefault = ScaleSettingDefault> e
             const minorTicksGroup = [];
             const interval = nextTick.value - prevTick.value;
             const minorInterval = interval / splitNumber;
+            const minorIntervalPrecision = helper.getIntervalPrecision(minorInterval);
 
             while (count < splitNumber - 1) {
-                const minorTick = roundNumber(prevTick.value + (count + 1) * minorInterval);
+                const minorTick = roundNumber(prevTick.value + (count + 1) * minorInterval, minorIntervalPrecision);
 
                 // For the first and last interval. The count may be less than splitNumber.
                 if (minorTick > extent[0] && minorTick < extent[1]) {
@@ -276,6 +277,12 @@ class IntervalScale<SETTING extends ScaleSettingDefault = ScaleSettingDefault> e
     }
 
     /**
+     * FIXME: refactor - disallow override, use composition instead.
+     *
+     * The override of `calcNiceTicks` should ensure these members are provided:
+     *  this._intervalPrecision
+     *  this._interval
+     *
      * @param splitNumber By default `5`.
      */
     calcNiceTicks(splitNumber?: number, minInterval?: number, maxInterval?: number): void {
@@ -345,12 +352,13 @@ class IntervalScale<SETTING extends ScaleSettingDefault = ScaleSettingDefault> e
 
         this.calcNiceTicks(opt.splitNumber, opt.minInterval, opt.maxInterval);
         const interval = this._interval;
+        const intervalPrecition = this._intervalPrecision;
 
         if (!opt.fixMin) {
-            extent[0] = roundNumber(Math.floor(extent[0] / interval) * interval);
+            extent[0] = roundNumber(Math.floor(extent[0] / interval) * interval, intervalPrecition);
         }
         if (!opt.fixMax) {
-            extent[1] = roundNumber(Math.ceil(extent[1] / interval) * interval);
+            extent[1] = roundNumber(Math.ceil(extent[1] / interval) * interval, intervalPrecition);
         }
         this._innerSetExtent(extent[0], extent[1]);
     }
diff --git a/src/scale/Log.ts b/src/scale/Log.ts
index 63665bbe0..bdd799056 100644
--- a/src/scale/Log.ts
+++ b/src/scale/Log.ts
@@ -27,7 +27,7 @@ import {
     DimensionLoose, DimensionName, ParsedAxisBreakList, AxisBreakOption,
     ScaleTick
 } from '../util/types';
-import { logTransform } from './helper';
+import { getIntervalPrecision, logTransform } from './helper';
 import SeriesData from '../data/SeriesData';
 import { getScaleBreakHelper } from './break';
 
@@ -165,6 +165,7 @@ class LogScale extends IntervalScale {
         ] as [number, number];
 
         this._interval = interval;
+        this._intervalPrecision = getIntervalPrecision(interval);
         this._niceExtent = niceExtent;
     }
 
diff --git a/src/scale/Time.ts b/src/scale/Time.ts
index 85768cacf..07f589867 100644
--- a/src/scale/Time.ts
+++ b/src/scale/Time.ts
@@ -297,6 +297,7 @@ class TimeScale extends IntervalScale<TimeScaleSetting> {
 
         // Interval that can be used to calculate ticks
         this._interval = scaleIntervals[idx][1];
+        this._intervalPrecision = scaleHelper.getIntervalPrecision(this._interval);
         // Min level used when picking ticks from top down.
         // We check one more level to avoid the ticks are to sparse in some case.
         this._minLevelUnit = scaleIntervals[Math.max(idx - 1, 0)][0];
diff --git a/src/util/number.ts b/src/util/number.ts
index b39e85e1c..f156e6d3d 100644
--- a/src/util/number.ts
+++ b/src/util/number.ts
@@ -157,8 +157,9 @@ export function round(x: number | string, precision: number, returnStr: false):
 export function round(x: number | string, precision: number, returnStr: true): string;
 export function round(x: number | string, precision?: number, returnStr?: boolean): string | number {
     if (precision == null) {
-        const expStr = (x + '').split('e')[1];
-        precision = expStr ? -expStr + 1 : 10;
+        // FIXME: the default precision should not be provided, since there is no universally adaptable
+        //  precision. The caller need to input a precision according to the scenarios.
+        precision = 10;
     }
     // Avoid range error
     precision = Math.min(Math.max(0, precision), ROUND_SUPPORTED_PRECISION_MAX);
diff --git a/test/runTest/actions/__meta__.json b/test/runTest/actions/__meta__.json
index 586bc8d00..aed89b72d 100644
--- a/test/runTest/actions/__meta__.json
+++ b/test/runTest/actions/__meta__.json
@@ -189,6 +189,7 @@
   "sankey-emphasis-lineStyle": 1,
   "sankey-jump": 1,
   "sankey-level": 1,
+  "scale-extreme-number": 2,
   "scatter-random-stream-fix-axis": 1,
   "scatter-single-axis": 3,
   "scatterMatrix": 3,
diff --git a/test/runTest/actions/scale-extreme-number.json b/test/runTest/actions/scale-extreme-number.json
new file mode 100644
index 000000000..a9492b341
--- /dev/null
+++ b/test/runTest/actions/scale-extreme-number.json
@@ -0,0 +1 @@
+[{"name":"Action 1","ops":[{"type":"mousemove","time":29,"x":328,"y":84},{"type":"mousemove","time":229,"x":235,"y":95},{"type":"mousemove","time":429,"x":180,"y":80},{"type":"mousemove","time":629,"x":141,"y":78},{"type":"mousemove","time":836,"x":113,"y":83},{"type":"mousemove","time":1053,"x":113,"y":83},{"type":"valuechange","selector":"#main0>div.test-chart-block-left>div.test-inputs.test-buttons.test-inputs-style-normal>span.test-inputs-select>select.test-inputs-select-select","val [...]
\ No newline at end of file


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org