You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by sh...@apache.org on 2022/02/17 03:21:19 UTC

[echarts] branch fix-memory-leak created (now c3726e1)

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

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


      at c3726e1  perf(symbol): fix potential memory leak in effect symbol with notMerge

This branch includes the following new commits:

     new c3726e1  perf(symbol): fix potential memory leak in effect symbol with notMerge

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: perf(symbol): fix potential memory leak in effect symbol with notMerge

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

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

commit c3726e1581ea7d57121c5ba43d2431677618e901
Author: pissang <bm...@gmail.com>
AuthorDate: Thu Feb 17 11:18:49 2022 +0800

    perf(symbol): fix potential memory leak in effect symbol with notMerge
---
 src/chart/helper/EffectLine.ts | 64 ++++++++++++++++++++++--------------------
 src/chart/helper/Symbol.ts     | 10 ++-----
 src/chart/helper/SymbolDraw.ts |  7 +++--
 src/chart/tree/TreeView.ts     |  2 +-
 test/lib/testHelper.js         |  4 +--
 test/node/ssr.js               | 20 ++++++-------
 6 files changed, 54 insertions(+), 53 deletions(-)

diff --git a/src/chart/helper/EffectLine.ts b/src/chart/helper/EffectLine.ts
index 3843e68..412b272 100644
--- a/src/chart/helper/EffectLine.ts
+++ b/src/chart/helper/EffectLine.ts
@@ -117,8 +117,6 @@ class EffectLine extends graphic.Group {
             return;
         }
 
-        const self = this;
-
         const points = lineData.getItemLayout(idx);
 
         let period = effectModel.get('period') * 1000;
@@ -138,42 +136,48 @@ class EffectLine extends graphic.Group {
         }
 
         if (period !== this._period || loop !== this._loop) {
-
             symbol.stopAnimation();
-
-            if (period > 0) {
-                let delayNum: number;
-                if (zrUtil.isFunction(delayExpr)) {
-                    delayNum = delayExpr(idx);
-                }
-                else {
-                    delayNum = delayExpr;
-                }
-                if (symbol.__t > 0) {
-                    delayNum = -period * symbol.__t;
-                }
-                symbol.__t = 0;
-                const animator = symbol.animate('', loop)
-                    .when(period, {
-                        __t: 1
-                    })
-                    .delay(delayNum)
-                    .during(function () {
-                        self._updateSymbolPosition(symbol);
-                    });
-                if (!loop) {
-                    animator.done(function () {
-                        self.remove(symbol);
-                    });
-                }
-                animator.start();
+            let delayNum: number;
+            if (zrUtil.isFunction(delayExpr)) {
+                delayNum = delayExpr(idx);
             }
+            else {
+                delayNum = delayExpr;
+            }
+            if (symbol.__t > 0) {
+                delayNum = -period * symbol.__t;
+            }
+
+            this._animateSymbol(
+                symbol, period, delayNum, loop
+            );
         }
 
         this._period = period;
         this._loop = loop;
     }
 
