1.0.0 • Published 4 years ago

@gilbva/mgraph v1.0.0

Weekly downloads
3
License
ISC
Repository
github
Last release
4 years ago

MGraph

MGraph is an in-memory graph structure who's main propose is to hold the information for a model of a GUI app in a consistent and easy to search and mutate structure.

Creating a graph

A graph can be created instantiating the MGraph class.

const graph = new MGraph();

Adding data to the graph

Data can be added to the graph by creating nodes and connecting them, the next example shows how to create a nodes with diferent configuration.

//Node without labels or properties.
const node1 = graph.add();
//Node with a single label and without properties.
const node2 = graph.add("label1");
//Node with a multiple labels and without properties.
const node3 = graph.add(["label1", "label2"]);
//Node without labels and with one property.
const node4 = graph.add(null, { prop1: "val1" });
//Node with one label and with one property.
const node5 = graph.add("label1", { prop1: "val1" });
//Node with several labels and several properties.
const node5 = graph.add(["label1", "label2"], { prop1: "val1", prop2: "val2 });

All elements (nodes and edges) in MGraph have labels and properties, labels help to identify and search elements, and properties hold the information of the elements.