-
Notifications
You must be signed in to change notification settings - Fork 605
/
index-spec.ts
45 lines (40 loc) · 1.31 KB
/
index-spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { deepMix } from '@antv/util';
import { WordCloud } from '../../../../src';
import { CountryEconomy } from '../../../data/country-economy';
import { createDiv } from '../../../utils/dom';
describe('word-cloud', () => {
const options = {
width: 400,
height: 300,
data: CountryEconomy,
wordField: 'Country',
weightField: 'GDP',
};
it('x*y', () => {
const cloud = new WordCloud(createDiv('x*y'), options);
cloud.render();
const geometry = cloud.chart.geometries[0];
const positionFields = geometry.getAttribute('position').getFields();
// 类型
expect(geometry.type).toBe('point');
// x & y
expect(positionFields).toHaveLength(2);
// 数据经过 DataSet 处理过,这里是处理之后的数据中的 x 和 y 字段
expect(positionFields[0]).toBe('_x');
expect(positionFields[1]).toBe('_y');
});
it('imageMask', () => {
const options1 = deepMix({}, options, {
imageMask: new Image(),
});
const options2 = deepMix({}, options, {
imageMask: 'ssss', // 无效值
});
const cloud1 = new WordCloud(createDiv('x*y'), options1);
const cloud2 = new WordCloud(createDiv('x*y'), options2);
expect(() => {
cloud1.render();
cloud2.render();
}).not.toThrow();
});
});