Skip to content
Walter Rafelsberger edited this page Nov 12, 2015 · 1 revision

# graph.get(spec)

Retrieves a vertex from the current graph having the required properties as defined by the method argument.

» vertex = graph.get({id: 'foo'});
» console.log(vertex.toString());
"<Vertex graph-vertex-foo: 1 outgoing, 2 incoming>"

# graph.indexOf(vertex)

Returns the current index of the vertex in the graph.vertices() array, -1 if the vertex is not contained in the array.

» console.log(graph.count());
4
» vertex = graph.add({});
» console.log(graph.indexOf(vertex));
4

The vertex argument does not necessarily have to be a reference to an existing vertex; a simple object having the desired id is also working:

» console.log(graph.indexOf({id: 'foo'}));
2

# graph.filter(spec)

Returns a collection of vertices or edges, depending on the spec:

» graph.filter({type: 'vertex'});
» graph.filter({type: 'edge'});
» graph.filter({type: 'vertex', size: 2});

# graph.time()

Returns the date the graph was started the last time.

# graph.canvas()

Returns the SVG element the graph is using as canvas, i.e. where all further SVG elements are being appended to.

# graph.contains(vertex)

Checks whether the vertex is contained in the graph’s array of vertices. Syntactic sugar for graph.indexOf(vertex) > -1.

# graph.bbox([vertex])

Without the optional argument this method returns the bounding box of the whole graph, i.e. the rectangle defined by the outermost top left and the outermost bottom right graph’s element.

With a given vertex as argument, the bounding box is calculated for those elements comprising the vertex only.

# graph.count()

Use this method to get the number of vertices contained in the graph. (A shortcut for graph.vertices().length.)

# graph.center()

Returns the x and y coordinates of the graph’s center position.

» graph.width(800).height(600);
» console.log(graph.center());
{x: 400, y: 300}

# graph.alpha()

Returns a value between 1.0 and 0.0 as measure of the current stability of the graph; i.e. if the graph’s layouts are in great movement this value is going to be closer to 1, while for a completely stable and calm graph the value equals zero.

# graph.export()

Exports the vertices and edges in a text-based format. Current supported formats are GraphViz’s dot and Pajek.

» console.log(graph.export('dot'));
"strict digraph { Foo Bar Foo -> Bar}"

# graph.running()

Returns true if the graph is currently running, false otherwise.

# graph.selection()

Returns the D3 element(s) the graph’s SVG element is added to – which is <body> by default.

Clone this wiki locally