updates
This commit is contained in:
parent
e9d3bb0b61
commit
776e9acd03
10 changed files with 1214 additions and 6 deletions
|
@ -80,9 +80,6 @@
|
|||
{
|
||||
name: "Node",
|
||||
children: [
|
||||
{
|
||||
name: "Children",
|
||||
},
|
||||
{
|
||||
name: "Scheme",
|
||||
children: [
|
||||
|
@ -125,10 +122,15 @@
|
|||
]
|
||||
},
|
||||
{
|
||||
name: "global_tree",
|
||||
name: "GlobalTree",
|
||||
children: [
|
||||
{
|
||||
name: "Node"
|
||||
name: "Node",
|
||||
children: [
|
||||
{
|
||||
name: "Children",
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "NodeTypes",
|
||||
|
|
182
templates/initi/tmpl/inheritance.tmpl
Normal file
182
templates/initi/tmpl/inheritance.tmpl
Normal file
|
@ -0,0 +1,182 @@
|
|||
<?js
|
||||
var data = obj;
|
||||
var self = this;
|
||||
|
||||
var str = JSON.stringify(inheritance);
|
||||
|
||||
?>
|
||||
|
||||
|
||||
|
||||
<style>
|
||||
|
||||
.node {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.node circle {
|
||||
fill: #fff;
|
||||
stroke: steelblue;
|
||||
stroke-width: 3px;
|
||||
}
|
||||
|
||||
.node text {
|
||||
font: 12px sans-serif;
|
||||
}
|
||||
|
||||
.link {
|
||||
fill: none;
|
||||
stroke: #ccc;
|
||||
stroke-width: 2px;
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
<div class="oa fs" id="arch-scroll" style="max-width: 100%">
|
||||
<div id="arch-content" class=""></div>
|
||||
</div>
|
||||
|
||||
<!-- load the d3.js library -->
|
||||
<script src="http://d3js.org/d3.v3.min.js"></script>
|
||||
|
||||
<script>
|
||||
var as = document.getElementById("arch-scroll");
|
||||
as.style.height = (screen.availHeight - 143) + "px";
|
||||
|
||||
|
||||
var sstr = '<?js= str ?>';
|
||||
|
||||
treeData = [JSON.parse(sstr)];
|
||||
|
||||
|
||||
// ************** Generate the tree diagram *****************
|
||||
var margin = {top: 20, right: 120, bottom: 20, left: 120},
|
||||
width = 3260 - margin.right - margin.left,
|
||||
height = 2100 - margin.top - margin.bottom;
|
||||
|
||||
var i = 0,
|
||||
duration = 350,
|
||||
root;
|
||||
|
||||
var tree = d3.layout.tree()
|
||||
.size([height, width]);
|
||||
|
||||
var diagonal = d3.svg.diagonal()
|
||||
.projection(function(d) { return [d.y, d.x]; });
|
||||
|
||||
var svg = d3.select("div#arch-content").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 * 180; });
|
||||
|
||||
// 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.y0 + "," + source.x0 + ")"; })
|
||||
.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 13; })
|
||||
.attr("y", function(d) { return -6; })
|
||||
.attr("dy", ".35em")
|
||||
.attr("text-anchor", function(d) { return "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.y + "," + d.x + ")"; });
|
||||
|
||||
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.y + "," + source.x + ")"; })
|
||||
.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>
|
||||
|
183
templates/initi/tmpl/inheritance2.tmpl
Normal file
183
templates/initi/tmpl/inheritance2.tmpl
Normal file
|
@ -0,0 +1,183 @@
|
|||
<?js
|
||||
var data = obj;
|
||||
var self = this;
|
||||
|
||||
var str = JSON.stringify(inheritance);
|
||||
|
||||
?>
|
||||
|
||||
|
||||
|
||||
<style>
|
||||
|
||||
.node {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.node circle {
|
||||
fill: #fff;
|
||||
stroke: steelblue;
|
||||
stroke-width: 3px;
|
||||
}
|
||||
|
||||
.node text {
|
||||
font: 12px sans-serif;
|
||||
}
|
||||
|
||||
.link {
|
||||
fill: none;
|
||||
stroke: #ccc;
|
||||
stroke-width: 2px;
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
<div class="oa fs" id="arch-scroll" style="max-width: 100%">
|
||||
<div id="arch-content" class=""></div>
|
||||
</div>
|
||||
|
||||
<!-- load the d3.js library -->
|
||||
<script src="http://d3js.org/d3.v3.min.js"></script>
|
||||
|
||||
<script>
|
||||
var as = document.getElementById("arch-scroll");
|
||||
as.style.height = (screen.availHeight - 243) + "px";
|
||||
|
||||
|
||||
var sstr = '<?js= str ?>';
|
||||
var hheight = '<?js= height ?>';
|
||||
|
||||
treeData = [JSON.parse(sstr)];
|
||||
|
||||
|
||||
// ************** Generate the tree diagram *****************
|
||||
var margin = {top: 20, right: 120, bottom: 20, left: 120},
|
||||
width = 3260 - margin.right - margin.left,
|
||||
height = hheight - margin.top - margin.bottom;
|
||||
|
||||
var i = 0,
|
||||
duration = 350,
|
||||
root;
|
||||
|
||||
var tree = d3.layout.tree()
|
||||
.size([height, width]);
|
||||
|
||||
var diagonal = d3.svg.diagonal()
|
||||
.projection(function(d) { return [d.y, d.x]; });
|
||||
|
||||
var svg = d3.select("div#arch-content").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 * 180; });
|
||||
|
||||
// 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.y0 + "," + source.x0 + ")"; })
|
||||
.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 13; })
|
||||
.attr("y", function(d) { return -6; })
|
||||
.attr("dy", ".35em")
|
||||
.attr("text-anchor", function(d) { return "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.y + "," + d.x + ")"; });
|
||||
|
||||
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.y + "," + source.x + ")"; })
|
||||
.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>
|
||||
|
231
templates/initi/tmpl/inheritance3.tmpl
Normal file
231
templates/initi/tmpl/inheritance3.tmpl
Normal file
|
@ -0,0 +1,231 @@
|
|||
<?js
|
||||
var data = obj;
|
||||
var self = this;
|
||||
|
||||
var str = JSON.stringify(inheritance);
|
||||
|
||||
?>
|
||||
|
||||
|
||||
|
||||
<style>
|
||||
|
||||
.node {
|
||||
cursor: pointer;
|
||||
stroke: #3182bd;
|
||||
stroke-width: 1.5px;
|
||||
}
|
||||
|
||||
.link {
|
||||
fill: none;
|
||||
stroke: #9ecae1;
|
||||
stroke-width: 1.5px;
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
<div class="oa fs" id="arch-scroll" style="max-width: 100%">
|
||||
<div id="arch-content" class=""></div>
|
||||
</div>
|
||||
|
||||
<!-- load the d3.js library -->
|
||||
<script src="http://d3js.org/d3.v3.min.js"></script>
|
||||
|
||||
<script>
|
||||
var as = document.getElementById("arch-scroll");
|
||||
as.style.height = (screen.availHeight - 243) + "px";
|
||||
|
||||
|
||||
var sstr = '<?js= str ?>';
|
||||
var hheight = '<?js= height ?>';
|
||||
|
||||
var treeData = [JSON.parse(sstr)];
|
||||
|
||||
|
||||
|
||||
// ------------
|
||||
var __updatelinks = function (links) {
|
||||
for (var a = 0; a < links.length; a++) {
|
||||
var link = links[a];
|
||||
|
||||
var minsize = 2150;
|
||||
var max = Math.max(link.source.children.length, link.target.children.length);
|
||||
|
||||
// link.strange = 2;
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// ************** Generate the tree diagram *****************
|
||||
var width = 2000,
|
||||
height = hheight,
|
||||
root;
|
||||
|
||||
var force = d3.layout.force()
|
||||
.size([width, height])
|
||||
.on("tick", tick)
|
||||
.linkDistance(function(link){
|
||||
var max = Math.sqrt(Math.max(link.source.children.length, link.target.children.length) * 20);
|
||||
return max < 20 ? 20 : max;
|
||||
})
|
||||
.charge(function () {
|
||||
return -50;
|
||||
});
|
||||
|
||||
var svg = d3.select("#arch-content").append("svg")
|
||||
.attr("width", width)
|
||||
.attr("height", height);
|
||||
|
||||
var link = svg.selectAll(".link"),
|
||||
node = svg.selectAll(".node");
|
||||
|
||||
root = treeData[0];
|
||||
update();
|
||||
|
||||
function update() {
|
||||
var nodes = window.nodes = flatten(root);
|
||||
var links = window.links = d3.layout.tree().links(nodes);
|
||||
|
||||
// __updatelinks(links);
|
||||
|
||||
// Restart the force layout.
|
||||
force
|
||||
.nodes(nodes)
|
||||
.links(links)
|
||||
.start();
|
||||
|
||||
|
||||
|
||||
|
||||
// Update the links…
|
||||
link = link.data(links, function(d) { return d.target.id; });
|
||||
|
||||
// Exit any old links.
|
||||
link.exit().remove();
|
||||
|
||||
// Enter any new links.
|
||||
link.enter().insert("line", ".node")
|
||||
.attr("class", "link")
|
||||
.attr("x1", function(d) { return d.source.x; })
|
||||
.attr("y1", function(d) { return d.source.y; })
|
||||
.attr("x2", function(d) { return d.target.x; })
|
||||
.attr("y2", function(d) { return d.target.y; });
|
||||
|
||||
// Update the nodes…
|
||||
node = node.data(nodes, function(d) { return d.id; }).style("fill", color);
|
||||
|
||||
// Exit any old nodes.
|
||||
node.exit().remove();
|
||||
|
||||
// Enter any new nodes.
|
||||
node.enter().append("circle")
|
||||
.attr("class", "node")
|
||||
.attr("cx", function(d) { return d.x; })
|
||||
.attr("cy", function(d) { return d.y; })
|
||||
.attr("r", function(d) {
|
||||
var size = 4.5;
|
||||
var res = Math.sqrt(d.children.length * size);
|
||||
return res < size ? size : res;
|
||||
})
|
||||
.style("fill", color)
|
||||
.on("click", click)
|
||||
.on("mouseover", handleMouseOver)
|
||||
.on("mouseout", handleMouseOut)
|
||||
.call(force.drag);
|
||||
|
||||
// node.enter().append("text")
|
||||
// .attr("dx", function(d){return d.x; })
|
||||
// .attr("dy", function(d){return d.y; })
|
||||
// .text(function(d){return d.name});
|
||||
}
|
||||
|
||||
function tick() {
|
||||
link.attr("x1", function(d) { return d.source.x; })
|
||||
.attr("y1", function(d) { return d.source.y; })
|
||||
.attr("x2", function(d) { return d.target.x; })
|
||||
.attr("y2", function(d) { return d.target.y; });
|
||||
|
||||
node.attr("cx", function(d) { return d.x; })
|
||||
.attr("cy", function(d) { return d.y; });
|
||||
}
|
||||
|
||||
// Color leaf nodes orange, and packages white or blue.
|
||||
function color(d) {
|
||||
return d._children ? "#3182bd" : d.children ? "#c6dbef" : "#fd8d3c";
|
||||
}
|
||||
|
||||
// Toggle children on click.
|
||||
function click(d) {
|
||||
if (!d3.event.defaultPrevented) {
|
||||
if (d.children) {
|
||||
d._children = d.children;
|
||||
d.children = null;
|
||||
} else {
|
||||
d.children = d._children;
|
||||
d._children = null;
|
||||
}
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
var currentNode;
|
||||
|
||||
// Create Event Handlers for mouse
|
||||
function handleMouseOver(d, i) { // Add interactivity
|
||||
|
||||
if(currentNode){
|
||||
currentNode.remove(); // Remove text location
|
||||
}
|
||||
|
||||
// Use D3 to select element, change color and size
|
||||
d3.select(this).attr({
|
||||
fill: "orange",
|
||||
// r: 15
|
||||
});
|
||||
|
||||
// Specify where to put label of text
|
||||
currentNode = svg.append("text").attr({
|
||||
id: d.name, // Create an id for text so we can select it later for removing on mouseout
|
||||
x: function() { return d.x + 10; },
|
||||
y: function() { return d.y - 15; }
|
||||
})
|
||||
.text(d.name);
|
||||
}
|
||||
|
||||
|
||||
|
||||
function handleMouseOut(d, i) {
|
||||
// Use D3 to select element, change color back to normal
|
||||
d3.select(this).attr({
|
||||
fill: "black",
|
||||
r: function(d) {
|
||||
var size = 4.5;
|
||||
var res = Math.sqrt(d.children.length * size);
|
||||
return res < size ? size : res;
|
||||
}
|
||||
});
|
||||
|
||||
// Select text by id and then remove
|
||||
currentNode.remove(); // Remove text location
|
||||
currentNode = null;
|
||||
}
|
||||
|
||||
|
||||
// Returns a list of all nodes under the root.
|
||||
function flatten(root) {
|
||||
var nodes = [], i = 0;
|
||||
|
||||
function recurse(node) {
|
||||
if (node.children) node.children.forEach(recurse);
|
||||
if (!node.id) node.id = ++i;
|
||||
nodes.push(node);
|
||||
}
|
||||
|
||||
recurse(root);
|
||||
return nodes;
|
||||
}
|
||||
|
||||
|
||||
</script>
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue