var labelType, useGradients, nativeTextSupport, animate; (function() { var ua = navigator.userAgent, iStuff = ua.match(/iPhone/i) || ua.match(/iPad/i), typeOfCanvas = typeof HTMLCanvasElement, nativeCanvasSupport = (typeOfCanvas == 'object' || typeOfCanvas == 'function'), textSupport = nativeCanvasSupport && (typeof document.createElement('canvas').getContext('2d').fillText == 'function'); //I'm setting this based on the fact that ExCanvas provides text support for IE //and that as of today iPhone/iPad current text support is lame labelType = (!nativeCanvasSupport || (textSupport && !iStuff))? 'Native' : 'HTML'; nativeTextSupport = labelType == 'Native'; useGradients = nativeCanvasSupport; animate = !(iStuff || !nativeCanvasSupport); })(); 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 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 //init RGraph var rgraph = new $jit.RGraph({ //Where to append the visualization injectInto: 'infovis', //Optional: create a background canvas that plots //concentric circles. background: { CanvasStyles: { strokeStyle: '#555' } }, //Add navigation capabilities: //zooming by scrolling and panning. Navigation: { enable: true, panning: true, zooming: 10 }, //Set Node and Edge styles. Node: { color: '#ddeeff' }, Edge: { color: '#C17878', lineWidth:1.5 }, 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. $jit.id('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); //trigger small animation rgraph.graph.eachNode(function(n) { var pos = n.getPos(); pos.setc(-200, -200); }); rgraph.compute('end'); rgraph.fx.animate({ modes:['polar'], duration: 2000 }); //end //append information about the root relations in the right column $jit.id('inner-details').innerHTML = rgraph.graph.getNode(rgraph.root).data.relation; }