+    private _animateSymbol(symbol: ECSymbolOnEffectLine, period: number, delayNum: number, loop: boolean) {
+        if (period > 0) {
+            symbol.__t = 0;
+            const self = this;
+            const animator = symbol.animate('', loop)
+                .when(period, {
+                    __t: 1
+                })
+                .delay(delayNum)
+                .during(function () {
+                    self._updateSymbolPosition(symbol);
+                });
+            if (!loop) {
+                animator.done(function () {
+                    self.remove(symbol);
+                });
+            }
+            animator.start();
+        }
+    }
+
     protected _getLineLength(symbol: ECSymbolOnEffectLine) {
         // Not so accurate
         return (vec2.dist(symbol.__p1, symbol.__cp1)
diff --git a/src/chart/helper/Symbol.ts b/src/chart/helper/Symbol.ts
index c9d6aff..d73e9ff 100644
--- a/src/chart/helper/Symbol.ts
+++ b/src/chart/helper/Symbol.ts
@@ -23,7 +23,7 @@ import {getECData} from '../../util/innerStore';
 import { enterEmphasis, leaveEmphasis, toggleHoverEmphasis } from '../../util/states';
 import {getDefaultLabel} from './labelHelper';
 import SeriesData from '../../data/SeriesData';
-import { ColorString, BlurScope, AnimationOption, ZRColor } from '../../util/types';
+import { ColorString, BlurScope, AnimationOption, ZRColor, AnimationOptionMixin } from '../../util/types';
 import SeriesModel from '../../model/Series';
 import { PathProps } from 'zrender/src/graphic/Path';
 import { SymbolDrawSeriesScope, SymbolDrawItemModelOption } from './SymbolDraw';
@@ -31,6 +31,7 @@ import { extend } from 'zrender/src/core/util';
 import { setLabelStyle, getLabelStatesModels } from '../../label/labelStyle';
 import ZRImage from 'zrender/src/graphic/Image';
 import { saveOldStyle } from '../../animation/basicTrasition';
+import Model from '../../model/Model';
 
 type ECSymbol = ReturnType<typeof createSymbol>;
 
@@ -43,8 +44,6 @@ interface SymbolOpts {
 
 class Symbol extends graphic.Group {
 
-    private _seriesModel: SeriesModel;
-
     private _symbolType: string;
 
     /**
@@ -201,8 +200,6 @@ class Symbol extends graphic.Group {
             // Must stop leave transition manually if don't call initProps or updateProps.
             this.childAt(0).stopAnimation('leave');
         }
-
-        this._seriesModel = seriesModel;
     }
 
     _updateCommon(
@@ -353,12 +350,11 @@ class Symbol extends graphic.Group {
         this.scaleX = this.scaleY = scale;
     }
 
-    fadeOut(cb: () => void, opt?: {
+    fadeOut(cb: () => void, seriesModel: Model<AnimationOptionMixin>, opt?: {
         fadeLabel: boolean,
         animation?: AnimationOption
     }) {
         const symbolPath = this.childAt(0) as ECSymbol;
-        const seriesModel = this._seriesModel;
         const dataIndex = getECData(this).dataIndex;
         const animationOpt = opt && opt.animation;
         // Avoid mistaken hover when fading out
diff --git a/src/chart/helper/SymbolDraw.ts b/src/chart/helper/SymbolDraw.ts
index 77d2f4c..1578278 100644
--- a/src/chart/helper/SymbolDraw.ts
+++ b/src/chart/helper/SymbolDraw.ts
@@ -40,6 +40,7 @@ import Model from '../../model/Model';
 import { ScatterSeriesOption } from '../scatter/ScatterSeries';
 import { getLabelStatesModels } from '../../label/labelStyle';
 import Element from 'zrender/src/Element';
+import SeriesModel from '../../model/Series';
 
 interface UpdateOpt {
     isIgnore?(idx: number): boolean
@@ -51,7 +52,7 @@ interface UpdateOpt {
 
 interface SymbolLike extends graphic.Group {
     updateData(data: SeriesData, idx: number, scope?: SymbolDrawSeriesScope, opt?: UpdateOpt): void
-    fadeOut?(cb: () => void): void
+    fadeOut?(cb: () => void, seriesModel: SeriesModel): void
 }
 
 interface SymbolLikeCtor {
@@ -252,7 +253,7 @@ class SymbolDraw {
                 const el = oldData.getItemGraphicEl(oldIdx) as SymbolLike;
                 el && el.fadeOut(function () {
                     group.remove(el);
-                });
+                }, seriesModel as SeriesModel);
             })
             .execute();
 
@@ -319,7 +320,7 @@ class SymbolDraw {
             data.eachItemGraphicEl(function (el: SymbolLike) {
                 el.fadeOut(function () {
                     group.remove(el);
-                });
+                }, data.hostModel as SeriesModel);
             });
         }
         else {
diff --git a/src/chart/tree/TreeView.ts b/src/chart/tree/TreeView.ts
index 6f9b44a..1a20497 100644
--- a/src/chart/tree/TreeView.ts
+++ b/src/chart/tree/TreeView.ts
@@ -706,7 +706,7 @@ function removeNode(
         removeOpt: removeAnimationOpt
     });
 
-    symbolEl.fadeOut(null, {
+    symbolEl.fadeOut(null, data.hostModel as TreeSeriesModel, {
         fadeLabel: true,
         animation: removeAnimationOpt
     });
diff --git a/test/lib/testHelper.js b/test/lib/testHelper.js
index 41edcd0..b901c7f 100644
--- a/test/lib/testHelper.js
+++ b/test/lib/testHelper.js
@@ -174,7 +174,7 @@
         initRecordCanvas(opt, chart, recordCanvasContainer);
 
         if (opt.recordVideo) {
-            initRecordVideo(chart, recordVideoContainer);
+testHelper.createRecordVideo(chart, recordVideoContainer);
         }
 
         chart.__testHelper = {
@@ -238,7 +238,7 @@
         }
     }
 
-    function initRecordVideo(chart, recordVideoContainer) {
+    testHelper.createRecordVideo = function (chart, recordVideoContainer) {
         var button = document.createElement('button');
         button.innerHTML = 'Start Recording';
         recordVideoContainer.appendChild(button);
diff --git a/test/node/ssr.js b/test/node/ssr.js
index 19312e4..5675f76 100644
--- a/test/node/ssr.js
+++ b/test/node/ssr.js
@@ -29,7 +29,7 @@ chart.setOption({
         {
             name: 'Nightingale Chart',
             type: 'pie',
-            radius: [25, 250],
+            radius: [50, 250],
             center: ['50%', '50%'],
             roseType: 'radius',
             label: {
@@ -49,18 +49,18 @@ chart.setOption({
                 return (1 - idx / 8) * 500;
             },
             data: [
-                { value: 40, name: 'rose 1', itemStyle: { borderRadius: [0, 20] } },
-                { value: 32, name: 'rose 2', itemStyle: { borderRadius: [0, 18] } },
-                { value: 28, name: 'rose 3', itemStyle: { borderRadius: [0, 16] } },
-                { value: 24, name: 'rose 4', itemStyle: { borderRadius: [0, 14] } },
-                { value: 19, name: 'rose 5', itemStyle: { borderRadius: [0, 12] } },
-                { value: 15, name: 'rose 6', itemStyle: { borderRadius: [0, 10] } },
-                { value: 12, name: 'rose 7', itemStyle: { borderRadius: [0, 8] } },
-                { value: 10, name: 'rose 8', itemStyle: { borderRadius: [0, 6] } },
+                { value: 40, name: 'rose 1', itemStyle: { borderRadius: [5, 20] } },
+                { value: 32, name: 'rose 2', itemStyle: { borderRadius: [5, 18] } },
+                { value: 28, name: 'rose 3', itemStyle: { borderRadius: [5, 16] } },
+                { value: 24, name: 'rose 4', itemStyle: { borderRadius: [5, 14] } },
+                { value: 19, name: 'rose 5', itemStyle: { borderRadius: [5, 12] } },
+                { value: 15, name: 'rose 6', itemStyle: { borderRadius: [5, 10] } },
+                { value: 12, name: 'rose 7', itemStyle: { borderRadius: [5, 8] } },
+                { value: 10, name: 'rose 8', itemStyle: { borderRadius: [5, 6] } },
             ],
         },
     ],
 });
-const str = chart.renderToString();
+const str = chart.renderToSVGString();
 console.log(str);
 chart.dispose();
\ 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