File tree 2 files changed +54
-1
lines changed
__tests__/unit/plots/word-cloud
2 files changed +54
-1
lines changed Original file line number Diff line number Diff line change
1
+ import { WordCloud } from '../../../../src' ;
2
+ import { CountryEconomy } from '../../../data/country-economy' ;
3
+ import { createDiv } from '../../../utils/dom' ;
4
+
5
+ describe ( 'word-cloud changeData' , ( ) => {
6
+ it ( 'changeData: normal' , ( ) => {
7
+ const cloud = new WordCloud ( createDiv ( ) , {
8
+ width : 1024 ,
9
+ height : 1024 ,
10
+ data : CountryEconomy ,
11
+ wordField : 'Country' ,
12
+ weightField : 'GDP' ,
13
+ } ) ;
14
+
15
+ cloud . render ( ) ;
16
+
17
+ expect ( cloud . chart . geometries [ 0 ] . elements . length ) . toEqual ( CountryEconomy . length + 2 ) ;
18
+
19
+ const newData = CountryEconomy . slice ( 0 , 20 ) ;
20
+ cloud . changeData ( newData ) ;
21
+ expect ( cloud . chart . geometries [ 0 ] . elements . length ) . toEqual ( newData . length + 2 ) ;
22
+ expect ( cloud . options . data ) . toEqual ( newData ) ;
23
+
24
+ cloud . destroy ( ) ;
25
+ } ) ;
26
+
27
+ it ( 'changeData: from empty to have data' , ( ) => {
28
+ const cloud = new WordCloud ( createDiv ( ) , {
29
+ width : 1024 ,
30
+ height : 1024 ,
31
+ data : [ ] ,
32
+ wordField : 'Country' ,
33
+ weightField : 'GDP' ,
34
+ } ) ;
35
+
36
+ cloud . render ( ) ;
37
+
38
+ cloud . changeData ( CountryEconomy ) ;
39
+ expect ( cloud . chart . geometries [ 0 ] . elements . length ) . toEqual ( CountryEconomy . length + 2 ) ;
40
+ expect ( cloud . options . data ) . toEqual ( CountryEconomy ) ;
41
+
42
+ cloud . destroy ( ) ;
43
+ } ) ;
44
+ } ) ;
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ import { Datum } from '../../types';
4
4
import { deepAssign } from '../../utils' ;
5
5
import { WordCloudOptions } from './types' ;
6
6
import { adaptor } from './adaptor' ;
7
- import { processImageMask } from './utils' ;
7
+ import { processImageMask , transform } from './utils' ;
8
8
// 注册的shape
9
9
import './shapes/word-cloud' ;
10
10
@@ -14,6 +14,15 @@ export class WordCloud extends Plot<WordCloudOptions> {
14
14
/** 词云图 */
15
15
public type : string = 'word-cloud' ;
16
16
17
+ /**
18
+ * @override
19
+ * @param data
20
+ */
21
+ public changeData ( data ) {
22
+ this . updateOption ( { data } ) ;
23
+ this . chart . changeData ( transform ( { chart : this . chart , options : this . options } ) ) ;
24
+ }
25
+
17
26
/**
18
27
* 获取默认的 options 配置项
19
28
*/
You can’t perform that action at this time.
0 commit comments