Describes how a vertex is related to other vertices in a graph. The rule
callback in the constructor's arguments takes 2 arguments 'from' (the origin
vertex) & 'to' (the destination vertex) and returns true if an edge edists from
the first to the second.
Below is an example that creates an edge between an instance of MyVertex
and any other vertex in the graph (not just instance of MyVertex) that have
an id greater than itself.
class MyVertex extends Vertex {
publicstatic edges = new Edge((from, to) =>from.id > to);
}
// Create a new graphconst graph = new Graph();
// Creates some vertices to add to the graphconst vertex1 = new MyVertex(1);
const vertex2 = new SomeOtherVertex(2); // Not an instance of Myvertexconst vertex3 = new MyVertex(3);
graph.addVertex(vertex1);
graph.addVertex(vertex2);
graph.addVertex(vertex3);
vertex1.edges // [vertex2, vertex3]
vertex2.edges // [vertex3]
vertex3.edges // []
Describes how a vertex is related to other vertices in a graph. The rule callback in the constructor's arguments takes 2 arguments 'from' (the origin vertex) & 'to' (the destination vertex) and returns true if an edge edists from the first to the second.
Below is an example that creates an edge between an instance of MyVertex and any other vertex in the graph (not just instance of MyVertex) that have an id greater than itself.
class MyVertex extends Vertex { public static edges = new Edge((from, to) => from.id > to); } // Create a new graph const graph = new Graph(); // Creates some vertices to add to the graph const vertex1 = new MyVertex(1); const vertex2 = new SomeOtherVertex(2); // Not an instance of Myvertex const vertex3 = new MyVertex(3); graph.addVertex(vertex1); graph.addVertex(vertex2); graph.addVertex(vertex3); vertex1.edges // [vertex2, vertex3] vertex2.edges // [vertex3] vertex3.edges // []