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: tooptip position offset in dodgeX #6483

Merged
merged 1 commit into from
Oct 8, 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,2 +1,3 @@
export { issue6396 } from './issue-6396';
export { issue6399 } from './issue-6399';
export { issueChart2719 } from './issue-chart-2719';
41 changes: 41 additions & 0 deletions __tests__/plots/bugfix/issue-chart-2719.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { Chart } from '../../../src';

export function issueChart2719(context) {
const { container, canvas } = context;
const chart = new Chart({
container: container,
canvas,
});

chart.options({
type: 'interval',
data: {
type: 'fetch',
value:
'https://gw.alipayobjects.com/os/antfincdn/iPY8JFnxdb/dodge-padding.json',
},
encode: {
x: '月份',
y: '月均降雨量',
color: 'name',
},
transform: [
{
type: 'dodgeX',
padding: 0,
},
],
interaction: {
tooltip: {
shared: true,
},
},
});

const finished = chart.render();

return {
chart,
finished,
};
}
10 changes: 9 additions & 1 deletion src/interaction/tooltip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1001,7 +1001,14 @@ export function tooltip(
const scaleSeries = scale.series;
const bandWidth = scaleX?.getBandWidth?.() ?? 0;
const xof = scaleSeries
? (d) => d.__data__.x
? (d) => {
const seriesCount = Math.round(1 / scaleSeries.valueBandWidth);
return (
d.__data__.x +
d.__data__.series * bandWidth +
bandWidth / (seriesCount * 2)
);
}
: (d) => d.__data__.x + bandWidth / 2;

// Sort for bisector search.
Expand All @@ -1023,6 +1030,7 @@ export function tooltip(
const search = bisector(xof).center;
const i = search(elements, abstractX);
const target = elements[i];

if (!shared) {
// For grouped bar chart without shared options.
const isGrouped = elements.find(
Expand Down
Loading