-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTask_Tree.html
165 lines (135 loc) · 4.7 KB
/
Task_Tree.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Tree</title>
<style>
.node circle {
fill: #fff;
stroke: #047B9C;
stroke-width: 4px;
}
text {
font: 12px sans-serif;
}
.node text { font: 12px sans-serif; }
.link {
fill: none;
stroke: #848484;
stroke-width: 1.5px;
}
.circle_clique {
width:75px;
height:75px;
border-radius:50px;
font-size:20px;
font-family: sans-serif;
color:#000;
line-height:75px;
text-align:center;
background:#DF0101
}
.circle_chain {
width:75px;
height:75px;
border-radius:50px;
font-size:20px;
font-family: sans-serif;
color:#000;
line-height:75px;
text-align:center;
background:#04B404;
}
.circle_none {
width:75px;
height:75px;
border-radius:50px;
font-size:20px;
font-family: sans-serif;
color:#000;
line-height:75px;
text-align:center;
background:#047B9C;
}
.invisible {
width:75px;
height:75px;
border-radius:50px;
font-size:20px;
font-family: sans-serif;
color:#fff;
line-height:75px;
text-align:center;
background:#fff;
}
</style>
</head>
<body>
<!-- load d3.js -->
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="jquery-2.1.4.min.js"></script>
<script>
var treeData =
[{"values": {"support_actions": [], "order_invariant": "chain", "name": "Assemble Chair", "actions": []}, "children": [{"values": {"support_actions": [], "order_invariant": "clique", "name": "Attach Supports", "actions": []}, "children": [{"values": {"support_actions": [], "order_invariant": "chain", "name": "Attach Left Support", "actions": []}, "children": [{"values": {"support_actions": [], "order_invariant": "primitive", "name": "Get Peg", "actions": []}, "children": []}, {"values": {"support_actions": [], "order_invariant": "primitive", "name": "Place Peg", "actions": []}, "children": []}]}, {"values": {"support_actions": [], "order_invariant": "chain", "name": "Attach Right Support", "actions": []}, "children": [{"values": {"support_actions": [], "order_invariant": "primitive", "name": "Get Peg", "actions": []}, "children": []}, {"values": {"support_actions": [], "order_invariant": "primitive", "name": "Place Peg", "actions": []}, "children": []}]}]}, {"values": {"support_actions": [], "order_invariant": "chain", "name": "Place Seat", "actions": []}, "children": []}, {"values": {"support_actions": [], "order_invariant": "clique", "name": "Place Front Frame", "actions": []}, "children": [{"values": {"support_actions": [], "order_invariant": "chain", "name": "Secure Left Side", "actions": []}, "children": []}, {"values": {"support_actions": [], "order_invariant": "chain", "name": "Secure Right Side", "actions": []}, "children": []}]}]}];
// Generate tree
var margin = {top: 20, right: 120, bottom: 20, left: 120},
width = 5000 - margin.right - margin.left,
height = 500 - margin.top - margin.bottom;
var i = 0;
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("body").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];
update(root);
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; });
// Declare the nodes
var node = svg.selectAll("g.node")
.data(nodes, function(d) { return d.id || (d.id = ++i); });
var nodeEnter = node.enter().append("g")
.attr("class", "node")
.attr("transform", function(d) {
return "translate(" + d.y + "," + d.x + ")"; });
nodeEnter.append("circle")
.attr("r", 7)
.style("stroke", function(d) {
if (d.values.order_invariant == "chain") {
return "04B404"; }
else if (d.values.order_invariant == "clique") {
return "DF0101"; }
else {
return "047B9C"; }
});
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.values.name; })
.style("fill-opacity", 1);
// Make the links
var link = svg.selectAll("path.link")
.data(links, function(d) { return d.target.id; });
link.enter().insert("path", "g")
.attr("class", "link")
.attr("d", diagonal);
}
</script>
<div text-align:center>
<div class="circle_clique">Clique</div>
<div class="circle_chain">Chain</div>
<div class="circle_none">Primitive</div>
</div>
</body>
</html>