Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing a position of root in DAG mode does not work #542

Open
jakajancar opened this issue Oct 8, 2024 · 2 comments
Open

Fixing a position of root in DAG mode does not work #542

jakajancar opened this issue Oct 8, 2024 · 2 comments

Comments

@jakajancar
Copy link

jakajancar commented Oct 8, 2024

Trying to set fx/fy on the root node of a radialout tree to keep it fixed instead of bouncing around cholerically (as in the example, but it does not work.

The properties get re-set to undefined here:

// Fix nodes to x,y for dag mode
if (state.dagMode) {
  var getFFn = function getFFn(fix, invert) {
    return function (node) {
      return !fix ? undefined : (nodeDepths[node[state.nodeId]] - maxDepth / 2) * dagLevelDistance * (invert ? -1 : 1);
    };
  };
  var fxFn = getFFn(['lr', 'rl'].indexOf(state.dagMode) !== -1, state.dagMode === 'rl');
  var fyFn = getFFn(['td', 'bu'].indexOf(state.dagMode) !== -1, state.dagMode === 'bu');
  state.graphData.nodes.filter(state.dagNodeFilter).forEach(function (node) {
    node.fx = fxFn(node); <-------
    node.fy = fyFn(node); <-------
  });
}

I believe this should check if fx/fy is already set, and if so, not set it to undefined.

If I exclude the node using dagNodeFilter then fx/fy remain set, but the other nodes are not repelled and instead sit on top of the root for some reason.

// edit: I can work around it by:

Object.defineProperty(node, 'fx', {
    get() { return 0 },
    set() {},
});
Object.defineProperty(node, 'fy', {
    get() { return 0 },
    set() {},
});
@vasturiano
Copy link
Owner

@jakajancar thanks for reaching out.

I've just modified the handling of the nodes' f* attributes in the case of dag mode, so that it doesn't reset them to undefined unnecessary, as was happening in your case.

The fix happened in a different repo:
vasturiano/force-graph@c6a8c09

So if you upgrade the version of force-graph in your dependency tree to the latest (1.44.2) you should automatically get the fix.

Let me know if that fixes the issue for you.

@jakajancar
Copy link
Author

Amazing, works as expected now, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants