score:1
Accepted answer
so i guess the solution could be found in this post: mouse coordinates don't match after scaling and panning canvas. draw function shouldn't be updated - stays the same as before.
function draw() {
// draw links
context.strokestyle = '#ccc';
context.beginpath();
links.foreach(function(d) {
context.moveto(d.source.x, d.source.y);
context.lineto(d.target.x, d.target.y);
});
context.stroke();
// draw nodes
context.fillstyle = 'steelblue';
context.beginpath();
nodes.foreach(function(d) {
context.moveto(d.x, d.y);
context.arc(d.x, d.y, radius, 0, 2 * math.pi);
});
context.fill();
}
dragging handler function should be updated:
var rect = canvas.getboundingclientrect();
function ondrag() {
d3.event.subject.fx = ((d3.event.sourceevent.pagex - rect.left) - translation[0]) / scale;
d3.event.subject.fy = ((d3.event.sourceevent.pagey - rect.top) - translation[1]) / scale;
}
Source: stackoverflow.com
Related Query
- D3.js - Zoom network graph with canvas and then drag node
- D3 force directed graph with drag and drop support to make selected node position fixed when dropped
- d3 zoom and drag with SVG axes and canvas chart
- d3 force layout zoom and pan conflict with node drag
- How do I remove all children elements from a node and then apply them again with different color and size?
- How do I replace a node with an image using D3 and CoffeeScript for a network visualization?
- Updating nodes and links with labels in d3 force directed network graph is not removing the nodes properly
- Pan, zoom canvas together with drag nodes in D3
- d3 force graph with divs and d3 zoom
- D3 force directed graph drag and zoom functions not working
- d3.js How to draw a directed graph with one node start and one node end
- Add grid lines compatible with zoom and drag in d3.js
- D3: zoom and pan with rect drag
- Add text label to d3 node in Force directed Graph and resize on hover
- Achieving animated zoom with d3 and Leaflet
- How can I show a graph using d3 force layout with initial positions set and no movement at all?
- Graph orientation and node positioning in d3.js
- How to use mouse click and drag to zoom in D3
- D3 Canvas graph zooming and panning slow redraw in Webview
- D3 Zoom with Scrollbars used as panning, Scrollbar width and height adjusts to zoom scale
- How to check d3 js force graph for nodes with no links and remove them?
- d3 v4 drag line chart with x and y axes
- how do i add a zoom in and zoom out button in a graph on d3
- d3.js: Drag is disabled when use zoom with force layout
- Tooltip in the network graph is flashing on and off
- d3 v4 drag and drop with TypeScript
- Accurate pan and zoom to svg node
- D3 Collapsible Tree only drag without zoom and jump and scroll
- d3 combine zoom and drag calls?
- Starting Transitions and Animations With Area Graph in D3.JS
More Query from same tag
- Can't animate a C3 chart with different datasets using scrollytelling (Scrolltop)
- Marking location on a country map using Longitude/Latitude
- D3 mouseover is fine on localhost but not on deploy site
- How to add border/outline/stroke to SVG elements in CSS?
- Y-Axis not updating at drop down filter change
- how to draw horizontal line in y axis in d3 column chart?
- How to properly get text width to center labels above graph bars?
- D3.js figure staying out of twitter bootstrap's div section
- Iterating over multidimensional array with variable length d3
- Consume nested data in d3
- D3 collapsible trees without flare.json
- d3.js Loading version 3 vs version 4 in Jupyter Notebook
- Set a threshold for each point
- Getting a parent's child to find parent's child text width
- Graph is not taking whole space in d3.js
- User input to create D3 pie chart
- How to apply custom format to .ValueFormat nvd3.js?
- rCharts nvd3 library force ticks
- Reload TSV File Without Refreshing Page
- What's the right way to conditionally append HTML elements with D3.js?
- D3 - attribute d: Expected number Error in creating curved chart
- With text labels for ticks in linear scale, zoom causes lables to extend beyond axis
- Automatic Layout of Swimlane Graphs
- D3 - Map with custom json
- Appending Stacked Bar and Another Bar Chart in D3
- Understanding D3 enter, update and exit selections with nested content
- What is the replacement of d3.scale.category10().range() in Version 4
- How specify tickValues in d3.js time scale?
- How to augment d3-selection module in TypeScript?
- D3 example not working