var Log = { elem: false, write: function(text){ if (!this.elem) this.elem = document.getElementById('log'); this.elem.innerHTML = text; this.elem.style.left = (500 - this.elem.offsetWidth / 2) + 'px'; } }; function addEvent(obj, type, fn) { if (obj.addEventListener) obj.addEventListener(type, fn, false); else obj.attachEvent('on' + type, fn); }; function init(){ var infovis = document.getElementById('infovis'); var w = infovis.offsetWidth, h = infovis.offsetHeight; //init data //If a node in this JSON structure //has the "$type" or "$dim" parameters //defined it will override the "type" and //"dim" parameters globally defined in the //RGraph constructor. var json = [{ "id": "node0", "name": "node0 name", "data": { "$dim": 16.759175934208628, "some other key": "some other value" }, "adjacencies": [{ "nodeTo": "node1", "data": { "weight": 3 } }, { "nodeTo": "node2", "data": { "weight": 3 } }, { "nodeTo": "node3", "data": { "weight": 3 } }, { "nodeTo": "node4", "data": { "$type":"arrow", "$color":"#dd99dd", "$dim":25, "weight": 1 } }, { "nodeTo": "node5", "data": { "weight": 1 } }] }, { "id": "node1", "name": "node1 name", "data": { "$dim": 13.077119090372014, "$type": "square", "some other key": "some other value" }, "adjacencies": [{ "nodeTo": "node0", "data": { "weight": 3 } }, { "nodeTo": "node2", "data": { "weight": 1 } }, { "nodeTo": "node3", "data": { "weight": 3 } }, { "nodeTo": "node4", "data": { "weight": 1 } }, { "nodeTo": "node5", "data": { "weight": 1 } }] }, { "id": "node2", "name": "node2 name", "data": { "$dim": 24.937383149648717, "$type": "triangle", "some other key": "some other value" }, "adjacencies": [{ "nodeTo": "node0", "data": { "weight": 3 } }, { "nodeTo": "node1", "data": { "weight": 1 } }, { "nodeTo": "node3", "data": { "weight": 3 } }, { "nodeTo": "node4", "data": { "weight": 3 } }, { "nodeTo": "node5", "data": { "weight": 1 } }] }, { "id": "node3", "name": "node3 name", "data": { "$dim": 10.53272740718869, "some other key": "some other value" }, "adjacencies": [{ "nodeTo": "node0", "data": { "weight": 3 } }, { "nodeTo": "node1", "data": { "weight": 3 } }, { "nodeTo": "node2", "data": { "weight": 3 } }, { "nodeTo": "node4", "data": { "$type":"arrow", "$direction": ["node4", "node3"], "$dim":25, "$color":"#dd99dd", "weight": 1 } }, { "nodeTo": "node5", "data": { "weight": 3 } }] }, { "id": "node4", "name": "node4 name", "data": { "$dim": 5.3754347037767345, "$type":"triangle", "some other key": "some other value" }, "adjacencies": [{ "nodeTo": "node0", "data": { "weight": 1 } }, { "nodeTo": "node1", "data": { "weight": 1 } }, { "nodeTo": "node2", "data": { "weight": 3 } }, { "nodeTo": "node3", "data": { "weight": 1 } }, { "nodeTo": "node5", "data": { "weight": 3 } }] }, { "id": "node5", "name": "node5 name", "data": { "$dim": 32.26403873194912, "$type": "star", "some other key": "some other value" }, "adjacencies": [{ "nodeTo": "node0", "data": { "weight": 1 } }, { "nodeTo": "node1", "data": { "weight": 1 } }, { "nodeTo": "node2", "data": { "weight": 1 } }, { "nodeTo": "node3", "data": { "weight": 3 } }, { "nodeTo": "node4", "data": { "weight": 3 } }] }]; //end //init canvas //Create a new canvas instance. var canvas = new Canvas('mycanvas', { 'injectInto': 'infovis', 'width': w, 'height': h, //Optional: Add a background canvas //that draws some concentric circles. 'backgroundCanvas': { 'styles': { 'strokeStyle': '#444' }, 'impl': { 'init': function(){}, 'plot': function(canvas, ctx){ var times = 6, d = 200; var pi2 = Math.PI * 2; for (var i = 1; i <= times; i++) { ctx.beginPath(); ctx.arc(0, 0, i * d, 0, pi2, true); ctx.stroke(); ctx.closePath(); } } } } }); //end //init RGraph var rgraph = new RGraph(canvas, { //Nodes and Edges parameters //can be overriden if defined in //the JSON input data. //This way we can define different node //types individually. Node: { 'overridable': true, 'color': '#cc0000' }, Edge: { 'overridable': true, 'color': '#cccc00' }, //Set polar interpolation. //Default's linear. interpolation: 'polar', //Change the transition effect from linear //to elastic. transition: Trans.Elastic.easeOut, //Change other animation parameters. duration:3500, fps: 30, //Change father-child distance. levelDistance: 200, //This method is called right before plotting //an edge. This method is useful to change edge styles //individually. onBeforePlotLine: function(adj){ //Add some random lineWidth to each edge. if (!adj.data.$lineWidth) adj.data.$lineWidth = Math.random() * 5 + 1; }, onBeforeCompute: function(node){ Log.write("centering " + node.name + "..."); //Make right column relations list. var html = "