From 6b8ea84ee9c27d2dc2ffcca82d81c42566a419ca Mon Sep 17 00:00:00 2001 From: Snacj <0xsnacj@proton.me> Date: Thu, 13 Nov 2025 13:28:30 +0100 Subject: [PATCH 1/3] Switch to Historical Mode will now preserve current scale. --- .../src/components/graph/historicalMode.ts | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/electron/src/components/graph/historicalMode.ts b/electron/src/components/graph/historicalMode.ts index 499744fac..a2708f978 100644 --- a/electron/src/components/graph/historicalMode.ts +++ b/electron/src/components/graph/historicalMode.ts @@ -122,6 +122,30 @@ export function useHistoricalMode({ // Switch to historical mode const switchToHistoricalMode = useCallback(() => { isInHistoricalModeRef.current = true; + + // Preserve current scale + try { + if (uplotRef.current) { + const xScale = uplotRef.current.scales.x; + const yScale = uplotRef.current.scales.y; + manualScaleRef.current = { + x: { + min: xScale?.min ?? 0, + max: xScale?.max ?? 0, + }, + y: { + min: yScale?.min ?? 0, + max: yScale?.max ?? 1, + }, + }; + } + } catch (err) { + console.warn( + "Error preserving chart scales when switching to historical mode:", + err, + ); + } + captureHistoricalFreezeTimestamp(); stopAnimations(animationRefs); lastProcessedCountRef.current = 0; // Reset processed count From 22ab8f32136868086b0e3838f42de01ddfc36f18 Mon Sep 17 00:00:00 2001 From: Snacj <0xsnacj@proton.me> Date: Wed, 19 Nov 2025 18:53:15 +0100 Subject: [PATCH 2/3] Changed Historical Button to work as before. Only keep scale on gesture --- .../src/components/graph/historicalMode.ts | 63 ++++++++++--------- electron/src/components/graph/types.ts | 7 ++- .../components/graph/useBigGraphEffects.ts | 2 +- electron/src/components/graph/useGraphSync.ts | 9 +++ 4 files changed, 50 insertions(+), 31 deletions(-) diff --git a/electron/src/components/graph/historicalMode.ts b/electron/src/components/graph/historicalMode.ts index a2708f978..28c10dddd 100644 --- a/electron/src/components/graph/historicalMode.ts +++ b/electron/src/components/graph/historicalMode.ts @@ -120,36 +120,43 @@ export function useHistoricalMode({ ); // Switch to historical mode - const switchToHistoricalMode = useCallback(() => { - isInHistoricalModeRef.current = true; - - // Preserve current scale - try { - if (uplotRef.current) { - const xScale = uplotRef.current.scales.x; - const yScale = uplotRef.current.scales.y; - manualScaleRef.current = { - x: { - min: xScale?.min ?? 0, - max: xScale?.max ?? 0, - }, - y: { - min: yScale?.min ?? 0, - max: yScale?.max ?? 1, - }, - }; + const switchToHistoricalMode = useCallback( + (origin?: "button" | "gesture" | null) => { + isInHistoricalModeRef.current = true; + + // Preserve current scale + if (origin === "gesture") { + try { + if (uplotRef.current) { + const xScale = uplotRef.current.scales.x; + const yScale = uplotRef.current.scales.y; + manualScaleRef.current = { + x: { + min: xScale?.min ?? 0, + max: xScale?.max ?? 0, + }, + y: { + min: yScale?.min ?? 0, + max: yScale?.max ?? 1, + }, + }; + } + } catch (err) { + console.warn( + "Error preserving chart scales when switching to historical mode:", + err, + ); + } + } else { + manualScaleRef.current = null; } - } catch (err) { - console.warn( - "Error preserving chart scales when switching to historical mode:", - err, - ); - } - captureHistoricalFreezeTimestamp(); - stopAnimations(animationRefs); - lastProcessedCountRef.current = 0; // Reset processed count - }, [captureHistoricalFreezeTimestamp, animationRefs, lastProcessedCountRef]); + captureHistoricalFreezeTimestamp(); + stopAnimations(animationRefs); + lastProcessedCountRef.current = 0; // Reset processed count + }, + [captureHistoricalFreezeTimestamp, animationRefs, lastProcessedCountRef], + ); // Switch back to live mode const switchToLiveMode = useCallback(() => { diff --git a/electron/src/components/graph/types.ts b/electron/src/components/graph/types.ts index beff72807..ee0718da5 100644 --- a/electron/src/components/graph/types.ts +++ b/electron/src/components/graph/types.ts @@ -3,6 +3,8 @@ import { Unit } from "@/control/units"; import { TimeSeries } from "@/lib/timeseries"; import { RefObject } from "react"; +export type SwitchOrigin = "button" | "gesture" | null; + // Prop-based sync types export type PropGraphSync = { timeWindow: number | "all"; @@ -11,6 +13,7 @@ export type PropGraphSync = { xRange?: { min: number; max: number }; historicalFreezeTimestamp?: number | null; showFromTimestamp?: number | null; + historicalSwitchOrigin?: SwitchOrigin; onTimeWindowChange?: (graphId: string, timeWindow: number | "all") => void; onViewModeChange?: ( graphId: string, @@ -83,7 +86,7 @@ export type ControlProps = { isLiveMode: boolean; onTimeWindowChange: (timeWindow: number | "all") => void; onSwitchToLive: () => void; - onSwitchToHistorical: () => void; + onSwitchToHistorical: (origin?: SwitchOrigin) => void; onExport?: () => void; timeWindowOptions?: TimeWindowOption[]; showFromTimestamp?: number | null; @@ -100,7 +103,7 @@ export interface HistoricalModeHandlers { captureHistoricalFreezeTimestamp: () => number; getHistoricalEndTimestamp: () => number; handleHistoricalTimeWindow: (timeWindow: number | "all") => void; - switchToHistoricalMode: () => void; + switchToHistoricalMode: (origin?: SwitchOrigin) => void; switchToLiveMode: () => void; } diff --git a/electron/src/components/graph/useBigGraphEffects.ts b/electron/src/components/graph/useBigGraphEffects.ts index 730bf1539..aab0476bc 100644 --- a/electron/src/components/graph/useBigGraphEffects.ts +++ b/electron/src/components/graph/useBigGraphEffects.ts @@ -175,7 +175,7 @@ export function useBigGraphEffects({ const newIsLiveMode = syncGraph.isLiveMode; if (lastState.isLiveMode && !newIsLiveMode) { - historicalMode.switchToHistoricalMode(); + historicalMode.switchToHistoricalMode(syncGraph.historicalSwitchOrigin); } else if (!lastState.isLiveMode && newIsLiveMode) { historicalMode.switchToLiveMode(); diff --git a/electron/src/components/graph/useGraphSync.ts b/electron/src/components/graph/useGraphSync.ts index a86ce7d39..57d071a18 100644 --- a/electron/src/components/graph/useGraphSync.ts +++ b/electron/src/components/graph/useGraphSync.ts @@ -19,6 +19,7 @@ export function useGraphSync(exportGroupId?: string) { null, ); + const historicalSwitchOriginRef = useRef<"button" | "gesture" | null>(null); const historicalFreezeTimestampRef = useRef(null); const graphDataRef = useRef GraphExportData | null>>( new Map(), @@ -65,6 +66,7 @@ export function useGraphSync(exportGroupId?: string) { showFromTimestamp?: number | null; clearHistoricalFreeze?: boolean; setHistoricalFreeze?: boolean; + historicalSwitchOrigin?: "button" | "gesture" | null; }, requestId?: number, ) => { @@ -104,6 +106,10 @@ export function useGraphSync(exportGroupId?: string) { historicalFreezeTimestampRef.current = Date.now(); } + if (updates.historicalSwitchOrigin !== undefined) { + historicalSwitchOriginRef.current = updates.historicalSwitchOrigin; + } + clearChangeSource(); }); }, @@ -164,6 +170,7 @@ export function useGraphSync(exportGroupId?: string) { viewMode: "manual", isLiveMode: false, setHistoricalFreeze: historicalFreezeTimestampRef.current === null, + historicalSwitchOrigin: "gesture", }); }, [updateSyncState], @@ -210,6 +217,7 @@ export function useGraphSync(exportGroupId?: string) { isLiveMode: false, viewMode: "manual", setHistoricalFreeze: true, + historicalSwitchOrigin: "button", }); }, [updateSyncState]); @@ -242,6 +250,7 @@ export function useGraphSync(exportGroupId?: string) { xRange, historicalFreezeTimestamp: historicalFreezeTimestampRef.current, showFromTimestamp, + historicalSwitchOrigin: historicalSwitchOriginRef.current, onTimeWindowChange: handleTimeWindowChange, onViewModeChange: handleViewModeChange, onZoomChange: handleZoomChangeThrottled, From c34da7e89e3a17017f8ac93531550ab216b00e10 Mon Sep 17 00:00:00 2001 From: Oshgnacknak Date: Wed, 4 Feb 2026 16:42:24 +0100 Subject: [PATCH 3/3] Fix compile errors --- electron/src/components/graph/GraphControls.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/electron/src/components/graph/GraphControls.tsx b/electron/src/components/graph/GraphControls.tsx index a5daa43d4..d171702cb 100644 --- a/electron/src/components/graph/GraphControls.tsx +++ b/electron/src/components/graph/GraphControls.tsx @@ -80,7 +80,7 @@ export function GraphControls({ )} onSwitchToHistorical("button")} variant="outline" className={`h-auto px-3 py-3 text-base font-medium transition-colors ${ !isLiveMode @@ -197,7 +197,7 @@ export function FloatingControlPanel({ )} onSwitchToHistorical("button")} variant="outline" className={`h-auto px-3 py-3 text-base font-medium transition-colors ${ !isLiveMode