Skip to content

Commit 9c16549

Browse files
committed
fix: expand single-step overlap range
1 parent 57851e5 commit 9c16549

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

src/components/ChartContainer.jsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,14 @@ export default function ChartContainer({
264264
const start = Math.max(...ranges.map(r => r.start));
265265
const end = Math.min(...ranges.map(r => r.end));
266266
if (end >= start) {
267+
let min = start;
268+
let max = end;
269+
if (min === max) {
270+
min -= 1;
271+
max += 1;
272+
}
267273
onXRangeChange(prev => {
268-
const next = { min: start, max: end };
274+
const next = { min, max };
269275
if (prev.min === next.min && prev.max === next.max) return prev;
270276
return next;
271277
});

src/components/__tests__/ChartContainer.test.jsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,20 @@ describe('ChartContainer', () => {
8585
expect(cb({})).toEqual({ min: 2, max: 4 });
8686
});
8787

88+
it('expands range when only a single overlapping step exists', async () => {
89+
const files = [
90+
{ name: 'a.log', id: 'a', content: 'step:1 loss:1\nstep:2 loss:2\nstep:3 loss:3' },
91+
{ name: 'b.log', id: 'b', content: 'step:2 loss:4\nstep:3 loss:5' },
92+
{ name: 'c.log', id: 'c', content: 'step:3 loss:6\nstep:4 loss:7' }
93+
];
94+
const { onXRangeChange } = renderComponent({ files, metrics: [metric], useStepKeyword: true, stepKeyword: 'step:' });
95+
await waitFor(() => {
96+
expect(onXRangeChange).toHaveBeenCalled();
97+
});
98+
const cb = onXRangeChange.mock.calls.at(-1)[0];
99+
expect(cb({})).toEqual({ min: 2, max: 4 });
100+
});
101+
88102
it('computes comparison only on overlapping steps', () => {
89103
const d1 = [{ x: 1, y: 1 }, { x: 2, y: 2 }, { x: 3, y: 3 }];
90104
const d2 = [{ x: 2, y: 2 }, { x: 3, y: 4 }, { x: 4, y: 5 }];

0 commit comments

Comments
 (0)