From 1d8d01a2ed21dc9db4a6ba10db1a01ff43821b05 Mon Sep 17 00:00:00 2001 From: grayTerminal-sh Date: Thu, 23 Jul 2026 14:03:53 +0200 Subject: [PATCH] fix(graph): preserve viewport across reloads --- include/widgets/investigation_graph_view.h | 20 +++++++++++++ src/widgets/investigation_graph_view.c | 34 ++++++++++++++++++++++ src/widgets/workspace.c | 21 +++++++++++++ 3 files changed, 75 insertions(+) diff --git a/include/widgets/investigation_graph_view.h b/include/widgets/investigation_graph_view.h index 4d384f1..8cd9d49 100644 --- a/include/widgets/investigation_graph_view.h +++ b/include/widgets/investigation_graph_view.h @@ -247,6 +247,26 @@ void investigation_graph_view_reset_view( InvestigationGraphView *graph_view ); +/** + * @brief Lit le zoom et le déplacement courants du canvas. + * + * @return TRUE lorsqu'un graphe est actuellement présenté. + */ +gboolean investigation_graph_view_get_view_transform( + const InvestigationGraphView *graph_view, + double *zoom, + double *offset_x, + double *offset_y +); + +/** @brief Restaure un zoom et un déplacement précédemment lus. */ +void investigation_graph_view_set_view_transform( + InvestigationGraphView *graph_view, + double zoom, + double offset_x, + double offset_y +); + /** * @brief Restaure la disposition déterministe initiale des nœuds. * diff --git a/src/widgets/investigation_graph_view.c b/src/widgets/investigation_graph_view.c index 7478ae8..5853552 100644 --- a/src/widgets/investigation_graph_view.c +++ b/src/widgets/investigation_graph_view.c @@ -12,6 +12,7 @@ #include "models/social_platform.h" #include +#include #include #define INVESTIGATION_GRAPH_VIEW_MARGIN 32.0 @@ -4642,6 +4643,39 @@ void investigation_graph_view_reset_view( } } +gboolean investigation_graph_view_get_view_transform( + const InvestigationGraphView *graph_view, + double *zoom, + double *offset_x, + double *offset_y) +{ + if (graph_view == NULL || graph_view->graph_model == NULL || + zoom == NULL || offset_x == NULL || offset_y == NULL) + return FALSE; + *zoom = graph_view->zoom; + *offset_x = graph_view->offset_x; + *offset_y = graph_view->offset_y; + return TRUE; +} + +void investigation_graph_view_set_view_transform( + InvestigationGraphView *graph_view, + double zoom, + double offset_x, + double offset_y) +{ + if (graph_view == NULL || + zoom < INVESTIGATION_GRAPH_VIEW_MIN_ZOOM || + zoom > INVESTIGATION_GRAPH_VIEW_MAX_ZOOM || + !isfinite(zoom) || !isfinite(offset_x) || !isfinite(offset_y)) + return; + graph_view->zoom = zoom; + graph_view->offset_x = offset_x; + graph_view->offset_y = offset_y; + if (graph_view->drawing_area != NULL) + gtk_widget_queue_draw(graph_view->drawing_area); +} + void investigation_graph_view_reset_layout( InvestigationGraphView *graph_view ) diff --git a/src/widgets/workspace.c b/src/widgets/workspace.c index 39a982a..3203adc 100644 --- a/src/widgets/workspace.c +++ b/src/widgets/workspace.c @@ -180,6 +180,10 @@ struct Workspace OsintActionCatalog *osint_action_catalog; WorkspaceGraphState graph_state; + gboolean saved_graph_transform_valid; + double saved_graph_zoom; + double saved_graph_offset_x; + double saved_graph_offset_y; }; /** @@ -3051,6 +3055,13 @@ void workspace_set_graph_loading( workspace->entity_details_panel ); + workspace->saved_graph_transform_valid = + investigation_graph_view_get_view_transform( + workspace->graph_view, + &workspace->saved_graph_zoom, + &workspace->saved_graph_offset_x, + &workspace->saved_graph_offset_y); + investigation_graph_view_clear( workspace->graph_view ); @@ -3156,6 +3167,16 @@ void workspace_set_graph( graph_model ); + if (workspace->saved_graph_transform_valid) + { + investigation_graph_view_set_view_transform( + workspace->graph_view, + workspace->saved_graph_zoom, + workspace->saved_graph_offset_x, + workspace->saved_graph_offset_y); + workspace->saved_graph_transform_valid = FALSE; + } + workspace->graph_state = WORKSPACE_GRAPH_STATE_READY;