Skip to content

Commit

Permalink
refactor(funnel): annotation 位置添加center,支持在漏斗图中正常显示 (#3611)
Browse files Browse the repository at this point in the history
* refactor(funnel): annotation 位置添加center,支持在漏斗图中正常显示

* test(annotation): 补充了单元测试

Co-authored-by: yangtao.yangtao <yangtao.yangtao@alibaba-inc.com>
  • Loading branch information
Aarebecca and yangtao.yangtao authored Sep 10, 2021
1 parent d0224cc commit 552500d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion examples/funnel/funnel/demo/basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ chart.on('beforepaint', () => {
top: true,
position: {
action: obj.action,
percent: 'median',
percent: 'center',
},
content: +obj.percent * 100 + '%', // 显示的文本内容
style: {
Expand Down
4 changes: 3 additions & 1 deletion src/util/annotation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export function getNormalizedValue(val: number | string, scale: Scale) {
switch (val) {
case 'start':
return 0;
case 'center':
return 0.5;
case 'end':
return 1;
case 'median': {
Expand All @@ -37,4 +39,4 @@ export function getNormalizedValue(val: number | string, scale: Scale) {
}

return scale.scale(scaled);
}
}
1 change: 1 addition & 0 deletions tests/unit/util/annotation-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ describe('util annotation', () => {
});

expect(getNormalizedValue('start', scale)).toEqual(0);
expect(getNormalizedValue('center', scale)).toEqual(0.5);
expect(getNormalizedValue('end', scale)).toEqual(1);
expect(near(getNormalizedValue('mean', scale), 0.055999999999999994)).toBe(true);
expect(getNormalizedValue('median', scale)).toEqual(0.065);
Expand Down

0 comments on commit 552500d

Please sign in to comment.