graph README

The project's README from github.com/statelyai/graph. As one markdown file: README.md.

@statelyai/graph

Graphs as plain JSON, with the algorithms, formats, and layout engines to do real work with them.

A graph is just { nodes, edges } data, and every operation is a standalone, tree-shakable function. Built and used by Stately to power its visual tooling for complex systems.

Documentation

Why @statelyai/graph?

Installation

npm install @statelyai/graph

Quick start

Create a publishing workflow and find the shortest route from draft to published:

import { createGraph, getShortestPath } from '@statelyai/graph';

const graph = createGraph({
  nodes: [
    { id: 'draft' },
    { id: 'review' },
    { id: 'published' },
  ],
  edges: [
    { id: 'submit', sourceId: 'draft', targetId: 'review' },
    { id: 'approve', sourceId: 'review', targetId: 'published' },
  ],
});

const path = getShortestPath(graph, { from: 'draft', to: 'published' });

if (path) {
  console.log([path.source.id, ...path.steps.map(({ node }) => node.id)]);
  // ['draft', 'review', 'published']
}

For guides, API details, and adapter dependencies, see the docs. To contribute, see CONTRIBUTING.md.

Inspiration

Inspired by NetworkX, Graphology, and graphlib.

License

MIT

graph (statelyai/graph)

Searching Database…

246 ·GitHub
这是什么?一个 TypeScript 库,提供通用的图处理工具:一个简单的 {nodes, edges} JSON 数据模型,外加实际使用这些数据的算法、格式转换器和布局引擎。
这是我导入的库,还是独立应用?它是一个库:每个操作都是可独立导入、支持摇树优化(tree-shaking)的函数,不是框架,也不是 GUI 工具。
怎么把它加到项目里?从 npm 安装该包,然后通过可选的子路径导入引入你需要的特定函数或适配器。
除了 Node/npm,使用它还需要别的吗?只需要一个 JS/TS 环境;格式转换器和布局引擎(Graphviz、ELK、dagre 等)都是可选适配器,只有在你使用时才会被引入。
所有格式和布局引擎都默认打包在内吗?不是,核心包只涵盖数据模型和算法;14 种格式和 8 种布局引擎各自都是独立的可选适配器,并带有各自的依赖。
谁会真正需要它?构建图表编辑器、节点编辑器、状态图或架构可视化工具,并且需要一个快速、可序列化、带真实算法的图模型的开发者。
与 graphology 之类的库相比,它为什么快?它以纯 JSON 加透明的索引查找方式存储图,而不是类实例,README 称这让它在构建 10 万节点图时比 graphology 快 9-15 倍。
它能把 XState 状态机转换成图吗?可以,它由 Stately 构建,并包含一个能把 XState 状态机转换成图的适配器。
包含哪些算法?最短路径、中心性、社区、流、匹配和同构,全部针对自环、平行边等边界情况做过测试,并且以迭代方式实现,因此很深的图也不会导致栈溢出。
图数据是强类型的吗?是的,它从头到尾使用泛型类型来定义节点、边、端口和图本身。
What are similar projects?networkx, cytoscape.js, G6, uPlot, LogicFlow, rete, Chart.js, liteparse
Creator
statelyai
Size
1.8 MB
Stars
246
Age
8mo
Commits · 90 Days