Skip to content

graphrs原生速度的图算法

JavaScript 的 igraph — 400+ 图算法,由 Rust/WASM 驱动。社区检测、中心性、布局、网络流、同构。可摇树。TypeScript。浏览器 & Node.js。

graphrs logo

快速开始

bash
npm install @graphrs/core @graphrs/community @graphrs/centrality
typescript
import { Graph } from '@graphrs/core';
import { louvain } from '@graphrs/community';
import { pagerank } from '@graphrs/centrality';

const graph = Graph.fromEdges([
  [0, 1], [1, 2], [2, 0],   // 社区 A
  [3, 4], [4, 5], [5, 3],   // 社区 B
  [2, 3],                    // 桥边
]);

const communities = await louvain(graph);
// → { membership: [0,0,0,1,1,1], modularity: 0.357 }

const pr = await pagerank(graph);
// → { scores: [0.12, 0.15, 0.23, 0.18, 0.16, 0.16] }

为什么选择 graphrs?

Python 有 igraph(C 内核,快)和 networkx(纯 Python,慢)。 JavaScript 在快速图计算领域一直是空白 — 直到现在。

graphologycytoscape.js@graphrs
社区检测2 种算法010+
中心性度量7215+
布局算法3扩展16
网络流00完整
同构00VF2
10k 节点 PageRank~5–10 秒N/A~100 毫秒

框架集成

bash
# AntV G6 — 布局 + 社区检测 + 中心性
npm install @graphrs/g6

# React Flow — 自动布局 Hook(React Flow 没有内置布局功能)
npm install @graphrs/react-flow
typescript
// G6: 即插即用布局
import { createGraphrsLayout } from '@graphrs/g6';
new G6Graph({ layout: createGraphrsLayout({ algorithm: 'fruchterman-reingold' }) });

// React Flow: 一行代码自动布局
import { useGraphrsLayout } from '@graphrs/react-flow';
const { nodes, edges } = useGraphrsLayout(initialNodes, initialEdges);

MIT License (TS code) · GPL-2.0 (WASM binary)