oostopitre
2/15/2013 - 10:03 PM

Cube Application Manager Visualization #d3

Cube Application Manager Visualization #d3

{
    "execOrder": 1,
    "groupName": "Parent",
    "isSubGroup": true,
    "isRoot": true,
    "progName": "Parent",
    "children": [
        {
            "execOrder": "2",
            "groupName": "C:\\_Viz\\myAppManager\\manilaCatalog\\HASSIGN.APP",
            "isSubGroup": true,
            "isRoot": false,
            "progName": "Highway Assignment",
            "children": [
                {
                    "execOrder": "1",
                    "groupName": "C:\\_Viz\\myAppManager\\manilaCatalog\\PREPROCESSNETWORK.APP",
                    "isSubGroup": true,
                    "isRoot": false,
                    "progName": "Network Pre-processing",
                    "children": [
                        {
                            "execOrder": "1",
                            "groupName": "",
                            "isSubGroup": false,
                            "isRoot": false,
                            "progName": "NETWORK",
                            "children": []
                        },
                        {
                            "execOrder": "2",
                            "groupName": "",
                            "isSubGroup": false,
                            "isRoot": false,
                            "progName": "NETWORK",
                            "children": []
                        },
                        {
                            "execOrder": "3",
                            "groupName": "",
                            "isSubGroup": false,
                            "isRoot": false,
                            "progName": "NETWORK",
                            "children": []
                        },
                        {
                            "execOrder": "4",
                            "groupName": "",
                            "isSubGroup": false,
                            "isRoot": false,
                            "progName": "MATRIX",
                            "children": []
                        }
                    ]
                },
                {
                    "execOrder": "2",
                    "groupName": "",
                    "isSubGroup": false,
                    "isRoot": false,
                    "progName": "HIGHWAY",
                    "children": []
                },
                {
                    "execOrder": "3",
                    "groupName": "",
                    "isSubGroup": false,
                    "isRoot": false,
                    "progName": "NETWORK",
                    "children": []
                },
                {
                    "execOrder": "4",
                    "groupName": "",
                    "isSubGroup": false,
                    "isRoot": false,
                    "progName": "NETWORK",
                    "children": []
                }
            ]
        },
        {
            "execOrder": "1",
            "groupName": "C:\\_Viz\\myAppManager\\manilaCatalog\\CONVERT.APP",
            "isSubGroup": true,
            "isRoot": false,
            "progName": "Convert TPLAN Inputs to Voyager",
            "children": [
                {
                    "execOrder": "1",
                    "groupName": "",
                    "isSubGroup": false,
                    "isRoot": false,
                    "progName": "MATRIX",
                    "children": []
                },
                {
                    "execOrder": "2",
                    "groupName": "",
                    "isSubGroup": false,
                    "isRoot": false,
                    "progName": "NETWORK",
                    "children": []
                },
                {
                    "execOrder": "3",
                    "groupName": "",
                    "isSubGroup": false,
                    "isRoot": false,
                    "progName": "NETWORK",
                    "children": []
                },
                {
                    "execOrder": "5",
                    "groupName": "",
                    "isSubGroup": false,
                    "isRoot": false,
                    "progName": "NETWORK",
                    "children": []
                },
                {
                    "execOrder": "4",
                    "groupName": "",
                    "isSubGroup": false,
                    "isRoot": false,
                    "progName": "NETWORK",
                    "children": []
                }
            ]
        },
        {
            "execOrder": "3",
            "groupName": "C:\\_Viz\\myAppManager\\manilaCatalog\\MATRIXESTIMATION00.APP",
            "isSubGroup": true,
            "isRoot": false,
            "progName": "Matrix Estimation",
            "children": [
                {
                    "execOrder": "4",
                    "groupName": "",
                    "isSubGroup": false,
                    "isRoot": false,
                    "progName": "MVESTM",
                    "children": []
                },
                {
                    "execOrder": "5",
                    "groupName": "",
                    "isSubGroup": false,
                    "isRoot": false,
                    "progName": "HIGHWAY",
                    "children": []
                },
                {
                    "execOrder": "3",
                    "groupName": "",
                    "isSubGroup": false,
                    "isRoot": false,
                    "progName": "",
                    "children": []
                },
                {
                    "execOrder": "1",
                    "groupName": "",
                    "isSubGroup": false,
                    "isRoot": false,
                    "progName": "PILOT",
                    "children": []
                },
                {
                    "execOrder": "11",
                    "groupName": "",
                    "isSubGroup": false,
                    "isRoot": false,
                    "progName": "PILOT",
                    "children": []
                },
                {
                    "execOrder": "7",
                    "groupName": "",
                    "isSubGroup": false,
                    "isRoot": false,
                    "progName": "NETWORK",
                    "children": []
                },
                {
                    "execOrder": "2",
                    "groupName": "",
                    "isSubGroup": false,
                    "isRoot": false,
                    "progName": "MATRIX",
                    "children": []
                },
                {
                    "execOrder": "6",
                    "groupName": "",
                    "isSubGroup": false,
                    "isRoot": false,
                    "progName": "MATRIX",
                    "children": []
                },
                {
                    "execOrder": "8",
                    "groupName": "",
                    "isSubGroup": false,
                    "isRoot": false,
                    "progName": "MATRIX",
                    "children": []
                },
                {
                    "execOrder": "9",
                    "groupName": "",
                    "isSubGroup": false,
                    "isRoot": false,
                    "progName": "MATRIX",
                    "children": []
                },
                {
                    "execOrder": "10",
                    "groupName": "",
                    "isSubGroup": false,
                    "isRoot": false,
                    "progName": "MATRIX",
                    "children": []
                }
            ]
        }
    ]
}
circle {
  cursor: pointer;
  fill: #fff;
  stroke: steelblue;
  stroke-width: 1.5px;
}

