ngraph.tojson
将图形存储为简单 json 格式的库
用法
var graph = require ( 'ngraph.graph' ) ( ) ;
graph . addLink ( 'hello' , 'world' ) ;
var toJSON = require ( 'ngraph.tojson' ) ;
console . log ( toJSON ( graph ) ) ;
// Produces output:
// {"nodes":[{"id":"hello"},{"id":"world"}],"links":[{"fromId":"hello","toId":"world"}]}
您还可以提供自定义变换函数来在将节点/边推送到输出之前对其进行变换:
var g = require ( 'ngraph.graph' ) ( ) ;
g . addNo
1