From 5caa74fa275dd7385a0669a70fb0cb53df6f90c5 Mon Sep 17 00:00:00 2001 From: Miguel Date: Fri, 15 Aug 2025 13:17:08 +0200 Subject: [PATCH] feat: Add detailed logging for plot sessions, update plot configuration, and enhance chart handling --- application_events.json | 171 +++++++++++++++++++++++- config/data/plot_definitions.json | 4 +- config/data/plot_variables.json | 4 +- frontend/src/components/ChartjsPlot.jsx | 28 +++- system_state.json | 4 +- 5 files changed, 198 insertions(+), 13 deletions(-) diff --git a/application_events.json b/application_events.json index 7029126..933fd19 100644 --- a/application_events.json +++ b/application_events.json @@ -4979,8 +4979,175 @@ "trigger_variable": null, "auto_started": true } + }, + { + "timestamp": "2025-08-15T13:06:24.612602", + "level": "info", + "event_type": "plot_session_created", + "message": "Plot session 'UR29' created and started", + "details": { + "session_id": "plot_1", + "variables": [ + "UR29_Brix", + "UR29_ma", + "AUX Blink_1.0S", + "AUX Blink_1.6S" + ], + "time_window": 10, + "trigger_variable": null, + "auto_started": true + } + }, + { + "timestamp": "2025-08-15T13:06:48.036346", + "level": "info", + "event_type": "plot_session_created", + "message": "Plot session 'UR29' created and started", + "details": { + "session_id": "plot_1", + "variables": [ + "UR29_Brix", + "UR29_ma", + "AUX Blink_1.0S", + "AUX Blink_1.6S" + ], + "time_window": 10, + "trigger_variable": null, + "auto_started": true + } + }, + { + "timestamp": "2025-08-15T13:06:54.887448", + "level": "info", + "event_type": "plot_session_created", + "message": "Plot session 'UR29' created and started", + "details": { + "session_id": "plot_1", + "variables": [ + "UR29_Brix", + "UR29_ma", + "AUX Blink_1.0S", + "AUX Blink_1.6S" + ], + "time_window": 10, + "trigger_variable": null, + "auto_started": true + } + }, + { + "timestamp": "2025-08-15T13:14:31.424812", + "level": "info", + "event_type": "application_started", + "message": "Application initialization completed successfully", + "details": {} + }, + { + "timestamp": "2025-08-15T13:14:31.473155", + "level": "info", + "event_type": "dataset_activated", + "message": "Dataset activated: DAR", + "details": { + "dataset_id": "DAR", + "variables_count": 2, + "streaming_count": 2, + "prefix": "gateway_phoenix" + } + }, + { + "timestamp": "2025-08-15T13:14:31.480168", + "level": "info", + "event_type": "dataset_activated", + "message": "Dataset activated: Fast", + "details": { + "dataset_id": "Fast", + "variables_count": 2, + "streaming_count": 1, + "prefix": "fast" + } + }, + { + "timestamp": "2025-08-15T13:14:31.487149", + "level": "info", + "event_type": "csv_recording_started", + "message": "CSV recording started: 2 datasets activated", + "details": { + "activated_datasets": 2, + "total_datasets": 3 + } + }, + { + "timestamp": "2025-08-15T13:14:39.254547", + "level": "info", + "event_type": "plot_session_created", + "message": "Plot session 'UR29' created and started", + "details": { + "session_id": "plot_1", + "variables": [ + "UR29_Brix", + "UR29_ma", + "AUX Blink_1.0S", + "AUX Blink_1.6S" + ], + "time_window": 10, + "trigger_variable": null, + "auto_started": true + } + }, + { + "timestamp": "2025-08-15T13:14:59.673582", + "level": "info", + "event_type": "plot_session_created", + "message": "Plot session 'UR29' created and started", + "details": { + "session_id": "plot_1", + "variables": [ + "UR29_Brix", + "UR29_ma", + "AUX Blink_1.0S", + "AUX Blink_1.6S" + ], + "time_window": 10, + "trigger_variable": null, + "auto_started": true + } + }, + { + "timestamp": "2025-08-15T13:15:06.665880", + "level": "info", + "event_type": "plot_session_created", + "message": "Plot session 'UR29' created and started", + "details": { + "session_id": "plot_1", + "variables": [ + "UR29_Brix", + "UR29_ma", + "AUX Blink_1.0S", + "AUX Blink_1.6S" + ], + "time_window": 10, + "trigger_variable": null, + "auto_started": true + } + }, + { + "timestamp": "2025-08-15T13:15:29.776996", + "level": "info", + "event_type": "plot_session_created", + "message": "Plot session 'UR29' created and started", + "details": { + "session_id": "plot_1", + "variables": [ + "UR29_Brix", + "UR29_ma", + "AUX Blink_1.0S", + "AUX Blink_1.6S" + ], + "time_window": 10, + "trigger_variable": null, + "auto_started": true + } } ], - "last_updated": "2025-08-15T13:04:44.329049", - "total_entries": 434 + "last_updated": "2025-08-15T13:15:29.776996", + "total_entries": 445 } \ No newline at end of file diff --git a/config/data/plot_definitions.json b/config/data/plot_definitions.json index a8b4619..f6a3565 100644 --- a/config/data/plot_definitions.json +++ b/config/data/plot_definitions.json @@ -6,9 +6,9 @@ "name": "UR29", "point_hover_radius": 4, "point_radius": 0, - "stacked": true, + "stacked": false, "stepped": true, - "time_window": 36, + "time_window": 10, "trigger_enabled": false, "trigger_on_true": true, "trigger_variable": null, diff --git a/config/data/plot_variables.json b/config/data/plot_variables.json index b241a24..3b7122f 100644 --- a/config/data/plot_variables.json +++ b/config/data/plot_variables.json @@ -23,14 +23,14 @@ "variable_name": "AUX Blink_1.0S", "color": "#3498db", "line_width": 2, - "y_axis": "left", + "y_axis": "right", "enabled": true }, { "variable_name": "AUX Blink_1.6S", "color": "#630de3", "line_width": 2, - "y_axis": "left", + "y_axis": "right", "enabled": true } ] diff --git a/frontend/src/components/ChartjsPlot.jsx b/frontend/src/components/ChartjsPlot.jsx index 2556390..d7cfadf 100644 --- a/frontend/src/components/ChartjsPlot.jsx +++ b/frontend/src/components/ChartjsPlot.jsx @@ -347,9 +347,20 @@ const ChartjsPlot = ({ session, height = '400px' }) => { }, []); const createStreamingChart = useCallback(async () => { - const cfg = resolvedConfigRef.current || session?.config; + // Ensure we have the most up-to-date config + const sessionConfig = session?.config; + const resolvedConfig = resolvedConfigRef.current; + + // Prefer session config if it's newer or if resolved config is missing + const cfg = sessionConfig || resolvedConfig; + if (!canvasRef.current || !cfg) return; + // Update resolvedConfigRef to ensure consistency + if (sessionConfig && (!resolvedConfig || JSON.stringify(sessionConfig) !== JSON.stringify(resolvedConfig))) { + resolvedConfigRef.current = sessionConfig; + } + console.log(`🔧 Creating chart for session ${session?.session_id}...`); try { @@ -1382,6 +1393,7 @@ const ChartjsPlot = ({ session, height = '400px' }) => { const needsRecreation = !oldConfig || oldConfig.line_tension !== newConfig.line_tension || oldConfig.stepped !== newConfig.stepped || + oldConfig.stacked !== newConfig.stacked || oldConfig.point_radius !== newConfig.point_radius || oldConfig.point_hover_radius !== newConfig.point_hover_radius || oldConfig.time_window !== newConfig.time_window || @@ -1486,13 +1498,19 @@ const ChartjsPlot = ({ session, height = '400px' }) => { } }, [session?.is_active, session?.is_paused, pauseStreaming, resumeStreaming]); - // Recreate chart when fullscreen mode changes to enable/disable zoom + // Handle fullscreen mode changes more gracefully useEffect(() => { if (chartRef.current && typeof session?.isFullscreen === 'boolean') { - console.log(`🔄 Fullscreen mode changed to ${session.isFullscreen}, recreating chart...`); - createStreamingChart(); + console.log(`🔄 Fullscreen mode changed to ${session.isFullscreen}`); + // Instead of recreating the chart, just trigger a resize and update zoom state + setTimeout(() => { + if (chartRef.current) { + chartRef.current.resize(); + console.log(`📐 Chart resized for fullscreen: ${session.isFullscreen}`); + } + }, 100); // Small delay to allow modal animation to complete } - }, [session?.isFullscreen, createStreamingChart]); + }, [session?.isFullscreen]); // Update zoom configuration when zoom enabled state changes useEffect(() => { diff --git a/system_state.json b/system_state.json index 1ac24b5..e92b6bb 100644 --- a/system_state.json +++ b/system_state.json @@ -3,11 +3,11 @@ "should_connect": true, "should_stream": false, "active_datasets": [ - "Fast", "Test", + "Fast", "DAR" ] }, "auto_recovery_enabled": true, - "last_update": "2025-08-15T13:03:20.882463" + "last_update": "2025-08-15T13:14:31.493157" } \ No newline at end of file