title: How do I specify the initial zoom level in D3?
body: <p>I have written a script to graphically display some row-oriented data, with bars, labels and connections between rows. As the dataset has grown, the resulting SVG element has exceeded the size of the screen. To keep the result on one screen (partly to make the d3 zoom behavior easier for the user to manage), I have scaled the SVG element before drawing so that it will fit the screen. I did this by appending a transform/scale attribute to the SVG element.</p>
  
  <p>The problem is, d3's behavior.zoom does not know about this change in scale, so when I start to zoom, it first resets the scale to 1. Is there a way to change the initial scale in d3's behavior.zoom?</p>
  
  <hr>
  
  <p>EDIT: added a work-around</p>
  
  <p>Kludged this by multiplying d3.event.scale by the initial scale in the redraw() function. So, initial declaration of SVG element is</p>
  
  <pre><code>var SVG = d3.select('#timeline')
      .append('svg:svg')
          .attr('class','chart')
          .attr('transform','scale('+bscale+')')
          .attr('width', wwidth)
          .attr('height', wheight)
          .call(d3.behavior.zoom()
              .extent([[0,Infinity],[0,Infinity],[0,Infinity]])
              .on('zoom', redraw));
  </code></pre>
  
  <p>and</p>
  
  <pre><code>function redraw() {
      SVG.attr("transform",
          "translate(" + d3.event.translate + ")"
          + "scale(" + d3.event.scale * bscale + ")");
  };
  </code></pre>