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: when update the position of tooltip, calculate the containerOffset #6469

Merged
merged 1 commit into from
Sep 19, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions __tests__/plots/bugfix/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { issue6396 } from './issue-6396';
export { issue6399 } from './issue-6399';
59 changes: 59 additions & 0 deletions __tests__/plots/bugfix/issue-6399.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { Chart, PLOT_CLASS_NAME } from '../../../src';

export function issue6399(context) {
const { container, canvas } = context;
const box1 = document.createElement('div', {});
const box2 = document.createElement('div', {});
box1.id = 'box1';
box2.style.height = '4000px';
container.style.height = '100vh';
container.style.overflow = 'auto';
box2.append(box1);
container.append(box2);
const chart = new Chart({
container: box1,
canvas,
});

chart
.line()
.data({
type: 'fetch',
value: 'https://assets.antv.antgroup.com/g2/indices.json',
})
.transform({ type: 'normalizeY', basis: 'first', groupBy: 'color' })
.encode('x', (d) => new Date(d.Date))
.encode('y', 'Close')
.encode('color', 'Symbol')
.axis('y', { title: '↑ Change in price (%)' })
.interaction('tooltip', {
mount: 'body',
crosshairsXStroke: 'red',
crosshairsYStroke: 'blue',
})
.tooltip({
title: (d) => new Date(d.Date).toUTCString(),
items: [
(d, i, data, column) => ({
name: 'Close',
value: column.y.value[i!].toFixed(1),

Check warning on line 39 in __tests__/plots/bugfix/issue-6399.ts

View workflow job for this annotation

GitHub Actions / build

Forbidden non-null assertion
}),
],
})
.label({
text: 'Symbol',
selector: 'last',
fontSize: 10,
});

setTimeout(() => {
container.scrollTo(0, 400);
}, 100);

const finished = chart.render();

return {
chart,
finished,
};
}
1 change: 1 addition & 0 deletions src/interaction/tooltip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ function showTooltip({
title,
position,
enterable,
container: containerOffset,
...(render !== undefined && {
content: render(event, { items, title }),
}),
Expand Down
Loading