@scalable.software/graph.structure
v2.1.3
Published
Nodes and Connections Data Structures with Utility Functions
Downloads
1
Keywords
Readme
Graph Structure
This is a ES6 modules that can be used to create a graph structure. The graph structure is a data structure that consists: metadata, nodes and connections.
Installation
Create a new repository using this template
Clone the repository to your local machine
Install the dependencies
npm install
- Run the unit tests to ensure everything is working as expected
npm test
- Build the web component
npm run build
Note: this module was build using the web.component templates. Follow the link to get more information about the unique features of the architecture in use.
Usage
A simple demo is provided in the demo
folder. To run the demo run the following command:
npm run serve
Open the console and you will see a sample node printed to the console.
API
Extended arrays as used for the graph nodes and connections. The methods available on graph.nodes
and graph.connections
includes a fluent API, where possible. The following methods are available:
Nodes
graph.nodes.create(details: Omit<Node, 'id'>): Nodes
Create a new node by using the provided details, adding a unique id and adding it tograph.nodes
graph.nodes.add(node: Node | Node[]): Nodes
Add a node to the graphgraph.nodes.addMetadata(id: UUID, metadata: NodeMetadata): Nodes
Add metadata to a node ingraph.nodes
where id matches the provided idgraph.nodes.update(id: UUID, update: Node): Nodes
Update a node ingraph.nodes
where id matches the provided idgraph.nodes.updateMetadata(id: UUID, metadata: NodeMetadata): Nodes
Update the metadata of a node ingraph.nodes
where id matches the provided idgraph.nodes.updateIcon(id: UUID, icon: string): Nodes
Update the icon of a node ingraph.nodes
where id matches the provided idgraph.nodes.updateCoordinates(id: UUID, coordinates: Coordinates): Nodes
Update the coordinates of a node ingraph.nodes
where id matches the provided idgraph.nodes.findById(id: UUID): Node
Find a node ingraph.nodes
where id matches the provided idgraph.nodes.findByType(type: NodeType): Node[]
Find all nodes ingraph.nodes
where type matches the provided typegraph.nodes.findByCoordinates(coordinates: Coordinates): Node[]
Find all nodes ingraph.nodes
where coordinates matches the provided coordinatesgraph.nodes.translate(id: UUID, offset: Offset): Nodes
Translate a node ingraph.nodes
where id matches the provided id by the provided offsetgraph.nodes.removeMetadata(id: UUID, type: NodeType): Nodes
Remove metadata from a node ingraph.nodes
where id matches the provided id and key matches the provided keygraph.nodes.remove(id: UUID): Nodes
Remove a node fromgraph.nodes
where id matches the provided id
Connections
graph.connections.create(details: Omit<Connection, 'id'>): Connections
Create a new connection by using the provided details, adding a unique id and adding it tograph.connections
graph.connections.add(connection: Connection | Connection[]): Connections
Add a connection to thegraph.connections
graph.connections.update(id: UUID, update: Connection): Connections
Update a connection ingraph.connections
where id matches the provided idgraph.connections.findById(id: UUID): Connection
Find a connection ingraph.connections
where id matches the provided idgraph.connections.translate(id: UUID, offset: Offset): Connections
Translate a connection ingraph.connections
where id matches the provided id by the provided offsetgraph.connections.remove(id: UUID): Connections
Remove a connection fromgraph.connections
where id matches the provided id
For more details see the documentation available at is available in the docs
folder after running the following command:
npm run document
License
his software and its documentation are released under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International Public License (CC BY-NC-SA 4.0). This means you are free to share, copy, distribute, and transmit the work, and to adapt it, but only under the following conditions:
Attribution: You must attribute the work in the manner specified by the author or licensor (but not in any way that suggests that they endorse you or your use of the work).
NonCommercial: You may not use this material for commercial purposes.
ShareAlike: If you alter, transform, or build upon this work, you may distribute the resulting work only under the same or similar license to this one.
For more details, please visit the full license agreement.