https://github.com/playcanvas/pcui-graph
A PCUI extension for creating node-based graphs
https://github.com/playcanvas/pcui-graph
javascript pcui playcanvas reactjs ui ui-components
Last synced: 6 months ago
JSON representation
A PCUI extension for creating node-based graphs
- Host: GitHub
- URL: https://github.com/playcanvas/pcui-graph
- Owner: playcanvas
- License: mit
- Created: 2020-10-22T15:03:59.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2025-03-29T00:48:39.000Z (6 months ago)
- Last Synced: 2025-04-03T18:15:47.783Z (6 months ago)
- Topics: javascript, pcui, playcanvas, reactjs, ui, ui-components
- Language: JavaScript
- Homepage: https://developer.playcanvas.com/user-manual/pcui/pcui-graph/
- Size: 7.89 MB
- Stars: 131
- Watchers: 9
- Forks: 16
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PCUI Graph - Node-based Graphs for PCUI
[](https://github.com/playcanvas/pcui-graph/blob/main/LICENSE)
[](https://www.npmjs.com/package/@playcanvas/pcui-graph)
[](https://npmtrends.com/@playcanvas/pcui=gra[j)| [User Guide](https://developer.playcanvas.com/user-manual/pcui/pcui-graph/) | [API Reference](https://api.playcanvas.com/pcui-graph/) | [React Examples](https://playcanvas.github.io/pcui-graph/storybook/) | [Blog](https://blog.playcanvas.com/) | [Forum](https://forum.playcanvas.com/) | [Discord](https://discord.gg/RSaMRzg) |

Create node based visual graphs in the browser. Supports undirected / directed graphs as well as visual scripting graphs containing nodes with input / output ports. Your graphs can be saved to a JSON file and loaded back into a new graph view at any time.
## Getting Started
First install PCUI Graph into your npm project:
npm install @playcanvas/pcui-graph --save-dev
You can then use the library in your own project by importing the PCUI Graph build and its styling file into your project. The graph can then be instantiated as follows:
```javascript
import Graph from '@playcanvas/pcui-graph';
import '@playcanvas/pcui/styles';
import '@playcanvas/pcui-graph/styles';const schema = {
nodes: {
0: {
name: 'Hello',
fill: 'red'
},
1: {
name: 'World',
fill: 'green'
}
},
edges: {
0: {
from: [0], // this edge can connect nodes of type 0
to: [1], // to nodes of type 1,
stroke: 'blue'
}
}
}const graph = new Graph(schema);
document.body.appendChild(graph.dom);
```The library is also available on [npm](https://www.npmjs.com/package/@playcanvas/pcui-graph) and can be installed in your project with:
npm install --save @playcanvas/pcui-graph @playcanvas/pcui @playcanvas/observer
The npm package includes two builds of the library:
@playcanvas/pcui-graph/dist/pcui-graph.js // UMD build (requires that the pcui and observer libraries are present in the global namespace)
@playcanvas/pcui-graph/dist/pcui-graph.mjs // module build (requires a build tool like rollup / webpack)## Storybook
Examples of graphs created using PCUI Graph are available in this library's [storybook](https://playcanvas.github.io/pcui-graph/storybook/). Alternatively you can run the storybook locally and use it as a development environment for your own graphs. To do so, run the following commands in this projects root directory:
npm install
npm run storybookThis will automatically open the storybook in a new browser tab.
# Documentation
Information on building the documentation can be found in the [docs](./docs/README.md) directory.