Skip to content

Commit cd1a1bb

Browse files
committed
root in center of container, zoom in and out
1 parent 2fbaa21 commit cd1a1bb

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/app/components/Chart.jsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,28 +35,30 @@ class Chart extends Component {
3535
duration=0;
3636

3737
var margin = {top: 20, right: 120, bottom: 20, left: 120},
38-
width = 400 - margin.right - margin.left,
39-
height = 400 - margin.top - margin.bottom;
38+
width = 600 - margin.right - margin.left,
39+
height = 600 - margin.top - margin.bottom;
4040

4141
var i = 0;
4242

4343
var tree = d3.layout.tree()
44-
.size([height, width]);
44+
.nodeSize([20,])
45+
.separation(function separation(a, b) {
46+
return a.parent == b.parent ? 3 : 1;
47+
});
4548

4649
var diagonal = d3.svg.diagonal()
4750
.projection(function(d) { return [d.y, d.x]; });
4851

4952
var svg = d3.select(this.refs.anchor).append("svg")
50-
// .attr("width", width + margin.right + margin.left)
51-
// .attr("height", height + margin.top + margin.bottom)
5253
.attr("width", "100%")
5354
.attr("height","100%")
55+
.attr("cursor", "-webkit-grab")
5456
.attr("preserveAspectRatio", "xMinYMin slice")
5557
.call(d3.behavior.zoom().on("zoom", function () {
5658
svg.attr("transform", "translate(" + d3.event.translate + ")" + " scale(" + d3.event.scale + ")")
5759
}))
58-
.append("g")
59-
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
60+
.append("g")
61+
.attr("transform", "translate(" + width/2 + "," + height/2 + ")")
6062

6163
// Add tooltip div
6264
var div = d3.select("body").append("div")

0 commit comments

Comments
 (0)