Last active
May 9, 2016 02:46
-
-
Save kaiwang0112006/ec14f11057289a3c32db16a1b4a1ea3d to your computer and use it in GitHub Desktop.
test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body{ | |
background-color:white; | |
font-family:Helvetica,Arial,Verdana,sans-serif; | |
} | |
.title { | |
margin: 0 auto; | |
text-align:center; | |
} | |
.title h1 a{ | |
font-family:Georgia; | |
color:#ced1d2; | |
font-weight:normal; | |
} | |
.hide{ | |
display:none; | |
} | |
.text-left{ | |
text-align:left; | |
} | |
.text-right{ | |
text-align:right; | |
} | |
.text-center{ | |
text-align:center; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> | |
<title></title> | |
<link rel="stylesheet" type="text/css" href="base.css"> | |
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script> | |
<script type="text/javascript" src="//d3js.org/d3.v3.min.js" charset="utf-8"></script> | |
</head> | |
<body> | |
<div class="title"> | |
<h1><br>Taste of Data</h1> | |
<hr> | |
</div> | |
<link rel="stylesheet" type="text/css" href="http://123.57.33.46/static/css/treeview.css"> | |
<div id="treeview"></div> | |
<script type="text/javascript"> | |
var treeData = [ | |
{ | |
"children": [ | |
{ | |
"name": "gini = 0.0000\\nsamples = 15\\nvalue = [ 15. 0.]", | |
"parent": "0" | |
}, | |
{ | |
"children": [ | |
{ | |
"children": [ | |
{ | |
"name": "gini = 0.0000\\nsamples = 1\\nvalue = [ 0. 1.]", | |
"parent": "3" | |
}, | |
{ | |
"name": "gini = 0.0000\\nsamples = 3\\nvalue = [ 3. 0.]", | |
"parent": "3" | |
} | |
], | |
"name": "cumsumOverdue_acc <= 0.0733\\ngini = 0.375\\nsamples = 4", | |
"parent": "2" | |
}, | |
{ | |
"children": [ | |
{ | |
"name": "gini = 0.0000\\nsamples = 1\\nvalue = [ 1. 0.]", | |
"parent": "6" | |
}, | |
{ | |
"children": [ | |
{ | |
"name": "gini = 0.0000\\nsamples = 15\\nvalue = [ 0. 15.]", | |
"parent": "8" | |
}, | |
{ | |
"children": [ | |
{ | |
"name": "gini = 0.0000\\nsamples = 4\\nvalue = [ 0. 4.]", | |
"parent": "10" | |
}, | |
{ | |
"name": "gini = 0.0000\\nsamples = 1\\nvalue = [ 1. 0.]", | |
"parent": "10" | |
} | |
], | |
"name": "maxday_wma <= 43.5932\\ngini = 0.32\\nsamples = 5", | |
"parent": "8" | |
} | |
], | |
"name": "cumsumOverdue_acc <= 1.0196\\ngini = 0.095\\nsamples = 20", | |
"parent": "6" | |
} | |
], | |
"name": "maxday_acc <= 5.6748\\ngini = 0.172335600907\\nsamples = 21", | |
"parent": "2" | |
} | |
], | |
"name": "cumsumOverdue_acc <= 0.5568\\ngini = 0.32\\nsamples = 25", | |
"parent": "0" | |
} | |
], | |
"name": "maxday_wma <= 22.8769\\ngini = 0.5\\nsamples = 40", | |
"parent": "null" | |
} | |
] | |
// ************** Generate the tree diagram ***************** | |
var margin = {top: 40, right: 120, bottom: 20, left: 120}, | |
width = 1200 - margin.right - margin.left, | |
height = 1200 - margin.top - margin.bottom; | |
var i = 0, | |
duration = 750, | |
root; | |
var tree = d3.layout.tree() | |
.size([height, width]); | |
var diagonal = d3.svg.diagonal() | |
.projection(function(d) { return [d.x, d.y]; }); | |
var svg = d3.select("#treeview").append("svg") | |
.attr("width", width + margin.right + margin.left) | |
.attr("height", height + margin.top + margin.bottom) | |
.append("g") | |
.attr("transform", "translate(" + margin.left + "," + margin.top + ")"); | |
root = treeData[0]; | |
root.x0 = height / 2; | |
root.y0 = 0; | |
update(root); | |
//d3.select(self.frameElement).style("height", "500px"); | |
function update(source) { | |
// Compute the new tree layout. | |
var nodes = tree.nodes(root).reverse(), | |
links = tree.links(nodes); | |
// Normalize for fixed-depth. | |
nodes.forEach(function(d) { d.y = d.depth * 100; }); | |
// Update the nodes… | |
var node = svg.selectAll("g.node") | |
.data(nodes, function(d) { return d.id || (d.id = ++i); }); | |
// Enter any new nodes at the parent's previous position. | |
var nodeEnter = node.enter().append("g") | |
.attr("class", "node") | |
.attr("transform", function(d) { return "translate(" + source.x0 + "," + source.y0 + ")"; }) | |
.on("click", click); | |
nodeEnter.append("circle") | |
.attr("r", 1e-6) | |
.style("fill", function(d) { return d._children ? "lightsteelblue" : "#fff"; }); | |
nodeEnter.append("text") | |
.attr("x", function(d) { return d.children || d._children ? -13 : 13; }) | |
.attr("dy", ".35em") | |
.attr("text-anchor", function(d) { return d.children || d._children ? "end" : "start"; }) | |
.text(function(d) { return d.name; }) | |
.style("fill-opacity", 1e-6); | |
// Transition nodes to their new position. | |
var nodeUpdate = node.transition() | |
.duration(duration) | |
.attr("transform", function(d) { return "translate(" + d.x + "," + d.y + ")"; }); | |
nodeUpdate.select("circle") | |
.attr("r", 10) | |
.style("fill", function(d) { return d._children ? "lightsteelblue" : "#fff"; }); | |
nodeUpdate.select("text") | |
.style("fill-opacity", 1); | |
// Transition exiting nodes to the parent's new position. | |
var nodeExit = node.exit().transition() | |
.duration(duration) | |
.attr("transform", function(d) { return "translate(" + source.x + "," + source.y + ")"; }) | |
.remove(); | |
nodeExit.select("circle") | |
.attr("r", 1e-6); | |
nodeExit.select("text") | |
.style("fill-opacity", 1e-6); | |
// Update the links… | |
var link = svg.selectAll("path.link") | |
.data(links, function(d) { return d.target.id; }); | |
// Enter any new links at the parent's previous position. | |
link.enter().insert("path", "g") | |
.attr("class", "link") | |
.attr("d", function(d) { | |
var o = {x: source.x0, y: source.y0}; | |
return diagonal({source: o, target: o}); | |
}); | |
// 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); | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment