Graph Operations

Underlying each instance of the Toolkit there is a directed graph. This
object - accessed via the getGraph method of a jsPlumbToolkitInstance - offers a complete set of methods for
querying the state of the graph - from questions like "is node A connected to node B" through to "what is the shortest
path from node A and node B?", or "what is the centrality of Node C?".

Note the last example returns undefined: remember that Edges in the Toolkit are, by default, directed. If you look
again at the dataset you can see that there is no route from Node 4 to Node 5, since both of these Nodes are connected
to the Graph only as targets of Edges from Node 3.

Shortest Paths

To get the shortest path from some Node/Port to another Node/Port, use the getPath method:

toolkit.getPath({source:"1",target:"3"})->e…s.Path{path:Object}

The return value from this method is a Path. This is a complex object with many helper functions; if you
need a more simple return value you can access the Graph's findPath method directly:

Centrality

Degree Centrality

The degree centrality of a node is the sum of the number of Edges entering and exiting the node divided by the total
number of Edges in the Graph. Looking at the dataset we're using on this page you may have noticed that Node 3 has more
connections than any other node, and this observation is reflected in the output of getDegreeCentrality :

Farness

The farness of a node is the sum of its distance from all other Nodes, where the distance from one Node to another
is given by the associated cost of the Edge joining the two Nodes. As with degree centrality, this is divided by
the number of Edges, to normalise the results. Note that here we have a Graph that has Nodes which cannot "reach"
every other Node (because all Edges are directed), so the "farness" of every Node is Infinity except Node 1, which
can trace a path to every other Node.

...so the only Node that has a useful value for closeness is Node 1. At the bottom of this page we present a revised
version of the dataset in which Edges are all marked directed:false, and then we show that the output of getFarness
and getCloseness provides a usable value for every Node.

Betweenness Centrality

The betweenness centrality of a Node measures how central
the Node is in the Graph. It is the number of shortest paths between any two Nodes in the Graph that pass through
the given Nodes. The jsPlumb Toolkit computes this by first computing all the shortest paths in the Graph using
the Floyd-Warshall algorithm.

We see from the output here that Node 3 is the most "central" Node in this Graph, with Node 2 next. Nodes 1, 4 and 5 are
not "central" as no paths go through these Nodes.

Graph Diameter

Use the getDiameter method to find the Graph's diameter - the length
of the "longest shortest path" in the Graph.

In a Graph that contains at least one pair of Nodes for which there is no available path, this value, strictly speaking,
is Infinity. Our dataset on this page is one such Graph, but it doesn't seem like an unreasonable dataset, right? So
the Toolkit allows you to specify that you're happy to ignore the case that there are one or more pairs of Nodes for
which no Path exists: