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:- Pearl Jam
(relation: member of band)
- Temple of the Dog
(relation: member of band)
- Mother Love Bone
(relation: member of band)
- Green River
(relation: member of band)
- M.A.C.C.
(relation: collaboration)
- Three Fish
(relation: member of band)
- Gossman Project
(relation: member of band)
"
},
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:- Pearl Jam
(relation: member of band)
- Temple of the Dog
(relation: member of band)
- Mother Love Bone
(relation: member of band)
- Brad
(relation: member of band)
- Green River
(relation: member of band)
- Gossman Project
(relation: member of band)
"
},
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:- Pearl Jam
(relation: member of band)
- Temple of the Dog
(relation: member of band)
- Eddie Vedder & Zeke
(relation: collaboration)
- Bad Radio
(relation: member of band)
- Beck & Eddie Vedder
(relation: collaboration)
"
},
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:- Pearl Jam
(relation: member of band)
- Mad Season
(relation: member of band)
- Temple of the Dog
(relation: member of band)
- $10,000 Gold Chain
(relation: collaboration)
- M.A.C.C.
(relation: collaboration)
- The Rockfords
(relation: member of band)
- Gossman Project
(relation: member of band)
"
},
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:- Pearl Jam
(relation: member of band)
- Soundgarden
(relation: member of band)
- Temple of the Dog
(relation: member of band)
- Eleven
(relation: supporting musician)
- Queens of the Stone Age
(relation: member of band)
- Wellwater Conspiracy
(relation: member of band)
- M.A.C.C.
(relation: collaboration)
- Tone Dogs
(relation: member of band)
"
},
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:- Pearl Jam
(relation: member of band)
- Critters Buggin
(relation: member of band)
- Edie Brickell and New Bohemians
(relation: member of band)
"
},
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:- Pearl Jam
(relation: member of band)
- Redd Kross
(relation: member of band)
- Eleven
(relation: member of band)
- Red Hot Chili Peppers
(relation: member of band)
- Anthym
(relation: member of band)
- What Is This?
(relation: member of band)
"
},
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:- Pearl Jam & Cypress Hill
(relation: collaboration)
- Neil Young & Pearl Jam
(relation: collaboration)
- Jeff Ament
(relation: member of band)
- Stone Gossard
(relation: member of band)
- Eddie Vedder
(relation: member of band)
- Mike McCready
(relation: member of band)
- Matt Cameron
(relation: member of band)
- Dave Krusen
(relation: member of band)
- Matt Chamberlain
(relation: member of band)
- Dave Abbruzzese
(relation: member of band)
- Jack Irons
(relation: member of band)
"
}
};
// end
// init RGraph
var rgraph = new $jit.RGraph({
// Where to append the visualization
injectInto: 'infovis',
// Optional: create a background canvas and plot
// concentric circles in it.
background: {
CanvasStyles: {
strokeStyle: '#555',
shadowBlur: 10,
shadowColor: '#ccc'
}
},
// Set Edge and Node styles
Node: {
overridable: true,
color: '#ccddee',
dim: 12
},
Edge: {
overridable: true,
color: '#C17878',
lineWidth: 1.5
},
// Use native canvas text
Label: {
type: labelType,
size: 11,
family: 'Verdana',
color: '#fff'
},
//Add events for Dragging and dropping nodes
Events: {
enable: true,
type: 'Native',
onMouseEnter: function(node, eventInfo, e){
rgraph.canvas.getElement().style.cursor = 'move';
},
onMouseLeave: function(node, eventInfo, e){
rgraph.canvas.getElement().style.cursor = '';
},
onDragMove: function(node, eventInfo, e){
var pos = eventInfo.getPos();
node.pos.setc(pos.x, pos.y);
rgraph.plot();
},
onDragEnd: function(node, eventInfo, e){
rgraph.compute('end');
rgraph.fx.animate( {
modes: [
'linear'
],
duration: 700,
transition: $jit.Trans.Elastic.easeOut
});
},
//touch events
onTouchStart: function(node, eventInfo, e) {
//stop the default event
$jit.util.event.stop(e);
},
onTouchMove: function(node, eventInfo, e){
//stop the default event
$jit.util.event.stop(e);
var pos = eventInfo.getPos();
node.pos.setc(pos.x, pos.y);
rgraph.plot();
},
onTouchEnd: function(node, eventInfo, e){
//stop the default event
$jit.util.event.stop(e);
rgraph.compute('end');
rgraph.fx.animate( {
modes: [
'linear'
],
duration: 700,
transition: $jit.Trans.Elastic.easeOut
});
}
},
//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;
},
//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
}