A native MoonBit graph layout and SVG rendering toolkit
Set-Location E:\moonbit\moon_graphmoon check
moon test
npm run build
node cli/moon-graph.mjs examples/pipeline.json --format svg --output examples/pipeline.svg
node cli/moon-graph.mjs examples/hierarchy-ports.json --pretty
node cli/moon-graph.mjs examples/workflow.txt --input-format text --format svg
node cli/moon-graph.mjs --algorithms
moon run examples/apinode cli/moon-graph.mjs [input-file|-] [options]
--input-format json|text 默认 json
--format json|svg 默认 json
--algorithm NAME 覆盖根节点算法
--direction DIRECTION RIGHT / DOWN / LEFT / UP
--pretty JSON 缩进输出
--output PATH 写入指定文件,默认 stdout
--algorithms 输出算法名称 JSON 数组
--help 查看帮助
-- 结束选项解析moon add code3055/moon_graphimport {
"code3055/moon_graph/graph",
}let graph = @graph.new_graph()
graph.children.push(@graph.new_node("build", width=120.0, height=52.0))
graph.children.push(@graph.new_node("test"))
graph.edges.push(@graph.new_edge("build-test", "build", "test"))
graph.options["elk.algorithm"] = "layered"
let output = @graph.new_elk_engine().layout(graph)
let json = @graph.graph_json(output, pretty=true)
let svg = @graph.render_svg(output)let graph = @graph.parse_graph(input)
let compact = @graph.graph_json(graph)
let laid_out_json = @graph.layout_json(input, pretty=true)
let text_graph = @graph.parse_text("node a 开始\nnode b 结束\nedge e a b")
let names = @graph.algorithms()
let problems = @graph.validate(graph)| 算法 | 适用场景 | 行为 |
|---|---|---|
| layered | 流程图、数据流、状态机 | 贪心反馈排序处理环,分层与重心排序 |
| force | 一般关系图 | 固定种子的斥力 / 弹簧迭代,随后排除重叠 |
| radial | 树状或层级关系 | BFS 环状分层;重叠消解可能改变精确圆环形状 |
| box | 元素目录、无边图 | 按行装箱,保留节点尺寸 |
| fixed | 手动位置、已布局图 | 保留节点 x/y,重新计算容器边界、端口与路由 |
| 键 | 默认值 | 允许值 |
|---|---|---|
| elk.algorithm | layered | 五个算法名,或 org.eclipse.elk. 加算法名 |
| elk.direction | RIGHT | RIGHT / DOWN / LEFT / UP |
| elk.spacing.nodeNode | 30 | 0..10000 |
| elk.layered.spacing.nodeNodeBetweenLayers | 60 | 0..10000 |
| moon.padding | 24 | 0..10000 |
| moon.force.iterations | 120 | 整数 1..1000 |
| moon.seed | 1 | 整数 0..1000000 |
| elk.edgeRouting | ORTHOGONAL | ORTHOGONAL / POLYLINE |
{
"id": "root",
"children": [{"id": "a"}, {"id": "b"}],
"edges": [{"id": "e", "sources": ["a"], "targets": ["b"]}]
}moon fmt --check
moon check --target wasm-gc
moon check --target js
moon test --target wasm-gc
moon test --target js
npm run build
npm test
npm run examplesInstall
Download zipA native MoonBit graph layout and SVG rendering toolkit