fix(graph): preserve viewport across reloads

This commit is contained in:
grayTerminal-sh 2026-07-23 14:03:53 +02:00
parent bdcbcce0aa
commit 1d8d01a2ed
3 changed files with 75 additions and 0 deletions

View file

@ -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.
*

View file

@ -12,6 +12,7 @@
#include "models/social_platform.h"
#include <glib.h>
#include <math.h>
#include <pango/pangocairo.h>
#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
)

View file

@ -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;