Skip to content

Commit c104dbe

Browse files
committed
fix: align tooltips by x coordinate
1 parent a151e73 commit c104dbe

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

src/components/ChartContainer.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ export default function ChartContainer({
291291
animations: { colors: false, x: false, y: false },
292292
hover: { animationDuration: 0 },
293293
responsiveAnimationDuration: 0,
294-
interaction: { mode: 'index', intersect: false },
294+
interaction: { mode: 'x', intersect: false },
295295
plugins: {
296296
zoom: {
297297
pan: {
@@ -340,7 +340,7 @@ export default function ChartContainer({
340340
}
341341
},
342342
tooltip: {
343-
mode: 'index',
343+
mode: 'x',
344344
intersect: false,
345345
animation: false,
346346
backgroundColor: 'rgba(15, 23, 42, 0.92)',

src/components/__tests__/ChartContainer.test.jsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,15 @@ describe('ChartContainer', () => {
101101
screen.getByText(//);
102102
expect(onMaxStepChange).toHaveBeenCalledWith(1);
103103

104+
// interaction and tooltip should use x mode to avoid index-based coupling
105+
const opts = __lineProps[0].options;
106+
expect(opts.interaction.mode).toBe('x');
107+
expect(opts.plugins.tooltip.mode).toBe('x');
108+
104109
// simulate hover to trigger sync
105-
const hover = __lineProps[0].options.onHover;
106-
hover({}, [{ index: 0, datasetIndex: 0 }]);
107-
expect(__charts[1].setActiveElements).toHaveBeenCalled();
110+
const hover = __lineProps[0].options.onHover;
111+
hover({}, [{ index: 0, datasetIndex: 0 }]);
112+
expect(__charts[1].setActiveElements).toHaveBeenCalled();
108113
});
109114

110115
it('parses metrics, applies range and triggers callbacks', () => {

0 commit comments

Comments
 (0)