module.exports.main = function () { var query = {}; //require('query-string').parse(window.location.search.substring(1)); var graph = getGraphFromQueryString(query); //graph.removeNode(1); graph.addLink(2, 'space'); graph.addNode(150, { size: Math.random() * 25 + 1, color: "red" }); // and links: graph.addLink(2, 150, { color: "red" }); var createThree = require('ngraph.three'); var graphics = createThree(graph, {interactive: true}); var THREE = graphics.THREE; console.debug(graph); console.log(JSON.stringify(graph)); //query is {} ?????? // tell graphics we want custom UI graphics.createNodeUI(function () { var size = Math.random() * 10 + 1; //var nodeGeometry = new THREE.BoxGeometry(size,size,size); //SphereGeometry(size); var nodeGeometry = new THREE.SphereGeometry(size); var nodeMaterial = new THREE.MeshPhongMaterial({ color: getNiceColor(), ambient: 0x996633, // should generally match color specular: 0x050505, shininess: 100 }); return new THREE.Mesh(nodeGeometry, nodeMaterial); }).createLinkUI(function() { var linkGeometry = new THREE.Geometry(); // we don't care about position here. linkRenderer will update it linkGeometry.vertices.push(new THREE.Vector3(0, 0, 0)); linkGeometry.vertices.push(new THREE.Vector3(0, 0, 0)); var linkMaterial = new THREE.LineBasicMaterial({ color: getNiceColor() }); return new THREE.Line(linkGeometry, linkMaterial); }); var scene = graphics.scene; var directionalLight = new THREE.DirectionalLight(0xffffff, 2); directionalLight.position.set( 1, 1, 1 ); scene.add(directionalLight); //var light = new THREE.PointLight(0xffffff, 10, 0); //light.position.set(0,0,0); //scene.add(light); graphics.run(); // begin animation loop: graphics.camera.position.z = getNumber(query.z, 400); }; function getGraphFromQueryString(query) { var graphGenerators = require('ngraph.generators'); //var createGraph = graphGenerators[query.graph] || graphGenerators.circularLadder; //var createGraph = graphGenerators[query.graph] || graphGenerators.grid; var createGraph = graphGenerators[query.graph] || graphGenerators.grid3; //var createGraph = graphGenerators[query.graph] || graphGenerators.balancedBinTree; //var createGraph = graphGenerators.complete; //graphGenerators[query.graph] || graphGenerators.complete; //var createGraph = graphGenerators.noLinks; return createGraph(getNumber(query.n), getNumber(query.m), getNumber(query.k)); } function getNumber(string, defaultValue) { var number = parseFloat(string); return (typeof number === 'number') && !isNaN(number) ? number : (defaultValue || 10); } var niceColors = [ 0x1f77b4, 0xaec7e8, 0xff7f0e, 0xffbb78, 0x2ca02c, 0x98df8a, 0xd62728, 0xff9896, 0x9467bd, 0xc5b0d5, 0x8c564b, 0xc49c94, 0xe377c2, 0xf7b6d2, 0x7f7f7f, 0xc7c7c7, 0xbcbd22, 0xdbdb8d, 0x17becf, 0x9edae5 ]; function getNiceColor() { return niceColors[(Math.random() * niceColors.length)|0]; }