Files
fn_registry/cpp/functions/viz/graph_force_layout.h
T
egutierrez 0bdf35a461 feat: add C++ ImGui functions for core UI and visualization
Funciones C++/ImGui para dashboards (grid, panel, docking, sidebar, tabs),
visualizaciones (candlestick, gauge, histogram, pie, sparkline, heatmap,
scatter, line, bar, surface3d, kpi, table), grafos (force layout, renderer,
viewport, spatial hash, types) y utilidades (time series buffer, tracy zones,
memory/fps overlay, plot theme).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-08 00:10:18 +02:00

28 lines
1.2 KiB
C

#pragma once
struct GraphData; // forward declare
struct ForceLayoutConfig {
float repulsion = 500.0f; // repulsion strength between all nodes
float attraction = 0.01f; // spring constant for edges
float damping = 0.85f; // velocity decay per step
float min_distance = 1.0f; // minimum distance (avoid division by zero)
float theta = 0.5f; // Barnes-Hut threshold (0 = exact, 1 = fast)
float gravity = 0.1f; // pull toward center (prevents drift)
float max_velocity = 50.0f; // cap velocity per axis
int iterations = 1; // steps per call
};
// Perform one (or more) steps of force-directed layout.
// Modifies node positions (x, y) and velocities (vx, vy) in-place.
// Returns the total kinetic energy (sum of |v|^2). When energy < threshold,
// layout has converged.
float graph_force_layout_step(GraphData& graph, const ForceLayoutConfig& config = {});
// Reset: randomize positions within [-spread, spread], zero velocities.
void graph_force_layout_reset(GraphData& graph, float spread = 200.0f);
// Preset layouts (non-iterative, instant positioning)
void graph_layout_circular(GraphData& graph, float radius = 100.0f);
void graph_layout_grid(GraphData& graph, float spacing = 20.0f);