File tree 2 files changed +23
-0
lines changed
2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -203,4 +203,20 @@ describe('core', () => {
203
203
expect ( line . chart . limitInPlot ) . toBe ( true ) ;
204
204
line . destroy ( ) ;
205
205
} ) ;
206
+
207
+ it ( 'plot dataset sourceType' , ( ) => {
208
+ const container = createDiv ( '' ) ;
209
+ const line = new Line ( container , {
210
+ data : partySupport . filter ( ( o ) => o . type === 'FF' ) ,
211
+ xField : 'date' ,
212
+ yField : 'value' ,
213
+ } ) ;
214
+
215
+ line . render ( ) ;
216
+
217
+ expect ( container . dataset . chartSourceType ) . toBe ( 'G2Plot' ) ;
218
+ line . destroy ( ) ;
219
+
220
+ expect ( container . dataset . chartSourceType ) . toBe ( undefined ) ;
221
+ } ) ;
206
222
} ) ;
Original file line number Diff line number Diff line change @@ -22,6 +22,8 @@ export type PickOptions = Pick<
22
22
| 'limitInPlot'
23
23
> ;
24
24
25
+ const SOURCE_ATTRIBUTE_NAME = 'data-chart-source-type' ;
26
+
25
27
/**
26
28
* 所有 plot 的基类
27
29
*/
@@ -77,6 +79,9 @@ export abstract class Plot<O extends PickOptions> extends EE {
77
79
supportCSSTransform,
78
80
limitInPlot,
79
81
} ) ;
82
+
83
+ // 给容器增加标识,知道图表的来源区别于 G2
84
+ this . container . setAttribute ( SOURCE_ATTRIBUTE_NAME , 'G2Plot' ) ;
80
85
}
81
86
82
87
/**
@@ -229,6 +234,8 @@ export abstract class Plot<O extends PickOptions> extends EE {
229
234
this . chart . destroy ( ) ;
230
235
// 清空已经绑定的事件
231
236
this . off ( ) ;
237
+
238
+ this . container . removeAttribute ( SOURCE_ATTRIBUTE_NAME ) ;
232
239
}
233
240
234
241
/**
You can’t perform that action at this time.
0 commit comments