diff --git a/packages/f2/src/components/pieLabel/pieLabeView.tsx b/packages/f2/src/components/pieLabel/pieLabeView.tsx index 752138da2..793914523 100644 --- a/packages/f2/src/components/pieLabel/pieLabeView.tsx +++ b/packages/f2/src/components/pieLabel/pieLabeView.tsx @@ -18,7 +18,15 @@ export default (props) => { const end = points[points.length - 1]; return ( - + { + onClick(label); + } + : null + } + > {/* 锚点 */} { it('默认显示', async () => { @@ -64,6 +64,75 @@ describe('PieLabel', () => { expect(context).toMatchImageSnapshot(); }); + it('事件回调对象', async () => { + const onClickCallback = jest.fn(); + const context = createContext('事件回调对象', { width: '300px', height: '150px' }); + const data = [ + { + amount: 20, + memo: 'Study', + const: 'const', + }, + { + amount: 10, + memo: 'Eat', + const: 'const', + }, + { + amount: 20, + memo: 'Sports', + const: 'const', + }, + { + amount: 10, + memo: 'Other', + const: 'const', + }, + ]; + const { props } = ( + + + + { + return { + text: data.memo, + }; + }} + label2={(data) => { + return { + fill: '#000000', + text: '$' + data.amount.toFixed(2), + }; + }} + onClick={(data) => { + onClickCallback(data); + }} + /> + + + ); + + const canvas = new Canvas(props); + await canvas.render(); + + await delay(300); + gestureSimulator(context.canvas, 'click', { x: 266, y: 94 }); + expect(onClickCallback.mock.calls[0][0].origin).toStrictEqual({ + amount: 10, + memo: 'Eat', + const: 'const', + }); + }); + it('左边超过最大显示个数,第四象限显示在第一象限', async () => { const context = createContext('左边超过最大显示个数,第四象限显示在第一象限', { width: '300px',