Skip to content

Commit

Permalink
fix: when update the position of tooltip, calculate the containerOffs…
Browse files Browse the repository at this point in the history
…et (#6469)
  • Loading branch information
interstellarmt authored Sep 19, 2024
1 parent d8d5394 commit ed5a1d6
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
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

0 comments on commit ed5a1d6

Please sign in to comment.