# Module: Edge

Accessible via `require('@buggyorg/graphtools').Edge`

Source:
  - edge.js, line 1

### Methods

#### (static) normalize(edge) → {Edge}

Normalizes the edge into the standard format

     {from: '<port>', to: '<port>'}

It accepts the following short forms:

     {from: '<node>@<port>', to: '<node>@<port>'}
     {from: '@<port>', to: '<node>@<port>'}
     {from: '<node>@<port>', to: '@<port>'}
     {from: '@<port>', to: '@<port>'}
     {from: '<node>', to: '<node>', outPort: '<port-name>', inPort: '<port-name>'}

The format must be consistent, you cannot have a mixture for `from` and `to`. It is not possible to always add those normalized edges into the graph. They must contain valid IDs of the graph. Use `Graph.normalize` for this.

##### Parameters:

Name | Type | Description
--- | --- | ---
`edge` | Edge | The edge object that should be normalized.

Source:
  - edge.js, line 67

##### Throws:

An error is thrown if the edge is not in a consistent format.

Type
  Error

##### Returns:

The normalized form of the edge.

Type
  Edge

#### (static) setPath(edge, path) → {Edge}

Returns a copy of the edge where the path is prefixed with the specified path. [Does nothing currently... can probably be removed. Is used in ./compound.js]

##### Parameters:

Name | Type | Description
--- | --- | ---
`edge` | Edge | The edge that will be prefixed
`path` | CompoundPath | The compound path that prefixes the edge paths.

Source:
  - edge.js, line 100

##### Returns:

A new edge that has the prefixed paths.

Type
  Edge

#### (static) setType(type, edge) → {Edge}

Explicitly sets the type of the edge. The type of an edge is determined by the connecting ports.

##### Parameters:

Name | Type | Description
--- | --- | ---
`type` | Type | The type of the edge.
`edge` | Edge | The edge that should get the type.

Source:
  - edge.js, line 128

##### Returns:

A new edge that has a field for the type.

Type
  Edge

#### (static) type(edge) → {Type|undefined}

Gets the type of an edge. Note that not every edge must have a type and that the type is not stored inside the json document. If you use the graph functions to iterate over edges you always get the type (if available) with the edge.

##### Parameters:

Name | Type | Description
--- | --- | ---
`edge` | Edge | The edge to use.

Source:
  - edge.js, line 118

##### Returns:

Either a real type, a typename or `undefined`. Some edges do not have type information. Usually non-dataflow edges like recursion indicators. Those will yield `undefined`.

Type
  Type | undefined

##### Examples

Get an edge via a graph method and then get its edge.

    var edge = Graph.incident(port, graph)
    var type = Edge.type(edge)

It will yield undefined if you simply access an edge in the json document, do not do that.

    var edge = graph.edges[0]
    //this will return undefined
    var type = Edge.type(edge) // = undefined

#### (inner) equal(edge1, edge2) → {boolean}

Checks whether two normalized edges are equal.

##### Parameters:

Name | Type | Description
--- | --- | ---
`edge1` | Edge | The first edge for the comparison.
`edge2` | Edge | The second edge for the comparison.

Source:
  - edge.js, line 78

##### Returns:

True if the edges are equal (i.e. they connect the same ports), false otherwise.

Type
  boolean