Vamonos.DataStructure.Graph

Back

The Graph data structure provides standard graph functionality to Vamonos.

Constructor Arguments

directed :: Boolean – default value: false

Whether the graph is directed.

edges :: Object Array – optional

A single edge or an array of edges to create the graph with.

For Example:

edges: [
    {source: 'v0',target: 'v4'},
    {source: 'v1',target: 'v2'},
]

prefix :: String – default value: ""

A string prepended to each new vertex id.

vertices :: Object Array – optional

A single vertex or an array of vertices to create the graph with.

For Example:

vertices: [
    {id: "v0", x: 17,  y: 10},
    {id: "v1", x: 98,  y: 10},
    {id: "v3", x: 15,  y: 78},
]

Public Interface

addEdge(source, target, attrs)

adds an edge from source to target with attributes copied from attrs

addVertex(vtx)

adds vtx to the graph

collapse(e, overlapFunc)

collapses e, creating a new vertex. By default vertex names are concatenations of the collapsed vertices’ names, vertices’ positions are averaged, and overlapping edges take the min weight. only works on undirected graphs. overlapFunc is an optional parameter for a function that decides what to do with overlapping edges after a collapse. By default overlapFunc keeps the edge with least w.

eachEdge(f)

applies f to each edge

eachEdgeBy(comp, f)

applies f to each edge, ordered by comp

eachNeighbor(v, f)

applies f to each neighbor of v

eachVertex(f)

applies f to each vertex in the graph

eachVertexBy(comp, f)

applies f to each vertex in the graph, ordered by comp

edge(source, target)

if there is an edge from source to target, returns it. understands undirected graphs.

edgeId(e)

returns a string identifying e

getEdges()

returns an array of all edges in the graph

getVertices()

returns an array of all vertices

incomingEdges(v)

returns all incoming edges of v

neighbors(v)

returns all neighbors of v

nextVertexId()

returns an unused vertex id

nextVertexName()

returns the next available vertex name

outgoingEdges(v)

returns all outgoing edges of v

removeEdge(source, target)

removes the edge from source to target. understands directedness.

removeVertex(v)

removes the vertex matching v and all related edges from the graph

removeVertexName(name)

removes name from the list of available vertex names

returnVertexName(n)

adds n to the list of available vertex names

toString()

returns a javascripty string you could use to initialize a graph with.

vertex(vid)

returns the vertex object matching vid