Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added JSON import function #80

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions lib/dracula.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,23 @@ var Dracula = function () {
* @return {Node}
*/

}, {
},{
key:"importCustomEdges",
value: function importCustomEdges(edges){
for(var node in edges){
if(edges.hasOwnProperty(node)){
for(var target of edges[node]){
this.addEdge(node, target);
}
}
}
}
},{
key:"importCustomNodes",
value: function importCustomNodes(nodes){
this.nodes = nodes;
}
},{
key: 'removeNode',
value: function removeNode(node) {
var _this = this;
Expand Down Expand Up @@ -170,4 +186,4 @@ var Dracula = function () {
return Dracula;
}();

exports.default = Dracula;
exports.default = Dracula;
20 changes: 20 additions & 0 deletions src/dracula.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,26 @@ export default class Dracula {
static create() {
return new Dracula()
}

importJSONnodes(nodes) {
this.nodes = nodes;
}

importJSONEdges(edges) {
//Vertex = Destination node
//JSON object must be like {Node: [VERTEX], ...}

//Loop through all nodes
for(var node in edges) {
if(edges.hasOwnProperty(node)) {

//Loop through all the vertex and add an edge from the node to the vertex
for(var target of edges[node] ){
this.addEdge(node, target);
}
}
}
}

/**
* Add node if it doesn't exist yet.
Expand Down