Skip to content

Commit 1d5e71c

Browse files
committed
fix: Center graph on load #11
1 parent 5f71c8c commit 1d5e71c

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/builder.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ class TreeBuilder {
1616
var allNodes = this.allNodes;
1717
var nodeSize = this.nodeSize;
1818

19+
var width = opts.width + opts.margin.left + opts.margin.right;
20+
var height = opts.height + opts.margin.top + opts.margin.bottom;
21+
1922
var zoom = d3.behavior.zoom()
2023
.scaleExtent([0.1, 10])
2124
.on('zoom', _.bind(function() {
@@ -26,11 +29,11 @@ class TreeBuilder {
2629
//make an SVG
2730
var svg = this.svg = d3.select(opts.target)
2831
.append('svg')
29-
.attr('width', opts.width + opts.margin.left + opts.margin.right)
30-
.attr('height', opts.height + opts.margin.top + opts.margin.bottom)
32+
.attr('width', width)
33+
.attr('height', height)
3134
.call(zoom)
3235
.append('g')
33-
.attr('transform', 'translate(' + opts.margin.left + ',' + opts.margin.top + ')');
36+
.attr('transform', 'translate(' + width / 2 + ',' + opts.margin.top + ')');
3437

3538
// Compute the layout.
3639
this.tree = d3.layout.tree()

0 commit comments

Comments
 (0)