{"_id":"graph-utils","_rev":"3-fb33bc7dfb864cd56dc240762572a2af","name":"graph-utils","description":"Utilities for working with graphs in javascript.","dist-tags":{"latest":"0.1.0"},"versions":{"0.1.0":{"name":"graph-utils","version":"0.1.0","description":"Utilities for working with graphs in javascript.","main":"dist/index.js","scripts":{"make":"make $@","precommit":"make test","test":"make test"},"devDependencies":{"babel-cli":"^6.5.1","babel-jest":"^6.0.1","babel-preset-es2015":"^6.5.0","husky":"^0.11.1","jasmine-reporters":"^1.0.2","jest-cli":"^0.9.0","standard":"^6.0.5"},"dependencies":{},"repository":{"type":"git","url":"git+https://github.com/sterpe/graph-utils.git"},"keywords":["graph","utility","tree","binary","tree","node","dag"],"author":{"name":"sterpe","email":"srterpe@gmail.com","url":"https://github.com/sterpe"},"license":"MIT","bugs":{"url":"https://github.com/sterpe/graph-utils/issues"},"homepage":"https://github.com/sterpe/graph-utils#readme","gitHead":"cd1ebbb7abc53424c99a1cf54ed45c3e0d62a3ab","_id":"graph-utils@0.1.0","_shasum":"bf817ed47c5912b039c1b2bad598d36a48a8672e","_from":".","_npmVersion":"3.8.2","_nodeVersion":"4.3.2","_npmUser":{"name":"sterpe","email":"srterpe@gmail.com"},"maintainers":[{"name":"sterpe","email":"srterpe@gmail.com"}],"dist":{"shasum":"bf817ed47c5912b039c1b2bad598d36a48a8672e","tarball":"https://registry.npmjs.org/graph-utils/-/graph-utils-0.1.0.tgz","integrity":"sha512-mgfmXFLaL/K1dvsM7SoG9WUn+btu94p+LDumCOR/jYnBP6BCfSDQ0FMp7YeSZIxirrHGwqN06/RRJTvveCpxsQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIG1v3Jh2bnSMUPq6QZQhw2aLp4KT/SwmZNU45dodQRgcAiAtMSP/F5JXyCbZdyXfOsW7fIjfvl9oApU7gHGfEPtgdA=="}]},"_npmOperationalInternal":{"host":"packages-13-west.internal.npmjs.com","tmp":"tmp/graph-utils-0.1.0.tgz_1458541355806_0.7436458140145987"}}},"readme":"# graph-utils\n\n[![js-standard-style](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard)\n\n## What is it?\n\n### install\n```\nnpm i --S graph-utils\n```\n\n### usage\n\n#### graph api\n\nThe fundamental entry point is a graph.\n```javascript\nconst grutils = require('graph-utils')\n\nconst g = new grutils.Graph()\n```\n\n##### Graph.addVertex(id:String, data:*=null):Vertex\nAdds a new vertex to the graph and returns the reference.\n\n```javascript\nv = g.addVertex('1', 'foo')\n\ng.vertices // { '1': Vertex { } }\n\nv.id // '1'\nv._ // 'foo'\nv.edges.outgoing // []\nv.edges.incoming // []\n```\n\n##### Graph.getVertex(id:String):Vertex\nGet a reference to the Vertex with `vertex.id === id`.  Note that at the\ncurrent time there is no equivalent `getEdge(id:String)` api.\n\n```javascript\n\ng.getVertex('1') // v { id: '1', _: 'foo' }\n\n```\n##### Graph.addEdge(weight:Number, sourceId:String, targetId:String, data:*=null):Edge\nAdds a new edge to the graph originating from one vertex to another.\nAt your option, you may add some metadata to the edge.\n\n```javascript\nv1 = g.addVertex('1', 'SanFrancisco')\nv2 = g.addVertex('2', 'Oakland')\n\ne1 = g.addEdge(3.1, v1.id, v2.id, 'Bay Bridge')\n\ne1._  // 'Bay Bridge'\ne1.weight // 3.1\ne1.source // '1'\ne1.target // '2'\n\ng.edges // [e]\nv1.edges.outgoing // [e]\nv2.edges.incoming // [e]\n```\n##### Graph.removeEdge(edge:Edge):Edge\nRemove an edge from the graph by reference.  The edge\nwill be unlinked from `edge.source` and `edge.target`.\n```javascript\n// Bye-bye Bay Bridge!\ng.removeEdge(e1)\n\ng.edges // []\nv1.edges.outgoing // []\nv2.edges.incoming // []\n```\n\n##### Graph.removeVertex(vertex:Vertex):Vertex\nRemove a vertex from the graph by reference.  Note that all edges \nthat have this vertex as `edge.source` or `edge.target` will \nbe removed from the graph as well.\n\n```javascript\nv1 = g.addVertex('1', 'SanFrancisco')\nv2 = g.addVertex('2', 'Oakland')\n\ne1 = g.addEdge(3.1, v1.id, v2.id, 'Bay Bridge')\n\n// Bye-bye Oakland and Bay Bridge!\ng.removeVertex(v2)\n\ng.edges // []\ng.vertices // { '1': Vertex { } }\n\nv1.edges.outgoing // []\n```\n##### Graph.setEdge(weight:Number, sourceId:String, sourceIndex:Number, targetId:String, targetIndex:Number=0, data:*=null)\nReplace a specific edge(s) in the graph: `g.getVertex(sourceId).edges.outgoing[sourceIndex]`\nand link the new edge to `g.getVertex(targetId).edges.incoming[targetIndex]`.  You shouldn't \nneed to call this directly, but it is used by the Tree/TreeNode implementation under the\ncovers.  See the [`lib/node.js`](lib/node.js) for more details.\n\n#### tree/tree node api\nThe fundamental entries are trees and nodes, respectively. \nUnderneath the hood the tree is implemented as a graph and\nunfortunately it is required to pass the reference to the \nunderlying `Graph` object as the first parameter when\nconstructing new trees and nodes.  Note that the underlying\nvertex of a node has a reference to the node in `vertex._`.\n\n```javascript\nconst grutils = require('graph-utils')\n\nconst g = new grutils.Graph()\nconst tree = new grutils.Tree(g, '1', { 'foo': 'bar' })\nconst node1 = new grutils.Node(g, '2', 'baz')\n\ntree.root // Node { id: '1', _: { 'foo': 'bar' } }\nnode1 // Node { id: '2', _: 'baz' }\n\ng.vertices // { '1': Vertex { }, '2': Vertex { } }\n\ntree.root.left = node1\n\ntree.root.left // Node { id: '2', _: 'baz' }\n\ng.edges // [ Edge { weight: 1, source: '1', target: '2' } ]\n```\n\n### Note that while some core functionality is there, this project is still very much a work in progress.\n## How do I work on it?\n\n### development\n```\ngit clone https://github.com/sterpe/graph-utils.git\ncd graph-utils\nmake\n```\n\n### build\n```\nmake build\n```\n### test\n```\nmake JEST_FLAGS=--coverage test\n```\n\n### lint\n```\nmake lint\n```\n\nConsult the [`Makefile`](Makefile) for further details.\n","maintainers":[{"name":"sterpe","email":"srterpe@gmail.com"}],"time":{"modified":"2022-06-18T13:51:24.344Z","created":"2016-03-21T06:22:36.235Z","0.1.0":"2016-03-21T06:22:36.235Z"},"homepage":"https://github.com/sterpe/graph-utils#readme","keywords":["graph","utility","tree","binary","tree","node","dag"],"repository":{"type":"git","url":"git+https://github.com/sterpe/graph-utils.git"},"author":{"name":"sterpe","email":"srterpe@gmail.com","url":"https://github.com/sterpe"},"bugs":{"url":"https://github.com/sterpe/graph-utils/issues"},"license":"MIT","readmeFilename":"README.md"}