Skip to content
dani edited this page Jul 15, 2016 · 1 revision

Welcome to the treevisualization wiki!

Tree Structure

The tree used in this project present a partitionSize (#children), #levels and it is always a full tree.

Example tree

Based on http://bl.ocks.org/mbostock/4339083

Converting the background structure to the tree visualization structure

jsonToFlare

Map the structure of the json file to the flare structure used to generate the example tree

            function jsonToFlare(data){ 
                var name = pidFop(data.partitionSize, 0);
                var children = getChildren(name, 1, data);               
                return [{"name": name, "children": children}];
            }

pidFop

Return the first child of the level

            function pidFop(ps, level){
                return (Math.pow(ps, level) - 1)/(ps-1);
            }

getChildren

Map all the children of a parent

           function getChildren(parent, level, data){
                var first = (parent*data.partitionSize) + 1;
                var last = (parent+1)*data.partitionSize;

                var children = [];
                var k = 0;

                if(level == data.levels){
                    var objects = data.objectMapping[parent];
                    if(data.objectMapping[parent] != null) {
                        for (var i = 0; i < objects.length; i++) {
                            children[i] = {name: objects[i].objName, "children": null};
                        }
                    }
                }
                else {

                    for (var i = first; i <= last; i++) { // for each child of this parent
                        if (data.usedPartitions.indexOf(i) > -1) {
                            if (level < data.levels)
                                children[k] = {"name": i, "children": getChildren(i, level + 1, data)};
                        }
                        //else children[k] = null;
                        k++;
                    }
                }
                return children;
            }