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 2022/07/05 08:49:12 UTC

[echarts] branch fix-13154 created (now c885e6503)

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

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


      at c885e6503 fix(log): fix log axis breaks a single data whose log value is negative #13154

This branch includes the following new commits:

     new c885e6503 fix(log): fix log axis breaks a single data whose log value is negative #13154

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(log): fix log axis breaks a single data whose log value is negative #13154

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

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

commit c885e65033b45ced14536b61be8265d1a842f8a2
Author: Ovilia <zw...@gmail.com>
AuthorDate: Tue Jul 5 16:46:52 2022 +0800

    fix(log): fix log axis breaks a single data whose log value is negative #13154
---
 src/scale/Interval.ts |  3 ++-
 src/scale/Log.ts      |  5 +++--
 test/logScale.html    | 33 ++++++++++++++++++++++++++++++++-
 3 files changed, 37 insertions(+), 4 deletions(-)

diff --git a/src/scale/Interval.ts b/src/scale/Interval.ts
index 1f4a7f98e..866051dcf 100644
--- a/src/scale/Interval.ts
+++ b/src/scale/Interval.ts
@@ -250,7 +250,8 @@ class IntervalScale<SETTING extends Dictionary<unknown> = Dictionary<unknown>> e
         if (extent[0] === extent[1]) {
             if (extent[0] !== 0) {
                 // Expand extent
-                const expandSize = extent[0];
+                // Note that extents can be both negative. See #13154
+                const expandSize = Math.abs(extent[0]);
                 // In the fowllowing case
                 //      Axis has been fixed max 100
                 //      Plus data are all 100 and axis extent are [100, 100].
diff --git a/src/scale/Log.ts b/src/scale/Log.ts
index 41586e877..6354e9eed 100644
--- a/src/scale/Log.ts
+++ b/src/scale/Log.ts
@@ -86,8 +86,9 @@ class LogScale extends Scale {
 
     setExtent(start: number, end: number): void {
         const base = this.base;
-        start = mathLog(start) / mathLog(base);
-        end = mathLog(end) / mathLog(base);
+        // log(-Infinity) is NaN, so safe guard here
+        start = mathLog(Math.max(0, start)) / mathLog(base);
+        end = mathLog(Math.max(0, end)) / mathLog(base);
         intervalScaleProto.setExtent.call(this, start, end);
     }
 
diff --git a/test/logScale.html b/test/logScale.html
index e91507ac1..def5bfdfd 100644
--- a/test/logScale.html
+++ b/test/logScale.html
@@ -26,12 +26,13 @@ under the License.
     </head>
     <body>
         <style>
-            html, body, #main {
+            html, body, #main, #main1 {
                 width: 100%;
                 height: 100%;
             }
         </style>
         <div id='main'></div>
+        <div id='main1'></div>
         <script>
 
             require([
@@ -82,5 +83,35 @@ under the License.
             });
 
         </script>
+        <script>
+
+            require([
+                'echarts'
+            ], function (echarts) {
+                var chart = echarts.init(document.getElementById('main1'));
+                // See #13154
+                chart.setOption({
+                    xAxis: {
+                        type: 'value',
+                    },
+                    yAxis: {
+                        type: 'log',
+                        logBase: 2,
+                    },
+                    series: [
+                        {
+                            type: 'scatter',
+                            itemStyle: {
+                                color: 'red',
+                            },
+                            data: [
+                                [1, .5],
+                            ],
+                        },
+                    ],
+                });
+            });
+
+        </script>
     </body>
 </html>
\ 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