Skip to content

Commit

Permalink
fix: tooltip tips 透出 record 参数 (#1947)
Browse files Browse the repository at this point in the history
  • Loading branch information
zengyue authored Mar 28, 2024
1 parent 207e6a5 commit 177fdc6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
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

0 comments on commit 177fdc6

Please sign in to comment.