-
Notifications
You must be signed in to change notification settings - Fork 605
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(word-cloud): fix tooltip and add demo for custom tooltip (#1762)
* 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
1 parent
57392a6
commit 187a8d7
Showing
18 changed files
with
326 additions
and
171 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); |
Oops, something went wrong.