0.0.3 • Published 7 years ago

graph-events v0.0.3

Weekly downloads
1
License
MIT
Repository
github
Last release
7 years ago

Graph Events

Build Status

npm version

Graph Events is a storage system to create and manipulate states of networks and graphs based on the evolution of their properties over time.

How it Works

  • Graph are stored using events, so you can easily maintain states and do / undo / moderate changes.
  • Everything is serializable in JSON, so all data can be stored in databases, plain files or just plain arrays.

See a live demo.

// example without browser
// use `node graph-events-demo.js` to test

const {GraphEvent, Graph} = require('../lib/index.js')

const nodes = [
  { id : 1, label : "Node A", type : "node" },
  { id : 2, label : "Node B", type : "node" },
  { id : 3, label : "Node C", type : "node" }
]

const edges = [
  { source : 1, target : 2, label : "Edge A -> B", type : "edge" },
  { source : 2, target : 3, label : "Edge B -> C", type : "edge" }
]

// create nodes and edges
const eventCreateNodes = new GraphEvent({
  action : "create",
  data : nodes
})
const eventCreateEdges = new GraphEvent({
  action : "create",
  data : edges
})

// make some changes
const eventDeleteNodeA = new GraphEvent({
  action : "delete",
  selector : { id : 1, type : "node" }
})

const graphInit = new Graph([eventCreateNodes, eventCreateEdges ])
console.log( graphInit.nodes().length + " nodes" )

const graphFinal = new Graph([eventCreateNodes, eventCreateEdges, eventUpdateNodeA])
console.log( graphFinal.nodes().length + " nodes" )

/*
* Results in the console :
*
* $ node graph-events-demo.js       
*   3 nodes
*   2 nodes
*
*/

Check the examples folder to see how it is used.

### Commands

CommandDescriptionOptions
createcreate new node(s)Object data
updateupdate elements with new propertiesObject selector, Object data
deletedelete nodesObject selector

Publish

npm run prepublish
npm publish

### Test

gulp test

Docs

gulp doc

then navigate to the /docs folder to see the documentation.

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago