orgchart
Version:
Simple and direct organization chart(tree-like hierarchy) library based on pure DOM.
87 lines (81 loc) • 2.27 kB
HTML
<html lang="en">
<head>
<meta charset="utf-8">
<title>OrgChart getHierarchy Demo</title>
<link rel="icon" href="img/logo.png">
<link rel="stylesheet" href="css/orgchart.css">
<link rel="stylesheet" href="css/style.css">
<style type="text/css">
#chart-container {
display: inline-block;
width: 50%;
margin-left: 10px;
}
pre {
display: inline-block;
vertical-align: top;
font-size: 16px;
font-weight: bold;
margin-left: 20px;
}
.home-link {
position: absolute;
bottom: 20px;
right: 20px;
display: block;
width: 100%;
text-align: right;
}
#btn-export-hier {
position: relative;
top: -200px;
left: 10px;
padding: 0.5rem 1rem;
}
</style>
</head>
<body>
<section class="demo-notes">
<h1>getHierarchy Demo</h1>
<p>This demo builds a chart from nested list markup and exports the current chart back to hierarchy JSON with getHierarchy().</p>
</section>
<ul id="ul-data" style="display: none;">
<li data-id="n1">Lao Lao
<ul>
<li data-id="n2">Bo Miao</li>
<li data-id="n3">Su Miao
<ul>
<li data-id="n4">Tie Hua</li>
<li data-id="n5">Hei Hei
<ul>
<li data-id="n6">Pang Pang</li>
<li data-id="n7">Xiang Xiang</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<div id="chart-container"></div>
<button id="btn-export-hier">Export Hierarchy</button>
<script type="text/javascript" src="js/orgchart.js"></script>
<script type="text/javascript">
document.addEventListener('DOMContentLoaded', () => {
const oc = new OrgChart({
chartContainer: '#chart-container',
'data' : document.getElementById('ul-data')
});
document.getElementById('btn-export-hier').addEventListener('click', () => {
if (!document.querySelector('pre')) {
const hierarchy = oc.getHierarchy();
const pre = document.createElement('pre');
pre.textContent = JSON.stringify(hierarchy, null, 2);
document.getElementById('btn-export-hier').after(pre);
}
});
});
</script>
</body>
</html>