Skip to content

Commit

Permalink
fix(word-cloud): fix tooltip and add demo for custom tooltip (#1762)
Browse files Browse the repository at this point in the history
* fix(word-cloud): 修复字体颜色问题

* fix(word-cloud): fix tooltip and add demo of custom tooltip

* chore: modify test

* chore: 处理之后的数据不与用户的数据合并

* feat(word-cloud): add colorField option

* chore: add test for 1754

* refactor: 优化代码

* chore: 调整单侧

* chore: 优化colorField
  • Loading branch information
zhangzhonghe authored Oct 22, 2020
1 parent 57392a6 commit 187a8d7
Show file tree
Hide file tree
Showing 18 changed files with 326 additions and 171 deletions.
35 changes: 35 additions & 0 deletions __tests__/bugs/issue-1754-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { TooltipCfg } from '@antv/g2/lib/interface';
import { WordCloud } from '../../src';
import { CountryEconomy } from '../data/country-economy';
import { createDiv } from '../utils/dom';

describe('issue 1754', () => {
it('customContent', () => {
const cloud = new WordCloud(createDiv(), {
width: 400,
height: 300,
data: CountryEconomy,
wordField: 'Country',
weightField: 'GDP',
});

const data = [
{
data: { text: 'name', value: 'weight' },
mappingData: { color: 'red' },
},
];
const result =
'<li class="g2-tooltip-list-item" style="margin-bottom:4px;display:flex;align-items:center;">' +
'<span style="background-color:red;" class="g2-tooltip-marker"></span>' +
'<span style="display:inline-flex;flex:1;justify-content:space-between">' +
'<span style="margin-right: 16px;">name:</span><span>weight</span>' +
'</span>' +
'</li>';

cloud.render();

const customContent = (cloud.chart.getOptions().tooltip as TooltipCfg).customContent;
expect(customContent(undefined, data)).toBe(result);
});
});
68 changes: 68 additions & 0 deletions __tests__/unit/plots/word-cloud/color-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { WordCloud } from '../../../../src';
import { CountryEconomy } from '../../../data/country-economy';
import { createDiv } from '../../../utils/dom';

describe('word-cloud color option', () => {
it('default', () => {
const cloud = new WordCloud(createDiv(), {
width: 400,
height: 300,
data: CountryEconomy,
wordField: 'Country',
weightField: 'GDP',
});

cloud.render();

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

it('wordField', () => {
const cloud = new WordCloud(createDiv(), {
width: 400,
height: 300,
data: CountryEconomy,
wordField: 'Country',
weightField: 'GDP',
colorField: 'Country', // wordField 字段值
});

cloud.render();

const field = cloud.chart.geometries[0].getGroupFields()[0];
expect(field).toBe('color');
});

it('weightField', () => {
const cloud = new WordCloud(createDiv(), {
width: 400,
height: 300,
data: CountryEconomy,
wordField: 'Country',
weightField: 'GDP',
colorField: 'GDP', // weightField 字段值
});

cloud.render();

const field = cloud.chart.geometries[0].getGroupFields()[0];
expect(field).toBe('color');
});

it('x', () => {
const cloud = new WordCloud(createDiv(), {
width: 400,
height: 300,
data: CountryEconomy,
wordField: 'Country',
weightField: 'GDP',
colorField: 'x',
});

cloud.render();

const field = cloud.chart.geometries[0].getGroupFields()[0];
expect(field).toBe('color');
});
});
4 changes: 2 additions & 2 deletions __tests__/unit/plots/word-cloud/style-spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { WordCloud } from '../../../../src';
import { CountryEconomy } from '../../../data/country-economy';
import { createDiv } from '../../../utils/dom';
import { DataItem } from '../../../../src/plots/word-cloud/types';
import { Tag } from '../../../../src/plots/word-cloud/types';

describe('word-cloud', () => {
it('style', () => {
Expand All @@ -22,7 +22,7 @@ describe('word-cloud', () => {

const { data } = cloud.chart.getOptions();

data.forEach((item: DataItem) => {
data.forEach((item: Tag) => {
// DataSet 处理之后会多出两个无用的数据
if (!item.hasText) return;

Expand Down
63 changes: 18 additions & 45 deletions __tests__/unit/utils/transform/word-cloud-spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import DataSet from '@antv/data-set';
import { DataItem } from '../../../../src/plots/word-cloud/types';
import { Tag, Word } from '../../../../src/plots/word-cloud/types';
import { processImageMask } from '../../../../src/plots/word-cloud/utils';
import { wordCloud, transform } from '../../../../src/utils/transform/word-cloud';

type Row = Pick<DataItem, 'text' | 'value'>;

const { View } = DataSet;
const options = {
type: 'tag-cloud',
Expand All @@ -22,11 +20,10 @@ const data = ['Hello', 'world', 'normally', 'you', 'want', 'more', 'words', 'tha
return {
text: d,
value: 5 + Math.random() * 10,
test: 'haha',
};
});

function basicCommon(v: DataItem) {
function basicCommon(v: Tag) {
expect(v.hasText).toBe(true);
expect(typeof v.text).toBe('string');
expect(typeof v.value).toBe('number');
Expand All @@ -52,7 +49,7 @@ describe('word-cloud', () => {
delete v.x;
delete v.y;
}
const result1 = wordCloud(data, options as any);
const result1 = wordCloud(data as Word[], options as any);
const result2 = dv.rows;

result1.forEach(removeXY);
Expand All @@ -62,32 +59,32 @@ describe('word-cloud', () => {
});

it('default', () => {
const result = wordCloud(data);
const result = wordCloud(data as Word[]);
basicCommon(result[0]);
});

it('callback', () => {
const common = (row: Row) => {
const common = (row: Word) => {
expect(typeof row.text).toBe('string');
expect(typeof row.value).toBe('number');
};
const font = (row: Row) => {
const font = (row: Word) => {
common(row);
return 'font-test';
};
const fontWeight = (row: Row): any => {
const fontWeight = (row: Word): any => {
common(row);
return 'fontWeight-test';
};
const fontSize = (row: Row) => {
const fontSize = (row: Word) => {
common(row);
return 11;
};
const rotate = (row: Row) => {
const rotate = (row: Word) => {
common(row);
return 22;
};
const padding = (row: Row) => {
const padding = (row: Word) => {
common(row);
return 33;
};
Expand All @@ -100,7 +97,7 @@ describe('word-cloud', () => {
};
};

const result = wordCloud(data, {
const result = wordCloud(data as Word[], {
font,
fontWeight,
fontSize,
Expand All @@ -127,51 +124,30 @@ describe('word-cloud', () => {
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAcoAAADHCAIAAAAWF4ThAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAAEnQAABJ0Ad5mH3gAAA5GSURBVHhe7d1teuOoFkXhO5+MJ/PxeDyezKcvyKTixLYEnLMPIK/3Vz9dHxYCluRUrPzvPwCAAHkFAAnyCgAS5BUAJMgrAEiQVwCQIK8AIEFeAUCCvA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fGZtgmr48x/m2ef1n62xAaNPysd+qPkFej5FXL7e7Es/dcnsoSvnrZ+HydUTlwJbJ653ytJt0Zs3nNv8Vn6mn1Q+LBZaSQ7vtlbLiW2y3Gop7DWfbEBtHmDe+fmgr5vVRSmNO7k1aTE+kgBbbbyaleEPb0r9tg4dtku8xsqV3x/fw8iXll+/9Hzu6c+QVAKZDXgFAgrwCgAR5BQAJ8goAEuQVACTIKwBIkFcAkCCvACBBXgFAgrwCgAR5BQAJ8goAEuQVACTIKwBIkFcAkCCvACBBXgFAgrwCgAR5BQAJ8goAEuQVACTIKwBIkFcAkCCvACBBXgFAgrwCgAR5BQAJ8goAEuQVACTIKwBIkFcAkCCvACBBXgFAgrwCgAR5BQAJ8goAEuQVACTIKwBIkFcAkCCvACBBXgFAgrwCgAR5BQAJ8goAEuQVAAT+++//CT3TAOpn61kAAAAASUVORK5CYII=';

const img = await processImageMask(base64);
const result = wordCloud(data, { imageMask: img });
const result = wordCloud(data as Word[], { imageMask: img });
basicCommon(result[0]);
});

it('spiral is rectangular', () => {
const result = wordCloud(data, { spiral: 'rectangular' });
const result = wordCloud(data as Word[], { spiral: 'rectangular' });
basicCommon(result[0]);
});
});

describe('transform', () => {
it('default', () => {
const result = transform(data, {
fields: ['text', 'value'],
const result = transform(data as Word[], {
size: [800, 800],
});
basicCommon(result[0]);
});

it('error of fields', () => {
expect(() => {
transform(data, {
fields: [null, null],
size: [800, 800],
});
}).toThrow();
});

it('fields is not exit', () => {
const result = transform(data, {
fields: ['a', 'b'],
size: [800, 800],
});

expect(result[0].text).toBe(undefined);
expect(result[0].value).toBe(undefined);
});

it('image mask with size is 0', async () => {
const base64 =
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAcoAAADHCAIAAAAWF4ThAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAAEnQAABJ0Ad5mH3gAAA5GSURBVHhe7d1teuOoFkXhO5+MJ/PxeDyezKcvyKTixLYEnLMPIK/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VmqjvZ20fqypH1Ia/HyKtB7IYZUtZv7l92fr+8FvlD0MMym9aQ2yIir8fIq5l8u2xfGZtgmr48x/m2ef1n62xAaNPysd+qPkFej5FXL7e7Es/dcnsoSvnrZ+HydUTlwJbJ653ytJt0Zs3nNv8Vn6mn1Q+LBZaSQ7vtlbLiW2y3Gop7DWfbEBtHmDe+fmgr5vVRSmNO7k1aTE+kgBbbbyaleEPb0r9tg4dtku8xsqV3x/fw8iXll+/9Hzu6c+QVAKZDXgFAgrwCgAR5BQAJ8goAEuQVACTIKwBIkFcAkCCvACBBXgFAgrwCgAR5BQAJ8goAEuQVACTIKwBIkFcAkCCvACBBXgFAgrwCgAR5BQAJ8goAEuQVACTIKwBIkFcAkCCvACBBXgFAgrwCgAR5BQAJ8goAEuQVACTIKwBIkFcAkCCvACBBXgFAgrwCgAR5BQAJ8goAEuQVACTIKwBIkFcAkCCvACBBXgFAgrwCgAR5BQAJ8goAEuQVAAT+++//CT3TAOpn61kAAAAASUVORK5CYII=';

const img = await processImageMask(base64);
const result = transform(data, {
fields: ['text', 'value'],
const result = transform(data as Word[], {
size: [0, 0],
imageMask: img,
});
Expand All @@ -182,8 +158,7 @@ describe('transform', () => {
});

it('timeInterval is 0', () => {
const result = transform(data, {
fields: ['text', 'value'],
const result = transform(data as Word[], {
size: [800, 800],
timeInterval: 0,
});
Expand All @@ -194,17 +169,15 @@ describe('transform', () => {
});

it('padding is 0', () => {
const result = transform(data, {
fields: ['text', 'value'],
const result = transform(data as Word[], {
size: [800, 800],
padding: 0,
});
basicCommon(result[0]);
});

it('rotate is 0', () => {
const result = transform(data, {
fields: ['text', 'value'],
const result = transform(data as Word[], {
size: [800, 800],
rotate: 0,
});
Expand Down
8 changes: 8 additions & 0 deletions docs/manual/plots/word-cloud.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ order: 0

默认配置: 无

#### colorField

**可选**, _string_

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

默认配置: 无

#### timeInterval

**可选**, _number_
Expand Down
10 changes: 9 additions & 1 deletion docs/manual/plots/word-cloud.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: 词云图
order: 0
---


## 配置属性

### 图表容器
Expand Down Expand Up @@ -37,6 +37,14 @@ order: 0

默认配置: 无

#### colorField

**可选**, _string_

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

默认配置: 无

#### timeInterval

**可选**, _number_
Expand Down
8 changes: 8 additions & 0 deletions examples/word-cloud/basic/API.en.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@

默认配置: 无

#### colorField

**可选**, _string_

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

默认配置: 无

#### timeInterval

**可选**, _number_
Expand Down
21 changes: 21 additions & 0 deletions examples/word-cloud/basic/demo/color-field.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { WordCloud } from '@antv/g2plot';

fetch('https://gw.alipayobjects.com/os/antvdemo/assets/data/antv-keywords.json')
.then((res) => res.json())
.then((data) => {
const wordCloud = new WordCloud('container', {
data,
width: 600,
height: 400,
wordField: 'name',
weightField: 'value',
colorField: 'value',
imageMask: 'https://gw.alipayobjects.com/mdn/rms_2274c3/afts/img/A*07tdTIOmvlYAAAAAAAAAAABkARQnAQ',
wordStyle: {
fontFamily: 'Verdana',
fontSize: [8, 32],
},
});

wordCloud.render();
});
Loading

0 comments on commit 187a8d7

Please sign in to comment.