| Author |
Family Tree Help
|
mainak maitra
Greenhorn
Joined: Feb 09, 2012
Posts: 2
|
|
Hi,
I am desperately in need of a code for implementing a family tree like structure where a node can have more than one child.
Please Help.
|
 |
Kumaravadivel Subramani
Ranch Hand
Joined: Jul 05, 2008
Posts: 162
|
|
|
Try out something yourself and if you are in trouble we would help you, without your effort it's not possible. We are not code Mill to generate code and give it to you.
|
No pain, No gain.
OCJP 1.6
|
 |
mainak maitra
Greenhorn
Joined: Feb 09, 2012
Posts: 2
|
|
ok...
i have written the following code myself
bt the tree gets distubed upon adding more subchilds
function famtree()
{
var array=new Array("main",new Array("F","S",new Array("SF","SS"),"T"));
pwidth=2000;
pheight=1000;
var paper = new Raphael(document.getElementById('canvas_container'), pwidth, pheight);
var bh=50;
var bw=50;
var Rx=0;
var Ry=0;
var a,b=0;
var count=0;
maketree(array,Rx,Ry,a,b,bw,bh,pwidth);
function maketree(array,Rx,Ry,a,b,bw,bh,pwidth)
{
nOfNodes=checknodes(array);
alert(nOfNodes);
var childpos=Rx;
var firstxpos=childpos+pwidth/(nOfNodes*2);
//var childwidth=pwidth/nOfNodes;
Ry=Ry+100;
for(i=0;i<array.length;i++)
{
if(!isArray(array[i]))
{
draw(firstxpos-(bw/2),Ry,array[i]);
firstxpos=firstxpos+(pwidth/nOfNodes);
if(count!=0)
childpos=childpos+(pwidth/(nOfNodes*2));
else count++;
}
else
{
var newRy=Ry+50;
maketree(array[i],childpos,newRy,a,b,bw,bh,(pwidth/nOfNodes));
}
}
return;
}
function checknodes(array)
{
var countnodes=0;
for(i=0;i<array.length;i++)
{
if(!isArray(array[i]))
countnodes++;
}
return countnodes
}
function draw(x,y,name)
{
paper.rect(x,y,50,50,3).attr({fill:'rgb(193,247,9)',stroke:'rgb(128,128,128)'});
var pt=name.toString();
paper.text(x+20,y+20,pt).attr({fill:'red'});
}
function drawline(Rx,Ry,a,b)
{
Rx=Rx+25;
var pth="M "+Rx+" "+Ry+" L"+a+" "+b;
paper.path(pth).attr({stroke:'rgb(70,185,128)'});
}
//function to check if an element is array or not
function isArray(obj) {
return (obj.constructor.toString().indexOf("Array") != -1);
}
}
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56174
|
|
That's JavaScript and has nothing at all to do with JSP. Please post in the appropriate forum.
This post has been moved to a more appropriate location.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
 |
|
|
subject: Family Tree Help
|
|
|