I'm currently working on a small genealogy experiment and would like to implement a simple family tree like in the picture below.
The best search results so far for this only yielded examples where a child can only have a parent node. But what I need is the ability to create links between entities (from father to mother) and links between nodes and other links (from child to the father-mother link).
Currently I don't have a fixed data schema for this.
I've chosen d3.js for this because it looks like would be capable of doing the job. I just don't know how or even where to start. Tutorials about d3.js only cover standard charts like bar charts.
I hope someone can help me with this.
My approach is as under:
Lets take the example you have illustrated in the attached figure:
Jenny Of Oldstones is also a the child of Aegon V but the difference between this child and other children of Aegon V is that in this case I am not drawing the link between it.
This is done by setting the node as no_parent: true in the node JSON
example:
//Here Q will not have a parent
{
name: "Q",
id: 16,
no_parent: true
}
In the code check the _elbow function_ this does the job of not drawing the line between it and its parent:
if (d.target.no_parent) {
return "M0,0L0,0";
}
Next scenario is the link going between Node Aerys II and Rahella this node has its set of children.
I have created a node between them which is marked as hidden: true,
I make the display:none for such node. It appears that the children are coming from the line between node Aerys II and Rahella
JSON Example:
//this node will not be displayed
{ name: "",
id: 2,
no_parent: true,
hidden: true,
children: [....]
}
In the code check the place where I make the rectangles, the code below hides the node:
.attr("display", function (d) {
if (d.hidden) {
return "none"
} else {
return ""
};
})
Full code is in here:
http://jsfiddle.net/cyril123/0vbtvoon/22/
In the example above, I have made the use of node names A/B/C... but you can change it as per you requirements. You will need to center the text.
I have added comments to the code to help you understand the flow.
Just in case you are not clear on any point please comment I ll be happy to clarify.
dTree is an open source library built on-top of D3 that creates family trees (or similar hierarchical graphs).
It handles the bothersome parts of generating the D3 graph manually and uses a simple json data format:
[{
name: "Father",
marriages: [{
spouse: {
name: "Mother",
},
children: [{
name: "Child",
}]
}]
}]
If you are interested in modifying it supports callback for node rendering and event handler. Finally the library is as of 2016 under development and pull requests are welcomed.
DISCLAIMER: I'm the author of dTree. I created the library after searching the web just like you did and not finding anything to my liking.
The not-as-good news: The research I have done shows that there is no out-of-the-box d3 library that directly accomplishes this without some customization.
The good news: There have been some other people who have looked into this and have found some great starting points! I realize that this is not a complete solution to the entire task at hand, but it seems from your question that a large portion of your difficulty so far has been simply figuring out where to start (e.g. "Tutorials about d3.js only cover standard charts like bar charts."). In the absence of anything better, I will at least respond to that portion here.
First, in the response to this related stackoverflow post from a few years back, inanutshellus provides some great d3 tools that are available and could be of use here. With some light customization/extension, they should be able to get you where you're going relatively quickly. For posterity, inanutshellus's answer is reproduced here:
There are some options, but I believe each would require a bit of
work. It would help if there were one single standard for representing
a family tree in JSON. I've recently noticed that geni.com has a quite
in-depth API for this. Perhaps coding against their API would be a
good idea for reusability...
-- Pedigree tree --
The Pedigree Tree
might be sufficient for your needs. You'd make in-law's linkable,
where if you clicked on their name the graph would redraw so you could
see their lineage.
-- Bracket Layout Tree --
Similar to the Pedigree Tree, but bidirectional, this Bracket Layout Tree
lets you handle a "here are my parents, grandparents, children,
grandchildren" type view. Like the Pedigree Tree, you'd make
individuals linkable to re-center the bracket on that node.
-- Force-Based Layout --
There are some interesting force-based layouts that seem promising.
Take a look at this example of a
force-based layout with smart labels. An adjustment to the
algorithm for how the "force" is determined could make this into a
very lovely tree, with older generations above or below newer ones.
-- Cluster Dendogram (why it fails) --
The d3.js layouts I've seen that would lend themselves best to family
trees assume a single node is the parent, whereas you need to
represent the parent as the combination of (visually a "T" between)
two nodes: one node that is a member of your tree, and one floating
node that represents the in-law. Adjusting a cluster dendogram to do
this should be feasible but not without significant modification.
If you--or anyone else for that matter--tackle this, let me know. I'd
like to see (and benefit from) the work and may be able to contribute
to it if feasible.
In terms of concrete implementation, mj8591 asked this question regarding a similar family tree with a different problem. However, luckily for you that question includes a fiddle (all the js code) that has most or all the components that you need, and the response from mdml includes another fiddle that adds some more granular "clickability" to each node.
Again, it's nothing automagic but hopefully these resources are enough to get you a great start!
I tried dtree and liked it. However, when you add several generations, the horizontal display can make the overall display very large and unwieldy. Instead, I used the Reingold–Tilford Tree. One disadvantage of this tree is each node can have only one parent: spouses cannot be displayed alongside each other: To get past this limitation, I tweaked the JSON to combine spouses into one entity (ex: "husband - wife" ) just before sending it to the tree.
Answering 3 years after the question.
There is now a Pedigree Tree graph from Mike
https://bl.ocks.org/mell0kat/5cb91a2048384560dfa8f041fd9a0295
Then there is this d3.tree - A Family Tree
https://bl.ocks.org/mell0kat/5cb91a2048384560dfa8f041fd9a0295
You can also try the D3 Tidy Tree again from Mike
https://beta.observablehq.com/#mbostock/d3-tidy-tree
You can use dTree (Based on D3) to achieve your requirement.
Demo: https://treehouse.gartner.io/ErikGartner/58e58be650453b6d49d7
Reference Link: https://github.com/ErikGartner/dTree
I don't know if this is of any help to you, because you said that you were going to use d3.js but there is another tool that you might want to look into using called jsplumb. It seems perfect for this kind of project: home page. They also have some decent tutorials. There is one more like docs, and another more interactive.
Like I said, if it's not too late to switch technologies, this might be worth trying. It's all html, css, and javascript, so it shouldn't be a harsh transition.
I'm trying to create a multi-leveled list that is sortable by drag and drop. The user can grab an element and move it up and down the tree or drop it into other elements and have it become a child.
Are there off the shelf JS solutions? The jQuery sortable/draggable worked fine for a single level list but less so on nested solutions.
You can also try https://github.com/dbushell/Nestable (demo: http://dbushell.github.io/Nestable/).
Works with mouse and touch and this plugin is compatible with jQuery and Zepto.
I am using johnny's jquery-sortable plugin, which can be found here http://johnny.github.io/jquery-sortable.
It seems to work pretty well.
I was also trying to get it to send back the sorted structure of the list via AJAX. See this topic if you want to see my working solution, as the official documentation on serialization seemed slightly unsatisfactory (at least for nested lists).
Hope this is helpful.
So while you can use https://github.com/dbushell/Nestable or http://johnny.github.io/jquery-sortable
You probably want to move to something like React these days so you can use packages like this: https://www.npmjs.com/package/react-drag-sortable
Try not to use jQuery for this sort of thing any more. By the time you have drag/drop interfaces you have the makings of a webapp, not a web page, and you're going the wrong direction.
I have came to see a package named react-nestable and it works to create nested drag and drop. I am putting a link for that package below - react-nestable npm
I've being working with a lot of WPF, and I used a lot of listviews to convey information. I wanted to create something like a detailed listview.
An example of what I'm looking for is the "listview" type interface on Facebook's newsfeed, or even Stack Overflow's question browsing list.
The data will come from an XML document. So far my solution was to use divs within divs, but unfortunately it ended up being very messy. I also tried making them with tables and then hiding the table borders (which worked to an extent) but I'm sure there must be a better way! I also heard using tables is not a very good way to do it.
I'm not even sure if the word "Listview" is the right term to describe what I'm trying to talk about. If there's a different term can you please also answer that so that I can search for that on Google too (because I've only been searching for Listview's in HTML/Javascript).
Thanks.
You can try listview plugins with ExtJs or Jquery.
Here's the listView example / doc from Jquery mobile
http://jquerymobile.com/test/docs/lists/docs-lists.html
Listview would be the term to identify the structure. The best possible way to implement it would be to use an un-ordered list ex: and style it with CSS. Its simple and not too messy.
I would like to know about the available js libraries for drawing multilevel trees. Some functionalities I'd like to add to the created tree would be to make the nodes click-able and to be able to select an area on the graph and do actions based on the selection.
Maybe you should try arbor.js?
I'd check out Protovis. I've had good success with it. However, it is a very general library, giving you lots of building blocks to make nice graphs, but it won't be a turnkey solution.
I'm tearing my hair out on this one; I want / need / would like something akin to one of the many tree viewers out there, but where I can also edit the structure, the name and the type of nodes (the world doesn't just have folders and files, people). I've Googled myself silly over this, looked at which plugin I could modify to do my bidding (not with much luck), but surely someone, somewhere must have had the need for an editor and not just a viewer? Surely someone must have more complex needs, like me?
The best one so far seems to be the one from Bassistance, but without the good editing part (just basic stuff). Is this the one I should extend, maybe?
I'm not married to JQuery, but the rest of my application use it and it would be the simplest, but if there's a Flash or other JS thing floating around, I'm cool. Input and output should be sane, and if you got a SQL backend, that's cool, too, but JSON or XML or whatever else that makes sense, er, makes sense.
Thoughts? Clues? Suggestions?
Yes the tree from Joern Zafferer (bassistance) is good.
There is also this one. (it has editing + exemples for server-side code):
http://www.jstree.com/reference/_examples/1_datasources.html
Ultimately all these scripts should be merged and refactored for jquery-ui, in the meantime you can check jqueryui.pbworks.com/Tree to check the current state of things.
Try jQuery Grid Plugin. It has a tree grid and can be edited.
Look at the demonstration page, New in version 3.3 -> Tree Grid.