You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by ov...@apache.org on 2019/10/25 06:47:11 UTC

[incubator-echarts] branch master updated (8862e2e -> d5c2522)

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

ovilia pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-echarts.git.


    from 8862e2e  fix: clarify the definition of dataZoom.rangeMode.
     new c789348  fix: quantityExponent #11249
     new d5c2522  style: add comment

The 2 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.


Summary of changes:
 src/util/number.js          | 15 ++++++++++++++-
 test/ut/spec/util/number.js |  2 ++
 2 files changed, 16 insertions(+), 1 deletion(-)


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


[incubator-echarts] 01/02: fix: quantityExponent #11249

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

ovilia pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-echarts.git

commit c78934837c088754362a448210e0ca26f24b4deb
Author: Ovilia <zw...@gmail.com>
AuthorDate: Fri Oct 25 14:10:04 2019 +0800

    fix: quantityExponent #11249
---
 src/util/number.js          | 10 +++++++++-
 test/ut/spec/util/number.js |  2 ++
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/src/util/number.js b/src/util/number.js
index 106fc4f..aecd858 100644
--- a/src/util/number.js
+++ b/src/util/number.js
@@ -394,7 +394,15 @@ export function quantity(val) {
  * @return {number}
  */
 export function quantityExponent(val) {
-    return val > 0 ? Math.floor(Math.log(val) / Math.LN10) : 0;
+    if (val === 0) {
+        return 0;
+    }
+
+    var exp = Math.floor(Math.log(val) / Math.LN10);
+    if (val / Math.pow(10, exp) >= 10) {
+        exp++;
+    }
+    return exp;
 }
 
 /**
diff --git a/test/ut/spec/util/number.js b/test/ut/spec/util/number.js
index 154152e..f185c5b 100755
--- a/test/ut/spec/util/number.js
+++ b/test/ut/spec/util/number.js
@@ -401,6 +401,7 @@ describe('util/number', function () {
             expect(numberUtil.quantityExponent(1234)).toEqual(3);
             expect(numberUtil.quantityExponent(1234.5678)).toEqual(3);
             expect(numberUtil.quantityExponent(10)).toEqual(1);
+            expect(numberUtil.quantityExponent(1000)).toEqual(3);
             expect(numberUtil.quantityExponent(10000)).toEqual(4);
         });
 
@@ -429,6 +430,7 @@ describe('util/number', function () {
             expect(numberUtil.quantity(1234)).toEqual(1000);
             expect(numberUtil.quantity(1234.5678)).toEqual(1000);
             expect(numberUtil.quantity(10)).toEqual(10);
+            expect(numberUtil.quantity(1000)).toEqual(1000);
             expect(numberUtil.quantity(10000)).toEqual(10000);
         });
 


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


[incubator-echarts] 02/02: style: add comment

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

ovilia pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-echarts.git

commit d5c25225872c491002d7cff3b104746041becf2a
Author: Ovilia <zw...@gmail.com>
AuthorDate: Fri Oct 25 14:37:01 2019 +0800

    style: add comment
---
 src/util/number.js | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/src/util/number.js b/src/util/number.js
index aecd858..cf84e9a 100644
--- a/src/util/number.js
+++ b/src/util/number.js
@@ -399,6 +399,11 @@ export function quantityExponent(val) {
     }
 
     var exp = Math.floor(Math.log(val) / Math.LN10);
+    /**
+     * exp is expected to be the rounded-down result of the base-10 log of val.
+     * But due to the precision loss with Math.log(val), we need to restore it
+     * using 10^exp to make sure we can get val back from exp. #11249
+     */
     if (val / Math.pow(10, exp) >= 10) {
         exp++;
     }


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