A component is a template for nodes. They represent the structure of the component.
A component consists of a componentId
and is an atomic or a compound node. It must have
a valid semver version and a list of ports (each component must have at least one port).
{
componentId: 'componentIdentifier',
version: "1.0.0",
atomic: true,
ports: [{port: 'in', kind: 'input', type: 'Number'},{port: 'out', kind: 'output', type: 'Number'}]
}
Accessible via require('@buggyorg/graphtools').Component
- Source:
Methods
(static) createNode(reference, comp) → {Node}
Create a node from a component.
Parameters:
Name | Type | Description |
---|---|---|
reference |
Reference | The reference to the component. |
comp |
Component | The component that is the basis for the new node. |
- Source:
Returns:
A node with the given name representing the component.
- Type
- Node
(static) id() → {string}
Returns the unique identifier of a node
- Source:
Throws:
-
If the node value is invalid.
- Type
- Error
Returns:
The unique identifier of the node
- Type
- string
(static) inputPorts(comp) → {Array.<Port>}
Gets all input ports of the component.
Parameters:
Name | Type | Description |
---|---|---|
comp |
Component | The component. |
- Source:
Returns:
A possibly empty list of input ports.
- Type
- Array.<Port>
(static) isomorph(graph1, graph2) → {Boolean}
Tests if two components are isomorphic i.e. deep equal.
Parameters:
Name | Type | Description |
---|---|---|
graph1 |
Portgraph | One of the graphs. |
graph2 |
Portgraph | And the other graph to test. |
- Source:
Returns:
True if the components of the two graphs are isomorphic, false otherwise. Components are isomorphic, if they are deep equal.
- Type
- Boolean
(static) isValid(comp) → {boolean}
Checks whether a component is in a valid format, i.e. if it has an id field and at least one port.
Parameters:
Name | Type | Description |
---|---|---|
comp |
Component | The component to test. |
- Source:
Returns:
True if the component is valid, false otherwise.
- Type
- boolean
(static) outputPorts(comp) → {Array.<Port>}
Gets all output ports of the comp.
Parameters:
Name | Type | Description |
---|---|---|
comp |
Component | The node. |
- Source:
Returns:
A possibly empty list of output ports.
- Type
- Array.<Port>
(static) ports(comp) → {Array.<Port>}
Gets all ports of the component.
Parameters:
Name | Type | Description |
---|---|---|
comp |
Component | The component. |
- Source:
Returns:
A list of ports.
- Type
- Array.<Port>
(inner) equal(comp1, comp2) → {boolean}
Tests whether two components are the same component. This tests only if their component IDs are the same not if both components contain the same information.
Parameters:
Name | Type | Description |
---|---|---|
comp1 |
Component | One of the components to test. |
comp2 |
Component | The other one. |
- Source:
Returns:
True if they have the same id, false otherwise.
- Type
- boolean
(inner) hasPort(name, comp) → {Port}
Checks whether the component has the specific port.
Parameters:
Name | Type | Description |
---|---|---|
name |
String | The name of the port. |
comp |
Component | The component which has the port. |
- Source:
Returns:
True if the port has a port with the given name, false otherwise.
- Type
- Port
(inner) port(comp, name) → {Port}
Returns the port data for a given port.
Parameters:
Name | Type | Description |
---|---|---|
comp |
Component | The component which has the port. |
name |
String | The name of the port. |
- Source:
Throws:
-
If no port with the given name exists in this component an error is thrown.
- Type
- Error
Returns:
The port data.
- Type
- Port