feat(viz): graph_types modelo extendido + EntityType/RelationType + flags (issue 0049e)
Extiende el modelo agnostico de graph_types.h para soportar shapes/iconos/ filtros/labels/streaming sin acoplar a backend. Migra el unico consumer (demos_graph) en el mismo cambio. - GraphNode v2: type_id + shape_override/color_override/size_override + flags (NF_PINNED/VISIBLE/SELECTED/HOVERED) + label_idx + user_data. - GraphEdge v2: type_id + style_override + flags (EF_DIRECTED/VISIBLE). - EntityType / RelationType: tablas en GraphData (types, rel_types). - Helpers de resolucion (resolve_node_color/shape/size, resolve_edge_*) y constructores ergonomicos (graph_node, graph_edge, entity_type, relation_type) — sentinel-based para herencia automatica del tipo. - graph_renderer v1.4: lee NF_VISIBLE / EF_VISIBLE, resuelve apariencia via override → EntityType → fallback indexado por type_id. Skipea aristas con endpoints invisibles. Shapes siguen pintandose como circulo (0049f cableara el dispatch real). - graph_force_layout v1.2: pinned ahora vive en flags & NF_PINNED. - graph_viewport v1.1: hover/seleccion publican NF_HOVERED/SELECTED en el grafo (clear-then-set). Drag usa NF_PINNED. Tooltip muestra Type/ user_data en lugar de community/value/label. - demos_graph: 8 EntityType (paleta antigua) + 1 RelationType. type_id por cluster. user_data = indice numerico del nodo. Apariencia visual identica al pre-cambio. - test_graph_types.cpp: 12 casos cubriendo helpers, defaults, bitmask manipulation y resoluciones override-vs-EntityType. test_graph_edge_ static actualizado al nuevo modelo (ya no tiene .color directo). - 4 .md de tipos nuevos (graph_node, graph_edge, entity_type, relation_type) + GraphData v2.0 actualizado. Tests: 31/31 ctest verdes (incluye test_visual golden). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -265,7 +265,7 @@ float graph_force_layout_step(GraphData& graph, const ForceLayoutConfig& config)
|
||||
// stack local en pila, asi que es thread-safe.
|
||||
#pragma omp parallel for if(graph.node_count >= 1024) schedule(dynamic, 256)
|
||||
for (int i = 0; i < graph.node_count; ++i) {
|
||||
if (graph.nodes[i].pinned) continue;
|
||||
if (graph.nodes[i].flags & NF_PINNED) continue;
|
||||
quad_force(root,
|
||||
graph.nodes[i].x, graph.nodes[i].y,
|
||||
config.theta, config.repulsion, config.min_distance,
|
||||
@@ -290,15 +290,15 @@ float graph_force_layout_step(GraphData& graph, const ForceLayoutConfig& config)
|
||||
float fx_e = force * dx / dist;
|
||||
float fy_e = force * dy / dist;
|
||||
|
||||
if (!graph.nodes[s].pinned) { fx_buf[s] += fx_e; fy_buf[s] += fy_e; }
|
||||
if (!graph.nodes[t].pinned) { fx_buf[t] -= fx_e; fy_buf[t] -= fy_e; }
|
||||
if (!(graph.nodes[s].flags & NF_PINNED)) { fx_buf[s] += fx_e; fy_buf[s] += fy_e; }
|
||||
if (!(graph.nodes[t].flags & NF_PINNED)) { fx_buf[t] -= fx_e; fy_buf[t] -= fy_e; }
|
||||
}
|
||||
|
||||
// ---- Gravity toward center (0,0) ----
|
||||
if (config.gravity != 0.0f) {
|
||||
#pragma omp parallel for if(graph.node_count >= 1024) schedule(static)
|
||||
for (int i = 0; i < graph.node_count; ++i) {
|
||||
if (graph.nodes[i].pinned) continue;
|
||||
if (graph.nodes[i].flags & NF_PINNED) continue;
|
||||
fx_buf[i] -= config.gravity * graph.nodes[i].x;
|
||||
fy_buf[i] -= config.gravity * graph.nodes[i].y;
|
||||
}
|
||||
@@ -309,7 +309,7 @@ float graph_force_layout_step(GraphData& graph, const ForceLayoutConfig& config)
|
||||
#pragma omp parallel for if(graph.node_count >= 1024) schedule(static) reduction(+:total_energy)
|
||||
for (int i = 0; i < graph.node_count; ++i) {
|
||||
GraphNode& n = graph.nodes[i];
|
||||
if (n.pinned) continue;
|
||||
if (n.flags & NF_PINNED) continue;
|
||||
|
||||
n.vx = n.vx * config.damping + fx_buf[i];
|
||||
n.vy = n.vy * config.damping + fy_buf[i];
|
||||
@@ -332,7 +332,7 @@ float graph_force_layout_step(GraphData& graph, const ForceLayoutConfig& config)
|
||||
void graph_force_layout_reset(GraphData& graph, float spread) {
|
||||
for (int i = 0; i < graph.node_count; ++i) {
|
||||
GraphNode& n = graph.nodes[i];
|
||||
if (n.pinned) continue;
|
||||
if (n.flags & NF_PINNED) continue;
|
||||
// rand() produces [0, RAND_MAX]; map to [-spread, spread]
|
||||
n.x = spread * (2.0f * (float)rand() / (float)RAND_MAX - 1.0f);
|
||||
n.y = spread * (2.0f * (float)rand() / (float)RAND_MAX - 1.0f);
|
||||
@@ -347,7 +347,7 @@ void graph_layout_circular(GraphData& graph, float radius) {
|
||||
const float two_pi = 6.28318530718f;
|
||||
for (int i = 0; i < graph.node_count; ++i) {
|
||||
GraphNode& n = graph.nodes[i];
|
||||
if (n.pinned) continue;
|
||||
if (n.flags & NF_PINNED) continue;
|
||||
float angle = two_pi * (float)i / (float)graph.node_count;
|
||||
n.x = radius * std::cos(angle);
|
||||
n.y = radius * std::sin(angle);
|
||||
@@ -370,7 +370,7 @@ void graph_layout_grid(GraphData& graph, float spacing) {
|
||||
float oy = -0.5f * (rows - 1) * spacing;
|
||||
for (int i = 0; i < graph.node_count; ++i) {
|
||||
GraphNode& n = graph.nodes[i];
|
||||
if (n.pinned) continue;
|
||||
if (n.flags & NF_PINNED) continue;
|
||||
int col = i % cols;
|
||||
int row = i / cols;
|
||||
n.x = ox + col * spacing;
|
||||
|
||||
Reference in New Issue
Block a user