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 2019/10/21 17:48:35 UTC

[incubator-echarts] 01/01: chore: tweak test case and tweak the patch of #11186

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

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

commit 39519dd9c536adbcbfac307a4f6dc558afd335f6
Author: SHUANG SU <su...@gmail.com>
AuthorDate: Tue Oct 22 01:47:45 2019 +0800

    chore: tweak test case and tweak the patch of #11186
---
 src/coord/Axis.js       | 11 +++---
 test/axis-interval.html | 96 +++++++++++++++++++++++++++++--------------------
 2 files changed, 62 insertions(+), 45 deletions(-)

diff --git a/src/coord/Axis.js b/src/coord/Axis.js
index 50e3f4a..2db0138 100644
--- a/src/coord/Axis.js
+++ b/src/coord/Axis.js
@@ -197,11 +197,9 @@ Axis.prototype = {
         }, this);
 
         var alignWithLabel = tickModel.get('alignWithLabel');
-        var dataExtent = this.scale.getExtent();
-        var tickLen = this.scale.getTicks().length + dataExtent[0];
 
         fixOnBandTicksCoords(
-            this, ticksCoords, result.tickCategoryInterval, alignWithLabel, opt.clamp, tickLen
+            this, ticksCoords, result.tickCategoryInterval, alignWithLabel, opt.clamp
         );
 
         return ticksCoords;
@@ -294,7 +292,7 @@ function fixExtentWithBands(extent, nTick) {
 // splitLine/spliteArea should layout appropriately corresponding
 // to displayed labels. (So we should not use `getBandWidth` in this
 // case).
-function fixOnBandTicksCoords(axis, ticksCoords, tickCategoryInterval, alignWithLabel, clamp, tickLen) {
+function fixOnBandTicksCoords(axis, ticksCoords, tickCategoryInterval, alignWithLabel, clamp) {
     var ticksLen = ticksCoords.length;
 
     if (!axis.onBand || alignWithLabel || !ticksLen) {
@@ -315,14 +313,15 @@ function fixOnBandTicksCoords(axis, ticksCoords, tickCategoryInterval, alignWith
 
         each(ticksCoords, function (ticksItem) {
             ticksItem.coord -= shift / 2;
-            var tickCategoryInterval = tickCategoryInterval || 0;
+            tickCategoryInterval = tickCategoryInterval || 0;
             // Avoid split a single data item when odd interval.
             if (tickCategoryInterval % 2 > 0) {
                 ticksItem.coord -= shift / ((tickCategoryInterval + 1) * 2);
             }
         });
 
-        diffSize = tickLen - ticksCoords[ticksLen - 1].tickValue;
+        var dataExtent = axis.scale.getExtent();
+        diffSize = 1 + dataExtent[1] - ticksCoords[ticksLen - 1].tickValue;
 
         last = {coord: ticksCoords[ticksLen - 1].coord + shift * diffSize};
 
diff --git a/test/axis-interval.html b/test/axis-interval.html
index 11864ca..46862a4 100644
--- a/test/axis-interval.html
+++ b/test/axis-interval.html
@@ -50,16 +50,21 @@ under the License.
     </style>
 
     <div class="chart" id="mainA"></div>
-
     <h1>[ Test minInterval ]&nbsp;&nbsp;&nbsp; yAxis: {minInterval: 1, min: 0}, series.data: [1]</h1>
     <div class="chart" id="main0"></div>
     <h1>[ Test category axis interval ]&nbsp;&nbsp;&nbsp; interval of xAxis should be approperiate after rotated.</h1>
     <div class="chart" id="main1"></div>
     <h1>[ Test time axis interval ]&nbsp;&nbsp;&nbsp; should not overlap when data zoom.</h1>
     <div class="chart" id="main2"></div>
-    <h1>[ Test xAxis.axisTick.interval ]&nbsp;&nbsp;&nbsp; var list = [true, false, true, true];axisTick.interval =
-        function(index){return list[index]} </h1>
-    <div class="chart" id="main3"></div>
+
+    <h1>Test xAxis.axisTick.interval</h1>
+    <div class="chart" id="main30"></div>
+    <div class="chart" id="main31"></div>
+    <div class="chart" id="main32"></div>
+    <div class="chart" id="main33"></div>
+    <div class="chart" id="main34"></div>
+    <div class="chart" id="main35"></div>
+
 
 
 
@@ -341,14 +346,16 @@ under the License.
     </script>
 
 
+
+
+
+
     <script>
 
         require([
             'echarts'
         ], function (echarts) {
 
-            var dataIndex = 0;
-
             var testArr = [
                 [true, false, true, true],
                 [true, false, true, false],
@@ -359,44 +366,56 @@ under the License.
             ];
 
             function print(index) {
-                return `intervalList = [${testArr[index].toString()}] ,currentIndex is ${index}`
+                return `intervalList:\n[${testArr[index].toString()}] \n\n currentIndex: ${index}`
             }
 
-            var option = {
-                title: {
-                    text: print(dataIndex)
-                },
-                xAxis: {
-                    type: 'category',
-                    data: ['Mon', 'Tue', 'Wed', 'Thu'],
-                    axisTick: {
-                        show: true,
-                        interval: function (index) {
-                            // return index && !!x2Data[index]
-                            return testArr[dataIndex][index]
+            function makeOption(dataIndex) {
+                var option = {
+                    title: {
+                        text: print(dataIndex),
+                        textStyle: {
+                            fontSize: 12
+                        }
+                    },
+                    grid: {
+                        top: 10,
+                        right: 50,
+                        left: 160,
+                        bottom: 30
+                    },
+                    xAxis: {
+                        type: 'category',
+                        data: ['Mon', 'Tue', 'Wed', 'Thu'],
+                        axisTick: {
+                            show: true,
+                            interval: function (index) {
+                                // return index && !!x2Data[index]
+                                return testArr[dataIndex][index]
+                            },
+                            length: 30,
+                            alignWithLabel: false
                         },
-                        length: 50,
-                        alignWithLabel: false,
                     },
-                },
-                yAxis: {
-                    type: 'value'
-                },
-                series: [{
-                    data: [820, 932, 901, 934],
-                    type: 'bar'
-                }]
-            };
-            var ec = echarts.init(document.getElementById('main3'));
+                    yAxis: {
+                        type: 'value'
+                    },
+                    series: [{
+                        data: [820, 932, 901, 934],
+                        type: 'bar'
+                    }]
+                };
 
-            setInterval(function () {
-                var next = ++dataIndex;
-                dataIndex = next > 5 ? 0 : next;
-                option.title.text = print(dataIndex);
-                ec.setOption(option);
-            }, 6000);
+                return option;
+            }
 
-            ec.setOption(option);
+            for (var i = 0; i < testArr.length; i++) {
+                var dom = document.getElementById('main3' + i);
+                if (dom) {
+                    dom.style.height = '90px';
+                    var chart = echarts.init(dom);
+                    chart.setOption(makeOption(i));
+                }
+            }
 
         });
 
@@ -407,7 +426,6 @@ under the License.
 
 
 
-
 </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