Skip to content

Instantly share code, notes, and snippets.

@marwahaha
Forked from ErikGartner/.treehouse
Last active November 23, 2016 03:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marwahaha/67c1fe4c749fde6ef5ef66dcf064d388 to your computer and use it in GitHub Desktop.
Save marwahaha/67c1fe4c749fde6ef5ef66dcf064d388 to your computer and use it in GitHub Desktop.
dTree Demo

dTree

dTree is the open source graph library that powers this site. It is written by the Swedish computer engineering student Erik Gärtner. It builds on top of D3 and aims at being a simple yet extensive library for building family trees.

Treehouse

This site acts as a playground that allows for easy demoing and hosting of dTree graphs.

Stylesheet

The stylesheet here is simple and only intended to show an easy example of what is possible. Most elementes in the graph can be customized using stylesheets and custom renderers.

Custom renderer

When using dTree on your own site you have the possibility to to fully customize how the library renders the text and the node. For security purposes Treehouse only allows for custom html templates using a handlebar template.

In this example the renderer displays the name of the node and the "favorite color" if the data is available.

[{
"name": "Sharwan Bagla",
"class": "man",
"marriages": [{
"spouse": {
"name": "Sheila Bagla",
"class": "woman"
},
"children": [{
"name": "Sangeeta Marwaha",
"class": "woman",
"children": [{
"name": "Kunal Marwaha",
"class": "man",
"extra": {
"email_address": "kmarwahaha@gmail.com"
}
}, {
"name": "Nisha Marwaha",
"class": "woman"
}, {
"name": "Surina Marwaha",
"class": "woman"
}]
}, {
"name": "Ritu McKeown",
"class": "woman",
"marriages": [{
"spouse": {
"name": "Don McKeown",
"class": "man"
},
"children": [{
"name": "Anika McKeown",
"class": "woman"
}, {
"name": "Sona McKeown",
"class": "woman"
}]
}]
}, {
"name": "Sandeep Bagla",
"class": "man",
"marriages": [{
"spouse": {
"name": "Lori Bagla",
"class": "woman"
},
"children": [{
"name": "Brayden Bagla",
"class": "man",
"marriages": []
}, {
"name": "Amiya Bagla",
"class": "woman"
}, {
"name": "Kiran Bagla",
"class": "man"
}]
}]
}]
}]
}]
<b>{{name}}</b>
{{#if extra.date_of_birth}}
<br>{{extra.date_of_birth}}
{{/if}}
{{#if extra.phone_number}}
<br>{{extra.phone_number}}
{{/if}}
{{#if extra.email_address}}
<br>{{extra.email_address}}
{{/if}}
{{#if extra.favorite_color}}
<br>({{extra.favorite_color}})
{{/if}}
svg {
font: 10px sans-serif;
}
.linage {
fill: none;
stroke: #000;
}
.marriage {
fill: none;
stroke: black;
}
.man {
background-color: lightblue;
border-style: solid;
border-width: 1px;
}
.woman {
background-color: pink;
border-style: solid;
border-width: 1px;
}
.emphasis{
font-style: italic;
}
p {
padding:0;
margin:0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment