ngraph.three
This is a 3d graph renderer, which uses three.js as a rendering engine.
This library is a part of ngraph project.
Please check out ngraph.pixel - it is also developed with three.js,
however it uses lower level primitive (ShaderMaterial)
which allows it to be really fast (the price is flexibility of your UI model).
usage
Basic example:
var createGraph = require('ngraph.graph');
var graph = createGraph();
graph.addLink(1, 2);
var nthree = require('ngraph.three');
var graphics = nthree(graph);
graphics.run();
Very often it is required to do something with scene before animation frame is rendered. To do so
use onFrame()
callback:
var nthree = require('ngraph.three');
var graphics = nthree(graph);
graphics.onFrame(function() {
console.log('Frame is being rendered');
});
graphics.run();
Configuration
You can configure renderer in many ways. To do so you can pass settings
object to the function. Calling
var nthree = require('ngraph.three');
var graphics = nthree(graph);
Is equivalent of calling:
var nthree = require('ngraph.three');
var graphics = nthree(graph, {
interactive: true,
container: document.body,
physicsSettings: {
springLength: 30,
springCoeff: 0.0008,
gravity: -1.2,
theta: 0.8,
dragCoeff: 0.02,
timeStep : 20
},
layout: require('ngraph.forcelayout3d')(graph, this.physicsSettings),
renderer: isWebGlSupported ? new THREE.WebGLRenderer(this) : new THREE.CanvasRenderer(this),
scene: new THREE.Scene(),
camera: new THREE.PerspectiveCamera(75, this.container.clientWidth/container.clientHeight, 0.1, 3000)
});
You can always override any of these settings with your own.
examples
Many examples are available in ngraph repository
install
With npm do:
npm install ngraph.three
license
MIT