Skip to content

Commit 136a0db

Browse files
author
Robert Jackson
committed
Move sample files to public.
1 parent 5a78bc6 commit 136a0db

File tree

4 files changed

+86
-72
lines changed

4 files changed

+86
-72
lines changed

app/components/basic-tree.js

Lines changed: 86 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -87,55 +87,99 @@ export default Ember.Component.extend({
8787
.nodeSize([6, 180]);
8888
graph(root);
8989

90-
let link = g.selectAll(".link")
91-
.data(root.descendants().slice(1));
92-
93-
link.enter()
94-
.append("path")
95-
.attr("class", "link")
96-
.attr("d", function(d) {
97-
return "M" + d.y + "," + d.x
98-
+ "C" + (d.parent.y + 50) + "," + d.x
99-
+ " " + (d.parent.y + 50) + "," + d.parent.x
100-
+ " " + d.parent.y + "," + d.parent.x;
101-
});
90+
function update(source) {
91+
let link = g.selectAll(".link")
92+
.data(root.descendants().slice(1));
93+
94+
link.enter()
95+
.append("path")
96+
.attr("class", "link")
97+
.attr("d", function(d) {
98+
return "M" + d.y + "," + d.x
99+
+ "C" + (d.parent.y + 50) + "," + d.x
100+
+ " " + (d.parent.y + 50) + "," + d.parent.x
101+
+ " " + d.parent.y + "," + d.parent.x;
102+
});
102103

103-
let node = g.selectAll(".node")
104-
.data(root.descendants());
104+
let node = g.selectAll(".node")
105+
.data(root.descendants());
106+
107+
let nodeEnter = node
108+
.enter()
109+
.append("g")
110+
.attr("class", 'node')
111+
.attr("transform", function(d) {
112+
return "translate(" + d.y + "," + d.x + ")";
113+
})
114+
.on('click', (d) => {
115+
// Toggle children on click.
116+
if (d.children) {
117+
d._children = d.children;
118+
d.children = null;
119+
} else {
120+
d.children = d._children;
121+
d._children = null;
122+
}
123+
update(d);
124+
});
125+
126+
// we want to wrap the next few text lines in a rect
127+
// but alignment is annoying, punting for now...
128+
//
129+
// nodeEnter.append("rect")
130+
// .attr('x', '-75')
131+
// .attr('y', '-1.5em')
132+
// .attr('width', '75px')
133+
// .attr('height', "3em")
134+
// .attr('stroke', "black")
135+
// .attr('stroke-width', 1)
136+
// .style('fill', "#fff");
137+
138+
nodeEnter.append('text')
139+
.attr('dy', '-1.1em')
140+
.style("text-anchor", function(d) { return d.children ? "end" : "start"; })
141+
.text(d => d.data._id);
142+
143+
nodeEnter.append("text")
144+
.attr("dy", '0.1em')
145+
.style("text-anchor", function(d) { return d.children ? "end" : "start"; })
146+
.text(function(d) {
147+
return d.data.id.name;
148+
});
105149

106-
let nodeEnter = node
107-
.enter()
108-
.append("g")
109-
.attr("class", function(d) { return "node" + (d.children ? " node--internal" : " node--leaf"); })
110-
.attr("transform", function(d) {
111-
return "translate(" + d.y + "," + d.x + ")";
150+
nodeEnter.append("text")
151+
.attr("dy", '1.1em')
152+
.style("text-anchor", function(d) { return d.children ? "end" : "start"; })
153+
.text(function(d) {
154+
return `total: ${(d.value / 1000000).toFixed(2)}`;
112155
});
113156

114-
nodeEnter.append('text')
115-
.attr('dy', '-1.1em')
116-
.style("text-anchor", function(d) { return d.children ? "end" : "start"; })
117-
.text(d => d.data._id);
157+
nodeEnter.append("text")
158+
.attr("dy", '2.1em')
159+
.style("text-anchor", function(d) { return d.children ? "end" : "start"; })
160+
.text(function(d) {
161+
return `self: ${(d.data.stats.time.self / 1000000).toFixed(2)}`;
162+
});
118163

119-
nodeEnter.append("text")
120-
.attr("dy", '0.1em')
121-
.style("text-anchor", function(d) { return d.children ? "end" : "start"; })
122-
.text(function(d) {
123-
return d.data.id.name;
124-
});
164+
// Transition exiting nodes to the parent's new position.
165+
node.exit()
166+
.transition()
167+
.duration(50)
168+
.attr("transform", function () {
169+
return "translate(" + source.x + "," + source.y + ")";
170+
})
171+
.remove();
125172

126-
nodeEnter.append("text")
127-
.attr("dy", '1.1em')
128-
.style("text-anchor", function(d) { return d.children ? "end" : "start"; })
129-
.text(function(d) {
130-
return `total: ${(d.value / 1000000).toFixed(2)}`;
131-
});
173+
link.exit()
174+
.transition()
175+
.duration(50)
176+
.attr("transform", function () {
177+
return "translate(" + source.x + "," + source.y + ")";
178+
})
179+
.remove();
180+
}
132181

133-
nodeEnter.append("text")
134-
.attr("dy", '2.1em')
135-
.style("text-anchor", function(d) { return d.children ? "end" : "start"; })
136-
.text(function(d) {
137-
return `self: ${(d.data.stats.time.self / 1000000).toFixed(2)}`;
138-
});
182+
update(root);
139183

140184
let zoomHandler = zoom()
141185
.scaleExtent([0.05, 3])

server/index.js

Lines changed: 0 additions & 24 deletions
This file was deleted.

server/mocks/broccoli-viz-files.js

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)