text {
  font-size:10px;
}

path.link {
  fill: none;
  stroke: #ccc;
  stroke-width: 1.5px;
}
<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
    <title>Node-Link Tree</title>
	<link href="interactive_tree.css" rel="stylesheet" type="text/css" />
	<script src="http://d3js.org/d3.v3.min.js"></script>
  </head>
  <body>
  <div id="body">
      <div id="footer">
        d3.layout.tree
        <div class="hint">click or option-click to expand or collapse</div>
      </div>
    </div>
    <div id="chart"></div>
    <script type="text/javascript">

var m = [20, 120, 20, 120],
    w = 1280 - m[1] - m[3],
    h = 500 - m[0] - m[2],
    i = 0,
    duration = 500,
    root;

var tree = d3.layout.tree()
    .size([h, w - 160]);

var diagonal = d3.svg.diagonal()
    .projection(function(d) { return [d.y, d.x]; });

var vis = d3.select("#chart").append("svg:svg")
    .attr("width", w)
    .attr("height", h)
  .append("svg:g")
    .attr("transform", "translate(40,0)");

d3.json("sampleCatalog.json", function(error, data) {
  json.x0 = 800;
  json.y0 = 0;
  update(root = json);
});

function update(source) {

  // Compute the new tree layout.
  var nodes = tree.nodes(root).reverse();
 console.log(nodes)
  // Update the nodes…
  	var node = vis.selectAll("g.node")
      .data(nodes, function(d) { return d.id || (d.id = ++i); });

	var nodeEnter = node.enter().append("svg:g")
    	.attr("class", "node")
    	.attr("transform", function(d) { return "translate(" + source.y0 + "," + source.x0 + ")"; });
    	//.style("opacity", 1e-6);
 
  // Enter any new nodes at the parent's previous position.
 
  	nodeEnter.append("svg:circle")
      .attr("r", 4.5)
      .style("fill", function(d) { return d._children ? "lightsteelblue" : "#fff"; })
      .on("click", click);
	
	nodeEnter.append("svg:text")
      	.attr("x", function(d) { return d._children ? -8 : 8; })
		.attr("y", 3)
      	//.attr("fill","#ccc")
      	//.attr("transform", function(d) { return "translate(" + d.y + "," + d.x + ")"; })
      	.text(function(d) { return d.execOrder+' - '+d.progName; });

  // Transition nodes to their new position.
	nodeEnter.transition()
		.duration(duration)
		.attr("transform", function(d) { return "translate(" + d.y + "," + d.x + ")"; })
      	.style("opacity", 1)
      .select("circle")
    	//.attr("cx", function(d) { return d.x; })
		//.attr("cy", function(d) { return d.y; })
        .style("fill", "lightsteelblue");
      
    node.transition()
      .duration(duration)
      .attr("transform", function(d) { return "translate(" + d.y + "," + d.x + ")"; })
      .style("opacity", 1);
    

	node.exit().transition()
      .duration(duration)
      .attr("transform", function(d) { return "translate(" + source.y + "," + source.x + ")"; })
      .style("opacity", 1e-6)
      .remove();

  // Update the links…
  var link = vis.selectAll("path.link")
      .data(tree.links(nodes), function(d) { return d.target.id; });

  // Enter any new links at the parent's previous position.
  link.enter().insert("svg:path", "g")
      .attr("class", "link")
      .attr("d", function(d) {
        var o = {x: source.x0, y: source.y0};
        return diagonal({source: o, target: o});
      })
    .transition()
      .duration(duration)
      .attr("d", diagonal);

  // Transition links to their new position.
  link.transition()
      .duration(duration)
      .attr("d", diagonal);

  // Transition exiting nodes to the parent's new position.
  link.exit().transition()
      .duration(duration)
      .attr("d", function(d) {
        var o = {x: source.x, y: source.y};
        return diagonal({source: o, target: o});
      })
      .remove();

  // Stash the old positions for transition.
  nodes.forEach(function(d) {
    d.x0 = d.x;
    d.y0 = d.y;
  });
}

// Toggle children on click.
function click(d) {
  if (d.children) {
    d._children = d.children;
    d.children = null;
  } else {
    d.children = d._children;
    d._children = null;
  }
  update(d);
}

d3.select(self.frameElement).style("height", "2000px");

    </script>
  </body>
</html>