Skip to content

Commit

Permalink
chore: 优化colorField
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangzhonghe committed Oct 22, 2020
1 parent 4ef598b commit bf85063
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 9 deletions.
4 changes: 2 additions & 2 deletions __tests__/unit/plots/word-cloud/color-spec.ts
Expand Up @@ -14,8 +14,8 @@ describe('word-cloud color option', () => {

cloud.render();

const field = cloud.chart.geometries[0].getGroupFields()[0];
expect(field).toBe('text');
const fields = cloud.chart.geometries[0].getGroupFields();
expect(fields.length).toBe(1);
});

it('wordField', () => {
Expand Down
2 changes: 1 addition & 1 deletion docs/manual/plots/word-cloud.en.md
Expand Up @@ -43,7 +43,7 @@ order: 0

功能描述: 根据该字段进行颜色映射

默认配置: wordField 字段的值
默认配置:

#### timeInterval

Expand Down
2 changes: 1 addition & 1 deletion docs/manual/plots/word-cloud.zh.md
Expand Up @@ -43,7 +43,7 @@ order: 0

功能描述: 根据该字段进行颜色映射

默认配置: wordField 字段的值
默认配置:

#### timeInterval

Expand Down
8 changes: 8 additions & 0 deletions examples/word-cloud/basic/API.en.md
Expand Up @@ -32,6 +32,14 @@

默认配置: 无

#### colorField

**可选**, _string_

功能描述: 根据该字段进行颜色映射

默认配置: 无

#### timeInterval

**可选**, _number_
Expand Down
8 changes: 8 additions & 0 deletions examples/word-cloud/basic/API.zh.md
Expand Up @@ -32,6 +32,14 @@

默认配置: 无

#### colorField

**可选**, _string_

功能描述: 根据该字段进行颜色映射

默认配置: 无

#### timeInterval

**可选**, _number_
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -55,7 +55,7 @@
},
"dependencies": {
"@antv/event-emitter": "^0.1.2",
"@antv/g2": "^4.1.0-beta.13",
"@antv/g2": "^4.1.0-beta.14",
"d3-hierarchy": "^2.0.0",
"dayjs": "^1.8.36",
"size-sensor": "^1.0.1",
Expand Down
4 changes: 1 addition & 3 deletions src/plots/word-cloud/adaptor.ts
Expand Up @@ -21,9 +21,7 @@ function geometry(params: Params<WordCloudOptions>): Params<WordCloudOptions> {
options: {
xField: 'x',
yField: 'y',
// 给 seriesField 一个默认值,否则它为空时
// 每个词语的颜色会显示成白色。
seriesField: colorField ? 'color' : 'text',
seriesField: colorField && 'color',
point: {
color,
shape: 'word-cloud',
Expand Down
2 changes: 1 addition & 1 deletion src/plots/word-cloud/shapes/word-cloud.ts
Expand Up @@ -33,7 +33,7 @@ function getTextAttrs(cfg: Config): ShapeAttrs {
textAlign: 'center',
fontFamily: cfg.data.font,
fontWeight: cfg.data.weight,
fill: cfg.color,
fill: cfg.color || cfg.defaultStyle.fill,
textBaseline: 'alphabetic',
};
}

0 comments on commit bf85063

Please sign in to comment.