Skip to content

Commit

Permalink
fix: tooptip position offset in dodgeX (#6483)
Browse files Browse the repository at this point in the history
  • Loading branch information
lxfu1 authored Oct 8, 2024
1 parent 1470c2e commit df4920f
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
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

0 comments on commit df4920f

Please sign in to comment.