@graspologic/graph
Provides a set of graph data structures, used with the layout engine and the renderer.
Usage
Below are several common usage patterns for this library.
Dynamically adding nodes to your graph
Standalone
import { NodeImpl } from '@graspologic/graph'
import { WebGLGraphRenderer } from '@graspologic/renderer'
const renderer = WebGLGraphRenderer.createInstance()
const node = new NodeImpl()
node.position = [10, 10, 0]
node.radius = 10
renderer.scene.add(node)
React
import React, { useEffect, useRef } from 'react'
import { NodeImpl } from '@graspologic/graph'
import { GraphView } from '@graspologic/react'
import { GraphRenderer } from '@graspologic/renderer'
export const MyRenderer: React.FC = () => {
const graphRef = useRef<GraphRenderer>(null)
useEffect(() => {
if (graphRef.current) {
const node = new NodeImpl()
node.position = [10, 10, 0]
node.radius = 10
graphRef.current!.scene.add(node)
}
}, [graphRef])
return (
<GraphView ref={graphRef} data={{ nodes: [], edges: [] }}/>
)
}
Dynamically adding edges to your graph
Standalone
import { EdgeImpl } from '@graspologic/graph'
import { WebGLGraphRenderer } from '@graspologic/renderer'
const renderer = WebGLGraphRenderer.createInstance()
const edge = new EdgeImpl()
edge.sourcePosition = [0, 0, 0]
edge.targetPosition = [10, 10, 0]
renderer.scene.add(edge)
React
import React, { useEffect, useRef } from 'react'
import { EdgeImpl } from '@graspologic/graph'
import { GraphView } from '@graspologic/react'
import { GraphRenderer } from '@graspologic/renderer'
export const MyRenderer: React.FC = () => {
const graphRef = useRef<GraphRenderer>(null)
useEffect(() => {
if (graphRef.current) {
const edge = new EdgeImpl()
edge.sourcePosition = [0, 0, 0]
edge.targetPosition = [10, 10, 0]
graphRef.current!.scene.add(edge)
}
}, [graphRef])
return (
<GraphView ref={graphRef} data={{ nodes: [], edges: [] }}/>
)
}
Dynamically animating the edges of your graph
Standalone
import { EdgeImpl } from '@graspologic/graph'
import { WebGLGraphRenderer } from '@graspologic/renderer'
const renderer = WebGLGraphRenderer.createInstance()
const edge = new EdgeImpl()
edge.sourcePosition = [0, 0, 0]
edge.targetPosition = [10, 10, 0]
renderer.scene.add(edge)
edge.animateSourcePosition([100, 100, 0], 1000)
React
import React, { useEffect, useRef } from 'react'
import { EdgeImpl } from '@graspologic/graph'
import { GraphView } from '@graspologic/react'
import { GraphRenderer } from '@graspologic/renderer'
export const MyRenderer: React.FC = () => {
const graphRef = useRef<GraphRenderer>(null)
useEffect(() => {
if (graphRef.current) {
const edge = new EdgeImpl()
edge.sourcePosition = [0, 0, 0]
edge.targetPosition = [10, 10, 0]
graphRef.current!.scene.add(edge)
edge.animateSourcePosition([100, 100, 0], 1000)
}
}, [graphRef])
return (
<GraphView ref={graphRef} data={{ nodes: [], edges: [] }}/>
)
}
Dynamically animating the nodes of your graph
Standalone
import { NodeImpl } from '@graspologic/graph'
import { WebGLGraphRenderer } from '@graspologic/renderer'
const renderer = WebGLGraphRenderer.createInstance()
const node = new NodeImpl()
node.position = [10, 10, 0]
node.radius = 10
renderer.scene.add(node)
node.animatePosition([100, 100, 0], 1000)
React
import React, { useEffect, useRef } from 'react'
import { NodeImpl } from '@graspologic/graph'
import { GraphView } from '@graspologic/react'
import { GraphRenderer } from '@graspologic/renderer'
export const MyRenderer: React.FC = () => {
const graphRef = useRef < GraphRenderer > null
useEffect(() => {
if (graphRef.current) {
const node = new NodeImpl()
node.position = [10, 10, 0]
node.radius = 10
renderer.scene.add(node)
node.animatePosition([100, 100, 0], 1000)
}
}, [graphRef])
return <GraphView ref={graphRef} data={{ nodes: [], edges: [] }} />
}
See the API documentation or examples for additional examples.