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