Skip to content

Commit

Permalink
fix: Center graph on load #11
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikGartner committed Dec 31, 2015
1 parent 5f71c8c commit 1d5e71c
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ class TreeBuilder {
var allNodes = this.allNodes;
var nodeSize = this.nodeSize;

var width = opts.width + opts.margin.left + opts.margin.right;
var height = opts.height + opts.margin.top + opts.margin.bottom;

var zoom = d3.behavior.zoom()
.scaleExtent([0.1, 10])
.on('zoom', _.bind(function() {
Expand All @@ -26,11 +29,11 @@ class TreeBuilder {
//make an SVG
var svg = this.svg = d3.select(opts.target)
.append('svg')
.attr('width', opts.width + opts.margin.left + opts.margin.right)
.attr('height', opts.height + opts.margin.top + opts.margin.bottom)
.attr('width', width)
.attr('height', height)
.call(zoom)
.append('g')
.attr('transform', 'translate(' + opts.margin.left + ',' + opts.margin.top + ')');
.attr('transform', 'translate(' + width / 2 + ',' + opts.margin.top + ')');

// Compute the layout.
this.tree = d3.layout.tree()
Expand Down

0 comments on commit 1d5e71c

Please sign in to comment.