@@ -29,12 +29,16 @@ function dispatchEvent(el, event, type) {
29
29
30
30
Component ( {
31
31
didMount ( ) {
32
+ const { onUpdate, onClear } = this . props ;
33
+ onUpdate && onUpdate ( this . createChart . bind ( this ) ) ;
34
+ onClear && onClear ( this . clear . bind ( this ) ) ;
32
35
this . createChart ( ) ;
33
36
} ,
34
37
didUpdate ( ) {
35
38
const { canvas, props } = this ;
36
39
if ( ! canvas ) return ;
37
40
const { theme, px2hd, reCreateOnUpdate } = props ;
41
+
38
42
if ( reCreateOnUpdate ) {
39
43
canvas . destroy ( ) ;
40
44
this . canvas = null ;
@@ -53,9 +57,7 @@ Component({
53
57
} ) ;
54
58
} ,
55
59
didUnmount ( ) {
56
- const { canvas } = this ;
57
- if ( ! canvas ) return ;
58
- canvas . destroy ( ) ;
60
+ this . clear ( ) ;
59
61
} ,
60
62
methods : {
61
63
createChart ( ) {
@@ -86,6 +88,25 @@ Component({
86
88
} ) ;
87
89
} ,
88
90
91
+ clear ( ) {
92
+ const canvas = this . canvas ;
93
+ if ( ! canvas ) return ;
94
+ const { width, height } = this . props ;
95
+ const { rpx2px, pixelRatio } = this . data ;
96
+ try {
97
+ canvas . context . ctx . clearRect (
98
+ 0 ,
99
+ 0 ,
100
+ width * rpx2px * pixelRatio ,
101
+ height * rpx2px * pixelRatio ,
102
+ ) ;
103
+ canvas . destroy ( ) ;
104
+ this . canvas = null ;
105
+ } catch ( error ) {
106
+ this . catchError ( error ) ;
107
+ }
108
+ } ,
109
+
89
110
catchError ( error ) {
90
111
console . error ( '图表渲染失败: ' , error ) ;
91
112
const { onError } = this . props ;
@@ -126,9 +147,9 @@ Component({
126
147
. select ( `f-web-canvas-${ this . $id } ` )
127
148
//@ts -ignore
128
149
. node ( )
129
- . exec ( ( time ) => {
150
+ . exec ( ( ) => {
130
151
// api 执行结束后的下一个通信才会上屏
131
- onCanvasRender && onCanvasRender ( time ) ;
152
+ onCanvasRender && onCanvasRender ( ) ;
132
153
} ) ;
133
154
} ,
134
155
// @ts -ignore
0 commit comments