arc-graph 0.4.0

GPUI knowledge-graph canvas (2D) built on arc-graph-core: force layout in a background thread, LOD, label culling and viewport culling.
Documentation
//! # arc-graph — GPUI 知识图谱画布(本地设计,方案 `docs/graph/knowledge-graph-plan.md`)
//!
//! 2D 知识图谱视图:Barnes–Hut 力导向布局在**进程内后台线程**跑(纯 UI 组件,
//! 无任何后端服务),本视图每帧只取最新坐标快照渲染。
//!
//! # 使用方法
//!
//! ```
//! use arc_graph::Graph2D;
//! use arc_graph_core::KnowledgeGraph;
//! use gpui_kit::{Context, Render, Window, div, prelude::*};
//!
//! struct Page {
//!     canvas: gpui_kit::Entity<Graph2D>,
//! }
//!
//! impl Page {
//!     pub fn new(cx: &mut Context<Self>) -> Self {
//!         let mut g = KnowledgeGraph::new();
//!         let person = g.add_kind("人物");
//!         let a = g.add_node("张三", Some(person));
//!         let b = g.add_node("李四", Some(person));
//!         g.add_edge(a, b, 1.0, None).unwrap();
//!         // 力导向布局在后台线程自动迭代;已有坐标可用 `new_static` 跳过布局。
//!         let canvas = cx.new(|cx| Graph2D::new("graph", g, cx).fit_on_mount());
//!         Self { canvas }
//!     }
//! }
//!
//! impl Render for Page {
//!     fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
//!         div().size_full().child(self.canvas.clone())
//!     }
//! }
//! ```
//!
//! # 交互与接入(G4,无后端)
//!
//! - 滚轮 / 背景拖动平移;Ctrl/⌘+滚轮或捏合缩放。
//! - 悬停高亮一度邻居,其余节点和边淡化(所有 LOD 一致)。
//! - 点击选择,Shift+点击切换多选,Shift+背景拖动框选。
//! - 拖动节点后保持固定,用 `set_pinned(id, false, cx)` 解除。
//! - `search(query)` 返回当前可见匹配项;点击搜索结果后用 `fly_to(id, cx)` 弹簧定位。
//! - `set_kind_filter(Some(kind), cx)` 筛选类型,`None` 恢复全部;
//!   筛选后双击节点或调用 `expand(id, cx)` 揭示一度邻居。
//! - 搜索框、类型按钮由宿主页组合;完整示例见 gallery 的 `graph-canvas` 页。
//!
//! ```no_run
//! # use arc_graph::{Graph2D, NodeId};
//! # use gpui_kit::{App, Entity};
//! fn locate(canvas: &Entity<Graph2D>, cx: &mut App) {
//!     if let Some(id) = canvas.read(cx).search("张").first().copied() {
//!         canvas.update(cx, |view, cx| view.fly_to(id, cx));
//!     }
//!     canvas.update(cx, |view, cx| {
//!         view.set_kind_filter(None, cx);
//!         view.set_pinned(NodeId(1), false, cx);
//!     });
//! }
//! ```
//!
//! LOD(方案 §5):缩得很小时节点批量画 quad 点;中等画外壳;
//! 放大才渲染 div 卡片(含文字)。缩小模式下按度数优先级显示浮动标签,
//! 屏幕网格碰撞剔除,同屏最多 200 个。

pub mod motion;
pub mod view;

pub use arc_graph_core::{
    Edge, EdgeId, ForceLayout2D, GraphError, GraphPayload, KnowledgeGraph, LayoutConfig, Node,
    NodeId, NodeKind,
};
pub use motion::{Appear, GraphMotion};
pub use view::{Graph2D, Lod, RenderCounts};