score:1

Accepted answer

I have created a fiddle to demonstrate this: https://jsfiddle.net/hsspve49/

Relevant part of the code are in the drag handler:

var drag = d3.drag().on("drag", function () {
  var rect  = d3.select(this);
  var theta = Math.atan2(d3.event.y - height / 2, d3.event.x - width / 2) * 180 / Math.PI

  rect
    .attr("x", d3.event.x)
    .attr("y", d3.event.y)
    .attr('transform', `rotate(${theta + 90}, ${d3.event.x}, ${d3.event.y})`)
})

Related Query

More Query from same tag