You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by wa...@apache.org on 2022/07/04 07:53:48 UTC

[echarts] 01/01: fix(custom): fix potential NPE when applying leave transition.

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

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

commit 70b10e198704167ac10bf24a2be1bfa51c5c7f16
Author: plainheart <yh...@all-my-life.cn>
AuthorDate: Mon Jul 4 15:49:42 2022 +0800

    fix(custom): fix potential NPE when applying leave transition.
---
 src/chart/custom/CustomView.ts     | 10 +++---
 test/custom.html                   | 73 ++++++++++++++++++++++++++------------
 test/runTest/actions/__meta__.json |  2 +-
 test/runTest/actions/custom.json   |  2 +-
 4 files changed, 57 insertions(+), 30 deletions(-)

diff --git a/src/chart/custom/CustomView.ts b/src/chart/custom/CustomView.ts
index 49fad9686..156807826 100644
--- a/src/chart/custom/CustomView.ts
+++ b/src/chart/custom/CustomView.ts
@@ -228,7 +228,7 @@ export default class CustomChartView extends ChartView {
             })
             .remove(function (oldIdx) {
                 const el = oldData.getItemGraphicEl(oldIdx);
-                applyLeaveTransition(el, customInnerStore(el).option, customSeries);
+                el && applyLeaveTransition(el, customInnerStore(el).option, customSeries);
             })
             .update(function (newIdx, oldIdx) {
                 const oldEl = oldData.getItemGraphicEl(oldIdx);
@@ -1326,11 +1326,11 @@ function mergeChildren(
         );
     }
     for (let i = el.childCount() - 1; i >= index; i--) {
-        // Do not supprot leave elements that are not mentioned in the latest
+        // Do not support leave elements that are not mentioned in the latest
         // `renderItem` return. Otherwise users may not have a clear and simple
-        // concept that how to contorl all of the elements.
+        // concept that how to control all of the elements.
         const child = el.childAt(i);
-        applyLeaveTransition(child, customInnerStore(el).option, seriesModel);
+        child && applyLeaveTransition(child, customInnerStore(el).option, seriesModel);
     }
 }
 
@@ -1383,7 +1383,7 @@ function processAddUpdate(
 function processRemove(this: DataDiffer<DiffGroupContext>, oldIndex: number): void {
     const context = this.context;
     const child = context.oldChildren[oldIndex];
-    applyLeaveTransition(child, customInnerStore(child).option, context.seriesModel);
+    child && applyLeaveTransition(child, customInnerStore(child).option, context.seriesModel);
 }
 
 /**
diff --git a/test/custom.html b/test/custom.html
index 1485c8a15..a8b727ea8 100644
--- a/test/custom.html
+++ b/test/custom.html
@@ -90,29 +90,37 @@ under the License.
                     {name: 'GPU', color: '#72b362'}
                 ];
 
+                var renderCount = 0;
                 // Generate mock data
-                echarts.util.each(categories, function (category, index) {
-                    var baseTime = startTime;
-                    for (var i = 0; i < dataCount; i++) {
-                        var typeItem = types[Math.round(Math.random() * (types.length - 1))];
-                        var duration = Math.round(Math.random() * 10000);
-                        data.push({
-                            name: typeItem.name,
-                            value: [
-                                index,
-                                baseTime,
-                                baseTime += duration,
-                                duration
-                            ],
-                            itemStyle: {
-                                normal: {
-                                    color: typeItem.color
+                function updateData() {
+                    data = [];
+                    echarts.util.each(categories, function (category, index) {
+                        var baseTime = startTime;
+                        for (var i = 0; i < dataCount; i++) {
+                            var typeItem = types[Math.round(Math.random() * (types.length - 1))];
+                            var duration = Math.round(Math.random() * 10000);
+                            var isEven = renderCount % 2 === 0;
+                            data.push({
+                                name: typeItem.name,
+                                value: [
+                                    index,
+                                    baseTime,
+                                    isEven ? (baseTime += duration) : NaN,
+                                    duration
+                                ],
+                                itemStyle: {
+                                    normal: {
+                                        color: typeItem.color
+                                    }
                                 }
-                            }
-                        });
-                        baseTime += Math.round(Math.random() * 2000);
-                    }
-                });
+                            });
+                            isEven && (baseTime += Math.round(Math.random() * 2000));
+                        }
+                    });
+                    renderCount++;
+                }
+
+                updateData();
 
                 console.log(JSON.stringify({
                     startTime: startTime,
@@ -211,7 +219,26 @@ under the License.
                     }]
                 };
 
-                testHelper.createChart(echarts, 'profile', option);
+                var chart = testHelper.create(echarts, 'profile', {
+                    option: option,
+                    title: [
+                        'The data should be cleared when clicking the **updateData** button firstly',
+                        'Should have no errors when clicking the **updateData** button once again'
+                    ],
+                    buttons: [
+                        {
+                            text: 'updateData',
+                            onclick: function () {
+                                updateData();
+                                chart.setOption({
+                                    series: [{
+                                        data: data
+                                    }]
+                                });
+                            }
+                        }
+                    ]
+                });
             });
         </script>
 
@@ -1398,4 +1425,4 @@ under the License.
 
 
     </body>
-</html>
\ No newline at end of file
+</html>
diff --git a/test/runTest/actions/__meta__.json b/test/runTest/actions/__meta__.json
index 388c569e0..baadde980 100644
--- a/test/runTest/actions/__meta__.json
+++ b/test/runTest/actions/__meta__.json
@@ -56,7 +56,7 @@
   "connect-manually": 1,
   "connect2": 1,
   "css-transform": 4,
-  "custom": 5,
+  "custom": 6,
   "custom-bmap-grid": 1,
   "custom-children-remove": 1,
   "custom-hexbin": 2,
diff --git a/test/runTest/actions/custom.json b/test/runTest/actions/custom.json
index 7e8098931..9d0864af4 100644
--- a/test/runTest/actions/custom.json
+++ b/test/runTest/actions/custom.json
@@ -1 +1 @@
-[{"name":"Action 1","ops":[{"type":"mousedown","time":408,"x":81,"y":475},{"type":"mousemove","time":570,"x":85,"y":475},{"type":"mousemove","time":770,"x":209,"y":479},{"type":"mouseup","time":1011,"x":209,"y":479},{"time":1012,"delay":400,"type":"screenshot-auto"},{"type":"mousedown","time":1403,"x":209,"y":479},{"type":"mousemove","time":1537,"x":210,"y":478},{"type":"mousemove","time":1738,"x":322,"y":473},{"type":"mousemove","time":1945,"x":325,"y":473},{"type":"mousemove","time":21 [...]
\ No newline at end of file
+[{"name":"Action 1","ops":[{"type":"mousedown","time":408,"x":81,"y":475},{"type":"mousemove","time":570,"x":85,"y":475},{"type":"mousemove","time":770,"x":209,"y":479},{"type":"mouseup","time":1011,"x":209,"y":479},{"time":1012,"delay":400,"type":"screenshot-auto"},{"type":"mousedown","time":1403,"x":209,"y":479},{"type":"mousemove","time":1537,"x":210,"y":478},{"type":"mousemove","time":1738,"x":322,"y":473},{"type":"mousemove","time":1945,"x":325,"y":473},{"type":"mousemove","time":21 [...]
\ 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