Re: [PHP] How do I make a HTML tree for a set of nodes?
Hi, On Tuesday 06 June 2006 21:05, Jochem Maas wrote: [snip] I might be late to the party but have you thought of trying the YAHOO UI lib (treeview widget) it even allows you to dynamically load subbranches as they are expanded (AJAX lovelyness): http://developer.yahoo.com/yui/treeview/ Thanks, that's a nice library. But it is really what I'm looking for, and it has many features I won't be using. I have used (and extended) the treeview code with great success (ok so I'm biased ;-) - if nothing else the guys at YAHOO have done a great job in showing how one can use prototyping (more or less the javascript equivalent to classes) to build [very] robust javascript libraries. testament to=YAHOO JS Lib being rather good I have made the YAHOO javascript lib(s) part of my core [reusable] js codebase - the only downside is that its a bit embarrassing hwo the YAHOO stuff has made alot of my own js code redundant :-P testament There are just sooo many libraries and code snippets and paradigms these days... disclaimerI have nothing to do with YAHOO apart from occasionally harassing one of their system architects (sorry Rasmus) about things not related to YAHOO/disclaimer Hands off Rasmus! He's a good guy! Thank you for your answer, Niels -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How do I make a HTML tree for a set of nodes?
Niels wrote: Hi, I have a set of nodes. Each node has a parent and so the set can be thought of as a tree. I want to show that tree somehow on a webpage, served by PHP. I cannot use Dot/Graphwiz for various reasons. What I'm looking for is an output of DIVs or tablecells, showing the nodes and their connections. It's not a trivial task, IMO, but doable. Possibly somebody has already made something similiar, but I can't find anything on Google. Can anybody point me to helpful information? I might be late to the party but have you thought of trying the YAHOO UI lib (treeview widget) it even allows you to dynamically load subbranches as they are expanded (AJAX lovelyness): http://developer.yahoo.com/yui/treeview/ I have used (and extended) the treeview code with great success (ok so I'm biased ;-) - if nothing else the guys at YAHOO have done a great job in showing how one can use prototyping (more or less the javascript equivalent to classes) to build [very] robust javascript libraries. testament to=YAHOO JS Lib being rather good I have made the YAHOO javascript lib(s) part of my core [reusable] js codebase - the only downside is that its a bit embarrassing hwo the YAHOO stuff has made alot of my own js code redundant :-P testament disclaimerI have nothing to do with YAHOO apart from occasionally harassing one of their system architects (sorry Rasmus) about things not related to YAHOO/disclaimer Thanks, Niels -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] How do I make a HTML tree for a set of nodes?
Hi, I have a set of nodes. Each node has a parent and so the set can be thought of as a tree. I want to show that tree somehow on a webpage, served by PHP. I cannot use Dot/Graphwiz for various reasons. What I'm looking for is an output of DIVs or tablecells, showing the nodes and their connections. It's not a trivial task, IMO, but doable. Possibly somebody has already made something similiar, but I can't find anything on Google. Can anybody point me to helpful information? Thanks, Niels -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How do I make a HTML tree for a set of nodes?
At 2:07 PM +0200 6/4/06, Niels wrote: Hi, I have a set of nodes. Each node has a parent and so the set can be thought of as a tree. I want to show that tree somehow on a webpage, served by PHP. I cannot use Dot/Graphwiz for various reasons. What I'm looking for is an output of DIVs or tablecells, showing the nodes and their connections. It's not a trivial task, IMO, but doable. Possibly somebody has already made something similiar, but I can't find anything on Google. Can anybody point me to helpful information? Thanks, Niels What, a binary-tree or linked-list sort of thing? tedd -- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How do I make a HTML tree for a set of nodes?
On Sunday 04 June 2006 14:58, tedd wrote: At 2:07 PM +0200 6/4/06, Niels wrote: Hi, I have a set of nodes. Each node has a parent and so the set can be thought of as a tree. I want to show that tree somehow on a webpage, served by PHP. I cannot use Dot/Graphwiz for various reasons. What I'm looking for is an output of DIVs or tablecells, showing the nodes and their connections. It's not a trivial task, IMO, but doable. Possibly somebody has already made something similiar, but I can't find anything on Google. Can anybody point me to helpful information? Thanks, Niels What, a binary-tree or linked-list sort of thing? tedd Not binary -- a node can have several children. Each node has an id and a parentId. The actual structure isn't important and can easily be objects, arrays-of-arrays or whatever is handy. //Niels -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How do I make a HTML tree for a set of nodes?
At 3:03 PM +0200 6/4/06, Niels wrote: On Sunday 04 June 2006 14:58, tedd wrote: At 2:07 PM +0200 6/4/06, Niels wrote: Hi, I have a set of nodes. Each node has a parent and so the set can be thought of as a tree. I want to show that tree somehow on a webpage, served by PHP. I cannot use Dot/Graphwiz for various reasons. What I'm looking for is an output of DIVs or tablecells, showing the nodes and their connections. It's not a trivial task, IMO, but doable. Possibly somebody has already made something similiar, but I can't find anything on Google. Can anybody point me to helpful information? Thanks, Niels What, a binary-tree or linked-list sort of thing? tedd Not binary -- a node can have several children. Each node has an id and a parentId. The actual structure isn't important and can easily be objects, arrays-of-arrays or whatever is handy. //Niels You can dynamically generate a table and place text (and/or color) the cells that are nodes -- that would be my approach. You would need to know the width and depth of the tree and then just fill in the cells that are nodes. hth's tedd -- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How do I make a HTML tree for a set of nodes?
On Sunday 04 June 2006 15:30, tedd wrote: [snip] You can dynamically generate a table and place text (and/or color) the cells that are nodes -- that would be my approach. You would need to know the width and depth of the tree and then just fill in the cells that are nodes. hth's tedd Yes, well... It's a tad more complicated I think. Yes, I can make a table, finding the dimensions shouldn't be a big problem. Placing the nodes in the right cells isn't as easy, and making the connections is downright difficult. A problem with using a table is that cells can't be individually sized. However DIVs or TDs is a minor problem. The major problem is to walk through the tree properly (recursively probably), and remember the connections. And then rendering them... Thank you for your answer, Niels -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How do I make a HTML tree for a set of nodes?
2006/6/4, Niels [EMAIL PROTECTED]: Hi, I have a set of nodes. Each node has a parent and so the set can be thought of as a tree. I want to show that tree somehow on a webpage, served by PHP. I cannot use Dot/Graphwiz for various reasons. What I'm looking for is an output of DIVs or tablecells, showing the nodes and their connections. It's not a trivial task, IMO, but doable. Possibly somebody has already made something similiar, but I can't find anything on Google. Can anybody point me to helpful information? Thanks, Niels -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php I had a similar problem that, although it was with a binary tree, it can be used with your tree. PHP doesn't like too much the use of recursion, but this time recursion is the way to go (if you want to keep the code maintainable). Hopefully the tree will not span deep enough to cause any problems... (hopefully). The function will receive a node and return a table representation of the branch started by this tree, if you point this function to the root node you'll have your table. In each cell it will have to indicate whether it is empty, it has a node or a line connecting neighbor cells. One important thing to define here is the way the function will organize the nodes in the table, in my function the root node was at the top in the center. First, the trivial case: if the node doesn't have children return a table with one cell, the node itself. Then, the recursive case: if the node have children, call the function with those nodes and store the tables returned. According to the representation I used, it calculated the combined width of those tables, created a new table where the first row contained the parent node centered, the second line an horizontal line from the column where the first children would be to the column where the last children would be. Then it build the rest of the table pasting together, horizontally, the tables of the children. Voila! a nice table representation of the tree.
Re: [PHP] How do I make a HTML tree for a set of nodes?
You could do it by dynamically generating an image. Mike Niels wrote: On Sunday 04 June 2006 15:30, tedd wrote: [snip] You can dynamically generate a table and place text (and/or color) the cells that are nodes -- that would be my approach. You would need to know the width and depth of the tree and then just fill in the cells that are nodes. hth's tedd Yes, well... It's a tad more complicated I think. Yes, I can make a table, finding the dimensions shouldn't be a big problem. Placing the nodes in the right cells isn't as easy, and making the connections is downright difficult. A problem with using a table is that cells can't be individually sized. However DIVs or TDs is a minor problem. The major problem is to walk through the tree properly (recursively probably), and remember the connections. And then rendering them... Thank you for your answer, Niels
Re: [PHP] How do I make a HTML tree for a set of nodes?
On Sunday 04 June 2006 18:37, Mike Bellerby wrote: You could do it by dynamically generating an image. Mike [snip] Yes. But how? I've settled for a simpler solution -- see my answer to Martin Alterisio. Thanks, Niels -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How do I make a HTML tree for a set of nodes?
Hi! On Sunday 04 June 2006 18:13, Martin Alterisio wrote: [snip] I had a similar problem that, although it was with a binary tree, it can be used with your tree. PHP doesn't like too much the use of recursion, but this time recursion is the way to go (if you want to keep the code maintainable). Hopefully the tree will not span deep enough to cause any problems... (hopefully). The function will receive a node and return a table representation of the branch started by this tree, if you point this function to the root node you'll have your table. In each cell it will have to indicate whether it is empty, it has a node or a line connecting neighbor cells. One important thing to define here is the way the function will organize the nodes in the table, in my function the root node was at the top in the center. First, the trivial case: if the node doesn't have children return a table with one cell, the node itself. Then, the recursive case: if the node have children, call the function with those nodes and store the tables returned. According to the representation I used, it calculated the combined width of those tables, created a new table where the first row contained the parent node centered, the second line an horizontal line from the column where the first children would be to the column where the last children would be. Then it build the rest of the table pasting together, horizontally, the tables of the children. Voila! a nice table representation of the tree. This sounds fine -- recursion is obviously the way to go. Where can I see your function? I tried several different solutions over the last couple of hours, and I've settled on only using indentation (like a nested ul/ul list), not a fancy graph with antialised branches. It's the simplest possible recursion but I like the results, even if it's a bit harder to grasp without connections clearly marked. function tree($nodes, $start, $indent=-30) { $indent+=30; global $tree; foreach ($nodes as $nodeID = $node) { if ($node['parent']!=$start) {continue;} $tree.=div style='margin-left:{$indent}px'{$node['name']}/div; tree($nodes, $nodeID, $indent); } return $tree; } Thanks! //Niels -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How do I make a HTML tree for a set of nodes?
2006/6/4, Niels [EMAIL PROTECTED]: Hi! On Sunday 04 June 2006 18:13, Martin Alterisio wrote: [snip] I had a similar problem that, although it was with a binary tree, it can be used with your tree. PHP doesn't like too much the use of recursion, but this time recursion is the way to go (if you want to keep the code maintainable). Hopefully the tree will not span deep enough to cause any problems... (hopefully). The function will receive a node and return a table representation of the branch started by this tree, if you point this function to the root node you'll have your table. In each cell it will have to indicate whether it is empty, it has a node or a line connecting neighbor cells. One important thing to define here is the way the function will organize the nodes in the table, in my function the root node was at the top in the center. First, the trivial case: if the node doesn't have children return a table with one cell, the node itself. Then, the recursive case: if the node have children, call the function with those nodes and store the tables returned. According to the representation I used, it calculated the combined width of those tables, created a new table where the first row contained the parent node centered, the second line an horizontal line from the column where the first children would be to the column where the last children would be. Then it build the rest of the table pasting together, horizontally, the tables of the children. Voila! a nice table representation of the tree. This sounds fine -- recursion is obviously the way to go. Where can I see your function? I tried several different solutions over the last couple of hours, and I've settled on only using indentation (like a nested ul/ul list), not a fancy graph with antialised branches. It's the simplest possible recursion but I like the results, even if it's a bit harder to grasp without connections clearly marked. function tree($nodes, $start, $indent=-30) { $indent+=30; global $tree; foreach ($nodes as $nodeID = $node) { if ($node['parent']!=$start) {continue;} $tree.=div style='margin-left:{$indent}px'{$node['name']}/div; tree($nodes, $nodeID, $indent); } return $tree; } Thanks! //Niels -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Sorry, I can't show you the code. Anyway you don't seem to need it. One recommendation, don't rely on global vars, look at this: function tree($nodes, $start, $indent=-30) { $indent+=30; $tree = ; foreach ($nodes as $nodeID = $node) { if ($node['parent']!=$start) {continue;} $tree .= div style='margin-left:{$indent}px'{$node['name']}/div; $tree .= tree($nodes, $nodeID, $indent); } return $tree; }
Re: [PHP] How do I make a HTML tree for a set of nodes?
At 3:38 PM +0200 6/4/06, Niels wrote: On Sunday 04 June 2006 15:30, tedd wrote: [snip] You can dynamically generate a table and place text (and/or color) the cells that are nodes -- that would be my approach. You would need to know the width and depth of the tree and then just fill in the cells that are nodes. hth's tedd Yes, well... It's a tad more complicated I think. Yes, I can make a table, finding the dimensions shouldn't be a big problem. Placing the nodes in the right cells isn't as easy, and making the connections is downright difficult. A problem with using a table is that cells can't be individually sized. However DIVs or TDs is a minor problem. The major problem is to walk through the tree properly (recursively probably), and remember the connections. And then rendering them... I've done this before, but not with html. My demo is at: http://www.sperling.com/freeware.php So, I have an idea of what's involved. If this just for display, then it shouldn't be too difficult to display the end results in a table -- provided, you know in advance the largest any row will be. It will be a simple grid, unless you want to play with column spacing, which will be very difficult indeed to manage. As for cells not being individually sized, you're right they can't be sized, but they do automatically size to their contents and that can be varied as well shown with different background colors. Are you going to use this for something other than display, is it functional in some way? Because if you're going to add functionality, such as editing, deleting, sorting, then you have a big chore in front of you. As for using recursive functions, absolutely -- they make the process (and code) much less. However, you need to wrap your mind around things spinning around to their conclusion, which is sometimes difficult to imagine. Good luck. tedd -- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How do I make a HTML tree for a set of nodes?
Hi, On Sunday 04 June 2006 19:02, Martin Alterisio wrote: [snip] Sorry, I can't show you the code. Anyway you don't seem to need it. One recommendation, don't rely on global vars, look at this: Quite right, I'd have gotten around to fixing that later. Thank you for your answer, I appreciate it! Niels -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How do I make a HTML tree for a set of nodes?
Hi, On Sunday 04 June 2006 19:08, tedd wrote: At 3:38 PM +0200 6/4/06, Niels wrote: On Sunday 04 June 2006 15:30, tedd wrote: [snip] You can dynamically generate a table and place text (and/or color) the cells that are nodes -- that would be my approach. You would need to know the width and depth of the tree and then just fill in the cells that are nodes. hth's tedd Yes, well... It's a tad more complicated I think. Yes, I can make a table, finding the dimensions shouldn't be a big problem. Placing the nodes in the right cells isn't as easy, and making the connections is downright difficult. A problem with using a table is that cells can't be individually sized. However DIVs or TDs is a minor problem. The major problem is to walk through the tree properly (recursively probably), and remember the connections. And then rendering them... I've done this before, but not with html. My demo is at: http://www.sperling.com/freeware.php So, I have an idea of what's involved. If this just for display, then it shouldn't be too difficult to display the end results in a table -- provided, you know in advance the largest any row will be. It will be a simple grid, unless you want to play with column spacing, which will be very difficult indeed to manage. As for cells not being individually sized, you're right they can't be sized, but they do automatically size to their contents and that can be varied as well shown with different background colors. Are you going to use this for something other than display, is it functional in some way? Because if you're going to add functionality, such as editing, deleting, sorting, then you have a big chore in front of you. As for using recursive functions, absolutely -- they make the process (and code) much less. However, you need to wrap your mind around things spinning around to their conclusion, which is sometimes difficult to imagine. Good luck. tedd Thank you for your answer, I appreciate it! Years ago I made Javascript navigation tree -- like a file browser, with expandable branches and so on. It was a big problem to parse all the relationships to img tags and links. I just had a looks at that code -- 10 years old, and it works! I couldn't change it to my current needs though. As I said elsewhere on this thread, I've settled for a simple, indented tree-view. Each node is a link and some text, and it's all reasonably easy to understand. And it's a small function -- I know about the dangers of recursion. Choosing this simple layout will also make it easier to render the output to PDF at a later stage. If I were to make a real tree, I wouldn't use a table. It's too difficult to manage IMO. I'd probably look for a generic graph algorithm somewhere, and try some dhtml voodoo with flying DIVs. Thanks again, Niels -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How do I make a HTML tree for a set of nodes?
At 7:26 PM +0200 6/4/06, Niels wrote: If I were to make a real tree, I wouldn't use a table. It's too difficult to manage IMO. I'd probably look for a generic graph algorithm somewhere, and try some dhtml voodoo with flying DIVs. Thanks again, Niels Niels: The below link may not at first look like what you're after, but belive me, you'll find stuff that will make you think how you can use it to do what you want. http://www.cssplay.co.uk/index.html Happy exploring. Using a combination of css and php will do what you want, I'm sure of it. tedd -- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How do I make a HTML tree for a set of nodes?
On Sunday 04 June 2006 19:49, tedd wrote: At 7:26 PM +0200 6/4/06, Niels wrote: If I were to make a real tree, I wouldn't use a table. It's too difficult to manage IMO. I'd probably look for a generic graph algorithm somewhere, and try some dhtml voodoo with flying DIVs. Thanks again, Niels Niels: The below link may not at first look like what you're after, but belive me, you'll find stuff that will make you think how you can use it to do what you want. http://www.cssplay.co.uk/index.html Happy exploring. Very cool!!! I've also started using the Javascript library from http://script.aculo.us/ -- that certainly saves me a lot of headaches. Using a combination of css and php will do what you want, I'm sure of it. I want world peace... Thanks again, Niels -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How do I make a HTML tree for a set of nodes?
At 8:00 PM +0200 6/4/06, Niels wrote: Using a combination of css and php will do what you want, I'm sure of it. I want world peace... Well, if we were all programming php, we wouldn't have any war, but we wouldn't have any peace either. :-) tedd -- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How do I make a HTML tree for a set of nodes?
On Sunday 04 June 2006 20:39, tedd wrote: At 8:00 PM +0200 6/4/06, Niels wrote: Using a combination of css and php will do what you want, I'm sure of it. I want world peace... Well, if we were all programming php, we wouldn't have any war, but we wouldn't have any peace either. :-) tedd There's always the good old Vi / Emacs war, if we get bored... //Niels -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How do I make a HTML tree for a set of nodes?
At 8:59 PM +0200 6/4/06, Niels wrote: On Sunday 04 June 2006 20:39, tedd wrote: At 8:00 PM +0200 6/4/06, Niels wrote: Using a combination of css and php will do what you want, I'm sure of it. I want world peace... Well, if we were all programming php, we wouldn't have any war, but we wouldn't have any peace either. :-) tedd There's always the good old Vi / Emacs war, if we get bored... Out of the xml camp, I liked this expression. /world tedd -- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php