var maxzoom = 100; var zoom = 280; var eyez = -500; var centerx = 125; var centery = 75; var timer; var currentEvent = "nothing"; var basecos = Math.cos(4*(Math.PI/180)); var basesin = Math.sin(4*(Math.PI/180)); myUrl = new Array(); myRel = new Array(); var linkid = 0; function createURL(urlid, x, urlname){ myUrl[urlid]= new Array(); myUrl[urlid].x=(x * 2) - 100; myUrl[urlid].y=0; myUrl[urlid].z=0; myUrl[urlid].urlname=urlname; myUrl[urlid].relatedto = new Array(); } function createRelationship(a, b){ myRel[linkid]= new Array(); myRel[linkid].a = a; myRel[linkid].b = b; linkid++; } function createRelationsRef(urlid){ for(i in myRel){ if (myRel[i].a == urlid){ myUrl[urlid].relatedto.push(myRel[i].b); } if (myRel[i].b == urlid){ myUrl[urlid].relatedto.push(myRel[i].a); } } } function buildRelationshipArrays(){ for(i in myUrl){ createRelationsRef(i); } } function initsvg(evt){ if ( window.svgDocument == null ){ svgDocument = e.target.ownerDocument; } svgObj = svgDocument.documentElement; createURL(0, 150, "www.google.com"); createURL(1, 20, "www.linux.com"); createURL(2, 35, "www.mysql.com"); createURL(3, 60, "www.perl.com"); createURL(4, 1, "www.microsoft.com"); createURL(5, 45, "www.yahoo.com"); createURL(6, 46, "www.mywebstuff.com"); createURL(7, 150, "www.svgx.org"); createURL(8, 250, "www.leo.org"); createURL(9, 65, "www.adobe.com"); createURL(10, 120, "www.w3c.org"); createURL(11, 40, "www.mozilla.org"); createURL(12, 65, "www.openoffice.org"); createURL(13, 35, "www.suse.de"); createURL(14, 15, "www.redhat.com"); createURL(15, 2, "www.apache.org") createURL(16, 30, "www.vegasystems.de"); createURL(17, 10, "www.rhino3d.com"); createURL(18, 2, "www.alltheweb.com"); createURL(19, 3, "www.web.de"); createURL(20, 15, "www.cnn.com"); createRelationship(0, 1); createRelationship(1, 2); createRelationship(2, 3); createRelationship(3, 0); createRelationship(1, 8); createRelationship(1, 6); createRelationship(1, 7); createRelationship(1, 9); createRelationship(9, 6); createRelationship(7, 9); createRelationship(1, 2); createRelationship(0, 13); createRelationship(2, 14); createRelationship(18, 11); createRelationship(18, 12); createRelationship(16, 1); createRelationship(18, 13); createRelationship(19, 5); createRelationship(20, 4); createRelationship(17, 13); createRelationship(2, 17); createRelationship(15, 14); createRelationship(10, 2); createRelationship(10, 7); createRelationship(14, 1); buildRelationshipArrays(); // calculate y axis value according to the number of links to each node. var i; for(i in myUrl){ if(myUrl[i].relatedto.length >=1){ myUrl[i].y = (myUrl[i].relatedto.length * 25) - 100; } else { myUrl[i].y = -100; } } // calculate z axis page rank based on x * y. for(i in myUrl){ myUrl[i].z = (myUrl[i].x * myUrl[i].y) / 100; } renderWorld(); domefirst(); } function domefirst(){ timer = setTimeout("doWorld()", 10); } function renderWorld(){ var i; var link; var textBlock; var textlink; var line; var u1, Dx1, Dy1; var u2, Dx2, Dy2; var depth = zoom * (eyez -maxzoom) / 100 + eyez; for(i in myRel){ u1 = (depth - eyez) / (myUrl[myRel[i].a].z - eyez); Dx1 = (u1 * myUrl[myRel[i].a].x) + centerx; Dy1 = (u1 * myUrl[myRel[i].a].y) + centery; u2 = (depth - eyez) / (myUrl[myRel[i].b].z - eyez); Dx2 = (u2 * myUrl[myRel[i].b].x) + centerx; Dy2 = (u2 * myUrl[myRel[i].b].y) + centery; line = svgDocument.createElement("line"); line.setAttribute("id", i + "Rel"); line.setAttribute("x1", Dx1); line.setAttribute("y1", Dy1); line.setAttribute("x2", Dx2); line.setAttribute("y2", Dy2); line.setAttribute("stroke", "#336699"); line.setAttribute("opacity", "0.2"); svgDocument.getElementById("world").appendChild(line); } var myFontsize; // render the urls for(i in myUrl){ u1 = (depth - eyez) / (myUrl[i].z - eyez); Dx1 = (u1 * myUrl[i].x) + centerx; Dy1 = (u1 * myUrl[i].y) + centery; link = svgDocument.createElement("a"); link.setAttributeNS('http://www.w3.org/2000/xlink/namespace/', 'xlink:href', "http://" + myUrl[i].urlname); textBlock = svgDocument.createTextNode(myUrl[i].urlname); textlink = svgDocument.createElement("text"); textlink.setAttribute("id", i + "Url"); textlink.setAttribute("x", Dx1); textlink.setAttribute("y", Dy1); textlink.setAttribute("text-anchor", "middle"); textlink.setAttribute("fill", "#000000"); myFontsize = 12 + (myUrl[i].z / 10); if(myFontsize >=24){ myFontsize = 24; } if(myFontsize <= 2){ myFontsize = 2; } textlink.setAttribute("font-size", myFontsize); textlink.appendChild(textBlock); textlink.addEventListener("mouseover", eventHighlightLineOn, false); textlink.addEventListener("mouseout", eventHighlightLineOff, false); link.appendChild(textlink); svgDocument.getElementById("world").appendChild(link); } } function doWorld(){ textlink = svgDocument.getElementById("monitorval"); textlink = textlink.getFirstChild(); textlink.setData("Currently doing " + currentEvent); doEvent(); if(currentEvent != "nothing"){ var i; var line; var u1, Dx1, Dy1; var u2, Dx2, Dy2; var myFontsize; var textlink; var depth = zoom * (eyez - maxzoom) / 100 + eyez; for(i in myRel){ u1 = (depth - eyez) / (myUrl[myRel[i].a].z - eyez); Dx1 = (u1 * myUrl[myRel[i].a].x) + centerx; Dy1 = (u1 * myUrl[myRel[i].a].y) + centery; u2 = (depth - eyez) / (myUrl[myRel[i].b].z - eyez); Dx2 = (u2 * myUrl[myRel[i].b].x) + centerx; Dy2 = (u2 * myUrl[myRel[i].b].y) + centery; line = svgDocument.getElementById(i + "Rel"); line.setAttribute("x1", Dx1); line.setAttribute("y1", Dy1); line.setAttribute("x2", Dx2); line.setAttribute("y2", Dy2); } // render the urls for(i in myUrl){ u1 = (depth - eyez) / (myUrl[i].z - eyez); Dx1 = (u1 * myUrl[i].x) + centerx; Dy1 = (u1 * myUrl[i].y) + centery; myFontsize = 12 + (myUrl[i].z / 10); if(myFontsize >=24){ myFontsize = 24; } if(myFontsize <= 2){ myFontsize = 2; } textlink = svgDocument.getElementById(i + "Url"); textlink.setAttribute("x", Dx1); textlink.setAttribute("y", Dy1); textlink.setAttribute("font-size", myFontsize); } } setTimeout("doWorld()", 10); } function eventHighlightLineOn(evt){ var target = evt.target.id; var svgtext=svgDocument.getElementById(target); var currenturl; var svgtexts; var i,j; for(i in myUrl){ svgtexts = svgDocument.getElementById(i + "Url"); if (target == (i + "Url")){ svgtexts.setAttribute("opacity", "1"); currenturl = i; } else { svgtexts.setAttribute("opacity", "0.1"); } } var svgLines; for(i in myRel){ svglines = svgDocument.getElementById(i + "Rel"); if(myRel[i].a == currenturl || myRel[i].b == currenturl){ svglines.setAttribute("opacity", "0.7"); svglines.setAttribute("stroke", "#FF0000"); } else { svglines.setAttribute("opacity", "0.1"); svglines.setAttribute("stroke", "#336699"); } } var N,P; var textBlock, link; // delete any children on the linkgroup DOM node - all the remains from last mouse over N = svgDocument.getElementById("Linklist"); N.setAttribute("opacity", "1"); while(N.childNodes.length > 0){ N.removeChild(N.firstChild); } var rect_h = 60 var rect_w = 200 var svgbackbox = svgDocument.createElement("rect"); svgbackbox.setAttribute("fill", "#336699"); svgbackbox.setAttribute("x", "5"); svgbackbox.setAttribute("y", "5"); svgbackbox.setAttribute("height", rect_h); svgbackbox.setAttribute("width", rect_w); svgDocument.getElementById("Linklist").appendChild(svgbackbox); link = svgDocument.createElement("a"); link.setAttributeNS('http://www.w3.org/2000/xlink/namespace/', 'xlink:href', "http://" + myUrl[currenturl].urlname); textBlock = svgDocument.createTextNode(myUrl[currenturl].urlname); svgtexts = svgDocument.createElement("text"); svgtexts.setAttribute("id", "HyperLinkText" + myUrl[currenturl].relatedto[i]); svgtexts.setAttribute("x", "10"); svgtexts.setAttribute("y", "30"); svgtexts.setAttribute("fill", "#FFFFFF"); svgtexts.setAttribute("font-size", "17"); svgtexts.appendChild(textBlock); link.appendChild(svgtexts); svgDocument.getElementById("Linklist").appendChild(link); if(myUrl[currenturl].relatedto.length >= 1){ for(i in myUrl[currenturl].relatedto){ svgtexts = svgDocument.getElementById(myUrl[currenturl].relatedto[i] + "Url"); svgtexts.setAttribute("font-size", "12"); svgtexts.setAttribute("opacity", "1"); // create any children on the linkgroup DOM node for the current link link = svgDocument.createElement("a"); link.setAttributeNS('http://www.w3.org/2000/xlink/namespace/', 'xlink:href', "http://" + myUrl[myUrl[currenturl].relatedto[i]].urlname); textBlock = svgDocument.createTextNode(myUrl[myUrl[currenturl].relatedto[i]].urlname); svgtexts = svgDocument.createElement("text"); svgtexts.setAttribute("id", "HyperLinkText" + myUrl[currenturl].relatedto[i]); svgtexts.setAttribute("x", "10"); svgtexts.setAttribute("y", (20 * i) + 55); svgtexts.setAttribute("fill", "#FFFFFF"); svgtexts.setAttribute("font-size", "15"); svgtexts.appendChild(textBlock); link.appendChild(svgtexts); svgDocument.getElementById("Linklist").appendChild(link); svgbackbox.setAttribute("height", rect_h + (20 * i)); } } } function eventHighlightLineOff(){ var svgtexts; var myFontsize; for(i in myUrl){ svgtexts = svgDocument.getElementById(i + "Url"); svgtexts.setAttribute("opacity", "1"); myFontsize = 12 + (myUrl[i].z / 10); if(myFontsize >=24){ myFontsize = 24; } if(myFontsize <= 2){ myFontsize = 2; } svgtexts.setAttribute("font-size", myFontsize); } } function setEvent(evt,eventin){ currentEvent = eventin; var blockbit = evt.currentTarget; if(currentEvent == "nothing"){ blockbit.setAttribute("opacity", "0.19"); } else { blockbit.setAttribute("opacity", "0.5"); } } function doEvent(){ var mysin; var mycos; if (currentEvent == "callZoomIn"){ if(zoom <= 400){ zoom = zoom + 4; } } if (currentEvent == "callZoomOut"){ if(zoom >= 175){ zoom = zoom - 4; } } if (currentEvent == "callXmin"){ mysin = -basesin; mycos = basecos; rotateXaxis(mysin, mycos); } if (currentEvent == "callXmax"){ mysin = basesin; mycos = basecos; rotateXaxis(mysin, mycos); } if (currentEvent == "callYmin"){ mysin = -basesin; mycos = basecos; rotateYaxis(mysin, mycos); } if (currentEvent == "callYmax"){ mysin = basesin; mycos = basecos; rotateYaxis(mysin, mycos); } if (currentEvent == "callZmax"){ mysin = basesin; mycos = basecos; rotateZaxis(mysin, mycos); } if (currentEvent == "callZmin"){ mysin = -basesin; mycos = basecos; rotateZaxis(mysin, mycos); } } function rotateXaxis(mysin, mycos){ var tmp; for(i in myUrl){ tmp = (mysin * myUrl[i].y) + (mycos * myUrl[i].z); myUrl[i].y = (mycos * myUrl[i].y) - (mysin * myUrl[i].z); myUrl[i].z = tmp; } } function rotateYaxis(mysin, mycos){ var tmp; for(i in myUrl){ tmp = - (mysin * myUrl[i].x) + (mycos * myUrl[i].z) myUrl[i].x = (mycos * myUrl[i].x) + (mysin * myUrl[i].z); myUrl[i].z = tmp; } } function rotateZaxis(mysin, mycos){ var tmp; for(i in myUrl){ tmp = (mysin * myUrl[i].x) + (mycos * myUrl[i].y) myUrl[i].x = (mycos * myUrl[i].x) - (mysin * myUrl[i].y); myUrl[i].y = tmp; } }