formating
This commit is contained in:
parent
c42fc8fd5e
commit
1d3eb5f378
3 changed files with 46 additions and 18 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
body {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
.node circle {
|
.node circle {
|
||||||
fill: #fff;
|
fill: #fff;
|
||||||
stroke: steelblue;
|
stroke: steelblue;
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<script src="d3.v3.min.js"></script>
|
<script src="d3.v3.min.js"></script>
|
||||||
<link rel="stylesheet" href="index.css">
|
<link rel="stylesheet" href="index.css" type="text/css">
|
||||||
<title>Ontology Tree</title>
|
<title>Ontology Tree</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
|
@ -1,7 +1,12 @@
|
||||||
var margin = {top: 20, right: 120, bottom: 20, left: 120},
|
var margin = {
|
||||||
width = 1200 - margin.right - margin.left,
|
top: 20,
|
||||||
height = 4000 - margin.top - margin.bottom;
|
right: 120,
|
||||||
|
bottom: 20,
|
||||||
|
left: 120
|
||||||
|
},
|
||||||
|
width = 3000 - margin.right - margin.left,
|
||||||
|
height = window.innerHeight - margin.top - margin.bottom;
|
||||||
|
|
||||||
var i = 0,
|
var i = 0,
|
||||||
duration = 750,
|
duration = 750,
|
||||||
root;
|
root;
|
||||||
|
@ -13,13 +18,13 @@ var diagonal = d3.svg.diagonal()
|
||||||
.projection(function(d) { return [d.y, d.x]; });
|
.projection(function(d) { return [d.y, d.x]; });
|
||||||
|
|
||||||
var svg = d3.select("body").append("svg")
|
var svg = d3.select("body").append("svg")
|
||||||
.attr("width", "100%")
|
.attr("width", width)
|
||||||
.attr("height", height + margin.top + margin.bottom)
|
.attr("height", height + margin.top + margin.bottom)
|
||||||
.append("g")
|
.append("g")
|
||||||
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
|
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
|
||||||
|
|
||||||
d3.json("sized_ontology.json", function(error, flare) {
|
d3.json("sized_ontology.json", function(error, nodes) {
|
||||||
root = flare;
|
root = nodes;
|
||||||
root.x0 = height / 2;
|
root.x0 = height / 2;
|
||||||
root.y0 = 0;
|
root.y0 = 0;
|
||||||
|
|
||||||
|
@ -40,7 +45,11 @@ d3.json("sized_ontology.json", function(error, flare) {
|
||||||
update(root);
|
update(root);
|
||||||
});
|
});
|
||||||
|
|
||||||
d3.select(self.frameElement).style("height", "800px");
|
function resize() {
|
||||||
|
root.x0 = height / 2;
|
||||||
|
root.y0 = 0;
|
||||||
|
update(root);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function get_color(d) {
|
function get_color(d) {
|
||||||
|
@ -60,12 +69,16 @@ function update(source) {
|
||||||
|
|
||||||
// Update the nodes…
|
// Update the nodes…
|
||||||
var node = svg.selectAll("g.node")
|
var node = svg.selectAll("g.node")
|
||||||
.data(nodes, function(d) { return d.id || (d.id = ++i); });
|
.data(nodes, function(d) {
|
||||||
|
return d.id || (d.id = ++i);
|
||||||
|
});
|
||||||
|
|
||||||
// Enter any new nodes at the parent's previous position.
|
// Enter any new nodes at the parent's previous position.
|
||||||
var nodeEnter = node.enter().append("g")
|
var nodeEnter = node.enter().append("g")
|
||||||
.attr("class", "node")
|
.attr("class", "node")
|
||||||
.attr("transform", function(d) { return "translate(" + source.y0 + "," + source.x0 + ")"; })
|
.attr("transform", function(d) {
|
||||||
|
return "translate(" + source.y0 + "," + source.x0 + ")";
|
||||||
|
})
|
||||||
.on("click", click);
|
.on("click", click);
|
||||||
|
|
||||||
nodeEnter.append("circle")
|
nodeEnter.append("circle")
|
||||||
|
@ -73,9 +86,13 @@ function update(source) {
|
||||||
.style("fill", get_color)
|
.style("fill", get_color)
|
||||||
|
|
||||||
nodeEnter.append("text")
|
nodeEnter.append("text")
|
||||||
.attr("x", function(d) { return d.children || d._children ? -10 : 10; })
|
.attr("x", function(d) {
|
||||||
|
return d.children || d._children ? -10 : 10;
|
||||||
|
})
|
||||||
.attr("dy", ".35em")
|
.attr("dy", ".35em")
|
||||||
.attr("text-anchor", function(d) { return d.children || d._children ? "end" : "start"; })
|
.attr("text-anchor", function(d) {
|
||||||
|
return d.children || d._children ? "end" : "start";
|
||||||
|
})
|
||||||
.text(function(d) {
|
.text(function(d) {
|
||||||
if (d.children || d._children) {
|
if (d.children || d._children) {
|
||||||
return d.name;
|
return d.name;
|
||||||
|
@ -88,7 +105,9 @@ function update(source) {
|
||||||
// Transition nodes to their new position.
|
// Transition nodes to their new position.
|
||||||
var nodeUpdate = node.transition()
|
var nodeUpdate = node.transition()
|
||||||
.duration(duration)
|
.duration(duration)
|
||||||
.attr("transform", function(d) { return "translate(" + d.y + "," + d.x + ")"; });
|
.attr("transform", function(d) {
|
||||||
|
return "translate(" + d.y + "," + d.x + ")";
|
||||||
|
});
|
||||||
|
|
||||||
nodeUpdate.select("circle")
|
nodeUpdate.select("circle")
|
||||||
.attr("r", 4.5)
|
.attr("r", 4.5)
|
||||||
|
@ -100,7 +119,9 @@ function update(source) {
|
||||||
// Transition exiting nodes to the parent's new position.
|
// Transition exiting nodes to the parent's new position.
|
||||||
var nodeExit = node.exit().transition()
|
var nodeExit = node.exit().transition()
|
||||||
.duration(duration)
|
.duration(duration)
|
||||||
.attr("transform", function(d) { return "translate(" + source.y + "," + source.x + ")"; })
|
.attr("transform", function(d) {
|
||||||
|
return "translate(" + source.y + "," + source.x + ")";
|
||||||
|
})
|
||||||
.remove();
|
.remove();
|
||||||
|
|
||||||
nodeExit.select("circle")
|
nodeExit.select("circle")
|
||||||
|
@ -111,7 +132,9 @@ function update(source) {
|
||||||
|
|
||||||
// Update the links…
|
// Update the links…
|
||||||
var link = svg.selectAll("path.link")
|
var link = svg.selectAll("path.link")
|
||||||
.data(links, function(d) { return d.target.id; });
|
.data(links, function(d) {
|
||||||
|
return d.target.id;
|
||||||
|
});
|
||||||
|
|
||||||
// Enter any new links at the parent's previous position.
|
// Enter any new links at the parent's previous position.
|
||||||
link.enter().insert("path", "g")
|
link.enter().insert("path", "g")
|
||||||
|
@ -158,7 +181,7 @@ function click(d) {
|
||||||
url = '/clip/created/keywords==' + d.name
|
url = '/clip/created/keywords==' + d.name
|
||||||
}
|
}
|
||||||
window.open(url, '_blank');
|
window.open(url, '_blank');
|
||||||
|
} else {
|
||||||
|
update(d);
|
||||||
}
|
}
|
||||||
update(d);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue