@graspologic/renderer
Contains the graspologic-js graph renderer.
React bindings are also available here.
Basic Usage
import { WebGLGraphRenderer } from '@graspologic/renderer'
import { GraphContainer } from '@graspologic/graph'
const GRAPH_DATA = {
nodes: [
{
id: 'A',
x: -10,
y: 10,
z: 0,
radius: 5,
color: 0x00ff00,
},
{
id: 'B',
x: 10,
y: 10,
z: 0,
radius: 5,
color: 0xff0000,
},
],
edges: [
{
source: 'A',
target: 'B',
weight: 1,
},
],
}
function createRenderer(data, width, height) {
const renderer = WebGLGraphRenderer.createInstance({
width,
height,
edgeMinWidth: 5,
edgeMaxWidth: 5,
edgeAlpha: 1,
})
renderer.load(GraphContainer.intern(data))
renderer.start()
return renderer
}
export default () => {
const renderer = createRenderer(GRAPH_DATA, 200, 200)
return renderer.view
}
Extended Usage
import {
WebGLGraphRenderer,
enableClickEvents,
VertexSetRenderable,
} from '@graspologic/renderer'
import { GraphContainer } from '@graspologic/graph'
import { exampleData, utils } from 'docs'
function createRenderer(data, width, height) {
const renderer = WebGLGraphRenderer.createInstance({
width,
height,
edgeMinWidth: 5,
edgeMaxWidth: 5,
edgeAlpha: 1,
nodeMinRadius: 5,
nodeMaxRadius: 5,
})
const categoricalColorizer = utils.createColorizer()
renderer.load(GraphContainer.intern(data), categoricalColorizer)
enableClickEvents(renderer)
const renderable = new VertexSetRenderable(renderer.gl)
renderable.color = [0.5, 0.5, 0.8, 1]
renderer.scene.addRenderable(renderable)
renderer.on('vertexHovered', hovered => {
renderable.setData(hovered ? [hovered] : [])
})
renderer.start()
return renderer
}
const GRAPH_DATA = exampleData.smallGraph()
export default () => {
const renderer = createRenderer(GRAPH_DATA, 600, 300)
let selectedNodeIds = []
renderer.on('vertexClick', id => {
console.log('click', id)
if (id) {
if (selectedNodeIds.indexOf(id) === -1) {
selectedNodeIds = [...selectedNodeIds, id]
} else {
selectedNodeIds = selectedNodeIds.filter(v => v !== id)
}
}
})
return renderer.view
}
See the API documentation or examples for additional examples.