You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by de...@apache.org on 2019/02/14 12:06:04 UTC

[incubator-echarts] branch master updated: fix: scrollable legend pager does not work when the target index is illegal. Fix #7568

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

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


The following commit(s) were added to refs/heads/master by this push:
     new ce88329  fix: scrollable legend pager does not work when the target index is illegal. Fix #7568
ce88329 is described below

commit ce88329d558bee7494257ad2522e95da5aaab605
Author: sushuang <su...@gmail.com>
AuthorDate: Mon Jan 28 22:32:50 2019 +0800

    fix: scrollable legend pager does not work when the target index is illegal. Fix #7568
---
 src/component/legend/ScrollableLegendView.js |  20 +++--
 test/legend.html                             |  47 +++++++++-
 test/lib/config.js                           | 128 ++++++++++++++-------------
 3 files changed, 125 insertions(+), 70 deletions(-)

diff --git a/src/component/legend/ScrollableLegendView.js b/src/component/legend/ScrollableLegendView.js
index 14a1dfd..a5e7cb0 100644
--- a/src/component/legend/ScrollableLegendView.js
+++ b/src/component/legend/ScrollableLegendView.js
@@ -304,6 +304,7 @@ var ScrollableLegendView = LegendView.extend({
         var orientIdx = legendModel.getOrient().index;
         var wh = WH[orientIdx];
         var xy = XY[orientIdx];
+
         var targetItemIndex = this._findTargetItemIndex(scrollDataIndex);
         var children = contentGroup.children();
         var targetItem = children[targetItemIndex];
@@ -415,17 +416,26 @@ var ScrollableLegendView = LegendView.extend({
     _findTargetItemIndex: function (targetDataIndex) {
         var index;
         var contentGroup = this.getContentGroup();
+        var defaultIndex;
+
         if (this._showController) {
             contentGroup.eachChild(function (child, idx) {
-                if (child.__legendDataIndex === targetDataIndex) {
+                var legendDataIdx = child.__legendDataIndex;
+                // FIXME
+                // If the given targetDataIndex (from model) is illegal,
+                // we use defualtIndex. But the index on the legend model and
+                // action payload is still illegal. That case will not be
+                // changed until some scenario requires.
+                if (defaultIndex == null && legendDataIdx != null) {
+                    defaultIndex = idx;
+                }
+                if (legendDataIdx === targetDataIndex) {
                     index = idx;
                 }
             });
         }
-        else {
-            index = 0;
-        }
-        return index;
+
+        return index != null ? index : defaultIndex;
     }
 
 });
diff --git a/test/legend.html b/test/legend.html
index 038a686..6462feb 100644
--- a/test/legend.html
+++ b/test/legend.html
@@ -72,6 +72,7 @@ under the License.
         <div id="icon-circle"></div>
         <div id="only-single-item"></div>
         <div id="vary-size"></div>
+        <div id="index-to-no-name"></div>
 
         <script>
 
@@ -1067,8 +1068,6 @@ under the License.
                     });
                 }
 
-                var seriesInfo = makeSeries(50, 3);
-
                 var option = {
                     legend: [{
                         type: 'scroll',
@@ -1098,5 +1097,49 @@ under the License.
 
 
 
+
+
+
+
+
+
+
+        <script>
+            require([
+                'echarts',
+            ], function (echarts) {
+
+                var seriesInfo = makeSeries(50, 3);
+                var series = seriesInfo.series.slice();
+                series.shift();
+
+                var option = {
+                    legend: [{
+                        type: 'scroll',
+                        data: seriesInfo.legendData
+                    }],
+                    tooltip: {
+                    },
+                    xAxis: {
+                        data: seriesInfo.xAxisData
+                    },
+                    yAxis: {
+                    },
+                    series: series
+                };
+
+                testHelper.create(echarts, 'index-to-no-name', {
+                    option: option,
+                    title: [
+                        'Pager should be OK when legend 0 (legendData index 0) is not be displayed.',
+                        'should be at **page 1** at the beginning'
+                    ],
+                    draggable: true
+                });
+            })
+        </script>
+
+
+
     </body>
 </html>
\ No newline at end of file
diff --git a/test/lib/config.js b/test/lib/config.js
index 5ca9b9e..58ec69e 100644
--- a/test/lib/config.js
+++ b/test/lib/config.js
@@ -77,74 +77,76 @@
         });
     }
 
+    // It is not a good solution.
+    // Do not need it any more:
 
     // Mount bundle version print.
