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(){ //init data var json = { id: "190_0", name: "Pearl Jam", children: [{ id: "306208_1", name: "Pearl Jam & Cypress Hill", data: { relation: "

Pearl Jam & Cypress Hill

Connections:" }, children: [{ id: "84_2", name: "Cypress Hill", data: { relation: "

Cypress Hill

Connections:" }, children: [] }] }, { id: "107877_3", name: "Neil Young & Pearl Jam", data: { relation: "

Neil Young & Pearl Jam

Connections:" }, children: [{ id: "964_4", name: "Neil Young", data: { relation: "

Neil Young

Connections:" }, children: [] }] }, { id: "236797_5", name: "Jeff Ament", data: { relation: "

Jeff Ament

Connections:" }, children: [{ id: "1756_6", name: "Temple of the Dog", data: { relation: "

Temple of the Dog

Connections:" }, children: [] }, { id: "14581_7", name: "Mother Love Bone", data: { relation: "

Mother Love Bone

Connections:" }, children: [] }, { id: "50188_8", name: "Green River", data: { relation: "

Green River

Connections:" }, children: [] }, { id: "65452_9", name: "M.A.C.C.", data: { relation: "

M.A.C.C.

Connections:" }, children: [] }, { id: "115632_10", name: "Three Fish", data: { relation: "

Three Fish

Connections:" }, children: [] }, { id: "346850_11", name: "Gossman Project", data: { relation: "

Gossman Project

Connections:" }, children: [] }] }, { id: "41529_12", name: "Stone Gossard", data: { relation: "

Stone Gossard

Connections:" }, children: [{ id: "1756_13", name: "Temple of the Dog", data: { relation: "

Temple of the Dog

Connections:" }, children: [] }, { id: "14581_14", name: "Mother Love Bone", data: { relation: "

Mother Love Bone

Connections:" }, children: [] }, { id: "24119_15", name: "Brad", data: { relation: "

Brad

Connections:" }, children: [] }, { id: "50188_16", name: "Green River", data: { relation: "

Green River

Connections:" }, children: [] }, { id: "346850_17", name: "Gossman Project", data: { relation: "

Gossman Project

Connections:" }, children: [] }] }, { id: "131161_18", name: "Eddie Vedder", data: { relation: "

Eddie Vedder

Connections:" }, children: [{ id: "1756_19", name: "Temple of the Dog", data: { relation: "

Temple of the Dog

Connections:" }, children: [] }, { id: "72007_20", name: "Eddie Vedder & Zeke", data: { relation: "

Eddie Vedder & Zeke

Connections:" }, children: [] }, { id: "236657_21", name: "Bad Radio", data: { relation: "

Bad Radio

Connections:" }, children: [] }, { id: "432176_22", name: "Beck & Eddie Vedder", data: { relation: "

Beck & Eddie Vedder

Connections:" }, children: [] }] }, { id: "236583_23", name: "Mike McCready", data: { relation: "

Mike McCready

Connections:" }, children: [{ id: "1744_24", name: "Mad Season", data: { relation: "

Mad Season

Connections:" }, children: [] }, { id: "1756_25", name: "Temple of the Dog", data: { relation: "

Temple of the Dog

Connections:" }, children: [] }, { id: "43661_26", name: "$10,000 Gold Chain", data: { relation: "

$10,000 Gold Chain

Connections:" }, children: [] }, { id: "65452_27", name: "M.A.C.C.", data: { relation: "

M.A.C.C.

Connections:" }, children: [] }, { id: "153766_28", name: "The Rockfords", data: { relation: "

The Rockfords

Connections:" }, children: [] }, { id: "346850_29", name: "Gossman Project", data: { relation: "

Gossman Project

Connections:" }, children: [] }] }, { id: "236585_30", name: "Matt Cameron", data: { relation: "

Matt Cameron

Connections:" }, children: [{ id: "1111_31", name: "Soundgarden", data: { relation: "

Soundgarden

Connections:" }, children: [] }, { id: "1756_32", name: "Temple of the Dog", data: { relation: "

Temple of the Dog

Connections:" }, children: [] }, { id: "9570_33", name: "Eleven", data: { relation: "

Eleven

Connections:" }, children: [] }, { id: "11783_34", name: "Queens of the Stone Age", data: { relation: "

Queens of the Stone Age

Connections:" }, children: [] }, { id: "61972_35", name: "Wellwater Conspiracy", data: { relation: "

Wellwater Conspiracy

Connections:" }, children: [] }, { id: "65452_36", name: "M.A.C.C.", data: { relation: "

M.A.C.C.

Connections:" }, children: [] }, { id: "353097_37", name: "Tone Dogs", data: { relation: "

Tone Dogs

Connections:" }, children: [] }] }, { id: "236594_38", name: "Dave Krusen", data: { relation: "

Dave Krusen

Connections:" }, children: [{ id: "2092_39", name: "Candlebox", data: { relation: "

Candlebox

Connections:" }, children: [] }] }, { id: "236022_40", name: "Matt Chamberlain", data: { relation: "

Matt Chamberlain

Connections:" }, children: [{ id: "54761_41", name: "Critters Buggin", data: { relation: "

Critters Buggin

Connections:" }, children: [] }, { id: "92043_42", name: "Edie Brickell and New Bohemians", data: { relation: "

Edie Brickell and New Bohemians

Connections:" }, children: [] }] }, { id: "236611_43", name: "Dave Abbruzzese", data: { relation: "

Dave Abbruzzese

Connections:" }, children: [{ id: "276933_44", name: "Green Romance Orchestra", data: { relation: "

Green Romance Orchestra

Connections:" }, children: [] }] }, { id: "236612_45", name: "Jack Irons", data: { relation: "

Jack Irons

Connections:" }, children: [{ id: "4619_46", name: "Redd Kross", data: { relation: "

Redd Kross

Connections:" }, children: [] }, { id: "9570_47", name: "Eleven", data: { relation: "

Eleven

Connections:" }, children: [] }, { id: "12389_48", name: "Red Hot Chili Peppers", data: { relation: "

Red Hot Chili Peppers

Connections:" }, children: [] }, { id: "114288_49", name: "Anthym", data: { relation: "

Anthym

Connections:" }, children: [] }, { id: "240013_50", name: "What Is This?", data: { relation: "

What Is This?

Connections:" }, children: [] }] }], data: { relation: "

Pearl Jam

Connections:" } }; //end var infovis = document.getElementById('infovis'); var w = infovis.offsetWidth, h = infovis.offsetHeight; //init canvas //Create a new canvas instance. var canvas = new Canvas('mycanvas', { //Where to append the canvas widget 'injectInto': 'infovis', 'width': w, 'height': h, //Optional: create a background canvas and plot //concentric circles in it. 'backgroundCanvas': { 'styles': { 'strokeStyle': '#555' }, 'impl': { 'init': function(){}, 'plot': function(canvas, ctx){ var times = 6, d = 100; 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, { //Set Node and Edge colors. Node: { color: '#ccddee' }, Edge: { color: '#772277' }, onBeforeCompute: function(node){ Log.write("centering " + node.name + "..."); //Add the relation list in the right column. //This list is taken from the data property of each JSON node. document.getElementById('inner-details').innerHTML = node.data.relation; }, onAfterCompute: function(){ Log.write("done"); }, //Add the name of the node in the correponding label //and a click handler to move the graph. //This method is called once, on label creation. onCreateLabel: function(domElement, node){ domElement.innerHTML = node.name; domElement.onclick = function(){ rgraph.onClick(node.id); }; }, //Change some label dom properties. //This method is called each time a label is plotted. onPlaceLabel: function(domElement, node){ var style = domElement.style; style.display = ''; style.cursor = 'pointer'; if (node._depth <= 1) { style.fontSize = "0.8em"; style.color = "#ccc"; } else if(node._depth == 2){ style.fontSize = "0.7em"; style.color = "#494949"; } else { style.display = 'none'; } var left = parseInt(style.left); var w = domElement.offsetWidth; style.left = (left - w / 2) + 'px'; } }); //load JSON data rgraph.loadJSON(json); //compute positions and make the first plot rgraph.refresh(); //end //append information about the root relations in the right column document.getElementById('inner-details').innerHTML = rgraph.graph.getNode(rgraph.root).data.relation; }