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: tooltip tips 透出 record 参数 #1947

Merged
merged 1 commit into from
Mar 28, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/f2/src/components/tooltip/tooltipView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ const RenderXTip = (props) => {
xPositionType === 'coord'
? coordData.xText
: isFunction(xTip)
? xTip(xFirstText)
? xTip(xFirstText, firstRecord)
: xFirstText,
}}
/>
Expand Down Expand Up @@ -250,7 +250,7 @@ const RenderYTip = (props) => {
yPositionType === 'coord'
? coordData.yText
: isFunction(yTip)
? yTip(yFirstText)
? yTip(yFirstText, firstRecord)
: yFirstText,
}}
/>
Expand Down
1 change: 1 addition & 0 deletions packages/f2/src/components/tooltip/withTooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export interface TooltipProps {
showTooltipMarker?: boolean;
customText?: any;
markerBackgroundStyle?: any;
[key: string]: any;
}

export interface TooltipState {
Expand Down
14 changes: 14 additions & 0 deletions packages/f2/test/components/tooltip/tooltip.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,8 @@ describe('tooltip', () => {
});

it('Tooltip-xTip-yTip相关配置', async () => {
const xTipFn = jest.fn();
const yTipFn = jest.fn();
const context = createContext('Tooltip xTip yTip相关配置');
const { props } = (
<Canvas context={context} pixelRatio={1} animate={false}>
Expand Down Expand Up @@ -448,6 +450,14 @@ describe('tooltip', () => {
fill: 'red',
text: '',
}}
xTip={(text, record) => {
xTipFn(text, record);
return text;
}}
yTip={(text, record) => {
yTipFn(text, record);
return text;
}}
/>
</Chart>
</Canvas>
Expand All @@ -460,6 +470,10 @@ describe('tooltip', () => {

await delay(100);
expect(context).toMatchImageSnapshot();
expect(xTipFn.mock.calls.length).toBe(1);
expect(yTipFn.mock.calls.length).toBe(1);
expect(xTipFn.mock.calls[0][1]).toBeDefined();
expect(yTipFn.mock.calls[0][1]).toBeDefined();
});

it('Tooltip 自动换行', async () => {
Expand Down