-
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.
feat: label.formatter 传参和 label.field 相对应 (#2188)
Co-authored-by: aiyin.lzy <nadia.lzy@antfin.com>
- Loading branch information
1 parent
470577a
commit 159f80c
Showing
6 changed files
with
94 additions
and
24 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 |
---|---|---|
|
@@ -8,6 +8,7 @@ export const TREEMAP_CHILDREN = { | |
{ | ||
name: '其他', | ||
value: 25.0965, | ||
ext: '自定义数据', | ||
}, | ||
], | ||
}, | ||
|
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 |
---|---|---|
@@ -1,25 +1,25 @@ | ||
export const TREEMAP = { | ||
name: 'root', | ||
children: [ | ||
{ name: '分类 1', value: 560 }, | ||
{ name: '分类 2', value: 500 }, | ||
{ name: '分类 3', value: 150 }, | ||
{ name: '分类 4', value: 140 }, | ||
{ name: '分类 5', value: 115 }, | ||
{ name: '分类 6', value: 95 }, | ||
{ name: '分类 7', value: 90 }, | ||
{ name: '分类 8', value: 75 }, | ||
{ name: '分类 9', value: 98 }, | ||
{ name: '分类 10', value: 60 }, | ||
{ name: '分类 11', value: 45 }, | ||
{ name: '分类 12', value: 40 }, | ||
{ name: '分类 13', value: 40 }, | ||
{ name: '分类 14', value: 35 }, | ||
{ name: '分类 15', value: 40 }, | ||
{ name: '分类 16', value: 40 }, | ||
{ name: '分类 17', value: 40 }, | ||
{ name: '分类 18', value: 30 }, | ||
{ name: '分类 19', value: 28 }, | ||
{ name: '分类 20', value: 16 }, | ||
{ name: '分类 1', value: 560, ext: '自定义数据' }, | ||
{ name: '分类 2', value: 500, ext: '自定义数据' }, | ||
{ name: '分类 3', value: 150, ext: '自定义数据' }, | ||
{ name: '分类 4', value: 140, ext: '自定义数据' }, | ||
{ name: '分类 5', value: 115, ext: '自定义数据' }, | ||
{ name: '分类 6', value: 95, ext: '自定义数据' }, | ||
{ name: '分类 7', value: 90, ext: '自定义数据' }, | ||
{ name: '分类 8', value: 75, ext: '自定义数据' }, | ||
{ name: '分类 9', value: 98, ext: '自定义数据' }, | ||
{ name: '分类 10', value: 60, ext: '自定义数据' }, | ||
{ name: '分类 11', value: 45, ext: '自定义数据' }, | ||
{ name: '分类 12', value: 40, ext: '自定义数据' }, | ||
{ name: '分类 13', value: 40, ext: '自定义数据' }, | ||
{ name: '分类 14', value: 35, ext: '自定义数据' }, | ||
{ name: '分类 15', value: 40, ext: '自定义数据' }, | ||
{ name: '分类 16', value: 40, ext: '自定义数据' }, | ||
{ name: '分类 17', value: 40, ext: '自定义数据' }, | ||
{ name: '分类 18', value: 30, ext: '自定义数据' }, | ||
{ name: '分类 19', value: 28, ext: '自定义数据' }, | ||
{ name: '分类 20', value: 16, ext: '自定义数据' }, | ||
], | ||
}; |
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,48 @@ | ||
import { Treemap } from '../../../../src'; | ||
import { createDiv } from '../../../utils/dom'; | ||
import { TREEMAP } from '../../../data/treemap'; | ||
|
||
describe('treemap basic', () => { | ||
it('default treemap', () => { | ||
const treemapPlot = new Treemap(createDiv(), { | ||
data: TREEMAP, | ||
colorField: 'name', | ||
}); | ||
|
||
treemapPlot.render(); | ||
|
||
// @ts-ignore | ||
expect(treemapPlot.chart.geometries[0].labelOption.fields).toEqual(['name']); | ||
|
||
// label with custom | ||
treemapPlot.update({ | ||
label: { | ||
position: 'top', | ||
style: { | ||
textAlign: 'start', | ||
}, | ||
fields: ['name', 'ext'], | ||
formatter: (v) => { | ||
return `${v.name}${v.ext}`; | ||
}, | ||
}, | ||
}); | ||
|
||
// @ts-ignore | ||
expect(treemapPlot.chart.geometries[0].labelOption.fields).toEqual(['name', 'ext']); | ||
// @ts-ignore | ||
expect(treemapPlot.chart.geometries[0].labelOption.cfg.position).toEqual('top'); | ||
expect(treemapPlot.chart.geometries[0].labelsContainer.getChildren()[0].cfg.children[0].attrs.text).toBe( | ||
TREEMAP.children[0].name + TREEMAP.children[0].ext | ||
); | ||
|
||
// label with custom | ||
treemapPlot.update({ | ||
label: false, | ||
}); | ||
|
||
// @ts-ignore | ||
expect(treemapPlot.chart.geometries[0].labelOption).toBeFalsy(); | ||
treemapPlot.destroy(); | ||
}); | ||
}); |
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