Double-clicking in d3.js does not result in releasing nodes

I am currently working on updating a force-directed graph from d3 version 3 to version 4. You can view my project here:

https://bl.ocks.org/anonymous/337d113cb77c3695ac6959bebe728795

I'm facing an issue where the double-click action on the nodes is not releasing the node back into the normal force layout. The drag and pin functions related to this behavior are located right below the node code.

Answer №1

After defining the d.fx and d.fy properties, the nodes will stay in place even if d.fixed is set differently. The setting of these properties can be seen here:

function dragged(d) {
    d.fx = d3.event.x;
    d.fy = d3.event.y;
}

This information is stated in the d3v4 API documentation:

If you want to fix a node at a specific position, you need to specify two additional properties:

fx - the fixed x-position of the node
fy - the fixed y-position of the node

At the end of each tick, when forces have been applied, a node with a defined node.fx will have its position reset to this value and its velocity on the x-axis (vx) set to zero. Similarly, a node with a defined node.fy will have its position reset to this value and its velocity on the y-axis (vy) set to zero. To unfix a node that was previously fixed, simply nullify node.fx and node.fy, or delete these properties.

I only discovered this after creating my demo which was based on your block. Interestingly, I removed the values of d.fx and d.fy upon double-clicking, allowing them to be repositioned according to the force diagram.

The reason why you may encounter the use of d.fixed to fix positions is because this was the method utilized in v3:

fixed - a boolean indicating whether the node's position is locked.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

using express to set templateURL in ui-router

I created an Express project with EJS as the views engine. While attempting to set a templateURL for my home views, I keep receiving a 404 error. Below are my code snippets: Code from public/javascripts/angularApp.js: app.config([ '$stateProvider& ...

Add unique content to a div upon page reload

Whenever the page is refreshed, I would like to add a random anchor from an array into a specific div. Here's my current code: <div id="exit-offer" class="exit-offer-dialog"> <div class="offer-content" id="banner-load"> <bu ...

How come input text values don't change when submitting a form with a link attached?

I have a form that includes some hidden input fields. Additionally, there's a link with a reset function - when clicked, it sets the hidden fields' value to "0" and submits the form. It seems to work fine, but when I check the POST array output, ...

show the day of the week for a specific date saved in a MongoDB database

I need to create a report showing the total number of purchases for each day in the past week, formatted like this: { "sunday":30, "monday":20, ... } Each purchase in the database is structured as follows: { _id: 603fcb ...

How can you protect your webhook from unauthorized access?

I am looking to create a webhook that will update the status of a document in my collection, triggering additional events in the process. Router.route('/mandrill/invitation_sent', { where: 'server' }) .post(function () { var resp ...

Having trouble uploading the file to IPFS: Encounter an issue with HTTPError: project id is mandatory

Currently in the process of developing a basic DApp for sharing chats, with similarities to Twitter but based on a smart contract. I am utilizing hardhat and running my application on localhost. While implementing the feature for users to upload a profile ...

Vercel - Deploying without the need to promote the project

How can I deploy my Nextjs app to production in a way that allows me to run E2E tests on a "pre-prod" version before promoting it to prod, similar to using a preview URL without public traffic being directed there? I am looking for a process where I can v ...

The functionality of a website's design acts as a safeguard against unauthorized data transfers

I am encountering a major issue with my website. The layout I have created seems to be hindering me from making any modifications. My website consists of several containers, with three small containers stacked on top of each other as the main section of ...

Preventing event propagation in Angular when clicking

What is the best way to call an Angular function within my jQuery code? I attempted to do so with the following: $(document).on('click', '.myBtn', function(e) { angular.element($(".someClass")).scope().clearBtnItems(); e.stop ...

Encountered an issue with reading property 'onLaunched' of undefined while operating in Kiosk mode

Is there a way to detect Google Chrome kiosk mode? I have been trying this code but encountering an error. chrome.app.runtime.onLaunched.addListener(function (launchData) { alert("chrome"); launchData.isKioskSession; //true or fal ...

Troubleshooting problems with the jQuery 'Add row' function counter

Recently, I encountered an issue with a simple form on my website. The problem arises when I click the 'Yes' radio button and then click 'Add 1 more' multiple times. Instead of adding the desired 4 rows, I end up with around 9 rows. Qu ...

AngularJS Custom Navigation based on User Roles

I am currently developing a small web application using angular. My goal is to implement role-based navigation in the app. However, I am facing an issue where the isAdmin function does not seem to be getting called on page load, resulting in only the foo a ...

jQuery - eliminate elements from an array using splice, and then return the modified array with the remaining items excluding the removed item

I'm encountering a frustrating issue while attempting to perform a seemingly simple task. I am adding elements to an array based on the selection of a dropdown. Adding elements is working fine, but when the user changes the selection to 'No&apos ...

Troubleshooting: Issue with AngularJS Image onload directive - "this" reference not functioning properly?

I have a custom directive that looks like this: .directive('ngImageOnLoad', function () { return { restrict: 'A', link: function(scope, element, attrs) { element.bind('load', function() { ...

Tips for creating horizontal dividers with CSS in Vuetify using <v-divider> and <v-divider/> styling

Currently, I am working on a project using Vue.js and adding Vuetify. However, I need to use a component. .horizontal{ border-color: #F4F4F4 !important; border-width: 2px ; } <v-divider horizontal class=" horizontal ...

The connection between Android and the MYSQL database has returned a null value

I have been encountering an issue while trying to fetch specific data from my MySQL database using Android to pass parameter values and then reading this value in a PHP script within the query to retrieve the data. Every time I run the application, I face ...

Exploring solutions for handling asynchronous issues with vue3-google-map

While working with a Vue library for managing Maps called vue3-google-map, I encountered an issue when trying to define certain polylines that would not allow me to select the center of the marked area: Here is my map template: <template> <Goo ...

404 Error: Express API Struggling to Serve Public Files

My current API setup looks like this... index.js require('dotenv').config(); const index = require('./server'); const port = process.env.PORT || 5000; index.listen(port, () => console.log(`Server is live at localhost:${port}`)); ...

Saving NVD3 Cumulative Line Charts as Image Files: A Simple Guide

I have been using the NVD3 Cumulative Line Chart and it has been working perfectly for me. However, I am interested in saving the graph as an image, similar to capturing a screen. I attempted to use html2canvas but unfortunately, it did not save the image ...

Invoke a class method once the Promise has been successfully resolved

I'm facing an issue with my simple class class A{ constructor(){ this.loadComponents().then(function(values) {callbackOnLoad();}); } callbackOnLoad(){ //do some things } loadComponents(){ ... return Promise.all([p1,p2,p3,p4,p ...