Accepted answer

You are applying your event on a different object (the g) then what the zoom is set up on (the svg). Since the zoom event is referenced against the element it is applied to, d3 does not now about your initial centering. From the docs:

The zoom behavior stores the zoom state on the element to which the zoom behavior was applied, not on the zoom behavior itself. This is because the zoom behavior can be applied to many elements simultaneously, and each element can be zoomed independently. The zoom state can change either on user interaction or programmatically via zoom.transform.

Changing your call to, center); fixes your issue.

Complete code:

var svg ="svg"),
    width = +svg.attr("width"),
    height = +svg.attr("height"),
    transform = d3.zoomIdentity;

var points = d3.range(2000).map(phyllotaxis(10));

var zoom = d3.zoom()
    .scaleExtent([1 / 2, 8])
    .on("zoom", zoomed);

var g = svg.append("g");

    .attr("cx", function(d) { return d.x; })
    .attr("cy", function(d) { return d.y; })
    .attr("r", 2.5)
        .on("drag", dragged));;

function zoomed() {
  g.attr("transform", d3.event.transform);

function center() {
  return d3.zoomIdentity

function dragged(d) {"cx", d.x = d3.event.x).attr("cy", d.y = d3.event.y);

function phyllotaxis(radius) {
  var theta = Math.PI * (3 - Math.sqrt(5));
  return function(i) {
    var r = radius * Math.sqrt(i), a = theta * i;
    return {
      x: width / 2 + r * Math.cos(a),
      y: height / 2 + r * Math.sin(a)
}, center);
<!DOCTYPE html>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
<svg width="960" height="500"></svg>
<script src=""></script>

Related Query

More Query from same tag