From 944260f125da4dbac0cf257ebdef8fe934c0756d Mon Sep 17 00:00:00 2001 From: Gwendoline Favre-Felix Date: Wed, 18 Sep 2024 15:10:52 +0200 Subject: [PATCH] [frontend] Disable forces when adding a new entity (#7298) --- .../analyses/reports/ReportKnowledgeGraph.jsx | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/opencti-platform/opencti-front/src/private/components/analyses/reports/ReportKnowledgeGraph.jsx b/opencti-platform/opencti-front/src/private/components/analyses/reports/ReportKnowledgeGraph.jsx index b6acea3226b5d..d5d7df3b0fd96 100644 --- a/opencti-platform/opencti-front/src/private/components/analyses/reports/ReportKnowledgeGraph.jsx +++ b/opencti-platform/opencti-front/src/private/components/analyses/reports/ReportKnowledgeGraph.jsx @@ -524,12 +524,28 @@ class ReportKnowledgeGraphComponent extends Component { async handleAddEntity(stixCoreObject) { if (R.map((n) => n.id, this.graphObjects).includes(stixCoreObject.id)) return; + + this.graph.current.d3Force('link').distance(0); + this.graph.current.d3Force('charge').strength(0); + const currentPositions = R.indexBy( + R.prop('id'), + R.map((n) => ({ id: n.id, x: n.fx, y: n.fy }), this.graphData.nodes), + ); + this.graphObjects = [...this.graphObjects, stixCoreObject]; this.graphData = buildGraphData( this.graphObjects, decodeGraphData(this.props.report.graph_data), this.props.t, ); + + this.graphData.nodes.forEach((node) => { + if (currentPositions[node.id]) { + node.fx = currentPositions[node.id].x; + node.fy = currentPositions[node.id].y; + } + }); + await this.resetAllFilters(); const selectedTimeRangeInterval = computeTimeRangeInterval( this.graphObjects, @@ -548,6 +564,7 @@ class ReportKnowledgeGraphComponent extends Component { }, () => { setTimeout(() => this.handleZoomToFit(), 1500); + this.forceUpdate(); }, ); }