Site Search:

how to use Treant.js in blogspt in 5 minutes

Back>

Treant.js allows you to create beautify representation for tree data structure.

Example

You need to include jquery.min.js, raphael.js, Treant.js.
Then You can create node structure. When adding a new node, the field "parent" is the link between nodes.


<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/raphael/2.2.7/raphael.js"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/treant-js/1.0/Treant.js"></script>

<script>
var simple_chart_config = {
 chart: {
  container: "#OrganiseChart-simple"
 },

 nodeStructure: {
  text: { name: "Parent node" },
  children: [
   {
    text: { name: "First child" }
   },
   {
    text: { name: "Second child" }
   }
  ]
 }
};
</script>

<style>
/* required LIB STYLES */
/* .Treant se automatski dodaje na svaki chart conatiner */
.Treant { position: relative; overflow: hidden; padding: 0 !important; }
.Treant > .node,
.Treant > .pseudo { position: absolute; display: block; visibility: hidden; }
.Treant.Treant-loaded .node,
.Treant.Treant-loaded .pseudo { visibility: visible; }
.Treant > .pseudo { width: 0; height: 0; border: none; padding: 0; }
.Treant .collapse-switch { width: 3px; height: 3px; display: block; border: 1px solid black; position: absolute; top: 1px; right: 1px; cursor: pointer; }
.Treant .collapsed .collapse-switch { background-color: #868DEE; }
.Treant > .node img { border: none; float: left; }
</style>

<style>

/* optional Container STYLES */
.chart { height: 159px; width: 332px; margin: 5px; margin: 5px auto; border: 3px solid #DDD; border-radius: 3px; }
.node { color: #9CB5ED; border: 2px solid #C8C8C8; border-radius: 3px; }
.node p { font-size: 20px; line-height: 20px; height: 20px; font-weight: bold; padding: 3px; margin: 0; }
</style>

 <br />
<div class="chart" id="OrganiseChart-simple">
</div>
<script>
  new Treant( simple_chart_config );
</script>