Basically you need to take care of the translate when you click.
So I created a variable :
var translateVar = [0,0];
When you pan update this variable :
translateVar = d3.event.translate; translateVar = d3.event.translate;
And add this to your coordinates of the circle :
.attr('cx', mouseCoords - translateVar ) .attr('cy', mouseCoords - translateVar)
Updated fiddle : https://jsfiddle.net/thatoneguy/53ftaw7r/2/
You also need to take care of the scale so do a similar thing :
var scaleVar = 1;
Update variable on zoom :
scaleVar = d3.event.scale
New coordinates :
.attr('cx', (mouseCoords - translateVar) /scaleVar ) .attr('cy', (mouseCoords - translateVar) /scaleVar )
Final fiddle : https://jsfiddle.net/thatoneguy/53ftaw7r/5/
- D3 click coordinates after pan and zoom
- SVG coordinates on click after pan and zooming
- d3.js click and apply zoom and pan to distribute points located inside a targeted division to the triggered subdivisions
- D3 - How to get correct scale and translate origin after manual zoom and pan to country path
- d3.js pan and zoom jumps when using mouse after programatic zoom
- D3.js Zoom and Pan to element on Click
- d3 click event is stopped with zoom and pan layer
- d3 v4: Clip path not updating after pan and zoom
- d3js. Coordinates after zoom and pan. How to calculate it?
- d3.js v4 d3.zoom and strange element order after zoom or pan
- d3 collapse tree zoom and pan - jumpiness after clicking a node
- d3 zoom and pan upgrade to version 4
- dagre-d3 how to click node and run an event after that
- How to use mouse click and drag to zoom in D3
- Constrain zoom and pan in d3
- Accurate pan and zoom to svg node
- D3 Map Pan and Zoom Performance on Chrome
- d3 update old scale when pan and zoom
- d3 world map with country click and zoom almost working not quite
- D3 change zoom and pan gestures
- Map zoom and pan in d3 js v4 + scale limit
- d3 zoom with button and double click but don't zoom with with scroll wheel
- D3 forced layout zoom and pan not working
- How to link D3 zoom and pan controls
- Apply zoom pan and axis rescale in d3
- D3.js - force diagram. How to add zoom and pan
- Using the zoom and pan functionality of d3
- How to proper zoom and pan only the y-axis in D3 v5 y-axis
- Simple Pan and Zoom in d3 v7
More Query from same tag
- d3 log scale: base not making an effect?
- D3 Layout : Tree-like Structure, but link length varies
- How to extract top 10 data in d3.js?
- D3 tree layout from json
- Render tick at zero y-value with d3 series plot
- Need assistance with adding text into nodes in codeflower graph via D3.js
- Shift x-axis to arbitrary position
- Draw curve between draggable points with control points to adjust curve SVG and d3.js
- Appending elements to d3 selection
- Responsive axis with percentage coordinates
- D3 DataMaps (or jvectormap): How to put a custom object on map by coords
- How to stop d3.drag triggering mouseover/mouseout events in chrome
- Are directed graphs only possible with files that contains a "source" and "target" value?
- Ember and d3v4 importing errors
- knockoutjs : dynamic binding with svg element
- How to highlight an array of words in D3 word cloud
- Modify Donut Chart Slices in C3/D3
- I am trying to build a d3js graph but on the x-axis i am getting the timestamps instead of date and time even after i used formatting
- How to make D3 line hidden from start?
- How to omit a column from stack?
- Multiple tree layouts on page, linking between them
- Ajax not working. Output not showing up
- SVG line out of arc starting position - d3.js
- best way to get available dimensions for svg in d3.js
- Using d3.behavior.drag() to pan a map
- how to map numbers to a three color scale with D3.js?
- How do I create a <dl> using d3.js
- Stumped by d3 error I'm receiving - Error: <path> attribute d: Expected number, "M0,NaNL21.923076923…"
- NetworkD3 Sankey Plot in R: How to switch text labels from the right to the left of the inner nodes only