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

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

commit 690ebe6ee6c3f914718d466942f1884252b8e0ea
Author: plainheart <y...@all-my-life.cn>
AuthorDate: Tue Jan 16 05:23:54 2024 +0800

    fix(graph): fix force layout iteration timer doesn't stop after disposing 
the chart
---
 src/chart/graph/GraphView.ts         |  8 ++++-
 test/graph-case.html                 | 57 +++++++++++++++++++++++++++++++++++-
 test/runTest/actions/__meta__.json   |  2 +-
 test/runTest/actions/graph-case.json |  2 +-
 4 files changed, 65 insertions(+), 4 deletions(-)

diff --git a/src/chart/graph/GraphView.ts b/src/chart/graph/GraphView.ts
index d5f51eba4..f4559521f 100644
--- a/src/chart/graph/GraphView.ts
+++ b/src/chart/graph/GraphView.ts
@@ -208,6 +208,8 @@ class GraphView extends ChartView {
     }
 
     dispose() {
+        this.remove();
+
         this._controller && this._controller.dispose();
         this._controllerHost = null;
     }
@@ -300,7 +302,11 @@ class GraphView extends ChartView {
         this._lineDraw.updateLayout();
     }
 
-    remove(ecModel: GlobalModel, api: ExtensionAPI) {
+    remove() {
+        clearTimeout(this._layoutTimeout);
+        this._layouting = false;
+        this._layoutTimeout = null;
+
         this._symbolDraw && this._symbolDraw.remove();
         this._lineDraw && this._lineDraw.remove();
     }
diff --git a/test/graph-case.html b/test/graph-case.html
index 7f199f5a4..4523593c7 100644
--- a/test/graph-case.html
+++ b/test/graph-case.html
@@ -39,7 +39,7 @@ under the License.
 
         <div id="main0"></div>
         <div id="main1"></div>
-
+        <div id="main2"></div>
 
 
 
@@ -154,6 +154,61 @@ under the License.
             });
             </script>
 
+            <script>
+                require(['echarts'], function (echarts) {
+                    var option = {
+                        series: [{
+                            type: 'graph',
+                            layout: 'force',
+                            roam: true,
+                            data: [
+                                {
+                                    name: 'Node 1',
+                                    x: 300,
+                                    y: 300
+                                },
+                                {
+                                    name: 'Node 2',
+                                    x: 800,
+                                    y: 300
+                                }
+                            ],
+                            links: [
+                                {
+                                    source: 'Node 1',
+                                    target: 'Node 2'
+                                }
+                            ]
+                        }]
+                    };
+
+                    var chart = testHelper.create(echarts, 'main2', {
+                        title: [
+                            'Layout timer should stop after disposing chart'
+                        ],
+                        buttons: [
+                            {
+                                text: 'Dispose',
+                                onclick() {
+                                    const seriesModel = 
chart.getModel().getSeriesByType('graph')[0]
+                                    const graphView = 
chart.getViewOfSeriesModel(seriesModel)
+
+                                    const container = chart.getDom()
+
+                                    chart.dispose()
+
+                                    if (graphView._layoutTimeout) {
+                                        const errMsg = 'Graph layout timer is 
not removed after disposing the chart!'
+                                        container.innerHTML = '<b 
style="color: red">' + errMsg + '</b>'
+                                        throw new Error(errMsg)
+                                    }
+                                }
+                            }
+                        ],
+                        option: option
+                    });
+                });
+                </script>
     </body>
 </html>
 
diff --git a/test/runTest/actions/__meta__.json 
b/test/runTest/actions/__meta__.json
index fb743cb9c..8592bb1be 100644
--- a/test/runTest/actions/__meta__.json
+++ b/test/runTest/actions/__meta__.json
@@ -101,7 +101,7 @@
   "geoScatter": 1,
   "getOption": 1,
   "graph": 2,
-  "graph-case": 1,
+  "graph-case": 2,
   "graph-grid": 1,
   "graph-simple": 2,
   "graphic-animation": 1,
diff --git a/test/runTest/actions/graph-case.json 
b/test/runTest/actions/graph-case.json
index ace16dc41..a4f345849 100644
--- a/test/runTest/actions/graph-case.json
+++ b/test/runTest/actions/graph-case.json
@@ -1 +1 @@
-[{"name":"Action 
1","ops":[{"type":"mousemove","time":475,"x":416,"y":188},{"type":"mousemove","time":675,"x":406,"y":208},{"type":"mousedown","time":848,"x":406,"y":210},{"type":"mousemove","time":881,"x":406,"y":210},{"type":"mouseup","time":979,"x":406,"y":210},{"time":980,"delay":400,"type":"screenshot-auto"},{"type":"mousedown","time":1837,"x":406,"y":210},{"type":"mouseup","time":1988,"x":406,"y":210},{"time":1989,"delay":400,"type":"screenshot-auto"},{"type":"mousemove","time":234
 [...]
\ No newline at end of file
+[{"name":"Action 
1","ops":[{"type":"mousemove","time":475,"x":416,"y":188},{"type":"mousemove","time":675,"x":406,"y":208},{"type":"mousedown","time":848,"x":406,"y":210},{"type":"mousemove","time":881,"x":406,"y":210},{"type":"mouseup","time":979,"x":406,"y":210},{"time":980,"delay":400,"type":"screenshot-auto"},{"type":"mousedown","time":1837,"x":406,"y":210},{"type":"mouseup","time":1988,"x":406,"y":210},{"time":1989,"delay":400,"type":"screenshot-auto"},{"type":"mousemove","time":234
 [...]
\ No newline at end of file


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

Reply via email to