merlyn has asked for the wisdom of the Perl Monks concerning the following question:
I have a client who has a database that has nodes. Each node can have zero or more children, and zero or more parents, although usually the number of parents is exactly one. All nodes are unique, and there are no loops.
The task is to build a "browser" for the database, to wander through looking for parents and kids to find a particular node, and to search for nodes meeting a given
set of criteria.
Initially, the client built a tool that uses an Explorer-style interface in HTML, with little "+" boxes to expand out a subtree. This is working fine until we get to the requirement that a node might have multiple parents. The underlying code is using Tree::DAG_node. Oops. {grin}
So, I've got to rewrite that, but then I'm also going to be hacking the GUI code then as well. I'm not much of a user interface designer, so I'm wondering if there are any models for me to draw on of browsing a structure that has few parents and many children, but is not strictly a tree.
Any clues out there? I'll be most appreciative.
-- Randal L. Schwartz, Perl hacker
Re: Representing the result of a node search in HTML
by stefp (Vicar) on Oct 05, 2001 at 04:18 UTC
|
There is Graphviz written by Leon Brocard.
This is a Perl front-end to ATT Graphviz.
I used the later and it works well for graphs of moderate complexity; I mean by that graphs that can be transformed to forests by removing a few edges.
I have no personal experience of the frond though and don't know if you can generate image-maps.
But, I once
generated a representation of perl grammar using ATT graphviz.
-- stefp | [reply] |
|
For an example of what Graphviz and perl can do,
check out this nifty DNS mapper.
-Blake
| [reply] |
|
| [reply] |
|
Re: Representing the result of a node search in HTML
by Zaxo (Archbishop) on Oct 05, 2001 at 05:26 UTC
|
I think a double-sided tree would work with the "You Are Here" node joining them. I picture parents to the left, kids to the right, all links with summary information. If disconnected components exist, list them separately by either entry point or last-visited.
Assuming you use some flavor of Graph::Base, here's a sketch:
Viewing [Local Mutts]
| [Mopsy]
[Spot] |______________________| [Rover]
[Molly] | [ Fido ] | [Gus]
| [Jack]
[AKC Registry]
[Fictional Dogs}
If 'Fido' is the current node, $_, then in $G (the overall graph of db keys) my @parents=$G->predecessors($_); my @kids=$G->successors($_);.
This local approach can handle circularities and self-loops as easily as the more sedate database you describe.
Update: Some corrections for Graph::Base calling conventions.
After Compline, Zaxo | [reply] [d/l] [select] |
Re: Representing the result of a node search in HTML
by footpad (Abbot) on Oct 05, 2001 at 06:36 UTC
|
I'm sure you've already thought of something along these lines, but I didn't see it mentioned. So...
I presume you have an easy way to know whether or not a given node has multiple parents? Assuming so, I have provided a "pivot" button in similar situations, one that takes the currently selected node and "reverses" the heirarchy, e.g. instead of showing the children, it shows the parents "belonging" to the child.
For example:
Books
+ Perl [ *Pivot* ]
+ Unix/Linux
+ SomethingElse
Reviews
Tech Sites
+ Perl
+ Unix/Linux
+ SomethingElse
Becomes:
Perl
+ Books
+ Tech Sites
SomethingElse
Unix/Linux
Implementation tends to be fairly straightforward, if you're using a reasonably well-designed database/schema.
I've also found this to be a really interesting way to allow users to learn your heirarchy.
--f | [reply] [d/l] [select] |
Hierarchies and multiple parentage
by perrin (Chancellor) on Oct 05, 2001 at 08:07 UTC
|
To tell you the truth, my advice is to fight the requirement for multiple parentage. I've worked on a number of projects that mapped complex hierarchies, and this multiple parents idea seems to come up a lot. It's usually a red herring. It looks like it will solve a certain problem, but in the end it hopelessly confuses users and dramatically complicates code.
People often think this is the way to handle cross-linked hierarchies. I think what Yahoo does makes more sense, essentially having symlinks to the other nodes rather than a standard parent-child relationship. Having multiple parents means you can never know your context (for something like a breadcrumb trail back up to the root node) without keeping a complete history of every node a user has visited on the way to this one.
The last time I had a problem like this was at an e-commerce site (see if you can guess which one) where we were trying to deal with the fact that a section like "new Pokemon junk" might need to show up under multiple areas in the store and the merchants controlling it don't want to keep track of that and double enter it. An obvious requirement for multiple parentage, but I saw all kinds of implementation problems with it. After trying various things, I ended up making two trees, one for concepts like "new Pokemon junk" with products attached, and one for site layout. The nodes on the concept tree were mapped many to many onto nodes of the layout tree. It sounds complex, but it was less confusing than multiple parentage and it was plenty fast in oracle. | [reply] |
|
hear hear
I bet the multiple parentage requirement is editorially-driven? I'd go for a symlinking mechanism rather than genuine multiple parentage, if you really want to keep a close match between visible and underlying structures. If not, create a layer of abstraction between the two, as perrin suggests.
One of my old employers is still, five years later, suffering from my conviction that there was a logical structure into which everything would fit and that once we'd built it, all we would need to do is show it to people. It turns out that editorial content isn't really like that :(
| [reply] |
Re: Representing the result of a node search in HTML
by dondelelcaro (Monk) on Oct 05, 2001 at 04:11 UTC
|
Not knowing what type of data you're representing through these nodes, I'll assume that typically you'll be browsing the nodes by looking from the parents to their children. (If the nodes have some sort of "meaning" associated with them, a better metaphor might be appropriate...)
In that case, the most logical thing to me is a node->subnode explorer style (like you were doing) with multi-parent nodes listed under their respective parents (perhaps with a identifier or something that indicated that they came from a complex family.)
Not particularly earth shattering, but that's what makes sense to me. (Just like entering a directory with soft links in it... makes sense to see the soft links in that directory, even if they exist in multiple directories.) | [reply] |
Re: Representing the result of a node search in HTML
by jeroenes (Priest) on Oct 05, 2001 at 11:58 UTC
|
Maybe you can take a look at the MeSH browser of PubMed.
It's fairly intuitive, anybody who can click can use that
browser. If you click on a child with multiple parents,
you get a list of those parents so that you can go upwards
again.
You can find it
here
(example purely coincidence).
HTH, Jeroen
"We are not alone"(FZ) | [reply] |
|
Thanks for pointing that one out. And that would work fine for focus on one node, except that the result of a search will be perhaps many distinct nodes, some of which will share parentage, and some of which will have distinct parentage. That darn
"0 or more but usually 1" parent thing gets in the way.
And yes, I agree with
perrin on this one, but the client has chosen to mix links of
both "is-like-a" and "contains-a" in the same syntax net. Ugh.
-- Randal L. Schwartz, Perl hacker
| [reply] |
|
|