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})`)
})
Source: stackoverflow.com
Related Query
- Rotate a rectangle during drag D3
- Drag to rotate an SVG:g group
- The mouse over event is not fired during the drag and drop action in d3.js
- d3.event.y has strange values during drag behavior
- D3 Triggering drag during mousedown
- How to drag and rotate orthographic map (globe) using d3.js
- Select SVG elements using rectangle select box not working during zoom : d3.js
- how to drag a svg rectangle in d3.js?
- Rotate a rectangle at origin
- D3 JS - Group Containing a SVG Rectangle Won't Translate Smoothly on Drag
- D3 position x axis label within rectangle and rotate 90 degrees
- How to drag and drop a rectangle
- D3+Leaflet map.on() issue - running function during (or after) drag event
- Rotate a rectangle on dragging event D3
- Rotate rectangle with 4 points using Angular
- d3 SVG drag drop plus rotate with button
- Suppress mouseover during click and drag in d3
- rotate a projection to follow mouse drag
- rotate x axis text in d3
- D3 Appending Text to a SVG Rectangle
- svg / d3.js rounded corners on one side of a rectangle
- D3 Differentiate between click and drag for an element which has a drag behavior
- Packing different sized circles into rectangle - d3.js
- D3 force directed graph with drag and drop support to make selected node position fixed when dropped
- Determine if Shift key is pressed during mousedown event
- "Stuttering" drag when using d3.behavior.drag() and transform
- Combining translate and rotate with D3
- How to prevent d3 from triggering drag on right click?
- How to set the origin while drag in d3.js in v4
- D3 grouped bar chart: How to rotate the text of x axis ticks?
More Query from same tag
- Regarding D3 stacked bar chart structure
- disable/enable dropdown list options based on filtered D3.js data
- unable to get d3.layout.stack to fill out d3.svg.area
- Argentina not showing up on world map with d3.js
- updating x axis label in nvd3 dynamically
- How to make charts in Rmarkdown mobile-responsive?
- Handling optional data in d3.js
- How to use ordinal scale in d3 to return month names
- Possibility to add images inside a bar of a bar chart - d3js
- line chart of json data in d3
- Add thinner arc for total in D3 Donut Chart
- Bar Chart Example D3
- How do I create a multiline chart using d3js with json formatted for nvd3?
- Axes displaying correctly with scale, but graph bars not being drawn correctly
- Unable to get the Zoom Effect in D3.js
- Swapping between multi-line plots with different numbers of lines D3
- Setting the graph name in C3.js
- How to create Bubble chart in C3.js
- D3.js nodes jump when restarting simulation to add or remove nodes
- D3 trouble parsing CSV file
- Dynamic filtering with D3
- not able to load external json file using d3.js
- Grails error loading big csv file with d3.js
- DC.js, crossfilter - generic grouping with varying number of columns
- How to display an image inside a circle inside an arc in d3
- SVG foreignObject contents do not display unless plain text
- d3 geo projection transitions from orthographic to X
- Using D3's path generators. How to assign data to them?
- Can one convert a variable string to D3 data reference?
- Eliminate sudden additions/deletions in D3 basis line chart transition