From 4d69e3f9e529adb202995d1f97b104006907e634 Mon Sep 17 00:00:00 2001 From: Gaurav Tewari Date: Thu, 20 Aug 2026 11:41:49 +0000 Subject: [PATCH] chore: remove last min trim logic in uplotScaleBuilder (#12627) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #### Description - `UPlotScaleBuilder` was overriding the x-axis max with `endTime - 1 minute`, rounded down to the minute — behaviour carried over from the legacy `getXAxisScale`. - On short time windows the trimmed max lands at or before the min, so the scale range is empty/inverted and the chart draws no data. - Removes the trim so the requested `min`/`max` pass through as-is and the scale always matches the selected time range. - Updates the scale builder tests, including a case for a sub-minute window. #### Issues closed by this PR Closes - https://github.com/orgs/SigNoz/projects/39/views/20?pane=issue&itemId=231774376&issue=SigNoz%7Cengineering-pod%7C5902 #### Screenshots / Screen Recordings Before - https://github.com/user-attachments/assets/11ca2fa4-9a07-42eb-9d8d-3a42daf4cfe1 Now - https://github.com/user-attachments/assets/0114fccd-a6ef-4717-8d1c-aa3faf820da7 #### Additional Information - Only the uPlotV2 path changes --------- Co-authored-by: Gaurav Tewari --- .../lib/uPlotV2/config/UPlotScaleBuilder.ts | 11 ------- .../__tests__/UPlotScaleBuilder.test.ts | 32 ++++++++++--------- 2 files changed, 17 insertions(+), 26 deletions(-) diff --git a/frontend/src/lib/uPlotV2/config/UPlotScaleBuilder.ts b/frontend/src/lib/uPlotV2/config/UPlotScaleBuilder.ts index 5c064623fdc..0eaf79b1f9a 100644 --- a/frontend/src/lib/uPlotV2/config/UPlotScaleBuilder.ts +++ b/frontend/src/lib/uPlotV2/config/UPlotScaleBuilder.ts @@ -56,17 +56,6 @@ export class UPlotScaleBuilder extends ConfigBuilder< maxTime = fallbackMax; } - // Align max time to "endTime - 1 minute", rounded down to minute precision - // This matches legacy getXAxisScale behavior and avoids empty space at the right edge - const oneMinuteAgoTimestamp = (maxTime - 60) * 1000; - const currentDate = new Date(oneMinuteAgoTimestamp); - - currentDate.setSeconds(0); - currentDate.setMilliseconds(0); - - const unixTimestampSeconds = Math.floor(currentDate.getTime() / 1000); - maxTime = unixTimestampSeconds; - return { [scaleKey]: { time: true, diff --git a/frontend/src/lib/uPlotV2/config/__tests__/UPlotScaleBuilder.test.ts b/frontend/src/lib/uPlotV2/config/__tests__/UPlotScaleBuilder.test.ts index c24d69c655d..53059cbf527 100644 --- a/frontend/src/lib/uPlotV2/config/__tests__/UPlotScaleBuilder.test.ts +++ b/frontend/src/lib/uPlotV2/config/__tests__/UPlotScaleBuilder.test.ts @@ -44,7 +44,7 @@ describe('UPlotScaleBuilder', () => { expect(adjustSpy).toHaveBeenCalledWith(null, null, undefined, undefined); }); - it('handles time scales using explicit min/max and rounds max down to the previous minute', () => { + it('handles time scales using explicit min/max', () => { const min = 1_700_000_000; // seconds const max = 1_700_000_600; // seconds @@ -62,21 +62,25 @@ describe('UPlotScaleBuilder', () => { expect(xScale.time).toBe(true); expect(xScale.auto).toBe(false); - expect(Array.isArray(xScale.range)).toBe(true); + expect(xScale.range).toStrictEqual([min, max]); + }); - const [resolvedMin, resolvedMax] = xScale.range as [number, number]; + it('keeps short time windows intact', () => { + const min = 1_786_527_160; + const max = 1_786_527_183; - // min is passed through - expect(resolvedMin).toBe(min); + const builder = new UPlotScaleBuilder( + createScaleProps({ + scaleKey: 'x', + time: true, + min, + max, + }), + ); - // max is coerced to "endTime - 1 minute" and rounded down to minute precision - const oneMinuteAgoTimestamp = (max - 60) * 1000; - const currentDate = new Date(oneMinuteAgoTimestamp); - currentDate.setSeconds(0); - currentDate.setMilliseconds(0); - const expectedMax = Math.floor(currentDate.getTime() / 1000); + const config = builder.getConfig(); - expect(resolvedMax).toBe(expectedMax); + expect(config.x.range).toStrictEqual([min, max]); }); it('falls back to getFallbackMinMaxTimeStamp when time scale has no min/max', () => { @@ -99,9 +103,7 @@ describe('UPlotScaleBuilder', () => { expect(getFallbackMinMaxSpy).toHaveBeenCalled(); expect(resolvedMin).toBe(100); - // max is aligned to "fallbackMax - 60 seconds" minute boundary - expect(resolvedMax).toBeLessThanOrEqual(200); - expect(resolvedMax).toBeGreaterThan(100); + expect(resolvedMax).toBe(200); }); it('pipes limits through soft-limit adjustment and log-scale normalization before range config', () => {