-    if (typeof require !== 'undefined') {
-        var originalRequire = require;
-        window.require = function (deps, cb) {
-            var newCb = function () {
-                if (deps && deps instanceof Array) {
-                    printBundleVersion(deps, [].slice.call(arguments));
-                }
-                cb && cb.apply(this, arguments);
-            };
-            return originalRequire.call(this, deps, newCb);
-        };
-    }
+    // if (typeof require !== 'undefined') {
+    //     var originalRequire = require;
+    //     window.require = function (deps, cb) {
+    //         var newCb = function () {
+    //             if (deps && deps instanceof Array) {
+    //                 printBundleVersion(deps, [].slice.call(arguments));
+    //             }
+    //             cb && cb.apply(this, arguments);
+    //         };
+    //         return originalRequire.call(this, deps, newCb);
+    //     };
+    // }
 
-    function printBundleVersion(bundleIds, bundles) {
-        var content = [];
-        for (var i = 0; i < bundleIds.length; i++) {
-            var bundle = bundles[i];
-            var bundleVersion = bundle && bundle.bundleVersion;
-            if (bundleVersion) {
-                var date = new Date(+bundleVersion);
-                // Check whether timestamp.
-                if (!isNaN(+date)) {
-                    bundleVersion = '<span style="color:yellow">'
-                        + pad(date.getHours(), 2) + ':'
-                        + pad(date.getMinutes(), 2) + ':'
-                        + pad(date.getSeconds(), 2) + '.' + pad(date.getMilliseconds(), 3)
-                        + '</span>';
-                }
-                else {
-                    bundleVersion = encodeHTML(bundleVersion);
-                }
-                content.push(encodeHTML(bundleIds[i]) + '.js: ' + bundleVersion);
-            }
-        }
+    // function printBundleVersion(bundleIds, bundles) {
+    //     var content = [];
+    //     for (var i = 0; i < bundleIds.length; i++) {
+    //         var bundle = bundles[i];
+    //         var bundleVersion = bundle && bundle.bundleVersion;
+    //         if (bundleVersion) {
+    //             var date = new Date(+bundleVersion);
+    //             // Check whether timestamp.
+    //             if (!isNaN(+date)) {
+    //                 bundleVersion = '<span style="color:yellow">'
+    //                     + pad(date.getHours(), 2) + ':'
+    //                     + pad(date.getMinutes(), 2) + ':'
+    //                     + pad(date.getSeconds(), 2) + '.' + pad(date.getMilliseconds(), 3)
+    //                     + '</span>';
+    //             }
+    //             else {
+    //                 bundleVersion = encodeHTML(bundleVersion);
+    //             }
+    //             content.push(encodeHTML(bundleIds[i]) + '.js: ' + bundleVersion);
+    //         }
+    //     }
 
-        var domId = 'ec-test-bundle-version';
-        var dom = document.getElementById(domId);
-        if (!dom) {
-            dom = document.createElement('div');
-            dom.setAttribute('id', domId);
-            dom.style.cssText = [
-                'background: rgb(52,56,64)',
-                'color: rgb(215,215,215)',
-                'position: fixed',
-                'right: 0',
-                'top: 0',
-                'font-size: 10px',
-                'padding: 1px 3px 1px 3px',
-                'border-bottom-left-radius: 3px'
-            ].join(';');
-            document.body.appendChild(dom);
-        }
-        dom.innerHTML += content.join('');
-    }
+    //     var domId = 'ec-test-bundle-version';
+    //     var dom = document.getElementById(domId);
+    //     if (!dom) {
+    //         dom = document.createElement('div');
+    //         dom.setAttribute('id', domId);
+    //         dom.style.cssText = [
+    //             'background: rgb(52,56,64)',
+    //             'color: rgb(215,215,215)',
+    //             'position: fixed',
+    //             'right: 0',
+    //             'top: 0',
+    //             'font-size: 10px',
+    //             'padding: 1px 3px 1px 3px',
+    //             'border-bottom-left-radius: 3px'
+    //         ].join(';');
+    //         document.body.appendChild(dom);
+    //     }
+    //     dom.innerHTML += content.join('');
+    // }
 
-    function pad(num, len) {
-        return ('000000' + num).substr(-len, len);
-    }
+    // function pad(num, len) {
+    //     return ('000000' + num).substr(-len, len);
+    // }
 
-    function encodeHTML(source) {
-        return String(source)
-            .replace(/&/g, '&amp;')
-            .replace(/</g, '&lt;')
-            .replace(/>/g, '&gt;')
-            .replace(/"/g, '&quot;')
-            .replace(/'/g, '&#39;');
-    }
+    // function encodeHTML(source) {
+    //     return String(source)
+    //         .replace(/&/g, '&amp;')
+    //         .replace(/</g, '&lt;')
+    //         .replace(/>/g, '&gt;')
+    //         .replace(/"/g, '&quot;')
+    //         .replace(/'/g, '&#39;');
+    // }
 
 })();
\ 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