-1

I have tried lots of Org Charts, this one is unique as it is amongst the very few allowing multiple parents. The only issue being that the first node is at the same level as the nodes supposed to be below it and the last node not being centered below parent node.

See image

enter image description here

The key here is making it adjust automatically. It is made using HTML-CSS. Not mine.

<html>
<head >
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Expires" CONTENT="-1">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>Test Family Tree</title>
<!-- I found and adapted this css code from: https://stackoverflow.com/questions/38192074/family-tree-css -->
<!-- There is also an example on codepen.io at: http://codepen.io/Pestov/pen/BLpgm -->
<!-- I am not sure who the original creator is -->
 
<style>
* {
margin: 0;
padding: 0;
font-family:sans-serif,Arial;
font-size:10pt;
}
.tree {
white-space: nowrap;
min-width: 800px;
min-height:500px;
}
.tree ul {
padding-top: 20px;
position: relative;
transition: all 0.5s;
-webkit-transition: all 0.5s;
-moz-transition: all 0.5s;
}
.tree li {
float: left;
text-align: center;
list-style-type: none;
position: relative;
padding: 20px 5px 0 5px;
transition: all 0.5s;
-webkit-transition: all 0.5s;
-moz-transition: all 0.5s;
}
/*We will use ::before and ::after to draw the connectors*/
.tree li::before, .tree li::after {
content: '';
position: absolute;
top: 0;
right: 50%;
border-top: 1px solid #ccc;
width: 50%;
height: 20px;
}
.tree li::after {
right: auto;
left: 50%;
border-left: 1px solid #ccc;
}
/*We need to remove left-right connectors from elements without any siblings*/
.tree li:only-child::after, .tree li:only-child::before {
display: none;
}
/*Remove space from the top of single children*/
.tree li:only-child {
content: '';
position: absolute;
top: 0;
right: 50%;
width: 50%;

}
/*Remove left connector from first child and right connector from last child*/
.tree li:first-child::before, .tree li:last-child::after {
border: 0 none;
}
/*Adding back the vertical connector to the last nodes*/
.tree li:last-child::before {
border-right: 1px solid #ccc;
border-radius: 0 5px 0 0;
-webkit-border-radius: 0 5px 0 0;
-moz-border-radius: 0 5px 0 0;
}
.tree li:first-child::after {
border-radius: 5px 0 0 0;
-webkit-border-radius: 5px 0 0 0;
-moz-border-radius: 5px 0 0 0;
}
/*Time to add downward connectors from parents*/
.tree ul ul::before {
content: '';
position: absolute;
top: 0;
left: 50%;
border-left: 1px solid #ccc;
width: 0;
height: 20px;
}
.tree li div {
border: 1px solid #ccc;
padding: 5px 10px;
text-decoration: none;
color: #fff;
font-family: arial, verdana, tahoma;
font-size: 11px;
display: inline-block;
min-width: 80px;
min-height: 30px;
border-radius: 5px;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
transition: all 0.5s;
-webkit-transition: all 0.5s;
-moz-transition: all 0.5s;
}
.tree li div .male {
background-color:#94A0B4;
display: inline-block;
width:fit-content;
padding:10px;
border-radius: 5px;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
}
.tree li div .spacer {
background-color:lightblue;
display: inline-block;
width:10px;
}
/*Time for some hover effects*/
/*We will apply the hover effect the the lineage of the element also*/
.tree li div:hover, .tree li div:hover + ul li div {
background: #c8e4f8;
color: #fff;
border: 1px solid #94a0b4;
}
/*Connector styles on hover*/
.tree li div:hover + ul li::after,
.tree li div:hover + ul li::before,
.tree li div:hover + ul::before,
.tree li div:hover + ul ul::before {
border-color: #94a0b4;
}
</style>
 
<body>
 
<form id="form1">
 
<div class="tree" id="FamilyTreeDiv">
 
<ul>
 
<li>
<div><span class="male">Alpha
</span></div>
</li>
 
 
<li>
<div><span class="male">Beta
</span><span class="spacer"></span><span class="male">Beta-1
</span></div>
 
 
<ul>
 
<li>
 
<div><span class="male">Gamma
</span><span class="spacer"></span><span class="male">Gamma-1
</span></div>

<li>
<div><span class="male">Delta
</span></div>
</li>

<li>
 
<div><span class="male">Epsilon
</span><span class="spacer"></span><span class="male">Epsilon-1
</span></div>
 
 
<ul>
 
<li>
<div><span class="male">Theta
</span><span class="spacer"></span><span class="male">Theta
</span></div>
 
 
<ul>
 
<li>
<div><span class="male">Kappa
</span></div>
</li>
 
</ul>
</li>
 
 
<li>
<div><span class="male">Iota
</span></div>
</li>
 
</ul>
 
</li>
 
 
<li>
<div><span class="male">Eta
</span></div>
</li>
 
</ul>

Appreciated.

A.A Noman
  • 4,233
  • 9
  • 23
  • 38
alain
  • 1
  • 2

1 Answers1

0

BALKANGraph developer evangelist here

Run the code below to see how you can achieve requested functionality

window.onload = function () { 

    var familyGroupTag = {
        group: true,
        template: "group_grey",
        groupState: BALKANGraph.EXPAND
    };


    var chart = new OrgChart(document.getElementById("tree"), {
        scaleInitial: BALKANGraph.match.boundary,
        enableDragDrop: true,
        nodeBinding: {
            field_0: "name",
            field_1: "title"
        },
        tags: {
            f1: familyGroupTag,
            f2: familyGroupTag,
            f3: familyGroupTag,
            f4: familyGroupTag,
            f5: familyGroupTag,
            f6: familyGroupTag,
            f7: familyGroupTag,
            f8: familyGroupTag,
            f9: familyGroupTag
        },
        nodes: [
            { id: 1, tags: ["f1"], name: "Alfa" },
            { id: 2, tags: ["f2"], pid: 1, name: "Beta-1" },
            { id: 3, tags: ["f2"], pid: 1, name: "Beta-1" },
            { id: 4, tags: ["f3"], pid: 2, name: "Gamma" },
            { id: 5, tags: ["f3"], pid: 2, name: "Gamma-1" },
            { id: 6, tags: ["f4"], pid: 2, name: "Delat" },
            { id: 7, tags: ["f5"], pid: 2, name: "Epsilon" },
            { id: 8, tags: ["f5"], pid: 2, name: "Epsilon-1" },
            { id: 9, tags: ["f6"], pid: 2, name: "Eta" },
            { id: 10, tags: ["f7"], pid: 7, name: "Tetha" },
            { id: 11, tags: ["f7"], pid: 7, name: "Tetha-1" },
            { id: 12, tags: ["f8"], pid: 7, name: "lata" },
            { id: 13, tags: ["f9"], pid: 11, name: "Kappa" }
        ]
    });
};
html, body {
    margin: 0px;
    padding: 0px;
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: Helvetica;
}

#tree {
    width: 100%;
    height: 100%;
}
<script src="https://balkangraph.com/js/latest/OrgChart.js"></script>

<div id="tree"></div>
BALKANGraph
  • 1,987
  • 1
  • 14
  • 16
  • Your solution resolves the problem eventhough it relies on an external library (and uses Javascript). I was looking for a solution using pure CSS. Thank you for sharing. – alain Mar 05 '19 at 10:58