A modern platform for visual, flexible, and extensible graph-based investigations. For cybersecurity analysts and investigators.
feat(app): adapt forces
dextmorgn94e7bd7f9fb9
diff --git a/flowsint-app/src/hooks/use-layout.ts b/flowsint-app/src/hooks/use-layout.tsindex 6b781e0d..2933484d 100644--- a/flowsint-app/src/hooks/use-layout.ts+++ b/flowsint-app/src/hooks/use-layout.ts@@ -105,7 +105,7 @@ export function useLayout({const width = containerSize.width || 800const height = containerSize.height || 600// Calculate maxRadius as 40% of the smallest dimension to keep nodes in view- const maxRadius = Math.min(width, height) *2+ // const maxRadius = Math.min(width, height) * 500worker.postMessage({type: 'force',@@ -114,14 +114,17 @@ export function useLayout({options: {width,height,- chargeStrength: forceSettings.d3ForceChargeStrength?.value ?? -30,- linkDistance: forceSettings.d3ForceLinkDistance?.value ?? 30,- linkStrength: forceSettings.d3ForceLinkStrength?.value ?? 2,- alphaDecay: forceSettings.d3AlphaDecay?.value ?? 0.045,- alphaMin: forceSettings.d3AlphaMin?.value ?? 0,- velocityDecay: forceSettings.d3VelocityDecay?.value ?? 0.41,+ chargeStrength: forceSettings.d3ForceChargeStrength?.value ?? -150,+ linkDistance: forceSettings.d3ForceLinkDistance?.value ?? 35,+ linkStrength: forceSettings.d3ForceLinkStrength?.value ?? 1.0,+ alphaDecay: forceSettings.d3AlphaDecay?.value ?? 0.06,+ alphaMin: forceSettings.d3AlphaMin?.value ?? 0.001,+ velocityDecay: forceSettings.d3VelocityDecay?.value ?? 0.75,iterations: forceSettings.cooldownTicks?.value ?? 300,- maxRadius,+ collisionRadius: forceSettings.collisionRadius?.value ?? 22,+ collisionStrength: forceSettings.collisionStrength?.value ?? 0.95,+ centerGravity: forceSettings.centerGravity?.value ?? 0.15,+ // maxRadius,},})}diff --git a/flowsint-app/src/stores/graph-settings-store.ts b/flowsint-app/src/stores/graph-settings-store.tsindex d72dd5c1..873bf7fb 100644--- a/flowsint-app/src/stores/graph-settings-store.ts+++ b/flowsint-app/src/stores/graph-settings-store.ts@@ -15,7 +15,7 @@ const DEFAULT_SETTINGS = {nodeSize: {type: 'number',value: 1,- min: 1,+ min: .2,max: 20,step: 0.1,description: 'Defines the width of the link between two nodes.'@@ -55,16 +55,16 @@ const DEFAULT_SETTINGS = {},d3ForceChargeStrength: {type: 'number',- value: -120,+ value: -150,min: -500,max: 0,step: 5,description:- 'Strength of repulsion between nodes (negative = repel, more negative = stronger repulsion, nodes further apart)'+ 'Base repulsion strength (adaptive: highly connected nodes/cluster hubs repel 2-3x more to separate clusters)'},d3ForceLinkDistance: {type: 'number',- value: 10,+ value: 35,min: 10,max: 200,step: 1,@@ -73,12 +73,12 @@ const DEFAULT_SETTINGS = {},d3ForceLinkStrength: {type: 'number',- value: 2,+ value: 1.0,min: 0,max: 2,step: 0.1,description:- 'Strength of links to maintain their target distance (higher = more rigid links, nodes stay closer to target distance, 2 = fixed distance)'+ 'Strength of links to maintain their target distance (higher = stronger cluster cohesion, lower = weaker clusters)'},linkDirectionalArrowRelPos: {type: 'number',@@ -133,7 +133,7 @@ const DEFAULT_SETTINGS = {},d3AlphaMin: {type: 'number',- value: 0,+ value: 0.001,min: 0,max: 0.1,step: 0.001,@@ -142,13 +142,40 @@ const DEFAULT_SETTINGS = {},d3VelocityDecay: {type: 'number',- value: 0.6,+ value: 0.75,min: 0,max: 1,step: 0.01,description:'Velocity decay factor that simulates friction/resistance (higher = more damping, nodes slow down faster)'},+ collisionRadius: {+ type: 'number',+ value: 22,+ min: 10,+ max: 50,+ step: 1,+ description:+ 'Radius of collision detection around nodes (prevents node overlap and improves readability)'+ },+ collisionStrength: {+ type: 'number',+ value: 0.95,+ min: 0,+ max: 1,+ step: 0.05,+ description:+ 'Strength of collision force (1 = fully rigid collision, 0 = no collision)'+ },+ centerGravity: {+ type: 'number',+ value: 0.15,+ min: 0,+ max: 1,+ step: 0.05,+ description:+ 'Gravity force pulling all nodes toward the center (prevents clusters from drifting apart, higher = stronger pull to center)'+ },// warmupTicks: {// type: 'number',// value: 0,@@ -171,7 +198,10 @@ const FORCE_PRESETS = {d3ForceLinkDistance: 10,d3ForceLinkStrength: 2,cooldownTicks: 300,- cooldownTime: 20000+ cooldownTime: 20000,+ collisionRadius: 15,+ collisionStrength: 0.7,+ centerGravity: 0.2},'Compact Network': {d3AlphaDecay: 0.08,@@ -181,7 +211,10 @@ const FORCE_PRESETS = {d3ForceLinkDistance: 20,d3ForceLinkStrength: 2,cooldownTicks: 250,- cooldownTime: 18000+ cooldownTime: 18000,+ collisionRadius: 18,+ collisionStrength: 0.75,+ centerGravity: 0.18},'Balanced Layout': {d3AlphaDecay: 0.06,@@ -191,7 +224,10 @@ const FORCE_PRESETS = {d3ForceLinkDistance: 30,d3ForceLinkStrength: 2,cooldownTicks: 200,- cooldownTime: 15000+ cooldownTime: 15000,+ collisionRadius: 22,+ collisionStrength: 0.8,+ centerGravity: 0.15},'Loose Organic': {d3AlphaDecay: 0.04,@@ -201,7 +237,10 @@ const FORCE_PRESETS = {d3ForceLinkDistance: 30,d3ForceLinkStrength: 2,cooldownTicks: 150,- cooldownTime: 12000+ cooldownTime: 12000,+ collisionRadius: 25,+ collisionStrength: 0.85,+ centerGravity: 0.12},'High Energy': {d3AlphaDecay: 0.02,@@ -211,7 +250,49 @@ const FORCE_PRESETS = {d3ForceLinkDistance: 20,d3ForceLinkStrength: 2,cooldownTicks: 100,- cooldownTime: 10000+ cooldownTime: 10000,+ collisionRadius: 20,+ collisionStrength: 0.8,+ centerGravity: 0.08+ },+ 'Readable clusters': {+ d3AlphaDecay: 0.06,+ d3AlphaMin: 0.001,+ d3VelocityDecay: 0.75,+ d3ForceChargeStrength: -150,+ d3ForceLinkDistance: 35,+ d3ForceLinkStrength: 1.0,+ cooldownTicks: 300,+ cooldownTime: 20000,+ collisionRadius: 22,+ collisionStrength: 0.95,+ centerGravity: 0.15+ },+ 'Medium spacing': {+ d3AlphaDecay: 0.055,+ d3AlphaMin: 0.001,+ d3VelocityDecay: 0.7,+ d3ForceChargeStrength: -200,+ d3ForceLinkDistance: 40,+ d3ForceLinkStrength: 0.8,+ cooldownTicks: 320,+ cooldownTime: 22000,+ collisionRadius: 26,+ collisionStrength: 0.9,+ centerGravity: 0.2+ },+ 'Osint friendly': {+ d3AlphaDecay: 0.07,+ d3AlphaMin: 0.001,+ d3VelocityDecay: 0.8,+ d3ForceChargeStrength: -100,+ d3ForceLinkDistance: 28,+ d3ForceLinkStrength: 1.4,+ cooldownTicks: 280,+ cooldownTime: 18000,+ collisionRadius: 18,+ collisionStrength: 1.0,+ centerGravity: 0.25}}@@ -258,7 +339,7 @@ export const useGraphSettingsStore = create<GraphGeneralSettingsStore>()((set, get) => ({// Settings statesettings: DEFAULT_SETTINGS,- currentPreset: 'High Energy',+ currentPreset: '🎯 Clusters Lisibles',forceSettings: DEFAULT_SETTINGS.graph,// UI StatesettingsModalOpen: false,diff --git a/flowsint-app/src/workers/layout.worker.ts b/flowsint-app/src/workers/layout.worker.tsindex 7c78a06c..f13f6d9d 100644--- a/flowsint-app/src/workers/layout.worker.ts+++ b/flowsint-app/src/workers/layout.worker.ts@@ -5,6 +5,7 @@ import {forceManyBody,forceCenter,forceCollide,+ forceRadial,} from 'd3-force'export interface GraphNode {@@ -42,6 +43,9 @@ interface ForceLayoutOptions {velocityDecay?: numberiterations?: numbermaxRadius?: number+ collisionRadius?: number+ collisionStrength?: number+ centerGravity?: number}interface LayoutMessage {@@ -108,14 +112,17 @@ function computeForceLayout(const {width = 800,height = 600,- chargeStrength = -30,- linkDistance = 30,- linkStrength = 2,- alphaDecay = 0.045,- alphaMin = 0,- velocityDecay = 0.41,+ chargeStrength = -150,+ linkDistance = 35,+ linkStrength = 1.0,+ alphaDecay = 0.06,+ alphaMin = 0.001,+ velocityDecay = 0.75,iterations = 300,maxRadius,+ collisionRadius = 22,+ collisionStrength = 0.95,+ centerGravity = 0.15,} = options// Create simulation nodes with initial random positions@@ -131,7 +138,20 @@ function computeForceLayout(target: typeof edge.target === 'object' ? edge.target.id : edge.target,}))+ // Calculate node degrees (number of connections) for adaptive repulsion+ const nodeDegrees = new Map<string, number>()+ simNodes.forEach((node: any) => nodeDegrees.set(node.id, 0))+ simLinks.forEach((link: any) => {+ const sourceId = typeof link.source === 'object' ? link.source.id : link.source+ const targetId = typeof link.target === 'object' ? link.target.id : link.target+ nodeDegrees.set(sourceId, (nodeDegrees.get(sourceId) || 0) + 1)+ nodeDegrees.set(targetId, (nodeDegrees.get(targetId) || 0) + 1)+ })+// Create D3 force simulation+ const centerX = width / 2+ const centerY = height / 2+const simulation = forceSimulation(simNodes as any).force('link',@@ -140,11 +160,29 @@ function computeForceLayout(.distance(linkDistance).strength(linkStrength))- .force('charge', forceManyBody().strength(chargeStrength))- .force('center', forceCenter(width / 2, height / 2))- // Add collision force with larger radius to account for label space below nodes- // Radius ~3x node size to prevent label overlap- // .force('collide', forceCollide().radius(30).strength(0.7))+ // Adaptive charge: nodes with more connections (cluster hubs) repel more+ .force('charge', forceManyBody().strength((node: any) => {+ const degree = nodeDegrees.get(node.id) || 1+ // Scale repulsion by degree: hubs repel 2-3x more than isolated nodes+ const scaleFactor = 1 + Math.log(degree + 1) / Math.log(10)+ return chargeStrength * scaleFactor+ }))+ .force('center', forceCenter(centerX, centerY))+ // Add collision force to prevent node overlap+ .force('collide', forceCollide()+ .radius(collisionRadius)+ .strength(collisionStrength)+ )+ // Add radial gravity to pull all nodes toward center+ .force('gravity', (alpha) => {+ const strength = centerGravity * alpha+ simNodes.forEach((node: any) => {+ const dx = centerX - node.x+ const dy = centerY - node.y+ node.vx += dx * strength+ node.vy += dy * strength+ })+ }).alphaDecay(alphaDecay).alphaMin(alphaMin).velocityDecay(velocityDecay)@@ -153,9 +191,6 @@ function computeForceLayout(// Send progress updates every 10 iterationsconst progressInterval = Math.max(1, Math.floor(iterations / 10))- const centerX = width / 2- const centerY = height / 2-for (let i = 0; i < iterations; i++) {simulation.tick()