network-collection
Version:
Baseline collection of graphs and network data structures using **socket.io**.
33 lines (30 loc) • 681 B
JavaScript
;
const uuid = require('node-uuid');
class Graph {
constructor(label, data, options) {
options = options || {};
this.nodes = options.nodes || {};
this.id = options.id || uuid.v4();
this.label = label || '';
this.data = data || {};
}
addNode(node) {
this.nodes[node.id] = node;
}
removeNode(nodeId) {
delete this.nodes[nodeId];
}
getNode(nodeId) {
return this.nodes[nodeId];
}
addEdge(fromId, toId) {
this.nodes[fromId].addEdge(toId);
}
removeEdge(fromId, toId) {
this.nodes[fromId].removeEdge(toId);
}
getEdge(fromId, toId) {
return this.nodes[fromId].getEdge(toId);
}
}
module.exports = Graph;