Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: pielabel 事件回调对象 #1857

Merged
merged 1 commit into from
Oct 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion packages/f2/src/components/pieLabel/pieLabeView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,15 @@ export default (props) => {
const end = points[points.length - 1];

return (
<group onClick={onClick}>
<group
onClick={
onClick
? () => {
onClick(label);
}
: null
}
>
{/* 锚点 */}
<circle
attrs={{
Expand Down
71 changes: 70 additions & 1 deletion packages/f2/test/components/pieLabel/pieLabel.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { jsx } from '../../../src';
import { Canvas, Chart } from '../../../src';
import { Interval, PieLabel } from '../../../src/components';
import { createContext, delay } from '../../util';
import { createContext, delay, gestureSimulator } from '../../util';

describe('PieLabel', () => {
it('默认显示', async () => {
Expand Down Expand Up @@ -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 } = (
<Canvas context={context} animate={false} pixelRatio={1}>
<Chart
data={data}
coord={{
type: 'polar',
transposed: true,
innerRadius: 0.3,
radius: 0.5,
}}
>
<Interval x="const" y="amount" adjust="stack" color="memo" />
<PieLabel
label1={(data) => {
return {
text: data.memo,
};
}}
label2={(data) => {
return {
fill: '#000000',
text: '$' + data.amount.toFixed(2),
};
}}
onClick={(data) => {
onClickCallback(data);
}}
/>
</Chart>
</Canvas>
);

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',
Expand Down
Loading