Expert Data Visualization by Jos Dirksen

Expert Data Visualization by Jos Dirksen

Author:Jos Dirksen [Dirksen, Jos]
Language: eng
Format: azw3, pdf
Publisher: Packt Publishing
Published: 2017-04-24T04:00:00+00:00


function dragged(d) {

d.fx = d3.event.x;

d.fy = d3.event.y;

}

function dragended(d) {

if (!d3.event.active) simulation.alphaTarget(0);

if (!d3.event.sourceEvent.shiftKey) {

d.fx = null;

d.fy = null;

}

}

The event handlers are rather simple. In the dragstarted function we restart a simulation that will eventually keep the simulation running at an alpha of 0.8 (because the alphaTarget is larger than the alphaMin). When we drag the node (dragged), we use the fx and fy properties to fix the dragged node to the location we're dragging it to. Finally, in the dragended function, we set the alphaTarget to 0, which will make the simulation end normally, and we remove the fixed positions. If you keep the shift key pressed when releasing the dragged node, we'll keep it fixed in that position:



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.