organigramm test

This commit is contained in:
holger.trampe 2020-03-26 22:52:02 +01:00
parent 780f84d318
commit 9f35e89748
1 changed files with 32 additions and 27 deletions

View File

@ -17,8 +17,11 @@
</div>
<style type="text/css">
div.diagram_class {
}
#diagram {
min-width: 768px;
min-height: 1200px;
padding-left: 120px;
}
</style>
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.9.1/underscore-min.js"></script>
@ -56,38 +59,41 @@ for(i = 0; i < data.length; i++){
}
}
//Creates nested array from data
function unflatten(arr) {
var tree = [],
mappedArr = {},
arrElem,
mappedElem;
var tree = [],
mappedArr = {},
arrElem,
mappedElem;
// First map the nodes of the array to an object -> create a hash table.
for(var i = 0, len = arr.length; i < len; i++) {
arrElem = arr[i];
mappedArr[arrElem.id] = arrElem;
mappedArr[arrElem.id]['children'] = [];
}
// First map the nodes of the array to an object -> create a hash table.
for(var i = 0, len = arr.length; i < len; i++) {
arrElem = arr[i];
mappedArr[arrElem.id] = arrElem;
mappedArr[arrElem.id]['children'] = [];
}
for (var id in mappedArr) {
if (mappedArr.hasOwnProperty(id)) {
mappedElem = mappedArr[id];
// If the element is not at the root level, add it to its parent array of children.
if (mappedElem.parent) {
mappedArr[mappedElem['parent']]['children'].push(mappedElem);
}
// If the element is at the root level, add it to first level elements array.
else {
tree.push(mappedElem);
}
}
for (var id in mappedArr) {
if (mappedArr.hasOwnProperty(id)) {
mappedElem = mappedArr[id];
// If the element is not at the root level, add it to its parent array of children.
if (mappedElem.parent) {
mappedArr[mappedElem['parent']]['children'].push(mappedElem);
}
// If the element is at the root level, add it to first level elements array.
else {
tree.push(mappedElem);
}
return tree;
}
}
return tree;
}
var html = ['<ul class="tree" >'];
//Create UL-LI-List for tree
function createList(arr) {
html.push('<ul>');
@ -105,7 +111,6 @@ function createList(arr) {
});
html.push('</ul>');
}
createList(unflatten(data));
//Remove double ul/ul-Elements at the End